mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 20:46:01 +00:00
fixed No mapping #575
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
function addObjectToMap() {
|
||||
if (!map) return;
|
||||
if (!geoJson) return;
|
||||
|
||||
for (const layer of layers) {
|
||||
layer.remove();
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
return res;
|
||||
}
|
||||
export function findLatPaths(obj) {
|
||||
return findLatLonPaths(obj, x => x.includes('lat'));
|
||||
return findLatLonPaths(obj, x => x.toLowerCase()?.includes('lat'));
|
||||
}
|
||||
export function findLonPaths(obj) {
|
||||
return findLatLonPaths(obj, x => x.includes('lon') || x.includes('lng'));
|
||||
return findLatLonPaths(obj, x => x.toLowerCase()?.includes('lon') || x.toLowerCase()?.includes('lng'));
|
||||
}
|
||||
export function findAllObjectPaths(obj) {
|
||||
return findLatLonPaths(obj, (_k, v) => v != null && !_.isNaN(Number(v)));
|
||||
@@ -33,21 +33,6 @@
|
||||
}
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import _ from 'lodash';
|
||||
import 'leaflet/dist/leaflet.css';
|
||||
import wellknown from 'wellknown';
|
||||
import { isWktGeometry, stringifyCellValue } from 'dbgate-tools';
|
||||
import MapView from './MapView.svelte';
|
||||
|
||||
export let selection;
|
||||
|
||||
export let latitudeField = '';
|
||||
export let longitudeField = '';
|
||||
|
||||
let geoJson;
|
||||
|
||||
function createColumnsTable(cells) {
|
||||
if (cells.length == 0) return '';
|
||||
@@ -56,9 +41,10 @@
|
||||
.join('\n')}</table>`;
|
||||
}
|
||||
|
||||
function createGeoJson() {
|
||||
export function createGeoJsonFromSelection(selection, latitudeFieldDef = null, longitudeFieldDef = null) {
|
||||
const selectedRows = _.groupBy(selection || [], 'row');
|
||||
|
||||
console.log('ROWS', selectedRows);
|
||||
const features = [];
|
||||
|
||||
for (const rowKey of _.keys(selectedRows)) {
|
||||
@@ -66,6 +52,9 @@
|
||||
|
||||
const geoValues = cells.map(x => x.value).filter(isWktGeometry);
|
||||
|
||||
const latitudeField = latitudeFieldDef ?? findLatPaths(cells[0].rowData)[0];
|
||||
const longitudeField = longitudeFieldDef ?? findLonPaths(cells[0].rowData)[0];
|
||||
|
||||
const lat = latitudeField ? Number(_.get(cells[0].rowData, latitudeField)) : NaN;
|
||||
const lon = longitudeField ? Number(_.get(cells[0].rowData, longitudeField)) : NaN;
|
||||
|
||||
@@ -97,14 +86,37 @@
|
||||
}
|
||||
|
||||
if (features.length == 0) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
geoJson = {
|
||||
return {
|
||||
type: 'FeatureCollection',
|
||||
features,
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import _ from 'lodash';
|
||||
import 'leaflet/dist/leaflet.css';
|
||||
import wellknown from 'wellknown';
|
||||
import { isWktGeometry, stringifyCellValue } from 'dbgate-tools';
|
||||
import MapView from './MapView.svelte';
|
||||
|
||||
export let selection;
|
||||
|
||||
export let latitudeField = '';
|
||||
export let longitudeField = '';
|
||||
|
||||
let geoJson;
|
||||
|
||||
function createGeoJson() {
|
||||
const res = createGeoJsonFromSelection(selection, latitudeField, longitudeField);
|
||||
|
||||
if (res) {
|
||||
geoJson = res;
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
selection;
|
||||
|
||||
Reference in New Issue
Block a user