fix: remote data loading on import from umap backup (#2598)

This commit is contained in:
David Larlet 2025-04-04 11:15:23 -04:00 committed by GitHub
commit d6f591b365
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 101 additions and 3 deletions

View file

@ -81,7 +81,7 @@ export class DataLayer {
this.connectToMap() this.connectToMap()
this.permissions = new DataLayerPermissions(this._umap, this) this.permissions = new DataLayerPermissions(this._umap, this)
this._needsFetch = this.createdOnServer this._needsFetch = this.createdOnServer || this.isRemoteLayer()
if (!this.createdOnServer) { if (!this.createdOnServer) {
if (this.showAtLoad()) this.show() if (this.showAtLoad()) this.show()
} }
@ -261,8 +261,11 @@ export class DataLayer {
if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat
geojson._umap_options.id = this.id geojson._umap_options.id = this.id
if (geojson._umap_options) this.setOptions(geojson._umap_options) if (geojson._umap_options) this.setOptions(geojson._umap_options)
if (this.isRemoteLayer()) await this.fetchRemoteData() if (this.isRemoteLayer()) {
else this.fromGeoJSON(geojson, false) await this.fetchRemoteData()
} else {
this.fromGeoJSON(geojson, false)
}
} }
clear() { clear() {

55
umap/tests/fixtures/remote_data.umap vendored Normal file
View file

@ -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
}
}
]
}

View file

@ -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 test_import_geojson_from_url(page, live_server, tilelayer):
def handle(route): def handle(route):
route.fulfill( route.fulfill(