Add click event for cells on the dash map
This commit is contained in:
parent
a88aa4c8a0
commit
e5080eaaf6
2 changed files with 21 additions and 6 deletions
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue