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

Unsnap events don't get fired reliably #55

Open
sidney-pauly opened this issue Nov 21, 2019 · 0 comments
Open

Unsnap events don't get fired reliably #55

sidney-pauly opened this issue Nov 21, 2019 · 0 comments

Comments

@sidney-pauly
Copy link

If a marker gets snapped to another marker before it was unsnapped from from the previous marker, no unsnap event is fired. Here is a working proposal to fix the issue by first firing the unsnap event before doing a new snap:

L.Snap.updateSnap = function (marker, layer, latlng) {
    if (! marker.hasOwnProperty('_latlng')) {
        return;
    }

    if(marker.snap != layer){
        if (marker.snap) {
            if (marker._icon) {
                L.DomUtil.removeClass(marker._icon, 'marker-snapped');
            }
            marker.fire('unsnap', {layer: marker.snap});
        }
        
        delete marker.snap;
    }

    if (layer && latlng) {
        // don't call setLatLng so that we don't fire an unnecessary 'move' event
        marker._latlng = L.latLng(latlng);
        marker.update();
        if (marker.snap != layer) {
            marker.snap = layer;
            if (marker._icon) {
                L.DomUtil.addClass(marker._icon, 'marker-snapped');
            }
            marker.fire('snap', {layer:layer, latlng: latlng});
        }
    }
    
};
@sidney-pauly sidney-pauly changed the title Unsnap events don't get fired reliably [BUG] Unsnap events don't get fired reliably Nov 21, 2019
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