src/pyams_gis/resources/js/Draw/draw/handler/Draw.Polyline.min.js
changeset 75 a430cc4ae715
equal deleted inserted replaced
74:31687784fa16 75:a430cc4ae715
       
     1 L.Draw.Polyline=L.Draw.Feature.extend({statics:{TYPE:"polyline"},Poly:L.Polyline,options:{allowIntersection:!0,repeatMode:!1,drawError:{color:"#b00b00",timeout:2500},icon:new L.DivIcon({iconSize:new L.Point(8,8),className:"leaflet-div-icon leaflet-editing-icon"}),touchIcon:new L.DivIcon({iconSize:new L.Point(20,20),className:"leaflet-div-icon leaflet-editing-icon leaflet-touch-icon"}),guidelineDistance:20,maxGuideLineLength:4e3,shapeOptions:{stroke:!0,color:"#3388ff",weight:4,opacity:.5,fill:!1,clickable:!0},metric:!0,feet:!0,nautic:!1,showLength:!0,zIndexOffset:2e3,factor:1,maxPoints:0},initialize:function(t,i){L.Browser.touch&&(this.options.icon=this.options.touchIcon),this.options.drawError.message=L.drawLocal.draw.handlers.polyline.error,i&&i.drawError&&(i.drawError=L.Util.extend({},this.options.drawError,i.drawError)),this.type=L.Draw.Polyline.TYPE,L.Draw.Feature.prototype.initialize.call(this,t,i)},addHooks:function(){L.Draw.Feature.prototype.addHooks.call(this),this._map&&(this._markers=[],this._markerGroup=new L.LayerGroup,this._map.addLayer(this._markerGroup),this._poly=new L.Polyline([],this.options.shapeOptions),this._tooltip.updateContent(this._getTooltipText()),this._mouseMarker||(this._mouseMarker=L.marker(this._map.getCenter(),{icon:L.divIcon({className:"leaflet-mouse-marker",iconAnchor:[20,20],iconSize:[40,40]}),opacity:0,zIndexOffset:this.options.zIndexOffset})),this._mouseMarker.on("mouseout",this._onMouseOut,this).on("mousemove",this._onMouseMove,this).on("mousedown",this._onMouseDown,this).on("mouseup",this._onMouseUp,this).addTo(this._map),this._map.on("mouseup",this._onMouseUp,this).on("mousemove",this._onMouseMove,this).on("zoomlevelschange",this._onZoomEnd,this).on("touchstart",this._onTouch,this).on("zoomend",this._onZoomEnd,this))},removeHooks:function(){L.Draw.Feature.prototype.removeHooks.call(this),this._clearHideErrorTimeout(),this._cleanUpShape(),this._map.removeLayer(this._markerGroup),delete this._markerGroup,delete this._markers,this._map.removeLayer(this._poly),delete this._poly,this._mouseMarker.off("mousedown",this._onMouseDown,this).off("mouseout",this._onMouseOut,this).off("mouseup",this._onMouseUp,this).off("mousemove",this._onMouseMove,this),this._map.removeLayer(this._mouseMarker),delete this._mouseMarker,this._clearGuides(),this._map.off("mouseup",this._onMouseUp,this).off("mousemove",this._onMouseMove,this).off("zoomlevelschange",this._onZoomEnd,this).off("zoomend",this._onZoomEnd,this).off("touchstart",this._onTouch,this).off("click",this._onTouch,this)},deleteLastVertex:function(){if(!(this._markers.length<=1)){var t=this._markers.pop(),i=this._poly,e=i.getLatLngs(),o=e.splice(-1,1)[0];this._poly.setLatLngs(e),this._markerGroup.removeLayer(t),i.getLatLngs().length<2&&this._map.removeLayer(i),this._vertexChanged(o,!1)}},addVertex:function(t){this._markers.length>=2&&!this.options.allowIntersection&&this._poly.newLatLngIntersects(t)?this._showErrorTooltip():(this._errorShown&&this._hideErrorTooltip(),this._markers.push(this._createMarker(t)),this._poly.addLatLng(t),2===this._poly.getLatLngs().length&&this._map.addLayer(this._poly),this._vertexChanged(t,!0))},completeShape:function(){this._markers.length<=1||!this._shapeIsValid()||(this._fireCreatedEvent(),this.disable(),this.options.repeatMode&&this.enable())},_finishShape:function(){var t=this._poly._defaultShape?this._poly._defaultShape():this._poly.getLatLngs(),i=this._poly.newLatLngIntersects(t[t.length-1]);!this.options.allowIntersection&&i||!this._shapeIsValid()?this._showErrorTooltip():(this._fireCreatedEvent(),this.disable(),this.options.repeatMode&&this.enable())},_shapeIsValid:function(){return!0},_onZoomEnd:function(){null!==this._markers&&this._updateGuide()},_onMouseMove:function(t){var i=this._map.mouseEventToLayerPoint(t.originalEvent),e=this._map.layerPointToLatLng(i);this._currentLatLng=e,this._updateTooltip(e),this._updateGuide(i),this._mouseMarker.setLatLng(e),L.DomEvent.preventDefault(t.originalEvent)},_vertexChanged:function(t,i){this._map.fire(L.Draw.Event.DRAWVERTEX,{layers:this._markerGroup}),this._updateFinishHandler(),this._updateRunningMeasure(t,i),this._clearGuides(),this._updateTooltip()},_onMouseDown:function(t){if(!this._clickHandled&&!this._touchHandled&&!this._disableMarkers){this._onMouseMove(t),this._clickHandled=!0,this._disableNewMarkers();var i=t.originalEvent,e=i.clientX,o=i.clientY;this._startPoint.call(this,e,o)}},_startPoint:function(t,i){this._mouseDownOrigin=L.point(t,i)},_onMouseUp:function(t){var i=t.originalEvent,e=i.clientX,o=i.clientY;this._endPoint.call(this,e,o,t),this._clickHandled=null},_endPoint:function(t,i,e){if(this._mouseDownOrigin){var o=L.point(t,i).distanceTo(this._mouseDownOrigin),s=this._calculateFinishDistance(e.latlng);this.options.maxPoints>1&&this.options.maxPoints==this._markers.length+1?(this.addVertex(e.latlng),this._finishShape()):s<10&&L.Browser.touch?this._finishShape():Math.abs(o)<9*(window.devicePixelRatio||1)&&this.addVertex(e.latlng),this._enableNewMarkers()}this._mouseDownOrigin=null},_onTouch:function(t){var i,e,o=t.originalEvent;!o.touches||!o.touches[0]||this._clickHandled||this._touchHandled||this._disableMarkers||(i=o.touches[0].clientX,e=o.touches[0].clientY,this._disableNewMarkers(),this._touchHandled=!0,this._startPoint.call(this,i,e),this._endPoint.call(this,i,e,t),this._touchHandled=null),this._clickHandled=null},_onMouseOut:function(){this._tooltip&&this._tooltip._onMouseOut.call(this._tooltip)},_calculateFinishDistance:function(t){var i;if(this._markers.length>0){var e;if(this.type===L.Draw.Polyline.TYPE)e=this._markers[this._markers.length-1];else{if(this.type!==L.Draw.Polygon.TYPE)return 1/0;e=this._markers[0]}var o=this._map.latLngToContainerPoint(e.getLatLng()),s=new L.Marker(t,{icon:this.options.icon,zIndexOffset:2*this.options.zIndexOffset}),n=this._map.latLngToContainerPoint(s.getLatLng());i=o.distanceTo(n)}else i=1/0;return i},_updateFinishHandler:function(){var t=this._markers.length;t>1&&this._markers[t-1].on("click",this._finishShape,this),t>2&&this._markers[t-2].off("click",this._finishShape,this)},_createMarker:function(t){var i=new L.Marker(t,{icon:this.options.icon,zIndexOffset:2*this.options.zIndexOffset});return this._markerGroup.addLayer(i),i},_updateGuide:function(t){var i=this._markers?this._markers.length:0;i>0&&(t=t||this._map.latLngToLayerPoint(this._currentLatLng),this._clearGuides(),this._drawGuide(this._map.latLngToLayerPoint(this._markers[i-1].getLatLng()),t))},_updateTooltip:function(t){var i=this._getTooltipText();t&&this._tooltip.updatePosition(t),this._errorShown||this._tooltip.updateContent(i)},_drawGuide:function(t,i){var e,o,s,n=Math.floor(Math.sqrt(Math.pow(i.x-t.x,2)+Math.pow(i.y-t.y,2))),r=this.options.guidelineDistance,a=this.options.maxGuideLineLength,h=n>a?n-a:r;for(this._guidesContainer||(this._guidesContainer=L.DomUtil.create("div","leaflet-draw-guides",this._overlayPane));h<n;h+=this.options.guidelineDistance)e=h/n,o={x:Math.floor(t.x*(1-e)+e*i.x),y:Math.floor(t.y*(1-e)+e*i.y)},(s=L.DomUtil.create("div","leaflet-draw-guide-dash",this._guidesContainer)).style.backgroundColor=this._errorShown?this.options.drawError.color:this.options.shapeOptions.color,L.DomUtil.setPosition(s,o)},_updateGuideColor:function(t){if(this._guidesContainer)for(var i=0,e=this._guidesContainer.childNodes.length;i<e;i++)this._guidesContainer.childNodes[i].style.backgroundColor=t},_clearGuides:function(){if(this._guidesContainer)for(;this._guidesContainer.firstChild;)this._guidesContainer.removeChild(this._guidesContainer.firstChild)},_getTooltipText:function(){var t,i,e=this.options.showLength;return 0===this._markers.length?t={text:L.drawLocal.draw.handlers.polyline.tooltip.start}:(i=e?this._getMeasurementString():"",t=1===this._markers.length?{text:L.drawLocal.draw.handlers.polyline.tooltip.cont,subtext:i}:{text:L.drawLocal.draw.handlers.polyline.tooltip.end,subtext:i}),t},_updateRunningMeasure:function(t,i){var e,o,s=this._markers.length;1===this._markers.length?this._measurementRunningTotal=0:(e=s-(i?2:1),o=L.GeometryUtil.isVersion07x()?t.distanceTo(this._markers[e].getLatLng())*(this.options.factor||1):this._map.distance(t,this._markers[e].getLatLng())*(this.options.factor||1),this._measurementRunningTotal+=o*(i?1:-1))},_getMeasurementString:function(){var t,i=this._currentLatLng,e=this._markers[this._markers.length-1].getLatLng();return t=L.GeometryUtil.isVersion07x()?e&&i&&i.distanceTo?this._measurementRunningTotal+i.distanceTo(e)*(this.options.factor||1):this._measurementRunningTotal||0:e&&i?this._measurementRunningTotal+this._map.distance(i,e)*(this.options.factor||1):this._measurementRunningTotal||0,L.GeometryUtil.readableDistance(t,this.options.metric,this.options.feet,this.options.nautic,this.options.precision)},_showErrorTooltip:function(){this._errorShown=!0,this._tooltip.showAsError().updateContent({text:this.options.drawError.message}),this._updateGuideColor(this.options.drawError.color),this._poly.setStyle({color:this.options.drawError.color}),this._clearHideErrorTimeout(),this._hideErrorTimeout=setTimeout(L.Util.bind(this._hideErrorTooltip,this),this.options.drawError.timeout)},_hideErrorTooltip:function(){this._errorShown=!1,this._clearHideErrorTimeout(),this._tooltip.removeError().updateContent(this._getTooltipText()),this._updateGuideColor(this.options.shapeOptions.color),this._poly.setStyle({color:this.options.shapeOptions.color})},_clearHideErrorTimeout:function(){this._hideErrorTimeout&&(clearTimeout(this._hideErrorTimeout),this._hideErrorTimeout=null)},_disableNewMarkers:function(){this._disableMarkers=!0},_enableNewMarkers:function(){setTimeout(function(){this._disableMarkers=!1}.bind(this),50)},_cleanUpShape:function(){this._markers.length>1&&this._markers[this._markers.length-1].off("click",this._finishShape,this)},_fireCreatedEvent:function(){var t=new this.Poly(this._poly.getLatLngs(),this.options.shapeOptions);L.Draw.Feature.prototype._fireCreatedEvent.call(this,t)}});