forked from MarcChasse/leaflet.ScaleFactor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet.scalefactor.min.js
7 lines (7 loc) · 1.23 KB
/
leaflet.scalefactor.min.js
1
2
3
4
5
6
7
!function(e,t){"function"==typeof define&&define.amd?define(["leaflet"],e):"object"==typeof exports&&(module.exports=e(require("leaflet"))),void 0!==t&&t.L&&(t.L.Control.ScaleFactor=e(L),L.control.scalefactor=function(e){return new t.L.Control.ScaleFactor(e)})}(function(e){var t=e.Control.extend({options:{position:"bottomleft",updateWhenIdle:!0},onAdd:function(t){var n="leaflet-control-scalefactor",o=e.DomUtil.create("div",n),i=this.options
return this._mScale=e.DomUtil.create("div",n+"-line",o),t.on(i.updateWhenIdle?"moveend":"move",this._update,this),t.whenReady(this._update,this),o},onRemove:function(e){e.off(this.options.updateWhenIdle?"moveend":"move",this._update,this)},_pxTOmm:function(){var e=document.createElement("div")
e.style="height:1mm;display:none",e.id="heightRef",document.body.appendChild(e),e=document.getElementById("heightRef")
var t=parseFloat(getComputedStyle(e, null).height.replace("px", ""))
return e.parentNode.removeChild(e),function(e){return e/t}}(),_update:function(){var e=this._map,t=e.getSize().y/2,n=e.distance(e.containerPointToLatLng([0,t]),e.containerPointToLatLng([100,t])),o=this._pxTOmm(100)/1e3,i=n/o
this._mScale.innerHTML="1:"+(""+Math.round(i)).replace(/\B(?=(\d{3})+(?!\d))/g,",")}})
return t},window)