Change cursor when the user hovers over a layer

This commit is contained in:
Eli Ribble 2026-04-24 00:36:18 +00:00
parent 6992031007
commit a88aa4c8a0
No known key found for this signature in database
2 changed files with 18 additions and 4 deletions

View file

@ -25,15 +25,19 @@ import {
ref,
type Ref,
shallowRef,
watch,
} from "vue";
interface Props {
bounds?: maplibregl.LngLatBounds;
center?: maplibregl.LngLatLike;
cursor?: string;
zoom?: number;
}
const props = withDefaults(defineProps<Props>(), {});
const props = withDefaults(defineProps<Props>(), {
cursor: "",
});
const mapDiv = ref<HTMLElement | null>(null);
const map: Ref<maplibregl.Map | null> = shallowRef(null);
@ -150,4 +154,12 @@ onBeforeUnmount(() => {
map.value.remove();
}
});
watch(
() => props.cursor,
(newCursor) => {
if (map.value && map.value.loaded()) {
map.value.getCanvas().style.cursor = newCursor;
}
},
);
</script>

View file

@ -135,6 +135,7 @@
<Map
:bounds="mapBounds()"
@cell-click="doClickMap"
:cursor="mapCursor"
class="map"
:markers="[]"
:organizationId="session.organization?.id ?? 1"
@ -234,7 +235,7 @@
</template>
<script setup lang="ts">
import { onMounted, reactive } from "vue";
import { onMounted, reactive, ref } from "vue";
import Map from "@/map/Map.vue";
import Layer from "@/map/Layer.vue";
import Source from "@/map/Source.vue";
@ -265,6 +266,7 @@ const dashboard = reactive({
},
recentRequests: [],
});
const mapCursor = ref<string>("");
const storeServiceRequest = useStoreServiceRequest();
const storeSync = useStoreSync();
const session = useSessionStore();
@ -277,10 +279,10 @@ function doClickMap(cell: string) {
router.push("/_/cell/" + cell);
}
function doLayerMouseEnter() {
console.log("enter");
mapCursor.value = "pointer";
}
function doLayerMouseLeave() {
console.log("leave");
mapCursor.value = "";
}
function mapBounds(): maplibregl.LngLatBounds {
if (session.organization?.service_area) {