Add click event for cells on the dash map

This commit is contained in:
Eli Ribble 2026-04-24 13:23:03 +00:00
parent a88aa4c8a0
commit e5080eaaf6
No known key found for this signature in database
2 changed files with 21 additions and 6 deletions

View file

@ -6,8 +6,10 @@
import maplibregl from "maplibre-gl";
import { inject, onMounted, onBeforeUnmount, Ref, useAttrs, watch } from "vue";
export type MouseEvent = maplibregl.MapLayerMouseEvent;
type LayerType = maplibregl.LayerSpecification["type"];
interface Emits {
(e: "click", evt: MouseEvent): void;
(e: "mouseenter"): void;
(e: "mouseleave"): void;
}
@ -24,7 +26,7 @@ const attrs = useAttrs();
const emit = defineEmits<Emits>();
const props = withDefaults(defineProps<Props>(), {});
type OnCallbackFunc = () => void;
type OnCallbackFunc = (e?: MouseEvent) => void;
type RegisterOnFunc = (
eventname: string,
layerid: string,
@ -56,6 +58,13 @@ onMounted(() => {
if (registerLayer) {
registerLayer(props.id, getLayerConfig());
}
if (registerOn) {
registerOn("click", props.id, (e?: MouseEvent) => {
if (e) {
emit("click", e);
}
});
}
if (registerOn) {
registerOn("mouseenter", props.id, () => {
emit("mouseenter");