Add map action for map click
This commit is contained in:
parent
d89b12c57d
commit
fcb3ce4da3
|
@ -2566,6 +2566,21 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "event",
|
||||||
|
"label": "On map click",
|
||||||
|
"key": "onMapClick",
|
||||||
|
"context": [
|
||||||
|
{
|
||||||
|
"label": "Clicked latitude",
|
||||||
|
"key": "lat"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Clicked longitude",
|
||||||
|
"key": "lng"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"label": "Enable Fullscreen",
|
"label": "Enable Fullscreen",
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
export let tileURL = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
export let tileURL = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||||
export let mapAttribution
|
export let mapAttribution
|
||||||
export let onMarkerClick
|
export let onMarkerClick
|
||||||
|
export let onMapClick
|
||||||
|
|
||||||
const { styleable, notificationStore } = getContext("sdk")
|
const { styleable, notificationStore } = getContext("sdk")
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
|
@ -65,6 +66,14 @@
|
||||||
paddingTopLeft: [0, 24],
|
paddingTopLeft: [0, 24],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
$: mapInstance?.on("click", e => {
|
||||||
|
if (onMapClick) {
|
||||||
|
onMapClick({
|
||||||
|
lat: e.latlng.lat,
|
||||||
|
lng: e.latlng.lng,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const updateMapDimensions = mapInstance => {
|
const updateMapDimensions = mapInstance => {
|
||||||
if (typeof mapInstance !== "object") {
|
if (typeof mapInstance !== "object") {
|
||||||
|
@ -197,7 +206,14 @@
|
||||||
maxZoomLevel,
|
maxZoomLevel,
|
||||||
}
|
}
|
||||||
|
|
||||||
const addMapMarkers = (mapInstance, rows, latKey, lngKey, titleKey, onClick) => {
|
const addMapMarkers = (
|
||||||
|
mapInstance,
|
||||||
|
rows,
|
||||||
|
latKey,
|
||||||
|
lngKey,
|
||||||
|
titleKey,
|
||||||
|
onClick
|
||||||
|
) => {
|
||||||
if (typeof mapInstance !== "object" || !rows || !latKey || !lngKey) {
|
if (typeof mapInstance !== "object" || !rows || !latKey || !lngKey) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -218,15 +234,17 @@
|
||||||
row[titleKey]
|
row[titleKey]
|
||||||
)
|
)
|
||||||
|
|
||||||
marker.bindTooltip(markerContent, {
|
marker
|
||||||
direction: "top",
|
.bindTooltip(markerContent, {
|
||||||
offset: [0, -25]
|
direction: "top",
|
||||||
}).addTo(mapMarkerGroup)
|
offset: [0, -25],
|
||||||
|
})
|
||||||
|
.addTo(mapMarkerGroup)
|
||||||
|
|
||||||
if (onClick) {
|
if (onClick) {
|
||||||
marker.on("click", () => {
|
marker.on("click", () => {
|
||||||
onClick({
|
onClick({
|
||||||
marker: row
|
marker: row,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue