text: "use strict";!function(t,e){"function"==typeof define&&define.amd?define(["leaflet"],t):"object"==typeof exports&&(module.exports=t(require("leaflet"))),void 0!==e&&e.L&&t(e.L)}(function(t){t.Editable=t.Evented.extend({statics:{FORWARD:1,BACKWARD:-1},options:{zIndex:1e3,polygonClass:t.Polygon,polylineClass:t.Polyline,markerClass:t.Marker,rectangleClass:t.Rectangle,circleClass:t.Circle,drawingCSSClass:"leaflet-editable-drawing",drawingCursor:"crosshair",editLayer:void 0,featuresLayer:void 0,polylineEditorClass:void 0,polygonEditorClass:void 0,markerEditorClass:void 0,rectangleEditorClass:void 0,circleEditorClass:void 0,lineGuideOptions:{},skipMiddleMarkers:!1},initialize:function(e,i){t.setOptions(this,i),this._lastZIndex=this.options.zIndex,this.map=e,this.editLayer=this.createEditLayer(),this.featuresLayer=this.createFeaturesLayer(),this.forwardLineGuide=this.createLineGuide(),this.backwardLineGuide=this.createLineGuide()},fireAndForward:function(t,e){(e=e||{}).editTools=this,this.fire(t,e),this.map.fire(t,e)},createLineGuide:function(){var e=t.extend({dashArray:"5,10",weight:1,interactive:!1},this.options.lineGuideOptions);return t.polyline([],e)},createVertexIcon:function(e){return t.Browser.touch?new t.Editable.TouchVertexIcon(e):new t.Editable.VertexIcon(e)},createEditLayer:function(){return this.options.editLayer||(new t.LayerGroup).addTo(this.map)},createFeaturesLayer:function(){return this.options.featuresLayer||(new t.LayerGroup).addTo(this.map)},moveForwardLineGuide:function(t){this.forwardLineGuide._latlngs.length&&(this.forwardLineGuide._latlngs[1]=t,this.forwardLineGuide._bounds.extend(t),this.forwardLineGuide.redraw())},moveBackwardLineGuide:function(t){this.backwardLineGuide._latlngs.length&&(this.backwardLineGuide._latlngs[1]=t,this.backwardLineGuide._bounds.extend(t),this.backwardLineGuide.redraw())},anchorForwardLineGuide:function(t){this.forwardLineGuide._latlngs[0]=t,this.forwardLineGuide._bounds.extend(t),this.forwardLineGuide.redraw()},anchorBackwardLineGuide:function(t){this.backwardLineGuide._latlngs[0]=t,this.backwardLineGuide._bounds.extend(t),this.backwardLineGuide.redraw()},attachForwardLineGuide:function(){this.editLayer.addLayer(this.forwardLineGuide)},attachBackwardLineGuide:function(){this.editLayer.addLayer(this.backwardLineGuide)},detachForwardLineGuide:function(){this.forwardLineGuide.setLatLngs([]),this.editLayer.removeLayer(this.forwardLineGuide)},detachBackwardLineGuide:function(){this.backwardLineGuide.setLatLngs([]),this.editLayer.removeLayer(this.backwardLineGuide)},blockEvents:function(){this._oldTargets||(this._oldTargets=this.map._targets,this.map._targets={})},unblockEvents:function(){this._oldTargets&&(this.map._targets=t.extend(this.map._targets,this._oldTargets),delete this._oldTargets)},registerForDrawing:function(e){this._drawingEditor&&this.unregisterForDrawing(this._drawingEditor),this.map.on("mousemove touchmove",e.onDrawingMouseMove,e),this.blockEvents(),this._drawingEditor=e,this.map.on("mousedown",this.onMousedown,this),this.map.on("mouseup",this.onMouseup,this),t.DomUtil.addClass(this.map._container,this.options.drawingCSSClass),this.defaultMapCursor=this.map._container.style.cursor,this.map._container.style.cursor=this.options.drawingCursor},unregisterForDrawing:function(e){this.unblockEvents(),t.DomUtil.removeClass(this.map._container,this.options.drawingCSSClass),this.map._container.style.cursor=this.defaultMapCursor,(e=e||this._drawingEditor)&&(this.map.off("mousemove touchmove",e.onDrawingMouseMove,e),this.map.off("mousedown",this.onMousedown,this),this.map.off("mouseup",this.onMouseup,this),e===this._drawingEditor&&(delete this._drawingEditor,e._drawing&&e.cancelDrawing()))},onMousedown:function(t){this._mouseDown=t,this._drawingEditor.onDrawingMouseDown(t)},onMouseup:function(e){if(this._mouseDown){if(this._drawingEditor.onDrawingMouseUp(e),!this._drawingEditor)return;var i=t.point(this._mouseDown.originalEvent.clientX,this._mouseDown.originalEvent.clientY),n=t.point(e.originalEvent.clientX,e.originalEvent.clientY).distanceTo(i);Math.abs(n)<9*(window.devicePixelRatio||1)&&this._drawingEditor.onDrawingClick(e)}this._mouseDown=null},drawing:function(){return this._drawingEditor&&this._drawingEditor.drawing()},stopDrawing:function(){this.unregisterForDrawing()},commitDrawing:function(t){this._drawingEditor&&this._drawingEditor.commitDrawing(t)},connectCreatedToMap:function(t){return this.featuresLayer.addLayer(t)},startPolyline:function(t,e){var i=this.createPolyline([],e);return i.enableEdit(this.map).newShape(t),i},startPolygon:function(t,e){var i=this.createPolygon([],e);return i.enableEdit(this.map).newShape(t),i},startMarker:function(t,e){t=t||this.map.getCenter().clone();var i=this.createMarker(t,e);return i.enableEdit(this.map).startDrawing(),i},startRectangle:function(e,i){var n=e||t.latLng([0,0]),a=new t.LatLngBounds(n,n),r=this.createRectangle(a,i);return r.enableEdit(this.map).startDrawing(),r},startCircle:function(t,e){t=t||this.map.getCenter().clone();var i=this.createCircle(t,e);return i.enableEdit(this.map).startDrawing(),i},startHole:function(t,e){t.newHole(e)},createLayer:function(e,i,n){var a=new e(i,n=t.Util.extend({editOptions:{editTools:this}},n));return this.fireAndForward("editable:created",{layer:a}),a},createPolyline:function(t,e){return this.createLayer(e&&e.polylineClass||this.options.polylineClass,t,e)},createPolygon:function(t,e){return this.createLayer(e&&e.polygonClass||this.options.polygonClass,t,e)},createMarker:function(t,e){return this.createLayer(e&&e.markerClass||this.options.markerClass,t,e)},createRectangle:function(t,e){return this.createLayer(e&&e.rectangleClass||this.options.rectangleClass,t,e)},createCircle:function(t,e){return this.createLayer(e&&e.circleClass||this.options.circleClass,t,e)}}),t.extend(t.Editable,{makeCancellable:function(t){t.cancel=function(){t._cancelled=!0}}}),t.Map.mergeOptions({editToolsClass:t.Editable,editable:!1,editOptions:{}}),t.Map.addInitHook(function(){this.whenReady(function(){this.options.editable&&(this.editTools=new this.options.editToolsClass(this,this.options.editOptions))})}),t.Editable.VertexIcon=t.DivIcon.extend({options:{iconSize:new t.Point(8,8)}}),t.Editable.TouchVertexIcon=t.Editable.VertexIcon.extend({options:{iconSize:new t.Point(20,20)}}),t.Editable.VertexMarker=t.Marker.extend({options:{draggable:!0,className:"leaflet-div-icon leaflet-vertex-icon"},initialize:function(e,i,n,a){this.latlng=e,this.latlngs=i,this.editor=n,t.Marker.prototype.initialize.call(this,e,a),this.options.icon=this.editor.tools.createVertexIcon({className:this.options.className}),this.latlng.__vertex=this,this.editor.editLayer.addLayer(this),this.setZIndexOffset(n.tools._lastZIndex+1)},onAdd:function(e){t.Marker.prototype.onAdd.call(this,e),this.on("drag",this.onDrag),this.on("dragstart",this.onDragStart),this.on("dragend",this.onDragEnd),this.on("mouseup",this.onMouseup),this.on("click",this.onClick),this.on("contextmenu",this.onContextMenu),this.on("mousedown touchstart",this.onMouseDown),this.addMiddleMarkers()},onRemove:function(e){this.middleMarker&&this.middleMarker.delete(),delete this.latlng.__vertex,this.off("drag",this.onDrag),this.off("dragstart",this.onDragStart),this.off("dragend",this.onDragEnd),this.off("mouseup",this.onMouseup),this.off("click",this.onClick),this.off("contextmenu",this.onContextMenu),this.off("mousedown touchstart",this.onMouseDown),t.Marker.prototype.onRemove.call(this,e)},onDrag:function(e){e.vertex=this,this.editor.onVertexMarkerDrag(e);var i=t.DomUtil.getPosition(this._icon),n=this._map.layerPointToLatLng(i);this.latlng.update(n),this._latlng=this.latlng,this.editor.refresh(),this.middleMarker&&this.middleMarker.updateLatLng();var a=this.getNext();a&&a.middleMarker&&a.middleMarker.updateLatLng()},onDragStart:function(t){t.vertex=this,this.editor.onVertexMarkerDragStart(t)},onDragEnd:function(t){t.vertex=this,this.editor.onVertexMarkerDragEnd(t)},onClick:function(t){t.vertex=this,this.editor.onVertexMarkerClick(t)},onMouseup:function(e){t.DomEvent.stop(e),e.vertex=this,this.editor.map.fire("mouseup",e)},onContextMenu:function(t){t.vertex=this,this.editor.onVertexMarkerContextMenu(t)},onMouseDown:function(t){t.vertex=this,this.editor.onVertexMarkerMouseDown(t)},delete:function(){var t=this.getNext();this.latlngs.splice(this.getIndex(),1),this.editor.editLayer.removeLayer(this),this.editor.onVertexDeleted({latlng:this.latlng,vertex:this}),this.latlngs.length||this.editor.deleteShape(this.latlngs),t&&t.resetMiddleMarker(),this.editor.refresh()},getIndex:function(){return this.latlngs.indexOf(this.latlng)},getLastIndex:function(){return this.latlngs.length-1},getPrevious:function(){if(!(this.latlngs.length<2)){var t=this.getIndex(),e=t-1;0===t&&this.editor.CLOSED&&(e=this.getLastIndex());var i=this.latlngs[e];return i?i.__vertex:void 0}},getNext:function(){if(!(this.latlngs.length<2)){var t=this.getIndex(),e=t+1;t===this.getLastIndex()&&this.editor.CLOSED&&(e=0);var i=this.latlngs[e];return i?i.__vertex:void 0}},addMiddleMarker:function(t){this.editor.hasMiddleMarkers()&&(t=t||this.getPrevious())&&!this.middleMarker&&(this.middleMarker=this.editor.addMiddleMarker(t,this,this.latlngs,this.editor))},addMiddleMarkers:function(){if(this.editor.hasMiddleMarkers()){var t=this.getPrevious();t&&this.addMiddleMarker(t);var e=this.getNext();e&&e.resetMiddleMarker()}},resetMiddleMarker:function(){this.middleMarker&&this.middleMarker.delete(),this.addMiddleMarker()},split:function(){this.editor.splitShape&&this.editor.splitShape(this.latlngs,this.getIndex())},continue:function(){if(this.editor.continueBackward){var t=this.getIndex();0===t?this.editor.continueBackward(this.latlngs):t===this.getLastIndex()&&this.editor.continueForward(this.latlngs),this.editor.reset()}}}),t.Editable.mergeOptions({vertexMarkerClass:t.Editable.VertexMarker}),t.Editable.MiddleMarker=t.Marker.extend({options:{opacity:.5,className:"leaflet-div-icon leaflet-middle-icon",draggable:!0},initialize:function(e,i,n,a,r){this.left=e,this.right=i,this.editor=a,this.latlngs=n,t.Marker.prototype.initialize.call(this,this.computeLatLng(),r),this._opacity=this.options.opacity,this.options.icon=this.editor.tools.createVertexIcon({className:this.options.className}),this.editor.editLayer.addLayer(this),this.setVisibility()},setVisibility:function(){var e=this._map.latLngToContainerPoint(this.left.latlng),i=this._map.latLngToContainerPoint(this.right.latlng),n=t.point(this.options.icon.options.iconSize);e.distanceTo(i)<3*n.x?this.hide():this.show()},show:function(){this.setOpacity(this._opacity)},hide:function(){this.setOpacity(0)},updateLatLng:function(){this.setLatLng(this.computeLatLng()),this.setVisibility()},computeLatLng:function(){var t=this.editor.map.latLngToContainerPoint(this.left.latlng),e=this.editor.map.latLngToContainerPoint(this.right.latlng),i=(t.y+e.y)/2,n=(t.x+e.x)/2;return this.editor.map.containerPointToLatLng([n,i])},onAdd:function(e){t.Marker.prototype.onAdd.call(this,e),t.DomEvent.on(this._icon,"mousedown touchstart",this.onMouseDown,this),e.on("zoomend",this.setVisibility,this)},onRemove:function(e){delete this.right.middleMarker,t.DomEvent.off(this._icon,"mousedown touchstart",this.onMouseDown,this),e.off("zoomend",this.setVisibility,this),t.Marker.prototype.onRemove.call(this,e)},onMouseDown:function(e){var i=t.DomUtil.getPosition(this._icon);if(e={originalEvent:e,latlng:this.editor.map.layerPointToLatLng(i)},0!==this.options.opacity&&(t.Editable.makeCancellable(e),this.editor.onMiddleMarkerMouseDown(e),!e._cancelled)){this.latlngs.splice(this.index(),0,e.latlng),this.editor.refresh();var n=this._icon,a=this.editor.addVertexMarker(e.latlng,this.latlngs),r=a._icon.parentNode;r.removeChild(a._icon),a._icon=n,r.appendChild(a._icon),a._initIcon(),a._initInteraction(),a.setOpacity(1),t.Draggable._dragging=!1,a.dragging._draggable._onDown(e.originalEvent),this.delete()}},delete:function(){this.editor.editLayer.removeLayer(this)},index:function(){return this.latlngs.indexOf(this.right.latlng)}}),t.Editable.mergeOptions({middleMarkerClass:t.Editable.MiddleMarker}),t.Editable.BaseEditor=t.Handler.extend({initialize:function(e,i,n){t.setOptions(this,n),this.map=e,this.feature=i,this.feature.editor=this,this.editLayer=new t.LayerGroup,this.tools=this.options.editTools||e.editTools},addHooks:function(){this.isConnected()?this.onFeatureAdd():this.feature.once("add",this.onFeatureAdd,this),this.onEnable(),this.feature.on(this._getEvents(),this)},removeHooks:function(){this.feature.off(this._getEvents(),this),this.feature.dragging&&this.feature.dragging.disable(),this.editLayer.clearLayers(),this.tools.editLayer.removeLayer(this.editLayer),this.onDisable(),this._drawing&&this.cancelDrawing()},drawing:function(){return!!this._drawing},onFeatureAdd:function(){this.tools.editLayer.addLayer(this.editLayer),this.feature.dragging&&this.feature.dragging.enable()},hasMiddleMarkers:function(){return!this.options.skipMiddleMarkers&&!this.tools.options.skipMiddleMarkers},fireAndForward:function(t,e){(e=e||{}).layer=this.feature,this.feature.fire(t,e),this.tools.fireAndForward(t,e)},onEnable:function(){this.fireAndForward("editable:enable")},onDisable:function(){this.fireAndForward("editable:disable")},onEditing:function(){this.fireAndForward("editable:editing")},onStartDrawing:function(){this.fireAndForward("editable:drawing:start")},onEndDrawing:function(){this.fireAndForward("editable:drawing:end")},onCancelDrawing:function(){this.fireAndForward("editable:drawing:cancel")},onCommitDrawing:function(t){this.fireAndForward("editable:drawing:commit",t)},onDrawingMouseDown:function(t){this.fireAndForward("editable:drawing:mousedown",t)},onDrawingMouseUp:function(t){this.fireAndForward("editable:drawing:mouseup",t)},startDrawing:function(){this._drawing||(this._drawing=t.Editable.FORWARD),this.tools.registerForDrawing(this),this.onStartDrawing()},commitDrawing:function(t){this.onCommitDrawing(t),this.endDrawing()},cancelDrawing:function(){this.onCancelDrawing(),this.endDrawing()},endDrawing:function(){this._drawing=!1,this.tools.unregisterForDrawing(this),this.onEndDrawing()},onDrawingClick:function(e){this.drawing&&(t.Editable.makeCancellable(e),this.fireAndForward("editable:drawing:click",e),e._cancelled||(this.isConnected()||this.connect(e),this.processDrawingClick(e)))},isConnected:function(){return this.map.hasLayer(this.feature)},connect:function(t){this.tools.connectCreatedToMap(this.feature),this.tools.editLayer.addLayer(this.editLayer)},onMove:function(t){this.fireAndForward("editable:drawing:move",t)},onDrawingMouseMove:function(t){this.onMove(t)},_getEvents:function(){return{dragstart:this.onDragStart,drag:this.onDrag,dragend:this.onDragEnd,remove:this.disable}},onDragStart:function(t){this.onEditing(),this.fireAndForward("editable:dragstart",t)},onDrag:function(t){this.onMove(t),this.fireAndForward("editable:drag",t)},onDragEnd:function(t){this.fireAndForward("editable:dragend",t)}}),t.Editable.MarkerEditor=t.Editable.BaseEditor.extend({onDrawingMouseMove:function(e){t.Editable.BaseEditor.prototype.onDrawingMouseMove.call(this,e),this._drawing&&this.feature.setLatLng(e.latlng)},processDrawingClick:function(t){this.fireAndForward("editable:drawing:clicked",t),this.commitDrawing(t)},connect:function(e){e&&(this.feature._latlng=e.latlng),t.Editable.BaseEditor.prototype.connect.call(this,e)}}),t.Editable.PathEditor=t.Editable.BaseEditor.extend({CLOSED:!1,MIN_VERTEX:2,addHooks:function(){return t.Editable.BaseEditor.prototype.addHooks.call(this),this.feature&&this.initVertexMarkers(),this},initVertexMarkers:function(e){if(this.enabled())if(e=e||this.getLatLngs(),t.Polyline._flat(e))this.addVertexMarkers(e);else for(var i=0;i<e.length;i++)this.initVertexMarkers(e[i])},getLatLngs:function(){return this.feature.getLatLngs()},reset:function(){this.editLayer.clearLayers(),this.initVertexMarkers()},addVertexMarker:function(t,e){return new this.tools.options.vertexMarkerClass(t,e,this)},addVertexMarkers:function(t){for(var e=0;e<t.length;e++)this.addVertexMarker(t[e],t)},refreshVertexMarkers:function(t){t=t||this.getDefaultLatLngs();for(var e=0;e<t.length;e++)t[e].__vertex.update()},addMiddleMarker:function(t,e,i){return new this.tools.options.middleMarkerClass(t,e,i,this)},onVertexMarkerClick:function(e){if(t.Editable.makeCancellable(e),this.fireAndForward("editable:vertex:click",e),!(e._cancelled||this.tools.drawing()&&this.tools._drawingEditor!==this)){var i,n=e.vertex.getIndex();e.originalEvent.ctrlKey?this.onVertexMarkerCtrlClick(e):e.originalEvent.altKey?this.onVertexMarkerAltClick(e):e.originalEvent.shiftKey?this.onVertexMarkerShiftClick(e):e.originalEvent.metaKey?this.onVertexMarkerMetaKeyClick(e):n===e.vertex.getLastIndex()&&this._drawing===t.Editable.FORWARD?n>=this.MIN_VERTEX-1&&(i=!0):0===n&&this._drawing===t.Editable.BACKWARD&&this._drawnLatLngs.length>=this.MIN_VERTEX?i=!0:0===n&&this._drawing===t.Editable.FORWARD&&this._drawnLatLngs.length>=this.MIN_VERTEX&&this.CLOSED?i=!0:this.onVertexRawMarkerClick(e),this.fireAndForward("editable:vertex:clicked",e),i&&this.commitDrawing(e)}},onVertexRawMarkerClick:function(t){this.fireAndForward("editable:vertex:rawclick",t),t._cancelled||this.vertexCanBeDeleted(t.vertex)&&t.vertex.delete()},vertexCanBeDeleted:function(t){return t.latlngs.length>this.MIN_VERTEX},onVertexDeleted:function(t){this.fireAndForward("editable:vertex:deleted",t)},onVertexMarkerCtrlClick:function(t){this.fireAndForward("editable:vertex:ctrlclick",t)},onVertexMarkerShiftClick:function(t){this.fireAndForward("editable:vertex:shiftclick",t)},onVertexMarkerMetaKeyClick:function(t){this.fireAndForward("editable:vertex:metakeyclick",t)},onVertexMarkerAltClick:function(t){this.fireAndForward("editable:vertex:altclick",t)},onVertexMarkerContextMenu:function(t){this.fireAndForward("editable:vertex:contextmenu",t)},onVertexMarkerMouseDown:function(t){this.fireAndForward("editable:vertex:mousedown",t)},onMiddleMarkerMouseDown:function(t){this.fireAndForward("editable:middlemarker:mousedown",t)},onVertexMarkerDrag:function(t){this.onMove(t),this.feature._bounds&&this.extendBounds(t),this.fireAndForward("editable:vertex:drag",t)},onVertexMarkerDragStart:function(t){this.fireAndForward("editable:vertex:dragstart",t)},onVertexMarkerDragEnd:function(t){this.fireAndForward("editable:vertex:dragend",t)},setDrawnLatLngs:function(t){this._drawnLatLngs=t||this.getDefaultLatLngs()},startDrawing:function(){this._drawnLatLngs||this.setDrawnLatLngs(),t.Editable.BaseEditor.prototype.startDrawing.call(this)},startDrawingForward:function(){this.startDrawing()},endDrawing:function(){this.tools.detachForwardLineGuide(),this.tools.detachBackwardLineGuide(),this._drawnLatLngs&&this._drawnLatLngs.length<this.MIN_VERTEX&&this.deleteShape(this._drawnLatLngs),t.Editable.BaseEditor.prototype.endDrawing.call(this),delete this._drawnLatLngs},addLatLng:function(e){this._drawing===t.Editable.FORWARD?this._drawnLatLngs.push(e):this._drawnLatLngs.unshift(e),this.feature._bounds.extend(e),this.addVertexMarker(e,this._drawnLatLngs),this.refresh()},newPointForward:function(t){this.addLatLng(t),this.tools.attachForwardLineGuide(),this.tools.anchorForwardLineGuide(t)},newPointBackward:function(t){this.addLatLng(t),this.tools.anchorBackwardLineGuide(t)},push:function(e){if(!e)return console.error("L.Editable.PathEditor.push expect a vaild latlng as parameter");this._drawing===t.Editable.FORWARD?this.newPointForward(e):this.newPointBackward(e)},removeLatLng:function(t){t.__vertex.delete(),this.refresh()},pop:function(){var e;if(!(this._drawnLatLngs.length<=1))return e=this._drawing===t.Editable.FORWARD?this._drawnLatLngs[this._drawnLatLngs.length-1]:this._drawnLatLngs[0],this.removeLatLng(e),this._drawing===t.Editable.FORWARD?this.tools.anchorForwardLineGuide(this._drawnLatLngs[this._drawnLatLngs.length-1]):this.tools.anchorForwardLineGuide(this._drawnLatLngs[0]),e},processDrawingClick:function(e){e.vertex&&e.vertex.editor===this||(this._drawing===t.Editable.FORWARD?this.newPointForward(e.latlng):this.newPointBackward(e.latlng),this.fireAndForward("editable:drawing:clicked",e))},onDrawingMouseMove:function(e){t.Editable.BaseEditor.prototype.onDrawingMouseMove.call(this,e),this._drawing&&(this.tools.moveForwardLineGuide(e.latlng),this.tools.moveBackwardLineGuide(e.latlng))},refresh:function(){this.feature.redraw(),this.onEditing()},newShape:function(t){var e=this.addNewEmptyShape();e&&(this.setDrawnLatLngs(e[0]||e),this.startDrawingForward(),this.fireAndForward("editable:shape:new",{shape:e}),t&&this.newPointForward(t))},deleteShape:function(e,i){var n={shape:e};if(t.Editable.makeCancellable(n),this.fireAndForward("editable:shape:delete",n),!n._cancelled)return e=this._deleteShape(e,i),this.ensureNotFlat&&this.ensureNotFlat(),this.feature.setLatLngs(this.getLatLngs()),this.refresh(),this.reset(),this.fireAndForward("editable:shape:deleted",{shape:e}),e},_deleteShape:function(t,e){if((e=e||this.getLatLngs()).length){var i,n=this,a=function(t,e){return t.splice(t.indexOf(e),1),t.length||n._deleteShape(t),e};if(e===t)return i=e,i.splice(0,Number.MAX_VALUE);for(var r=0;r<e.length;r++){if(e[r]===t)return a(e,t);if(-1!==e[r].indexOf(t))return a(e[r],t)}}},deleteShapeAt:function(t){var e=this.feature.shapeAt(t);if(e)return this.deleteShape(e)},appendShape:function(t){this.insertShape(t)},prependShape:function(t){this.insertShape(t,0)},insertShape:function(t,e){this.ensureMulti(),t=this.formatShape(t),void 0===e&&(e=this.feature._latlngs.length),this.feature._latlngs.splice(e,0,t),this.feature.redraw(),this._enabled&&this.reset()},extendBounds:function(t){this.feature._bounds.extend(t.vertex.latlng)},onDragStart:function(e){this.editLayer.clearLayers(),t.Editable.BaseEditor.prototype.onDragStart.call(this,e)},onDragEnd:function(e){this.initVertexMarkers(),t.Editable.BaseEditor.prototype.onDragEnd.call(this,e)}}),t.Editable.PolylineEditor=t.Editable.PathEditor.extend({startDrawingBackward:function(){this._drawing=t.Editable.BACKWARD,this.startDrawing()},continueBackward:function(t){this.drawing()||(t=t||this.getDefaultLatLngs(),this.setDrawnLatLngs(t),t.length>0&&(this.tools.attachBackwardLineGuide(),this.tools.anchorBackwardLineGuide(t[0])),this.startDrawingBackward())},continueForward:function(t){this.drawing()||(t=t||this.getDefaultLatLngs(),this.setDrawnLatLngs(t),t.length>0&&(this.tools.attachForwardLineGuide(),this.tools.anchorForwardLineGuide(t[t.length-1])),this.startDrawingForward())},getDefaultLatLngs:function(e){return!(e=e||this.feature._latlngs).length||e[0]instanceof t.LatLng?e:this.getDefaultLatLngs(e[0])},ensureMulti:function(){this.feature._latlngs.length&&t.Polyline._flat(this.feature._latlngs)&&(this.feature._latlngs=[this.feature._latlngs])},addNewEmptyShape:function(){if(this.feature._latlngs.length){var t=[];return this.appendShape(t),t}return this.feature._latlngs},formatShape:function(e){return t.Polyline._flat(e)?e:e[0]?this.formatShape(e[0]):void 0},splitShape:function(e,i){if(i&&!(i>=e.length-1)){this.ensureMulti();var n=this.feature._latlngs.indexOf(e);if(-1!==n){var a=e.slice(0,i+1),r=e.slice(i);r[0]=t.latLng(r[0].lat,r[0].lng,r[0].alt),this.feature._latlngs.splice(n,1,a,r),this.refresh(),this.reset()}}}}),t.Editable.PolygonEditor=t.Editable.PathEditor.extend({CLOSED:!0,MIN_VERTEX:3,newPointForward:function(e){t.Editable.PathEditor.prototype.newPointForward.call(this,e),this.tools.backwardLineGuide._latlngs.length||this.tools.anchorBackwardLineGuide(e),2===this._drawnLatLngs.length&&this.tools.attachBackwardLineGuide()},addNewEmptyHole:function(t){this.ensureNotFlat();var e=this.feature.shapeAt(t);if(e){var i=[];return e.push(i),i}},newHole:function(t){var e=this.addNewEmptyHole(t);e&&(this.setDrawnLatLngs(e),this.startDrawingForward(),t&&this.newPointForward(t))},addNewEmptyShape:function(){if(this.feature._latlngs.length&&this.feature._latlngs[0].length){var t=[];return this.appendShape(t),t}return this.feature._latlngs},ensureMulti:function(){this.feature._latlngs.length&&t.Polyline._flat(this.feature._latlngs[0])&&(this.feature._latlngs=[this.feature._latlngs])},ensureNotFlat:function(){this.feature._latlngs.length&&!t.Polyline._flat(this.feature._latlngs)||(this.feature._latlngs=[this.feature._latlngs])},vertexCanBeDeleted:function(e){var i=this.feature.parentShape(e.latlngs);return t.Util.indexOf(i,e.latlngs)>0||t.Editable.PathEditor.prototype.vertexCanBeDeleted.call(this,e)},getDefaultLatLngs:function(){return this.feature._latlngs.length||this.feature._latlngs.push([]),this.feature._latlngs[0]},formatShape:function(e){return!t.Polyline._flat(e)||e[0]&&0===e[0].length?e:[e]}}),t.Editable.RectangleEditor=t.Editable.PathEditor.extend({CLOSED:!0,MIN_VERTEX:4,options:{skipMiddleMarkers:!0},extendBounds:function(e){var i=e.vertex.getIndex(),n=e.vertex.getNext(),a=e.vertex.getPrevious(),r=(i+2)%4,s=e.vertex.latlngs[r],o=new t.LatLngBounds(e.latlng,s);a.latlng.update([e.latlng.lat,s.lng]),n.latlng.update([s.lat,e.latlng.lng]),this.updateBounds(o),this.refreshVertexMarkers()},onDrawingMouseDown:function(e){t.Editable.PathEditor.prototype.onDrawingMouseDown.call(this,e),this.connect();var i=this.getDefaultLatLngs();3===i.length&&i.push(e.latlng);var n=new t.LatLngBounds(e.latlng,e.latlng);this.updateBounds(n),this.updateLatLngs(n),this.refresh(),this.reset(),this.map.dragging._draggable._onUp(e.originalEvent),i[3].__vertex.dragging._draggable._onDown(e.originalEvent)},onDrawingMouseUp:function(e){this.commitDrawing(e),t.Editable.PathEditor.prototype.onDrawingMouseUp.call(this,e)},getDefaultLatLngs:function(t){return t||this.feature._latlngs[0]},updateBounds:function(t){this.feature._bounds=t},updateLatLngs:function(t){for(var e=this.getDefaultLatLngs(),i=this.feature._boundsToLatLngs(t),n=0;n<e.length;n++)e[n].update(i[n])}}),t.Editable.CircleEditor=t.Editable.PathEditor.extend({MIN_VERTEX:2,options:{skipMiddleMarkers:!0},initialize:function(e,i,n){t.Editable.PathEditor.prototype.initialize.call(this,e,i,n),this._resizeLatLng=this.computeResizeLatLng()},computeResizeLatLng:function(){var t=(this.feature._radius||this.feature._mRadius)*Math.cos(Math.PI/4),e=this.map.project(this.feature._latlng);return this.map.unproject([e.x+t,e.y-t])},updateResizeLatLng:function(){this._resizeLatLng.update(this.computeResizeLatLng()),this._resizeLatLng.__vertex.update()},getLatLngs:function(){return[this.feature._latlng,this._resizeLatLng]},getDefaultLatLngs:function(){return this.getLatLngs()},onVertexMarkerDrag:function(e){1===e.vertex.getIndex()?this.resize(e):this.updateResizeLatLng(e),t.Editable.PathEditor.prototype.onVertexMarkerDrag.call(this,e)},resize:function(t){var e=this.feature._latlng.distanceTo(t.latlng);this.feature.setRadius(e)},onDrawingMouseDown:function(e){t.Editable.PathEditor.prototype.onDrawingMouseDown.call(this,e),this._resizeLatLng.update(e.latlng),this.feature._latlng.update(e.latlng),this.connect(),this.map.dragging._draggable._onUp(e.originalEvent),this._resizeLatLng.__vertex.dragging._draggable._onDown(e.originalEvent)},onDrawingMouseUp:function(e){this.commitDrawing(e),t.Editable.PathEditor.prototype.onDrawingMouseUp.call(this,e)},onDrag:function(e){t.Editable.PathEditor.prototype.onDrag.call(this,e),this.feature.dragging.updateLatLng(this._resizeLatLng)}});var e={createEditor:function(t){t=t||this._map;var e=(this.options.editOptions||{}).editTools||t.editTools;if(!e)throw Error("Unable to detect Editable instance.");return new(this.options.editorClass||this.getEditorClass(e))(t,this,this.options.editOptions)},enableEdit:function(t){return this.editor||this.createEditor(t),this.editor.enable(),this.editor},editEnabled:function(){return this.editor&&this.editor.enabled()},disableEdit:function(){this.editor&&(this.editor.disable(),delete this.editor)},toggleEdit:function(){this.editEnabled()?this.disableEdit():this.enableEdit()},_onEditableAdd:function(){this.editor&&this.enableEdit()}};t.Polyline.include(e),t.Polygon.include(e),t.Marker.include(e),t.Rectangle.include(e),t.Circle.include(e),t.Polyline.include({getEditorClass:function(e){return e&&e.options.polylineEditorClass?e.options.polylineEditorClass:t.Editable.PolylineEditor},shapeAt:function(e,i){var n=null;if(!(i=i||this._latlngs).length)return n;if(t.Polyline._flat(i)&&this.isInLatLngs(e,i))n=i;else for(var a=0;a<i.length;a++)if(this.isInLatLngs(e,i[a]))return i[a];return n},isInLatLngs:function(e,i){if(!i)return!1;var n,a,r,s,o=[],d=this._clickTolerance();if(this._projectLatlngs(i,o,this._pxBounds),o=o[0],s=this._map.latLngToLayerPoint(e),!this._pxBounds.contains(s))return!1;for(n=1,r=o.length,a=0;n<r;a=n++)if(t.LineUtil.pointToSegmentDistance(s,o[a],o[n])<=d)return!0;return!1}}),t.Polygon.include({getEditorClass:function(e){return e&&e.options.polygonEditorClass?e.options.polygonEditorClass:t.Editable.PolygonEditor},shapeAt:function(e,i){var n=null;if(!(i=i||this._latlngs).length)return n;if(t.Polyline._flat(i)&&this.isInLatLngs(e,i))n=i;else if(t.Polyline._flat(i[0])&&this.isInLatLngs(e,i[0]))n=i;else for(var a=0;a<i.length;a++)if(this.isInLatLngs(e,i[a][0]))return i[a];return n},isInLatLngs:function(t,e){var i,n,a,r,s,o=!1;for(a=0,r=(s=e.length)-1;a<s;r=a++)i=e[a],n=e[r],i.lat>t.lat!=n.lat>t.lat&&t.lng<(n.lng-i.lng)*(t.lat-i.lat)/(n.lat-i.lat)+i.lng&&(o=!o);return o},parentShape:function(e,i){if(i=i||this._latlngs){var n=t.Util.indexOf(i,e);if(-1!==n)return i;for(var a=0;a<i.length;a++)if(-1!==(n=t.Util.indexOf(i[a],e)))return i[a]}}}),t.Marker.include({getEditorClass:function(e){return e&&e.options.markerEditorClass?e.options.markerEditorClass:t.Editable.MarkerEditor}}),t.Rectangle.include({getEditorClass:function(e){return e&&e.options.rectangleEditorClass?e.options.rectangleEditorClass:t.Editable.RectangleEditor}}),t.Circle.include({getEditorClass:function(e){return e&&e.options.circleEditorClass?e.options.circleEditorClass:t.Editable.CircleEditor}});var i=function(){this.on("add",this._onEditableAdd)};t.Marker.addInitHook(i),t.Polyline.addInitHook(i),t.LatLng.prototype.update=function(e){e=t.latLng(e),this.lat=e.lat,this.lng=e.lng}},window);