diff --git a/umap/models.py b/umap/models.py index 31c1b01a..6cd032ae 100644 --- a/umap/models.py +++ b/umap/models.py @@ -443,6 +443,8 @@ class DataLayer(NamedModel): "name": self.name, "displayOnLoad": self.display_on_load, } + if self.old_id: + obj["old_id"] = self.old_id obj["id"] = self.pk obj["permissions"] = {"edit_status": self.edit_status} obj["editMode"] = "advanced" if self.can_edit(user, request) else "disabled" diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 1b7ff197..a380ded6 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -69,13 +69,13 @@ U.Map = L.Map.extend({ this.options.zoomControl = zoomControl !== undefined ? zoomControl : true this.options.fullscreenControl = fullscreenControl !== undefined ? fullscreenControl : true - this.datalayersOnLoad = L.Util.queryString('datalayers') - if (this.datalayersOnLoad) { - this.datalayersOnLoad = this.datalayersOnLoad.toString().split(',') + this.datalayersFromQueryString = L.Util.queryString('datalayers') + if (this.datalayersFromQueryString) { + this.datalayersFromQueryString = this.datalayersFromQueryString + .toString() + .split(',') } - if (L.Browser.ielt9) this.options.editMode = 'disabled' // TODO include ie9 - let editedFeature = null const self = this try { @@ -1527,7 +1527,9 @@ U.Map = L.Map.extend({ metadataFields = ['options.name', 'options.description'], title = L.DomUtil.create('h3', '', container) title.textContent = L._('Edit map properties') - const builder = new U.FormBuilder(this, metadataFields, {className: 'map-metadata'}) + const builder = new U.FormBuilder(this, metadataFields, { + className: 'map-metadata', + }) const form = builder.build() container.appendChild(form) this._editControls(container) diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 8624597c..1ae0b1ac 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -609,12 +609,13 @@ U.DataLayer = L.Evented.extend({ }, autoLoaded: function () { - return ( - (this.map.datalayersOnLoad && - this.umap_id && - this.map.datalayersOnLoad.indexOf(this.umap_id.toString()) !== -1) || - (!this.map.datalayersOnLoad && this.options.displayOnLoad) - ) + if (!this.map.datalayersFromQueryString) return this.options.displayOnLoad + const datalayerIds = this.map.datalayersFromQueryString + let loadMe = datalayerIds.includes(this.umap_id.toString()) + if (this.options.old_id) { + loadMe = loadMe || datalayerIds.includes(this.options.old_id.toString()) + } + return loadMe }, insertBefore: function (other) { diff --git a/umap/tests/integration/test_datalayer.py b/umap/tests/integration/test_datalayer.py index 946bae9d..da4ec622 100644 --- a/umap/tests/integration/test_datalayer.py +++ b/umap/tests/integration/test_datalayer.py @@ -106,3 +106,25 @@ def test_should_honour_color_variable(live_server, map, page): expect(page.locator(".leaflet-overlay-pane path[fill='tomato']")) markers = page.locator(".leaflet-marker-icon .icon_container") expect(markers).to_have_css("background-color", "rgb(240, 248, 255)") + + +def test_datalayers_in_query_string(live_server, datalayer, map, page): + with_old_id = DataLayerFactory(old_id=134, map=map, name="with old id") + set_options(with_old_id, name="with old id") + visible = page.locator(".leaflet-control-browse li:not(.off) span") + hidden = page.locator(".leaflet-control-browse li.off span") + page.goto(f"{live_server.url}{map.get_absolute_url()}") + expect(visible).to_have_count(2) + expect(hidden).to_have_count(0) + page.goto(f"{live_server.url}{map.get_absolute_url()}?datalayers={datalayer.pk}") + expect(visible).to_have_count(1) + expect(visible).to_have_text(datalayer.name) + expect(hidden).to_have_count(1) + expect(hidden).to_have_text(with_old_id.name) + page.goto( + f"{live_server.url}{map.get_absolute_url()}?datalayers={with_old_id.old_id}" + ) + expect(visible).to_have_count(1) + expect(visible).to_have_text(with_old_id.name) + expect(hidden).to_have_count(1) + expect(hidden).to_have_text(datalayer.name)