2026-03-31 14:52:53 +00:00
|
|
|
<style scoped>
|
|
|
|
|
.map-container {
|
|
|
|
|
background-color: #e9ecef;
|
|
|
|
|
border-radius: 10px;
|
|
|
|
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
|
|
|
|
|
height: 500px;
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
position: relative;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.map {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 0;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="map-container">
|
|
|
|
|
<div ref="mapContainer" class="map"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2026-03-22 00:55:48 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import "maplibre-gl/dist/maplibre-gl.css";
|
2026-03-31 14:52:53 +00:00
|
|
|
import maplibregl from "maplibre-gl";
|
2026-04-03 19:45:12 +00:00
|
|
|
import type { LngLatBoundsLike, Map as MapLibreMap } from "maplibre-gl";
|
2026-03-31 14:52:53 +00:00
|
|
|
import { onMounted, onUnmounted, ref, shallowRef, type Ref } from "vue";
|
2026-04-09 01:02:25 +00:00
|
|
|
import { Marker } from "@/types";
|
|
|
|
|
import type { Bounds } from "@/type/api";
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-03-31 14:52:53 +00:00
|
|
|
interface Emits {
|
2026-04-22 15:46:02 +00:00
|
|
|
(e: "cell-click", cell: string): void;
|
2026-03-31 14:52:53 +00:00
|
|
|
}
|
2026-03-22 00:55:48 +00:00
|
|
|
interface Props {
|
2026-03-31 14:52:53 +00:00
|
|
|
bounds?: Bounds;
|
2026-04-03 19:45:12 +00:00
|
|
|
markers?: Marker[];
|
2026-03-22 00:55:48 +00:00
|
|
|
organizationId: number;
|
|
|
|
|
tegola: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 14:52:53 +00:00
|
|
|
const emit = defineEmits<Emits>();
|
2026-03-22 00:55:48 +00:00
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
2026-03-31 14:52:53 +00:00
|
|
|
// default bounds cover a bunch of the continental US
|
2026-04-09 00:25:21 +00:00
|
|
|
bounds: (): Bounds => {
|
2026-03-31 14:52:53 +00:00
|
|
|
return {
|
2026-04-06 16:54:48 +00:00
|
|
|
max: { longitude: -70, latitude: 50 },
|
|
|
|
|
min: { longitude: -125, latitude: 25 },
|
2026-03-31 14:52:53 +00:00
|
|
|
};
|
|
|
|
|
},
|
2026-03-22 00:55:48 +00:00
|
|
|
});
|
|
|
|
|
|
2026-03-31 14:52:53 +00:00
|
|
|
const boundsSafe = props.bounds as Bounds;
|
2026-03-22 00:55:48 +00:00
|
|
|
const mapContainer = ref<HTMLElement | null>(null);
|
2026-03-31 14:52:53 +00:00
|
|
|
const map: Ref<MapLibreMap | null> = shallowRef(null);
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-03-31 14:52:53 +00:00
|
|
|
function _bounds(): LngLatBoundsLike {
|
|
|
|
|
return new maplibregl.LngLatBounds(
|
2026-04-06 16:54:48 +00:00
|
|
|
new maplibregl.LngLat(boundsSafe.min.longitude, boundsSafe.min.latitude),
|
|
|
|
|
new maplibregl.LngLat(boundsSafe.max.longitude, boundsSafe.max.latitude),
|
2026-03-31 14:52:53 +00:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-22 00:55:48 +00:00
|
|
|
const initializeMap = () => {
|
|
|
|
|
if (!mapContainer.value) return;
|
|
|
|
|
|
2026-03-31 14:52:53 +00:00
|
|
|
const bounds = _bounds();
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-04-22 15:40:42 +00:00
|
|
|
const _map = new maplibregl.Map({
|
2026-03-22 00:55:48 +00:00
|
|
|
bounds: bounds,
|
|
|
|
|
container: mapContainer.value,
|
|
|
|
|
style: "https://tiles.stadiamaps.com/styles/alidade_smooth.json",
|
|
|
|
|
});
|
2026-04-22 15:40:42 +00:00
|
|
|
map.value = _map;
|
2026-03-22 00:55:48 +00:00
|
|
|
|
|
|
|
|
console.log("Initializing map to bounds", bounds);
|
2026-03-31 14:52:53 +00:00
|
|
|
const mapInstance = map.value;
|
|
|
|
|
if (mapInstance) {
|
|
|
|
|
map.value.on("load", () => {
|
2026-04-22 15:40:42 +00:00
|
|
|
_map.addSource("tegola", {
|
2026-03-31 14:52:53 +00:00
|
|
|
type: "vector",
|
|
|
|
|
tiles: [
|
|
|
|
|
`${props.tegola}maps/nidus/{z}/{x}/{y}?id=${props.organizationId}&organization_id=${props.organizationId}`,
|
|
|
|
|
],
|
|
|
|
|
});
|
2026-04-22 15:40:42 +00:00
|
|
|
console.log("Added tegola", props.tegola, props.organizationId);
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-04-22 15:40:42 +00:00
|
|
|
_map.addLayer({
|
2026-03-31 14:52:53 +00:00
|
|
|
id: "mosquito_source",
|
|
|
|
|
type: "fill",
|
|
|
|
|
filter: [
|
|
|
|
|
"==",
|
|
|
|
|
["zoom"],
|
|
|
|
|
["+", 2, ["to-number", ["get", "resolution"]]],
|
|
|
|
|
],
|
|
|
|
|
source: "tegola",
|
|
|
|
|
"source-layer": "mosquito_source",
|
|
|
|
|
paint: {
|
|
|
|
|
"fill-opacity": 0.4,
|
|
|
|
|
"fill-color": "#dc3545",
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-04-22 15:40:42 +00:00
|
|
|
_map.addLayer({
|
2026-03-31 14:52:53 +00:00
|
|
|
id: "service_request",
|
|
|
|
|
type: "fill",
|
|
|
|
|
filter: [
|
|
|
|
|
"==",
|
|
|
|
|
["zoom"],
|
|
|
|
|
["+", 2, ["to-number", ["get", "resolution"]]],
|
|
|
|
|
],
|
|
|
|
|
source: "tegola",
|
|
|
|
|
"source-layer": "service_request",
|
|
|
|
|
paint: {
|
|
|
|
|
"fill-opacity": 0.4,
|
|
|
|
|
"fill-color": "#ffc107",
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-04-22 15:40:42 +00:00
|
|
|
_map.addLayer({
|
2026-03-31 14:52:53 +00:00
|
|
|
id: "trap",
|
|
|
|
|
type: "fill",
|
|
|
|
|
filter: [
|
|
|
|
|
"==",
|
|
|
|
|
["zoom"],
|
|
|
|
|
["+", 2, ["to-number", ["get", "resolution"]]],
|
|
|
|
|
],
|
|
|
|
|
source: "tegola",
|
|
|
|
|
"source-layer": "trap",
|
|
|
|
|
paint: {
|
|
|
|
|
"fill-opacity": 0.4,
|
|
|
|
|
"fill-color": "#0dcaf0",
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-04-22 15:40:42 +00:00
|
|
|
_map.addLayer({
|
2026-03-31 14:52:53 +00:00
|
|
|
id: "service-area",
|
|
|
|
|
source: "tegola",
|
|
|
|
|
"source-layer": "service-area-bounds",
|
|
|
|
|
type: "line",
|
|
|
|
|
paint: {
|
|
|
|
|
"line-color": "#f00",
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-04-22 15:40:42 +00:00
|
|
|
_map.on("mouseenter", "mosquito_source", () => {
|
2026-03-31 14:52:53 +00:00
|
|
|
if (map.value) {
|
|
|
|
|
map.value.getCanvas().style.cursor = "pointer";
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-04-22 15:40:42 +00:00
|
|
|
_map.on("mouseleave", "mosquito_source", () => {
|
2026-03-31 14:52:53 +00:00
|
|
|
if (map.value) {
|
|
|
|
|
map.value.getCanvas().style.cursor = "";
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-03-31 14:52:53 +00:00
|
|
|
const handleClick = (e: maplibregl.MapLayerMouseEvent) => {
|
|
|
|
|
if (!e.features || e.features.length === 0) return;
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-03-31 14:52:53 +00:00
|
|
|
const feature = e.features[0];
|
|
|
|
|
const properties = feature.properties;
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-03-31 14:52:53 +00:00
|
|
|
emit("cell-click", properties.cell);
|
|
|
|
|
};
|
2026-03-22 00:55:48 +00:00
|
|
|
|
2026-04-22 15:40:42 +00:00
|
|
|
_map.on("click", "mosquito_source", handleClick);
|
|
|
|
|
_map.on("click", "service_request", handleClick);
|
|
|
|
|
_map.on("click", "trap", handleClick);
|
2026-03-31 14:52:53 +00:00
|
|
|
});
|
|
|
|
|
}
|
2026-03-22 00:55:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const jumpTo = (args: maplibregl.JumpToOptions) => {
|
|
|
|
|
if (map.value) {
|
|
|
|
|
map.value.jumpTo(args);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
setTimeout(() => initializeMap(), 0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
if (map.value) {
|
|
|
|
|
map.value.remove();
|
|
|
|
|
map.value = null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Expose public methods
|
|
|
|
|
defineExpose({
|
|
|
|
|
jumpTo,
|
|
|
|
|
});
|
|
|
|
|
</script>
|