add interactive option on ImageOverlay

This commit is contained in:
Steve Kashishian 2014-11-09 13:18:50 -06:00
parent 8682511e2c
commit ca2f1171b7
2 changed files with 22 additions and 3 deletions

View File

@ -34,10 +34,15 @@
map.fitBounds(bounds);
var overlay = new L.ImageOverlay("https://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg", bounds, {
opacity: 0.5
opacity: 0.5,
interactive: true
});
map.addLayer(overlay);
overlay.on('dblclick',function (e) {
console.log('Double click on image.')
})
</script>
</body>
</html>

View File

@ -6,7 +6,8 @@ L.ImageOverlay = L.Layer.extend({
options: {
opacity: 1,
alt: ''
alt: '',
interactive: false
},
initialize: function (url, bounds, options) { // (String, LatLngBounds, Object)
@ -26,7 +27,7 @@ L.ImageOverlay = L.Layer.extend({
}
this.getPane().appendChild(this._image);
this._initInteraction();
this._reset();
},
@ -57,6 +58,19 @@ L.ImageOverlay = L.Layer.extend({
return this;
},
_initInteraction: function () {
if (!this.options.interactive) { return; }
L.DomUtil.addClass(this._image, 'leaflet-interactive');
L.DomEvent.on(this._image, 'click dblclick mousedown mouseup mouseover mousemove mouseout contextmenu',
this._fireMouseEvent, this);
},
_fireMouseEvent: function (e, type) {
if (this._map) {
this._map._fireMouseEvent(this, e, type, true);
}
},
setUrl: function (url) {
this._url = url;