X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/0a6d1a8dabd6a51c6f2b7de73ea8644a650d9dca..8f7f02b025f59db466fdb22ea3686cb6c5adc400:/app/assets/javascripts/leaflet.map.js diff --git a/app/assets/javascripts/leaflet.map.js b/app/assets/javascripts/leaflet.map.js index 92c441b82..91d9efbde 100644 --- a/app/assets/javascripts/leaflet.map.js +++ b/app/assets/javascripts/leaflet.map.js @@ -115,22 +115,18 @@ L.OSM.Map = L.Map.extend({ }, updateLayers: function (layerParam) { - var layers = layerParam || "M", - layersAdded = ""; + const oldBaseLayer = this.getMapBaseLayer(); + let newBaseLayer; - for (let i = this.baseLayers.length - 1; i >= 0; i--) { - if (layers.indexOf(this.baseLayers[i].options.code) === -1) { - this.removeLayer(this.baseLayers[i]); + for (const layer of this.baseLayers) { + if (!newBaseLayer || layerParam.includes(layer.options.code)) { + newBaseLayer = layer; } } - for (let i = this.baseLayers.length - 1; i >= 0; i--) { - if (layers.indexOf(this.baseLayers[i].options.code) >= 0) { - this.addLayer(this.baseLayers[i]); - layersAdded = layersAdded + this.baseLayers[i].options.code; - } else if (i === 0 && layersAdded === "") { - this.addLayer(this.baseLayers[i]); - } + if (newBaseLayer !== oldBaseLayer) { + if (oldBaseLayer) this.removeLayer(oldBaseLayer); + if (newBaseLayer) this.addLayer(newBaseLayer); } }, @@ -156,13 +152,10 @@ L.OSM.Map = L.Map.extend({ }, getUrl: function (marker) { - var precision = OSM.zoomPrecision(this.getZoom()), - params = {}; + const params = {}; if (marker && this.hasLayer(marker)) { - var latLng = marker.getLatLng().wrap(); - params.mlat = latLng.lat.toFixed(precision); - params.mlon = latLng.lng.toFixed(precision); + [params.mlat, params.mlon] = OSM.cropLocation(marker.getLatLng(), this.getZoom()); } var url = window.location.protocol + "//" + OSM.SERVER_URL + "/", @@ -240,21 +233,14 @@ L.OSM.Map = L.Map.extend({ }, getGeoUri: function (marker) { - var precision = OSM.zoomPrecision(this.getZoom()), - latLng, - params = {}; + let latLng = this.getCenter(); + const zoom = this.getZoom(); if (marker && this.hasLayer(marker)) { - latLng = marker.getLatLng().wrap(); - } else { - latLng = this.getCenter(); + latLng = marker.getLatLng(); } - params.lat = latLng.lat.toFixed(precision); - params.lon = latLng.lng.toFixed(precision); - params.zoom = this.getZoom(); - - return "geo:" + params.lat + "," + params.lon + "?z=" + params.zoom; + return `geo:${OSM.cropLocation(latLng, zoom).join(",")}?z=${zoom}`; }, addObject: function (object, callback) {