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

Adding a empty layer as the guide layer leads to errors #53

Open
sidney-pauly opened this issue Sep 4, 2019 · 0 comments
Open

Adding a empty layer as the guide layer leads to errors #53

sidney-pauly opened this issue Sep 4, 2019 · 0 comments

Comments

@sidney-pauly
Copy link

var guideLayer = new L.LayerGroup()
var marker = new L.Marker(...)

marker.snapediting = new L.Handler.MarkerSnap(map, marker);
marker.snapediting.addGuideLayer(guideLayer);
marker.snapediting.enable();

If the guide is just a empty layer just like in this example above and you start moving the marker an error is thrown in L.Handler.MarkerSnap in the _snapMarker function. This is because no snap target is found but one is expected in this function. I propose to just add a condition like this into the function:

_snapMarker: function(e) {
        var closest = L.Snap.snapMarker(e, this._guides, this._map, this.options, this._buffer);
        

        if (closest && e.originalEvent && e.originalEvent.clientX && closest.layer && closest.latlng) 
     //       ^
     //       |
     //     Add this
{
            var snapTouchPoint = this._map.project(closest.latlng, this._map.getZoom());
            e.originalEvent.clientX = snapTouchPoint.x;
            e.originalEvent.clientY = snapTouchPoint.y;
            e.originalEvent.snapped = true;
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant