Skip to content

Commit

Permalink
Merge pull request #82 from Starefossen/marker-on-polygon-80
Browse files Browse the repository at this point in the history
Fixes #80 when adding markers over polygons
  • Loading branch information
jacobtoye committed Feb 21, 2013
2 parents 7d30523 + 45a64bc commit 33e86a8
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/draw/handler/Draw.Marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,27 @@ L.Draw.Marker = L.Draw.Feature.extend({

if (this._map) {
this._tooltip.updateContent({ text: 'Click map to place marker.' });
this._map.on('mousemove', this._onMouseMove, this);

// Same mouseMarker as in Draw.Polyline
if (!this._mouseMarker) {
this._mouseMarker = L.marker(this._map.getCenter(), {
icon: L.divIcon({
className: 'leaflet-mouse-marker',
iconAnchor: [20, 20],
iconSize: [40, 40]
}),
opacity: 0,
zIndexOffset: this.options.zIndexOffset
});
}

this._mouseMarker
.on('click', this._onClick, this)
.addTo(this._map);

this._map
.on('mousemove', this._onMouseMove, this)
.on('zoomend', this._onZoomEnd, this);
}
},

Expand All @@ -36,15 +56,22 @@ L.Draw.Marker = L.Draw.Feature.extend({
delete this._marker;
}

this._map.off('mousemove', this._onMouseMove);
}
this._mouseMarker.off('click', this._onClick);
this._map.removeLayer(this._mouseMarker);
delete this._mouseMarker;

this._map
.off('mousemove', this._onMouseMove)
.off('zoomend', this._onZoomEnd);
}
},

_onMouseMove: function (e) {
var latlng = e.latlng;

this._tooltip.updatePosition(latlng);

this._mouseMarker.setLatLng(latlng);

if (!this._marker) {
this._marker = new L.Marker(latlng, {
icon: this.options.icon,
Expand Down

0 comments on commit 33e86a8

Please sign in to comment.