Merge pull request #1753 from umap-project/msg-no-csv-header

feat: display a message when importer cannot find lat/lng columns
This commit is contained in:
Yohan Boniface 2024-04-19 16:05:04 +02:00 committed by GitHub
commit 65e226ff1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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 !== undefined
? this._latlngs[i].alt ? this._latlngs[i].alt
: this._latlngs[i][2] !== undefined : this._latlngs[i][2] !== undefined
? +this._latlngs[i][2] ? +this._latlngs[i][2]
: 1 : 1
grid[y] = grid[y] || [] grid[y] = grid[y] || []
cell = grid[y][x] cell = grid[y][x]
@ -947,6 +947,17 @@ U.DataLayer = L.Evented.extend({
includeLatLon: false, includeLatLon: false,
}, },
(err, result) => { (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) { if (err) {
let message let message
if (err.type === 'Error') { if (err.type === 'Error') {

View file

@ -431,3 +431,19 @@ def test_import_multipolyline(live_server, page, tilelayer):
# A layer has been created # A layer has been created
expect(layers).to_have_count(1) expect(layers).to_have_count(1)
expect(paths).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()