Skip to content

Commit

Permalink
fix: pass actual position of contextmenu to callback
Browse files Browse the repository at this point in the history
Before the position a user has started to open the contextmenu, has been passed to
callback even if the user has moved the map while opening the contextmenu. In these
case the position of contextmenu on map, differed from the position which as passed
to callback function.

Before 212a57f this bug could only occure if user
has opened the contextmenu using a touch input. If using a mouse, contextmenu would
have been closed if user moved the map while opening contextmenu.
  • Loading branch information
jelhan committed Apr 2, 2018
1 parent 212a57f commit 3653808
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
24 changes: 16 additions & 8 deletions dist/leaflet.contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ L.Map.mergeOptions({

L.Map.ContextMenu = L.Handler.extend({
_touchstart: L.Browser.msPointer ? 'MSPointerDown' : L.Browser.pointer ? 'pointerdown' : 'touchstart',

statics: {
BASE_CLS: 'leaflet-contextmenu'
},

initialize: function (map) {
L.Handler.prototype.initialize.call(this, map);

this._items = [];
this._visible = false;

Expand Down Expand Up @@ -318,12 +318,24 @@ L.Map.ContextMenu = L.Handler.extend({
return;
}

var map = me._map,
containerPoint = me._showLocation.containerPoint,
layerPoint = map.containerPointToLayerPoint(containerPoint),
latlng = map.layerPointToLatLng(layerPoint),
relatedTarget = me._showLocation.relatedTarget,
data = {
containerPoint: containerPoint,
layerPoint: layerPoint,
latlng: latlng,
relatedTarget: relatedTarget
};

if (hideOnSelect) {
me._hide();
}

if (func) {
func.call(context || map, me._showLocation);
func.call(context || map, data);
}

me._map.fire('contextmenu.select', {
Expand Down Expand Up @@ -359,13 +371,9 @@ L.Map.ContextMenu = L.Handler.extend({
_showAtPoint: function (pt, data) {
if (this._items.length) {
var map = this._map,
layerPoint = map.containerPointToLayerPoint(pt),
latlng = map.layerPointToLatLng(layerPoint),
event = L.extend(data || {}, {contextmenu: this});

this._showLocation = {
latlng: latlng,
layerPoint: layerPoint,
containerPoint: pt
};

Expand Down
2 changes: 1 addition & 1 deletion dist/leaflet.contextmenu.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3653808

Please sign in to comment.