L.Control.EdgeScale=L.Control.extend({options:{position:"bottomleft",icon:!0,coords:!0,bar:!0,onMove:!0,template:"{y} | {x}",projected:!1,formatProjected:"#.##0,000",latlngFormat:"DD",latlngDesignators:!0,latLngFormatter:void 0,iconStyle:{background:`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 100 100'%3E%3Cg stroke='%23fff'%3E%3Ccircle cx='50' cy='50.2' r='3.9' stroke-width='2' /%3E%3Cpath stroke-width='3' d='M5 54h32a4 4 0 1 0 0-8H5a4 4 0 1 0 0 8z M54 5a4 4 0 1 0-8 0v32a4 4 0 1 0 8 0V5z M99 50c0-2-2-4-4-4H63a4 4 0 1 0 0 8h32c2 0 4-1 4-4zM46 95a4 4 0 1 0 8 0V64a4 4 0 1 0-8 0v31z'/%3E%3C/g%3E%3C/svg%3E%0A")`,width:"24px",height:"24px",left:"calc(50% - 12px)",top:"calc(50% - 12px)",content:"",display:"block",position:"absolute",zIndex:999,pointerEvents:"none"},containerStyle:{backgroundColor:"rgba(255, 255, 255, 0.7)",boxShadow:"0 0 5px #bbb",borderRadius:"3px",padding:"3px 2px",color:"#333",font:"11px/1.5 Consolas, monaco, monospace",writingMode:"vertical-lr"}},initialize(t){L.Util.setOptions(this,t)},onAdd(t){return this.options.bar&&(this._scaleBar=new L.Control.EdgeScale.Layer(this.options.bar===!0?{}:this.options.bar).addTo(t)),this.options.icon&&(this._icon=L.DomUtil.create("div","leaflet-crosshair"),Object.assign(this._icon.style,this.options.iconStyle),t.getContainer().insertBefore(this._icon,t.getContainer().firstChild)),this._container=L.DomUtil.create("div","leaflet-control-mapcentercoord"),Object.assign(this._container.style,this.options.containerStyle),this.options.coords||(this._container.style.display="none"),L.DomEvent.disableClickPropagation(this._container),this._container.innerHTML=this._getMapCenterCoord(),t.on("move",this._onMapMove,this),t.on("moveend",this._onMapMove,this),this._container},onRemove(t){this.options.bar&&this._scaleBar.remove(),this.options.icon&&t.getContainer().removeChild(this._icon),t.off("move",this._onMapMove,this),t.off("moveend",this._onMapMove,this)},_onMapMove(t){(this.options.onMove||t.type==="moveend")&&(this._container.innerHTML=this._getMapCenterCoord())},_getMapCenterCoord(){const t=this._map.getCenter();return this.options.projected?this._getProjectedCoord(this._map.options.crs.project(t)):this._getLatLngCoord(t)},_getProjectedCoord(t){return L.Util.template(this.options.template,{x:this._format(this.options.formatProjected,t.x),y:this._format(this.options.formatProjected,t.y)})},_getLatLngCoord(t){const{latLngFormatter:i,latlngFormat:a,latlngDesignators:s}=this.options;if(i!==void 0)return i(t.lat,t.lng);let h,l,e,n,o={lat:t.lat,lng:t.lng,lng_neg:t.lng<0,lat_neg:t.lat<0};return o.lng<0&&(o.lng=Math.abs(o.lng)),o.lng>180&&(o.lng=360-o.lng,o.lng_neg=!o.lng_neg),o.lat<0&&(o.lat=Math.abs(o.lat)),a==="DM"?(e=parseInt(o.lng),l=e+"\xBA "+this._format("00.000",(o.lng-e)*60)+"'",e=parseInt(o.lat),h=e+"\xBA "+this._format("00.000",(o.lat-e)*60)+"'"):a==="DMS"?(e=parseInt(o.lng),n=(o.lng-e)*60,l=e+"\xBA "+this._format("00",parseInt(n))+"' "+this._format("00.0",(n-parseInt(n))*60)+"''",e=parseInt(o.lat),n=(o.lat-e)*60,h=e+"\xBA "+this._format("00",parseInt(n))+"' "+this._format("00.0",(n-parseInt(n))*60)+"''"):(l=this._format("#0.00000",o.lng)+"\xBA",h=this._format("##0.00000",o.lat)+"\xBA"),L.Util.template(this.options.template,{x:(!s&&o.lng_neg?"-":"")+l+(s?o.lng_neg?" W":" E":""),y:(!s&&o.lat_neg?"-":"")+h+(s?o.lat_neg?" S":" N":"")})},_format(t,i){if(!t||isNaN(+i))return i;i=t.charAt(0)=="-"?-i:+i;let a=i<0?i=-i:0,s=t.match(/[^\d\-\+#]/g),h=s&&s[s.length-1]||".",l=s&&s[1]&&s[0]||",";t=t.split(h),i=i.toFixed(t[1]&&t[1].length),i=+i+"";let e=t[1]&&t[1].lastIndexOf("0"),n=i.split(".");(!n[1]||n[1]&&n[1].length<=e)&&(i=(+i).toFixed(e+1));let o=t[0].split(l);t[0]=o.join("");let _=t[0]&&t[0].indexOf("0");if(_>-1)for(;n[0].length=i){this._interval=s.interval;break}}else this._interval=L.Control.Scale.prototype._getRoundNum(this._map.containerPointToLatLng([0,this._map.getSize().y/2]).distanceTo(this._map.containerPointToLatLng([L.Control.Scale.prototype.options.maxWidth,this._map.getSize().y/2])));this._currZoom=i},_draw(){this._ctx.strokeStyle=this.options.color,this._create_lat_ticks(),this._create_lon_ticks(),this._ctx.fillStyle=this.options.color,this._ctx.font=this.options.font;const t=this._map.getSize(),i=this._interval>=1e3?this._interval/1e3+" km":this._interval+" m";this._ctx.textAlign="left",this._ctx.textBaseline="middle",this._ctx.fillText(i,12,t.y/2),this._ctx.textAlign="center",this._ctx.textBaseline="top",this._ctx.fillText(i,t.x/2,12)},_create_lat_ticks(){const{weight:t}=this.options,i=this._map.getSize(),a=Math.PI/180,s=this._merLength(this._map.containerPointToLatLng(new L.Point(0,i.y/2)).lat*a),h=this._merLength(this._map.containerPointToLatLng(new L.Point(0,0)).lat*a),l=this._merLength(this._map.containerPointToLatLng(new L.Point(0,i.y)).lat*a);for(let e=s+this._interval/2;e-this._LIMIT_PHI&&this._draw_lat_tick(n,10,t*1.5)}for(let e=s-this._interval/2;e>l;e=e-this._interval){const n=this._invmerLength(e);n>-this._LIMIT_PHI&&n-this._LIMIT_PHI&&this._draw_lat_tick(n,4,t)}for(let e=s-this._interval/10;e>l;e=e-this._interval/10){const n=this._invmerLength(e);n>-this._LIMIT_PHI&&nl.lng;r=r-_)this._draw_lon_tick(r,10,t*1.5);for(let r=h.lng;rl.lng;r=r-_/10)this._draw_lon_tick(r,4,t)},_setCanvasPosition(){let t=this._map.containerPointToLayerPoint([0,0]);this._map._bearing&&(t=this._map.rotatedPointToMapPanePoint(this._map.containerPointToLayerPoint(new L.Point(this._map._container.getBoundingClientRect())))),L.DomUtil.setPosition(this._canvas,t)},_latLngToCanvasPoint(t){return new L.Point(this._map.project(t)._subtract(this._map.getPixelOrigin())).add(this._map._getMapPanePos())},_draw_lat_tick(t,i,a){const s=180/Math.PI,h=this._map.getSize(),l=this._latLngToCanvasPoint(new L.LatLng(t*s,0)).y;this._ctx.lineWidth=a,this._ctx.beginPath(),this._ctx.moveTo(0,l),this._ctx.lineTo(+i,l),this._ctx.stroke()},_draw_lon_tick(t,i,a){const s=this._latLngToCanvasPoint(new L.LatLng(0,t)).x;this._ctx.lineWidth=a,this._ctx.beginPath(),this._ctx.moveTo(s,0),this._ctx.lineTo(s,i),this._ctx.stroke()},_merLength(t){const i=Math.cos(2*t),a=Math.sin(2*t);return this._A*(t+a*(this._c1+(this._c2+(this._c3+(this._c4+this._c5*i)*i)*i)*i))},_invmerLength(t){const i=t/this._A,a=Math.cos(2*i),s=Math.sin(2*i);return i+s*(this._ic1+(this._ic2+(this._ic3+(this._ic4+this._ic5*a)*a)*a)*a)}}),L.control=L.control||{},L.control.edgeScale=function(t){return new L.Control.EdgeScale(t)},L.Map.mergeOptions({edgeScaleControl:!1}),L.Map.addInitHook(function(){this.options.edgeScaleControl&&(this.edgeScaleControl=new L.Control.EdgeScale,this.addControl(this.edgeScaleControl))});