diff --git a/umap/static/umap/js/modules/data/layer.js b/umap/static/umap/js/modules/data/layer.js index 5d7e8eaf..f3e51eac 100644 --- a/umap/static/umap/js/modules/data/layer.js +++ b/umap/static/umap/js/modules/data/layer.js @@ -81,7 +81,7 @@ export class DataLayer { this.connectToMap() this.permissions = new DataLayerPermissions(this._umap, this) - this._needsFetch = this.createdOnServer + this._needsFetch = this.createdOnServer || this.isRemoteLayer() if (!this.createdOnServer) { if (this.showAtLoad()) this.show() } @@ -261,8 +261,11 @@ export class DataLayer { if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat geojson._umap_options.id = this.id if (geojson._umap_options) this.setOptions(geojson._umap_options) - if (this.isRemoteLayer()) await this.fetchRemoteData() - else this.fromGeoJSON(geojson, false) + if (this.isRemoteLayer()) { + await this.fetchRemoteData() + } else { + this.fromGeoJSON(geojson, false) + } } clear() { diff --git a/umap/tests/fixtures/remote_data.umap b/umap/tests/fixtures/remote_data.umap new file mode 100644 index 00000000..abd2aea4 --- /dev/null +++ b/umap/tests/fixtures/remote_data.umap @@ -0,0 +1,55 @@ +{ + "type": "umap", + "uri": "http://localhost:8020/fr/map/carte-sans-nom_128#6/50.233/6.910", + "properties": { + "easing": false, + "embedControl": true, + "fullscreenControl": true, + "searchControl": true, + "datalayersControl": true, + "zoomControl": true, + "permanentCreditBackground": true, + "slideshow": {}, + "captionMenus": true, + "captionBar": false, + "limitBounds": {}, + "overlay": null, + "licence": "", + "description": "", + "name": "Carte sans nom", + "displayPopupFooter": false, + "miniMap": false, + "moreControl": true, + "scaleControl": true, + "scrollWheelZoom": true, + "zoom": 6 + }, + "geometry": { + "type": "Point", + "coordinates": [ + 6.734619140625, + 50.359480346298696 + ] + }, + "layers": [ + { + "type": "FeatureCollection", + "features": [], + "_umap_options": { + "name": "Itinéraire D", + "color": "#d34e8d", + "editMode": "advanced", + "browsable": true, + "inCaption": true, + "remoteData": { + "url": "https://remote.org/data.json", + "format": "geojson" + }, + "permissions": { + "edit_status": 0 + }, + "displayOnLoad": true + } + } + ] +} diff --git a/umap/tests/integration/test_import.py b/umap/tests/integration/test_import.py index 9429be55..779aae75 100644 --- a/umap/tests/integration/test_import.py +++ b/umap/tests/integration/test_import.py @@ -650,6 +650,46 @@ def test_create_remote_data(page, live_server, tilelayer): ) +def test_create_remote_data_from_umap_backup(page, live_server, tilelayer): + def handle(route): + route.fulfill( + json={ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [4.3375, 51.2707], + }, + } + ], + } + ) + + page.route("https://remote.org/data.json", handle) + page.goto(f"{live_server.url}/map/new/") + expect(page.locator(".leaflet-marker-icon")).to_be_hidden() + page.get_by_title("Import data").click() + file_input = page.locator("input[type='file']") + with page.expect_file_chooser() as fc_info: + file_input.click() + file_chooser = fc_info.value + path = Path(__file__).parent.parent / "fixtures/remote_data.umap" + file_chooser.set_files(path) + page.get_by_role("button", name="Import data", exact=True).click() + page.get_by_title("Open browser").click() + layers = page.locator(".umap-browser .datalayer") + expect(layers).to_have_count(1) + expect(page.locator(".leaflet-marker-icon")).to_be_visible() + page.get_by_role("button", name="Edit", exact=True).click() + page.locator("summary").filter(has_text="Remote data").click() + expect(page.locator('.panel input[name="url"]')).to_have_value( + "https://remote.org/data.json" + ) + + def test_import_geojson_from_url(page, live_server, tilelayer): def handle(route): route.fulfill(