Skip to content

Commit c2064ef

Browse files
committed
Merge pull request Leaflet#1273 from snkashis/fix_circle_clicks
Remove canvas click handler with onRemove, Leaflet#1006
2 parents eb518f3 + b3a7f2f commit c2064ef

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

debug/tests/add_remove_layers.html

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Leaflet debug page</title>
5+
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
7+
8+
<link rel="stylesheet" href="../../dist/leaflet.css" />
9+
<!--[if lte IE 8]><link rel="stylesheet" href="../../dist/leaflet.ie.css" /><![endif]-->
10+
11+
<link rel="stylesheet" href="../css/screen.css" />
12+
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.0.js'></script>
13+
14+
<script>
15+
L_PREFER_CANVAS = true;
16+
$(document).ready(function() {
17+
var map;
18+
var myLayerGroup = new L.LayerGroup();
19+
20+
initmap();
21+
22+
23+
function initmap() {
24+
25+
// set up the map
26+
map = new L.Map('map');
27+
28+
// create the tile layer with correct attribution
29+
var osmUrl = 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png';
30+
var osmAttrib = 'Map data © OpenStreetMap contributors';
31+
var osm = new L.TileLayer(osmUrl, { minZoom: 1, maxZoom: 17, attribution: osmAttrib, detectRetina: true });
32+
map.addLayer(osm);
33+
map.fitBounds(new L.LatLngBounds([51,7],[51,7]));
34+
drawTestLine();
35+
36+
37+
};
38+
39+
function drawTestLine() {
40+
var lat = 51;
41+
var long = 7;
42+
for (var i = 0; i < 50; i++) {
43+
44+
var myCircle = new L.Circle(new L.LatLng(lat, long),3);
45+
myCircle.on('click',
46+
function (e) {
47+
popup = new L.Popup();
48+
popup.setLatLng(this.getLatLng());
49+
50+
var popuptxt = "Hello!";
51+
alert("I am the click function");
52+
popup.setContent(popuptxt);
53+
54+
map.openPopup(popup);
55+
56+
57+
});
58+
myLayerGroup.addLayer(myCircle);
59+
lat = lat + 0.0001;
60+
long = long + 0.0001;
61+
62+
}
63+
64+
map.addLayer(myLayerGroup);
65+
66+
};
67+
68+
$("#b1").click(function() {
69+
map.addLayer(myLayerGroup);
70+
});
71+
72+
$("#b2").click(function() {
73+
map.removeLayer(myLayerGroup);
74+
});
75+
76+
});
77+
</script>
78+
79+
<script src="../leaflet-include.js"></script>
80+
</head>
81+
<body>
82+
<div id="map"></div>
83+
<div id="buttons">
84+
<button type="button" id="b1"> Add Layer</button>
85+
<button type="button" id="b2"> Remove Layer</button>
86+
</div>
87+
</body>
88+
</html>

src/layer/vector/canvas/Path.Canvas.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
3636
.off('viewreset', this.projectLatlngs, this)
3737
.off('moveend', this._updatePath, this);
3838

39+
if (this.options.clickable) {
40+
this._map.off('click', this._onClick, this);
41+
}
42+
3943
this._requestUpdate();
4044

4145
this._map = null;

0 commit comments

Comments
 (0)