canvas polyline click events

This commit is contained in:
Mourner 2011-06-21 14:04:35 +03:00
parent f80674a9e3
commit a46c9040a7
2 changed files with 27 additions and 13 deletions

View File

@ -27,9 +27,6 @@
map.fitBounds(new L.LatLngBounds(latlngs)); map.fitBounds(new L.LatLngBounds(latlngs));
map.addLayer(new L.Marker(latlngs[0]));
map.addLayer(new L.Marker(latlngs[len - 1]));
var circleLocation = new L.LatLng(51.508, -0.11), var circleLocation = new L.LatLng(51.508, -0.11),
circleOptions = { circleOptions = {
color: 'red', color: 'red',
@ -40,10 +37,10 @@
var circle = new L.Circle(circleLocation, 500000, circleOptions); var circle = new L.Circle(circleLocation, 500000, circleOptions);
map.addLayer(circle); map.addLayer(circle);
circle.bindPopup('I am a circle'); circle.bindPopup('I am a circle');
map.addLayer(path); map.addLayer(path);
path.bindPopup('I am a polyline');
var p1 = latlngs[0], var p1 = latlngs[0],
p2 = latlngs[parseInt(len/4)], p2 = latlngs[parseInt(len/4)],
@ -73,12 +70,6 @@
}); });
map.addLayer(polygon); map.addLayer(polygon);
/*var hole = new L.Polygon([h1,h2,h3,h4,h5], {
fillColor: "green"
});
map.addLayer(hole);
*/
path.bindPopup("Hello world");
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,6 +1,29 @@
L.Polyline.include(L.Path.SVG || !L.Path.CANVAS ? {} : { L.Polyline.include(L.Path.SVG || !L.Path.CANVAS ? {} : {
_initEvents: function() { _initEvents: function() {
// TODO polyline events (through loop with pointToSegmentDistance) if (this.options.clickable) {
// TODO hand cursor
// TODO mouseover, mouseout, dblclick
this._map.on('click', this._onClick, this);
}
},
_onClick: function(e) {
var p1 = this._point,
p2 = e.layerPoint;
var i, j, len, len2, dist, part;
for (i = 0, len = this._parts.length; i < len; i++) {
part = this._parts[i];
for (j = 0, len2 = part.length; j < len2 - 1; j++) {
dist = L.LineUtil.pointToSegmentDistance(e.layerPoint, part[j], part[j+1]);
if (dist <= this.options.weight / 2) {
this.fire('click', e);
return;
}
}
}
} }
}); });