2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
|
/*! leaflet.freedraw by Adam Timberlake <adam.timberlake@gmail.com> created on 2015-06-20 */
|
||
|
!function(a,b,c,d){"use strict";b.freeDraw=function(a){return new b.FreeDraw(a)},b.FreeDraw=b.FeatureGroup.extend({map:null,state:[],defaultPreferences:{},svg:{},element:{},creating:!1,lineFunction:function(){},latLngs:[],options:{},lastNotification:"",markerLayer:b.layerGroup(),hull:{},memory:{},polygons:[],edges:[],mode:1,polygonCount:0,fromPoint:{x:0,y:0},movingEdge:null,boundaryUpdateRequired:!1,silenced:!1,RECOUNT_TIMEOUT:1,initialize:function(a){"undefined"==typeof c&&b.FreeDraw.Throw("D3 is a required library","http://d3js.org/"),"undefined"==typeof d&&b.FreeDraw.Throw("JSClipper is a required library","http://sourceforge.net/p/jsclipper/wiki/Home%206/"),this.fromPoint={x:0,y:0},this.polygons=[],this.edges=[],this.hull={},this._latLngs=[],a=a||{},this.memory=new b.FreeDraw.Memory,this.options=new b.FreeDraw.Options,this.hull=new b.FreeDraw.Hull,this.element=a.element||null,this.setMode(a.mode||this.mode),this.options.setPathClipperPadding(100),b.FreeDraw.Polygon=b.Polygon.extend({options:{className:"leaflet-freedraw-polygon"}})},recreateEdges:function(a){return this.edges=this.edges.filter(function(b){return b._freedraw.polygon!==a?!0:void this.map.removeLayer(b)}.bind(this)),this.createEdges(a)},resurrectOrphans:function(){var a=function(a){setTimeout(function(){this.silently(function(){this.recreateEdges(a)}.bind(this))}.bind(this))},b=this.getPolygons(!0);b.forEach(function(b){b&&b._parts[0]&&a.call(this,b)}.bind(this)),setTimeout(function(){this.notifyBoundaries()}.bind(this))},onAdd:function(d){d.on("zoomend",function(){setTimeout(this.resurrectOrphans.bind(this))}.bind(this)),this.map=d,this.mode=this.mode||b.FreeDraw.MODES.VIEW,this.defaultPreferences={dragging:d.dragging._enabled,touchZoom:d.touchZoom._enabled,doubleClickZoom:d.doubleClickZoom._enabled,scrollWheelZoom:d.scrollWheelZoom._enabled},this.element||(this.element=d._container),this.lineFunction=c.svg.line().x(function(a){return a.x}).y(function(a){return a.y}).interpolate("linear"),this.createD3(),this.map.on(this.options.events[0]||"mousedown touchstart",this.bindEvents().mouseDown),this.map.on(this.options.events[1]||"mousemove touchmove",this.bindEvents().mouseMove),this.map.on(this.options.events[2]||"mouseup touchend",this.bindEvents().mouseUpLeave);var e=a.document.getElementsByTagName("body")[0];e.addEventListener("mouseleave",this.bindEvents().mouseUpLeave),this.setMode(this.mode)},onRemove:function(){this._clearPolygons(),this.map.off(this.options.events[0]||"mousedown touchstart",this.bindEvents().mouseDown),this.map.off(this.options.events[1]||"mousemove touchmove",this.bindEvents().mouseMove),this.map.off(this.options.events[2]||"mousedown touchstart",this.bindEvents().mouseUpLeave);var b=a.document.getElementsByTagName("body")[0];b.removeEventListener("mouseleave",this.bindEvents().mouseUpLeave)},silently:function(a){var b=this.silenced;this.silenced=!0,a.apply(this),b||(this.silenced=!1)},cancelAction:function(){this.creating=!1,this.movingEdge=null,this.destroyD3().createD3()},setMapPermissions:function(a){this.map.dragging[a](),this.map.touchZoom[a](),this.map.doubleClickZoom[a](),this.map.scrollWheelZoom[a](),"enable"===a&&(this.defaultPreferences.dragging||this.map.dragging.disable(),this.defaultPreferences.touchZoom||this.map.touchZoom.disable(),this.defaultPreferences.doubleClickZoom||this.map.doubleClickZoom.disable(),this.defaultPreferences.scrollWheelZoom||this.map.scrollWheelZoom.disable())},setMode:function(a){if(a=0===a?b.FreeDraw.MODES.VIEW:a,this.mode=a,this.fire("mode",{mode:a}),this.map){var c=!!(a&b.FreeDraw.MODES.CREATE),d=c?"disable":"enable";this.map.dragging[d](),!this.boundaryUpdateRequired||this.mode&b.FreeDraw.MODES.EDIT||(this.notifyBoundaries(),this.boundaryUpdateRequired=!1,this.options.memoriseEachEdge||this.memory.save(this.getPolygons(!0))),function(b,c,d,e){e(c,"mode-create"),e(c,"mode-edit"),e(c,"mode-delete"),e(c,"mode-view"),e(c,"mode-append"),a&b.CREATE&&d(c,"mode-create"),a&b.EDIT&&d(c,"mode-edit"),a&b.DELETE&&d(c,"mode-delete"),a&b.VIEW&&d(c,"mode-view"),a&b.APPEND&&d(c,"mode-append")}(b.FreeD
|