leaflet-betterscale
leaflet-betterscale copied to clipboard
Doesnt to well with maps including antermeridian using CRS with -180:180, nor with polar stereographic
Scalebar becomes unrealistic as Leaflet.getBounds as LatLngBounds stuffs up in antemeridian and polar system. The suggested fix is: _update: function () { // var t = this._map.getBounds(), // e = t.getCenter().lat, // i = 6378137 * Math.PI * Math.cos(e * Math.PI / 180), // n = i * (t.getNorthEast().lng - t.getSouthWest().lng) / 180, var bounds = this._map.getPixelBounds(), sw = this._map.unproject(bounds.getBottomLeft()), ne = this._map.unproject(bounds.getTopRight()); var swp = this._map.options.crs.projection.project(sw), nep = this._map.options.crs.projection.project(ne), n = Math.abs(nep.x - swp.x), o = this._map.getSize(), s = this.options, a = 0; o.x > 0 && (a = n * (s.maxWidth / o.x)), this._updateScales(s, a)