Skip to content
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

how to stop removing marker & circle marker when "edit" button is triggerd? #1013

Open
mdg6496 opened this issue Oct 17, 2021 · 2 comments
Open

Comments

@mdg6496
Copy link

mdg6496 commented Oct 17, 2021

When the edit mode edit is triggered to remove polygon's vertex, it also allows me to remove marker and circle marker by right click.

Is there any way to prevent it? (only allow to remove vertex but not the whole object like marker or circle marker)

The reason is if you remove marker or circle marker while edit mode is on from mobile device (press holding finger), you can't pan the map around (but you can still zoom in-out)

@Falke-Design
Copy link
Collaborator

You can use the option preventMarkerRemoval: true (in the Edit Options ) but then vertexes can't removed too.

preventMarkerRemoval false Disable the removal of markers/vertexes via right click.

I made a workaround for you:

map.on('pm:globaleditmodetoggled', e => {
        if(e.enabled){
          var markerLayers = map.pm.getGeomanLayers().filter(layer=> layer instanceof L.Marker || layer instanceof L.CircleMarker)
          markerLayers.forEach((layer)=>{
            layer.off('contextmenu', layer.pm._removeMarker, layer.pm)
          })
        }
      });

It checks if the edit mode is enabled and then gets all Markers and CircleMarkers and removes from them the listener to remove the marker.

@mdg6496
Copy link
Author

mdg6496 commented Oct 17, 2021

Sweet. I will take workaround one as a solution.
Cheers~!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants