(function () { L.Handler.MarkerSnap = L.Handler.extend({ options: { snapDistance: 15, // in pixels snapVertices: true }, initialize: function (map, marker, options) { L.Handler.prototype.initialize.call(this, map); this._markers = []; this._guides = []; if (arguments.length == 2) { if (!(marker instanceof L.Class)) { options = marker; marker = null; } } L.Util.setOptions(this, options || {}); if (marker) { // new markers should be draggable ! if (!marker.dragging) marker.dragging = new L.Handler.MarkerDrag(marker); marker.dragging.enable(); this.watchMarker(marker); } // Convert snap distance in pixels into buffer in degres, for searching around mouse // It changes at each zoom change. function computeBuffer() { this._buffer = map.layerPointToLatLng(new L.Point(0,0)).lat - map.layerPointToLatLng(new L.Point(this.options.snapDistance, 0)).lat; } map.on('zoomend', computeBuffer, this); map.whenReady(computeBuffer, this); computeBuffer.call(this); }, enable: function () { this.disable(); for (var i=0; i