diff --git a/packages/web/src/celldata/MapCellView.svelte b/packages/web/src/celldata/MapCellView.svelte index e0d080c5..6a0d58d6 100644 --- a/packages/web/src/celldata/MapCellView.svelte +++ b/packages/web/src/celldata/MapCellView.svelte @@ -1,7 +1,60 @@ - +
+ {#if allFields.length >= 2} +
+ Lat: + ({ label: x, value: x }))} + value={latitudeField} + on:change={e => { + latitudeField = e.detail; + }} + /> + Lon: + ({ label: x, value: x }))} + value={longitudeField} + on:change={e => { + longitudeField = e.detail; + }} + /> +
+ {/if} + + +
+ + diff --git a/packages/web/src/datagrid/InplaceEditor.svelte b/packages/web/src/datagrid/InplaceEditor.svelte index 3da02876..dee1f17e 100644 --- a/packages/web/src/datagrid/InplaceEditor.svelte +++ b/packages/web/src/datagrid/InplaceEditor.svelte @@ -1,12 +1,3 @@ - - @@ -21,7 +49,7 @@ import 'leaflet/dist/leaflet.css'; import leaflet from 'leaflet'; import wellknown from 'wellknown'; - import { isWktGeometry, ScriptWriter, ScriptWriterJson } from 'dbgate-tools'; + import { isWktGeometry, ScriptWriter, ScriptWriterJson, stringifyCellValue } from 'dbgate-tools'; import resizeObserver from '../utility/resizeObserver'; import openNewTab from '../utility/openNewTab'; import contextMenu from '../utility/contextMenu'; @@ -31,6 +59,9 @@ export let selection; + export let latitudeField = ''; + export let longitudeField = ''; + let refContainer; let map; @@ -39,7 +70,9 @@ function createColumnsTable(cells) { if (cells.length == 0) return ''; - return `${cells.map(cell => ``).join('\n')}
${cell.column}${cell.value}
`; + return `${cells + .map(cell => ``) + .join('\n')}
${cell.column}${stringifyCellValue(cell.value)}
`; } function addSelectionToMap() { @@ -57,12 +90,15 @@ for (const rowKey of _.keys(selectedRows)) { const cells = selectedRows[rowKey]; - const lat = cells.find(x => x.column.toLowerCase().includes('lat')); - const lon = cells.find(x => x.column.toLowerCase().includes('lon') || x.column.toLowerCase().includes('lng')); + // const lat = cells.find(x => x.column.toLowerCase().includes('lat')); + // const lon = cells.find(x => x.column.toLowerCase().includes('lon') || x.column.toLowerCase().includes('lng')); const geoValues = cells.map(x => x.value).filter(isWktGeometry); - if (lat && lon) { + const lat = latitudeField ? Number(_.get(cells[0].rowData, latitudeField)) : NaN; + const lon = longitudeField ? Number(_.get(cells[0].rowData, longitudeField)) : NaN; + + if (!_.isNaN(lat) && !_.isNaN(lon)) { features.push({ type: 'Feature', properties: { @@ -70,7 +106,7 @@ }, geometry: { type: 'Point', - coordinates: [lon.value, lat.value], + coordinates: [Number(lon), Number(lat)], }, }); } @@ -156,6 +192,8 @@ $: { selection; + latitudeField; + longitudeField; addSelectionToMap(); } diff --git a/packages/web/src/widgets/CellDataWidget.svelte b/packages/web/src/widgets/CellDataWidget.svelte index 4d7b9c0a..7889c8c6 100644 --- a/packages/web/src/widgets/CellDataWidget.svelte +++ b/packages/web/src/widgets/CellDataWidget.svelte @@ -47,14 +47,14 @@ ]; function autodetect(selection) { - if (selection[0]?.engine?.databaseEngineTypes?.includes('document')) { - return 'jsonRow'; - } - if (selectionCouldBeShownOnMap(selection)) { return 'map'; } + if (selection[0]?.engine?.databaseEngineTypes?.includes('document')) { + return 'jsonRow'; + } + const value = selection.length == 1 ? selection[0].value : null; if (_.isString(value)) { if (value.startsWith('[') || value.startsWith('{')) return 'json';