diff --git a/README.md b/README.md index bf2c45e..c7f1e56 100644 --- a/README.md +++ b/README.md @@ -77,3 +77,5 @@ Checkout the [Demo](https://marcchasse.github.io/leaflet.ScaleFactor/) |----------------|---------|--------------|-------------------------------------------------------------------------------------------------| | position | String | 'bottomleft' | The position of the control (one of the map corners). See control positions. | | updateWhenIdle | Boolean | false | If true, the control is updated on moveend, otherwise it's always up-to-date (updated on move). | +| thousand_separator | String | "," | The thousand separator. | +| scale_separator | String | ":" | The scale separator. | diff --git a/leaflet.scalefactor.js b/leaflet.scalefactor.js index f75f02a..f96c516 100644 --- a/leaflet.scalefactor.js +++ b/leaflet.scalefactor.js @@ -20,7 +20,9 @@ var ScaleFactor = L.Control.extend({ options: { position: 'bottomleft', - updateWhenIdle: true + updateWhenIdle: true, + thousand_separator: ",", + scale_separator: ':' }, onAdd: function (map) { @@ -71,7 +73,8 @@ var scaleFactor = RealWorlMetersPer100Pixels / ScreenMetersPer100Pixels; //.replace formats the scale with commas 50000 -> 50,000 - this._mScale.innerHTML = '1:' + Math.round(scaleFactor).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); + this._mScale.innerHTML = '1' + this.options.scale_separator + + Math.round(scaleFactor).toString().replace(/\B(?=(\d{3})+(?!\d))/g, this.options.thousand_separator); } }); diff --git a/leaflet.scalefactor.min.js b/leaflet.scalefactor.min.js index 6f62e73..d0894d8 100644 --- a/leaflet.scalefactor.min.js +++ b/leaflet.scalefactor.min.js @@ -1,7 +1 @@ -!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=$("#heightRef").height() -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) \ No newline at end of file +!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){return e.Control.extend({options:{position:"bottomleft",updateWhenIdle:!0,thousand_separator:",",scale_separator:":"},onAdd:function(t){var o=e.DomUtil.create("div","leaflet-control-scalefactor"),n=this.options;return this._mScale=e.DomUtil.create("div","leaflet-control-scalefactor-line",o),t.on(n.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=$("#heightRef").height();return e.parentNode.removeChild(e),function(e){return e/t}}(),_update:function(){var e=this._map,t=e.getSize().y/2,o=e.distance(e.containerPointToLatLng([0,t]),e.containerPointToLatLng([100,t]))/(this._pxTOmm(100)/1e3);this._mScale.innerHTML="1"+this.options.scale_separator+Math.round(o).toString().replace(/\B(?=(\d{3})+(?!\d))/g,this.options.thousand_separator)}})},window); \ No newline at end of file