feat: display a message when importer cannot find lat/lng columns

fix #1699
This commit is contained in:
Yohan Boniface 2024-04-16 17:39:15 +02:00
parent 05fd33deb7
commit 8c418287e4
2 changed files with 29 additions and 2 deletions

View file

@ -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') {

View file

@ -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()