Skip to content

Commit b2e3f16

Browse files
author
snkashis
committed
pass the clicked obj, not the map.
1 parent 5109492 commit b2e3f16

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

debug/tests/click_on_canvas.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 = L.map('map', {
18+
minZoom: 1,
19+
maxZoom: 19,
20+
center: [51.505, -0.09],
21+
zoom: 9
22+
});
23+
24+
var polygons = new L.FeatureGroup();
25+
var points = [[51.505, -0.01], [51.505, -0.09], [51.55, -0.09]];
26+
27+
polygons.addLayer(
28+
new L.Polyline(
29+
points, {
30+
weight: 2,
31+
opacity: 1,
32+
smoothFactor: 1,
33+
color: 'red'
34+
}));
35+
36+
polygons.on('click', function(m) {
37+
// m.layer is the clicked polygon here
38+
//m.layer.bindPopup('hello!').openPopup();
39+
console.log(m.layer)
40+
});
41+
42+
polygons.addTo(map);
43+
});
44+
</script>
45+
46+
<script src="../leaflet-include.js"></script>
47+
</head>
48+
<body>
49+
<div id="map"></div>
50+
</body>
51+
</html>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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="http://cdn.leafletjs.com/leaflet-0.4.5/leaflet.css" />
9+
<link rel="stylesheet" href="../css/screen.css" />
10+
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.0.js'></script>
11+
12+
<script>
13+
L_PREFER_CANVAS = true;
14+
$(document).ready(function() {
15+
var map = L.map('map', {
16+
minZoom: 1,
17+
maxZoom: 19,
18+
center: [51.505, -0.09],
19+
zoom: 9
20+
});
21+
22+
var polygons = new L.FeatureGroup();
23+
var points = [[51.505, -0.01], [51.505, -0.09], [51.55, -0.09]];
24+
25+
polygons.addLayer(
26+
new L.Polyline(
27+
points, {
28+
weight: 2,
29+
opacity: 1,
30+
smoothFactor: 1,
31+
color: 'red'
32+
}));
33+
34+
polygons.on('click', function(m) {
35+
// m.layer is the clicked polygon here
36+
//m.layer.bindPopup('hello!').openPopup();
37+
console.log(m.layer)
38+
});
39+
40+
polygons.addTo(map);
41+
});
42+
</script>
43+
44+
<script src="http://cdn.leafletjs.com/leaflet-0.4.5/leaflet.js"></script>
45+
</head>
46+
<body>
47+
<div id="map"></div>
48+
</body>
49+
</html>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
127127

128128
_onClick: function (e) {
129129
if (this._containsPoint(e.layerPoint)) {
130-
this.fire('click', e);
130+
this.fire('click', {
131+
latlng: e.latlng,
132+
layerPoint: e.layerPoint,
133+
containerPoint: e.containerPoint,
134+
originalEvent: e
135+
});
131136
}
132137
}
133138
});

0 commit comments

Comments
 (0)