Skip to content

Commit

Permalink
dont start drag on right click, fixes #260
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofsumit committed Mar 11, 2018
1 parent 8d48753 commit 20e1a6a
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/js/Mixins/Drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const DragMixin = {
const el = this._layer._path;

// re-enable map drag
if(this._originalMapDragState) {
if (this._originalMapDragState) {
this._layer._map.dragging.enable();
}

// if mouseup event fired, it's safe to cache the map draggable state on the next mouse down
this._safeToCacheDragState = true
this._safeToCacheDragState = true;

// clear up mousemove event
this._layer._map.off('mousemove', this._dragMixinOnMouseMove, this);
Expand All @@ -33,7 +33,7 @@ const DragMixin = {
this._layer.off('mouseup', this._dragMixinOnMouseUp, this);

// if no drag happened, don't do anything
if(!this._dragging) {
if (!this._dragging) {
return false;
}

Expand All @@ -59,7 +59,7 @@ const DragMixin = {
_dragMixinOnMouseMove(e) {
const el = this._layer._path;

if(!this._dragging) {
if (!this._dragging) {
// set state
this._dragging = true;
L.DomUtil.addClass(el, 'leaflet-pm-dragging');
Expand All @@ -68,11 +68,10 @@ const DragMixin = {
this._layer.bringToFront();

// disbale map drag
if(this._originalMapDragState) {
if (this._originalMapDragState) {
this._layer._map.dragging.disable();
}


// hide markers
this._markerGroup.clearLayers();

Expand All @@ -83,12 +82,16 @@ const DragMixin = {
this._onLayerDrag(e);
},
_dragMixinOnMouseDown(e) {
// cancel if mouse button is NOT the left button
if (e.originalEvent.button > 0) {
return;
}
// save current map dragging state
if(this._safeToCacheDragState){
if (this._safeToCacheDragState) {
this._originalMapDragState = this._layer._map.dragging._enabled;

// don't cache the state again until another mouse up is registered
this._safeToCacheDragState = false
this._safeToCacheDragState = false;
}

// save for delta calculation
Expand All @@ -115,18 +118,19 @@ const DragMixin = {
};

// move the coordinates by the delta
const moveCoords = coords => coords.map((currentLatLng) => {
const c = {
lat: currentLatLng.lat + deltaLatLng.lat,
lng: currentLatLng.lng + deltaLatLng.lng,
};
return c;
});
const moveCoords = coords =>
coords.map((currentLatLng) => {
const c = {
lat: currentLatLng.lat + deltaLatLng.lat,
lng: currentLatLng.lng + deltaLatLng.lng,
};
return c;
});

// create the new coordinates array
let newCoords;

if(this.isPolygon()) {
if (this.isPolygon()) {
newCoords = this._layer._latlngs.map(moveCoords, this);
} else {
newCoords = moveCoords(this._layer._latlngs);
Expand Down

0 comments on commit 20e1a6a

Please sign in to comment.