Skip to content

Marker drag check #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cypress/integration/marker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,22 @@ describe('Draw Marker', () => {
expect($p).to.have.length(4);
});
});


it('add interactive:false marker to the map and enable edit', () => {
// Adds a interactive Marker to the map and enable / disable the edit mode to check if a error is thrown because it is not draggable
cy.window().then(({ map, L }) => {
return L.marker([51.505, -0.09], { interactive: false }).addTo(map);
}).as('marker');

cy.toolbarButton('edit').click();

cy.wait(100);

cy.toolbarButton('edit').click();

cy.get('@marker').then( marker => {
marker.removeFrom(marker._map);
});
});
});
2 changes: 1 addition & 1 deletion src/js/Edit/L.PM.Edit.Marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Edit.Marker = Edit.extend({
this._disableSnapping();
}

if (this.options.draggable) {
if (this.options.draggable && this._layer.dragging) {
this._layer.dragging.enable();
}

Expand Down
9 changes: 8 additions & 1 deletion src/js/Mixins/Dragging.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ const DragMixin = {
// before enabling layer drag, disable layer editing
this.disable();

// if layer never enabled and _map is not set (for snapping)
if(!this._map){
this._map = this._layer._map;
}

if (this._layer instanceof L.Marker) {
if(this.options.snappable) {
this._initSnappableMarkers();
}else{
this._disableSnapping();
}
this._layer.dragging.enable();
if(this._layer.dragging){
this._layer.dragging.enable();
}
return;
}

Expand Down