From 8c418287e4169f0ae72382846ba861bb2684e86a Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 16 Apr 2024 17:39:15 +0200 Subject: [PATCH] feat: display a message when importer cannot find lat/lng columns fix #1699 --- umap/static/umap/js/umap.layer.js | 15 +++++++++++++-- umap/tests/integration/test_import.py | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index e7d730fe..be440642 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -463,8 +463,8 @@ U.Layer.Heat = L.HeatLayer.extend({ this._latlngs[i].alt !== undefined ? this._latlngs[i].alt : this._latlngs[i][2] !== undefined - ? +this._latlngs[i][2] - : 1 + ? +this._latlngs[i][2] + : 1 grid[y] = grid[y] || [] cell = grid[y][x] @@ -947,6 +947,17 @@ U.DataLayer = L.Evented.extend({ includeLatLon: false, }, (err, result) => { + // csv2geojson fallback to null geometries when it cannot determine + // lat or lon columns. This is valid geojson, but unwanted from a user + // point of view. + if (result && result.features.length) { + if (result.features[0].geometry === null) { + err = { + type: 'Error', + message: L._('Cannot determine latitude and longitude columns.'), + } + } + } if (err) { let message if (err.type === 'Error') { diff --git a/umap/tests/integration/test_import.py b/umap/tests/integration/test_import.py index 684eae04..53c680d2 100644 --- a/umap/tests/integration/test_import.py +++ b/umap/tests/integration/test_import.py @@ -411,3 +411,19 @@ def test_import_multipolyline(live_server, page, tilelayer): # A layer has been created expect(layers).to_have_count(1) expect(paths).to_have_count(1) + + +def test_import_csv_without_valid_latlon_headers(tilelayer, live_server, page): + page.goto(f"{live_server.url}/map/new/") + page.get_by_title("See layers").click() + layers = page.locator(".umap-browser .datalayer") + markers = page.locator(".leaflet-marker-icon") + page.get_by_title("Import data").click() + textarea = page.locator(".umap-upload textarea") + textarea.fill("a,b,c\n12.23,48.34,mypoint\n12.23,48.34,mypoint2") + page.locator('select[name="format"]').select_option("csv") + page.get_by_role("button", name="Import", exact=True).click() + # FIXME do not create a layer + expect(layers).to_have_count(1) + expect(markers).to_have_count(0) + expect(page.locator(".umap-alert")).to_be_visible()