|
@@ -125,7 +125,7 @@ import mapIconFire from "../assets/images/map-icon-fire.png"; // 着火点
|
|
|
import mapIconSzxhs from "../assets/images/map-icon-szxhs.png"; // 市政消火栓
|
|
|
import mapIconTrsy from "../assets/images/map-icon-trsy.png"; // 天然水源
|
|
|
import mapIconSfsc from "../assets/images/map-icon-xfsc.png"; // 消防水池
|
|
|
-import { getZy } from "@/api/map.js";
|
|
|
+import { getZy, getCarInfo } from "@/api/map.js";
|
|
|
export default {
|
|
|
name: "MapContainer",
|
|
|
components: {},
|
|
@@ -200,16 +200,17 @@ export default {
|
|
|
jzKey: [],
|
|
|
xfzKey: [],
|
|
|
jgKey: [],
|
|
|
- xfcKey: [],
|
|
|
},
|
|
|
+ xfcKey: [],
|
|
|
legendWindow: null,
|
|
|
infoWindow: null,
|
|
|
+ AMap: null,
|
|
|
+ timer: null
|
|
|
};
|
|
|
},
|
|
|
props: {
|
|
|
id: {
|
|
|
- type: Number,
|
|
|
- default: 1,
|
|
|
+ type: String
|
|
|
},
|
|
|
data: {
|
|
|
type: Object,
|
|
@@ -236,6 +237,7 @@ export default {
|
|
|
// this.$refs.map.addEventListener('click', () => {
|
|
|
// this.$refs.mapLegend.close();
|
|
|
// })
|
|
|
+ this.loadCarInfo();
|
|
|
},
|
|
|
methods: {
|
|
|
changeType(type) {
|
|
@@ -243,6 +245,16 @@ export default {
|
|
|
return;
|
|
|
}
|
|
|
let showType = JSON.parse(JSON.stringify(this.showType));
|
|
|
+ if (type === 'xfcKey') {
|
|
|
+ if (showType.indexOf(type) >= 0) {
|
|
|
+ showType = showType.filter((p) => p !== type);
|
|
|
+ } else {
|
|
|
+ showType.push(type);
|
|
|
+ }
|
|
|
+ this.showType = showType;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// console.log(this.markerCache);
|
|
|
if (showType.indexOf(type) >= 0) {
|
|
|
showType = showType.filter((p) => p !== type);
|
|
@@ -335,6 +347,76 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+ loadCarInfo() {
|
|
|
+ console.log("=----------------------",window.timer)
|
|
|
+ if (window.timer) {
|
|
|
+ window.clearInterval(window.timer);
|
|
|
+ window.timer = null;
|
|
|
+ }
|
|
|
+ const id = this.id;
|
|
|
+ window.timer = setInterval(() => {
|
|
|
+ this.loadCarOps(id)
|
|
|
+ }, 1000)
|
|
|
+ console.log(window.timer)
|
|
|
+ },
|
|
|
+ loadCarOps(id) {
|
|
|
+ getCarInfo({
|
|
|
+ ajid: id
|
|
|
+ }).then(res => {
|
|
|
+ // console.log(res)
|
|
|
+ if( this.AMap && res.data && res.data.length > 0 && this.showType.indexOf('xfcKey') >= 0) {
|
|
|
+ if (this.xfcKey && this.xfcKey.length >= 0) {
|
|
|
+ this.xfcKey.forEach(marker => this.map.remove(marker))
|
|
|
+ this.xfcKey = []
|
|
|
+ }
|
|
|
+
|
|
|
+ res.data.forEach(item => {
|
|
|
+ const icon = JSON.parse(JSON.stringify(this.icons['xfcKey']));
|
|
|
+ const AMap = this.AMap;
|
|
|
+ icon.size = new AMap.Size(icon.size[0], icon.size[1]);
|
|
|
+ icon.imageSize = new AMap.Size(
|
|
|
+ icon.imageSize[0],
|
|
|
+ icon.imageSize[1]
|
|
|
+ );
|
|
|
+ const p = {
|
|
|
+ icon: 'xfcKey',
|
|
|
+ position: [item.longitude, item.latitude],
|
|
|
+ anchor: "bottom-center",
|
|
|
+ data: item,
|
|
|
+ }
|
|
|
+ // 消息框
|
|
|
+ p.icon = new AMap.Icon(icon);
|
|
|
+ var marker = new AMap.Marker(p);
|
|
|
+ let infoContent = [];
|
|
|
+ infoContent.push(item.cph);
|
|
|
+ infoContent.push(item.speed + "公里/小时");
|
|
|
+ let content = [
|
|
|
+ "<div class='info_box_contant' style=\"line-height: 30px;min-width: 250px; padding: 20px; font-size: 20px; color: #7ea2ff; font-family: 'Abel'; background: rgba(0, 0, 0, 0.82);\">" +
|
|
|
+ infoContent.join("<br />") +
|
|
|
+ " </div>",
|
|
|
+ ];
|
|
|
+ const infoWindow = new AMap.InfoWindow({
|
|
|
+ isCustom: true, //使用自定义窗体
|
|
|
+ content: content.join("<br>"),
|
|
|
+ offset: new AMap.Pixel(0, -70),
|
|
|
+ });
|
|
|
+
|
|
|
+ marker.on("mouseover", (e) => {
|
|
|
+ infoWindow.open(this.map, p.position); //后面的参数指的是经纬度,在此显示窗口
|
|
|
+ });
|
|
|
+
|
|
|
+ marker.on("mouseout", (e) => {
|
|
|
+ infoWindow.close();
|
|
|
+ });
|
|
|
+ this.xfcKey.push(marker)
|
|
|
+ this.map.add(marker)
|
|
|
+ })
|
|
|
+ } else if (this.xfcKey && this.xfcKey.length >= 0) {
|
|
|
+ this.xfcKey.forEach(marker => this.map.remove(marker))
|
|
|
+ this.xfcKey = []
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
//刷新地图
|
|
|
refershMap(val){
|
|
|
if(this.radius==val) return
|
|
@@ -344,6 +426,7 @@ export default {
|
|
|
addClass(item){
|
|
|
return this.radius==item?'map-num active':'map-num '
|
|
|
},
|
|
|
+
|
|
|
async initMap() {
|
|
|
await AMapLoader.load({
|
|
|
key: "4776c927b5ebe35e9e33e5b14ec78b8f", // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
@@ -351,6 +434,7 @@ export default {
|
|
|
plugins: [""], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
|
|
})
|
|
|
.then((AMap) => {
|
|
|
+ this.AMap = AMap;
|
|
|
this.map = new AMap.Map("map-container", {
|
|
|
//设置地图容器id
|
|
|
// viewMode: "3D", //是否为3D地图模式
|
|
@@ -363,6 +447,7 @@ export default {
|
|
|
const markers = [];
|
|
|
this.markers.forEach((p, i) => {
|
|
|
const type = p.icon;
|
|
|
+ if (type == 'xfcKey') return;
|
|
|
let infoContent = [];
|
|
|
if (type === "jzKey" || type === "currentJzKey") {
|
|
|
infoContent.push(p.data.gcjzmc);
|
|
@@ -386,10 +471,12 @@ export default {
|
|
|
infoContent.push(p.data.code);
|
|
|
infoContent.push(p.data.sylx);
|
|
|
infoContent.push(p.data.address);
|
|
|
- } else if (type === "xfcKey") {
|
|
|
- infoContent.push(p.data.cph);
|
|
|
- infoContent.push(p.data.speed + "公里/小时");
|
|
|
- } else if (type === "lldKey") {
|
|
|
+ }
|
|
|
+ // else if (type === "xfcKey") {
|
|
|
+ // infoContent.push(p.data.cph);
|
|
|
+ // infoContent.push(p.data.speed + "公里/小时");
|
|
|
+ // }
|
|
|
+ else if (type === "lldKey") {
|
|
|
infoContent.push(p.data.deviceName);
|
|
|
infoContent.push(p.data.cameraType);
|
|
|
} else if (type === "xfzKey") {
|
|
@@ -731,6 +818,11 @@ export default {
|
|
|
immediate: true,
|
|
|
deep: true,
|
|
|
},
|
|
|
+ id: {
|
|
|
+ handler() {
|
|
|
+ console.log("打印", this.timer)
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
};
|
|
|
</script>
|