yak_handcuffs/src/views/monitoringCenter/deviceLocationMap.vue

119 lines
3.3 KiB
Vue
Raw Normal View History

2025-04-25 18:23:20 +08:00
<template>
<div class="monitoringMap" id="mapcontainer"></div>
<div :style="{ display: 'none' }">
<InfoWindow class="infoBox" :value="locationInfo" @close="InfoWin.close()" />
</div>
</template>
<script lang="ts" setup>
import { locateRecord } from "@/api";
import { format } from "@/utils";
import { MapCustom } from "@/utils/mapCustom";
import { onMounted, ref, watch } from "vue";
import InfoWindow from "@/components/InfoWindow.vue";
2025-04-28 17:18:11 +08:00
import ViaMarker from "@/assets/img/via-marker.png";
import endMarker from "@/assets/img/end-marker.png";
import startMarker from "@/assets/img/start-marker.png";
2025-04-25 18:23:20 +08:00
let InfoWin = null;
let newMap = null;
let locationInfo = ref({});
const props = defineProps({
deviceId: {
type: String || Number,
default: "",
},
});
watch(
() => props.deviceId,
(newVal) => {
if (newVal) {
getLocateRecord();
}
}
);
const getLocateRecord = () => {
let d = new Date();
locateRecord({
deviceId: props.deviceId,
startDate: `${format(d, "YYYY-MM-DD")} 00:00:00`,
endDate: `${format(d, "YYYY-MM-DD")} 23:59:59`,
}).then((res) => {
if (res && res.length) {
let list = res;
newMap.clearMap();
newMap.setCenter([list[0].lng, list[0].lat]);
newMap.polyline(list);
2025-04-28 17:18:11 +08:00
let startIcon = newMap.newIcon({
image: startMarker,
size: [20, 29],
});
let endIcon = newMap.newIcon({
image: endMarker,
size: [20, 29],
});
let ViaIcon = newMap.newIcon({
image: ViaMarker,
size: [20, 29],
});
2025-04-29 18:31:02 +08:00
let markers = [];
2025-04-28 17:18:11 +08:00
list.forEach((item, index) => {
2025-04-29 18:31:02 +08:00
if (list.length < 50) {
let marker: any = "";
if (index == 0) {
marker = newMap.marker({ icon: endIcon, position: [item.lng, item.lat], zIndex: 13 });
} else if (index == list.length - 1) {
marker = newMap.marker({ icon: startIcon, position: [item.lng, item.lat], zIndex: 13 });
} else {
marker = newMap.marker({ icon: ViaIcon, position: [item.lng, item.lat], zIndex: 12 });
}
marker.on("click", () => {
locationInfo.value = item;
InfoWin = newMap.infoWindow();
InfoWin.open(newMap.map, marker.getPosition());
});
markers.push(marker);
2025-04-28 17:18:11 +08:00
} else {
2025-04-29 18:31:02 +08:00
if (index % 5 == 0) {
let marker: any = "";
if (index == 0) {
marker = newMap.marker({ icon: endIcon, position: [item.lng, item.lat], zIndex: 13 });
} else if (index == list.length - 1) {
marker = newMap.marker({ icon: startIcon, position: [item.lng, item.lat], zIndex: 13 });
} else {
marker = newMap.marker({ icon: ViaIcon, position: [item.lng, item.lat], zIndex: 12 });
}
marker.on("click", () => {
locationInfo.value = item;
InfoWin = newMap.infoWindow();
InfoWin.open(newMap.map, marker.getPosition());
});
markers.push(marker);
}
2025-04-28 17:18:11 +08:00
}
2025-04-25 18:23:20 +08:00
});
2025-04-29 18:31:02 +08:00
newMap.map.add(markers);
2025-04-25 18:23:20 +08:00
}
});
};
2025-04-29 18:31:02 +08:00
const fn = () => {
// this.cluster.on("click", this.clusterClickEvent);
};
2025-04-25 18:23:20 +08:00
onMounted(() => {
newMap = new MapCustom({ dom: "mapcontainer" });
getLocateRecord();
});
</script>
<style scoped lang="less">
.monitoringMap {
width: 100%;
height: 400px;
flex-shrink: 0;
}
</style>