mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 03:45:59 +00:00
show popup on map
This commit is contained in:
@@ -19,6 +19,10 @@
|
|||||||
|
|
||||||
let selectionLayers = [];
|
let selectionLayers = [];
|
||||||
|
|
||||||
|
function createColumnsTable(cells) {
|
||||||
|
return `<table>${cells.map(cell => `<tr><td>${cell.column}</td><td>${cell.value}</td></tr>`).join('\n')}</table>`;
|
||||||
|
}
|
||||||
|
|
||||||
function addSelectionToMap() {
|
function addSelectionToMap() {
|
||||||
if (!map) return;
|
if (!map) return;
|
||||||
if (!selection) return;
|
if (!selection) return;
|
||||||
@@ -28,36 +32,51 @@
|
|||||||
}
|
}
|
||||||
selectionLayers = [];
|
selectionLayers = [];
|
||||||
|
|
||||||
const geoValues = selection.map(x => x.value).filter(isWktGeometry);
|
|
||||||
|
|
||||||
const geometries = [];
|
|
||||||
|
|
||||||
if (geoValues.length > 0) {
|
|
||||||
// parse WKT to geoJSON array
|
|
||||||
geometries.push(...geoValues.map(wellknown));
|
|
||||||
}
|
|
||||||
|
|
||||||
const selectedRows = _.groupBy(selection || [], 'row');
|
const selectedRows = _.groupBy(selection || [], 'row');
|
||||||
|
|
||||||
|
const features = [];
|
||||||
|
|
||||||
for (const rowKey of _.keys(selectedRows)) {
|
for (const rowKey of _.keys(selectedRows)) {
|
||||||
const cells = selectedRows[rowKey];
|
const cells = selectedRows[rowKey];
|
||||||
const lat = cells.find(x => x.column.toLowerCase().includes('lat'));
|
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 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) {
|
if (lat && lon) {
|
||||||
geometries.push({
|
features.push({
|
||||||
type: 'Point',
|
type: 'Feature',
|
||||||
coordinates: [lon.value, lat.value],
|
properties: {
|
||||||
|
popupContent: createColumnsTable(cells),
|
||||||
|
},
|
||||||
|
geometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: [lon.value, lat.value],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (geoValues.length > 0) {
|
||||||
|
// parse WKT to geoJSON array
|
||||||
|
features.push(
|
||||||
|
...geoValues.map(wellknown).map(geometry => ({
|
||||||
|
type: 'Feature',
|
||||||
|
properties: {
|
||||||
|
popupContent: createColumnsTable(cells.filter(x => !isWktGeometry(x.value))),
|
||||||
|
},
|
||||||
|
geometry,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (geometries.length == 0) {
|
if (features.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const geoJson = {
|
const geoJson = {
|
||||||
type: 'GeometryCollection',
|
type: 'FeatureCollection',
|
||||||
geometries,
|
features,
|
||||||
};
|
};
|
||||||
|
|
||||||
const geoJsonObj = leaflet
|
const geoJsonObj = leaflet
|
||||||
@@ -71,7 +90,7 @@
|
|||||||
fillOpacity: 0.4,
|
fillOpacity: 0.4,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
pointToLayer: function (feature, latlng) {
|
pointToLayer: (feature, latlng) => {
|
||||||
return leaflet.circleMarker(latlng, {
|
return leaflet.circleMarker(latlng, {
|
||||||
radius: 7,
|
radius: 7,
|
||||||
weight: 2,
|
weight: 2,
|
||||||
@@ -81,29 +100,21 @@
|
|||||||
fillOpacity: 0.4,
|
fillOpacity: 0.4,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
onEachFeature: (feature, layer) => {
|
||||||
|
// does this feature have a property named popupContent?
|
||||||
|
if (feature.properties && feature.properties.popupContent) {
|
||||||
|
layer.bindPopup(feature.properties.popupContent);
|
||||||
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.addTo(map);
|
.addTo(map);
|
||||||
|
// geoJsonObj.bindPopup('This is the Transamerica Pyramid'); //.openPopup();
|
||||||
map.fitBounds(geoJsonObj.getBounds());
|
map.fitBounds(geoJsonObj.getBounds());
|
||||||
selectionLayers.push(geoJsonObj);
|
selectionLayers.push(geoJsonObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
// new Map({
|
map = leaflet.map(refContainer).setView([50, 15], 13);
|
||||||
// target: refContainer,
|
|
||||||
// layers: [
|
|
||||||
// new TileLayer({
|
|
||||||
// source: new XYZ({
|
|
||||||
// url: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
||||||
// }),
|
|
||||||
// }),
|
|
||||||
// ],
|
|
||||||
// view: new View({
|
|
||||||
// center: [0, 0],
|
|
||||||
// zoom: 2,
|
|
||||||
// }),
|
|
||||||
// });
|
|
||||||
|
|
||||||
map = leaflet.map(refContainer); // .setView([51.505, -0.09], 13);
|
|
||||||
|
|
||||||
leaflet
|
leaflet
|
||||||
.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ import { isWktGeometry } from 'dbgate-tools';
|
|||||||
return 'jsonRow';
|
return 'jsonRow';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selection.length > 0 && _.every(selection, x => isWktGeometry(x.value))) {
|
if (selection.length > 0 && _.find(selection, x => isWktGeometry(x.value))) {
|
||||||
return 'map';
|
return 'map';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user