Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions app/assets/javascripts/leaflet.map.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,19 @@ L.OSM.Map = L.Map.extend({
},

updateLayers: function (layerParam) {
var layers = layerParam || "O",
layersAdded = "";

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]);
} else {
this.removeLayer(this.baseLayers[i]);
const oldBaseLayer = this.getMapBaseLayer();
let newBaseLayer;

for (const layer of this.baseLayers) {
if (!newBaseLayer || layerParam.includes(layer.options.code)) {
newBaseLayer = layer;
}
}

if (newBaseLayer !== oldBaseLayer) {
if (oldBaseLayer) this.removeLayer(oldBaseLayer);
if (newBaseLayer) this.addLayer(newBaseLayer);
}
},

getLayersCode: function () {
Expand All @@ -143,11 +142,8 @@ L.OSM.Map = L.Map.extend({
},

getMapBaseLayerId: function () {
var baseLayerId;
this.eachLayer(function (layer) {
if (layer.options && layer.options.keyid) baseLayerId = layer.options.keyid;
});
return baseLayerId;
const layer = this.getMapBaseLayer();
if (layer) return layer.options.layerId;
},

getMapBaseLayer: function () {
Expand Down
4 changes: 2 additions & 2 deletions test/javascripts/osm_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,15 @@ describe("OSM", function () {
it("creates a location cookie value", function () {
$("body").append("<div id='map'>");
const map = new L.OSM.Map("map", { center: [57.6247, -3.6845], zoom: 9 });
map.updateLayers("");
map.updateLayers("M");
expect(OSM.locationCookie(map)).to.eq("-3.685|57.625|9|M");
$("#map").remove();
});

it("respects zoomPrecision", function () {
$("body").append("<div id='map'>");
const map = new L.OSM.Map("map", { center: [57.6247, -3.6845], zoom: 9 });
map.updateLayers("");
map.updateLayers("M");
expect(OSM.locationCookie(map)).to.eq("-3.685|57.625|9|M");
// map.setZoom() doesn't update the zoom level for some reason
// using map._zoom here to update the zoom level manually
Expand Down
Loading