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;
}
}
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: