|
|
@@ -30,17 +30,24 @@ import { radioData } from "./radioData";
|
|
|
import { otherData } from "./otherData";
|
|
|
// 景区点位标记数据
|
|
|
import { scenicData } from "./scenicData";
|
|
|
+// 引入景区防火相关的接口
|
|
|
+import { reqGetSmokeCount } from "@/api/fire/index";
|
|
|
|
|
|
const $props = defineProps({
|
|
|
type: {
|
|
|
type: String,
|
|
|
default: "乡镇",
|
|
|
},
|
|
|
+ showFire: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false,
|
|
|
+ },
|
|
|
});
|
|
|
|
|
|
const $emit = defineEmits(["clickMarker"]);
|
|
|
|
|
|
console.log($props.type);
|
|
|
+console.log($props.showFire);
|
|
|
|
|
|
// 地图实例对象
|
|
|
let map: any = null;
|
|
|
@@ -111,7 +118,7 @@ const initAMap = () => {
|
|
|
new AMap.TileLayer.RoadNet(),
|
|
|
// 添加卫星图层
|
|
|
new AMap.TileLayer.Satellite({
|
|
|
- opacity: 0.4,
|
|
|
+ opacity: 0.9,
|
|
|
}),
|
|
|
// 添加实时交通路况图层
|
|
|
new AMap.TileLayer.Traffic({
|
|
|
@@ -207,102 +214,90 @@ const initAMap = () => {
|
|
|
};
|
|
|
|
|
|
// 监听地图类型变化重新渲染标记点
|
|
|
-watch(
|
|
|
- () => $props.type,
|
|
|
- () => {
|
|
|
- console.log($props.type);
|
|
|
-
|
|
|
- if ($props.type === "防火点位") {
|
|
|
- // 更新地图描点上的数据
|
|
|
- fireproofData[0].markerContent = `
|
|
|
- <div class="fire"">
|
|
|
- <div class="fire_text">
|
|
|
- ${3}
|
|
|
- <div class="icon"></div>
|
|
|
- </div>
|
|
|
- <div class="fire_icon">
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- `;
|
|
|
- fireproofData[1].markerContent = `
|
|
|
- <div class="fire"">
|
|
|
- <div class="fire_text">
|
|
|
- ${4}
|
|
|
- <div class="icon"></div>
|
|
|
- </div>
|
|
|
- <div class="fire_icon">
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- `;
|
|
|
- fireproofData[2].markerContent = `
|
|
|
- <div class="fire"">
|
|
|
- <div class="fire_text">
|
|
|
- ${5}
|
|
|
- <div class="icon"></div>
|
|
|
- </div>
|
|
|
- <div class="fire_icon">
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- `;
|
|
|
+watch($props, async () => {
|
|
|
+ console.log($props.type);
|
|
|
+
|
|
|
+ if ($props.type === "防火点位") {
|
|
|
+ const res = await reqGetSmokeCount();
|
|
|
+
|
|
|
+ // console.log(res);
|
|
|
+
|
|
|
+ if ((res as any).code == 200 && res.data.length) {
|
|
|
+ // 匹配数据 更新地图描点上的数据
|
|
|
+ fireproofData.forEach((ele: any) => {
|
|
|
+ res.data.forEach((item: any) => {
|
|
|
+ if (ele.title === item.place) {
|
|
|
+ ele.markerContent = `
|
|
|
+ <div class="fire"">
|
|
|
+ <div class="fire_text">
|
|
|
+ ${item.count}
|
|
|
+ <div class="icon"></div>
|
|
|
+ </div>
|
|
|
+ <div class="fire_icon">
|
|
|
+ </div>
|
|
|
+ </div>`;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // 先清除之前标记点
|
|
|
- markerList.value.forEach((element: any) => {
|
|
|
- element.setMap(null);
|
|
|
- });
|
|
|
+ // 先清除之前标记点
|
|
|
+ markerList.value.forEach((element: any) => {
|
|
|
+ element.setMap(null);
|
|
|
+ });
|
|
|
|
|
|
- // 重新添加标记点并绑定事件
|
|
|
- AMapLoader.load({
|
|
|
- key: "d5b00a2684bdf5b38fcfbcf1f35c30bf",
|
|
|
- version: "",
|
|
|
- })
|
|
|
- .then((AMap) => {
|
|
|
- // 定义回调函数
|
|
|
- function clearMarker(e: any) {
|
|
|
- $emit("clickMarker", e.target.De.title, $props.type);
|
|
|
- }
|
|
|
-
|
|
|
- // 判断需要展示什么标记
|
|
|
- let dataList: any = [];
|
|
|
-
|
|
|
- // 获取标记点数据
|
|
|
- dataList = getData();
|
|
|
-
|
|
|
- //添加点标记
|
|
|
- for (let i = 0; i < dataList.length; i++) {
|
|
|
- // 文本内容
|
|
|
- const markerContent = dataList[i].markerContent;
|
|
|
-
|
|
|
- //Marker 经纬度
|
|
|
- const position = new AMap.LngLat(dataList[i].lng, dataList[i].lat);
|
|
|
-
|
|
|
- // 标记对象
|
|
|
- const marker = new AMap.Marker({
|
|
|
- // 经纬度
|
|
|
- position: position,
|
|
|
- //将 html 传给 content
|
|
|
- content: markerContent,
|
|
|
- //以 icon 的 [center bottom] 为原点
|
|
|
- offset: new AMap.Pixel(dataList[i].left, dataList[i].right),
|
|
|
- // 鼠标滑过点标记时的文字提示
|
|
|
- title: dataList[i].title,
|
|
|
- // 点标记的叠加顺序,默认12
|
|
|
- // zIndex: dataList[i].zIndex ? dataList[i].zIndex : 12,
|
|
|
- map: map,
|
|
|
- });
|
|
|
+ // 重新添加标记点并绑定事件
|
|
|
+ AMapLoader.load({
|
|
|
+ key: "d5b00a2684bdf5b38fcfbcf1f35c30bf",
|
|
|
+ version: "",
|
|
|
+ })
|
|
|
+ .then((AMap) => {
|
|
|
+ // 定义回调函数
|
|
|
+ function clearMarker(e: any) {
|
|
|
+ $emit("clickMarker", e.target.De.title, $props.type);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断需要展示什么标记
|
|
|
+ let dataList: any = [];
|
|
|
+
|
|
|
+ // 获取标记点数据
|
|
|
+ dataList = getData();
|
|
|
+
|
|
|
+ //添加点标记
|
|
|
+ for (let i = 0; i < dataList.length; i++) {
|
|
|
+ // 文本内容
|
|
|
+ const markerContent = dataList[i].markerContent;
|
|
|
+
|
|
|
+ //Marker 经纬度
|
|
|
+ const position = new AMap.LngLat(dataList[i].lng, dataList[i].lat);
|
|
|
+
|
|
|
+ // 标记对象
|
|
|
+ const marker = new AMap.Marker({
|
|
|
+ // 经纬度
|
|
|
+ position: position,
|
|
|
+ //将 html 传给 content
|
|
|
+ content: markerContent,
|
|
|
+ //以 icon 的 [center bottom] 为原点
|
|
|
+ offset: new AMap.Pixel(dataList[i].left, dataList[i].right),
|
|
|
+ // 鼠标滑过点标记时的文字提示
|
|
|
+ title: dataList[i].title,
|
|
|
+ // 点标记的叠加顺序,默认12
|
|
|
+ // zIndex: dataList[i].zIndex ? dataList[i].zIndex : 12,
|
|
|
+ map: map,
|
|
|
+ });
|
|
|
|
|
|
- // 绑定点击事件
|
|
|
- marker.on("click", clearMarker);
|
|
|
+ // 绑定点击事件
|
|
|
+ marker.on("click", clearMarker);
|
|
|
|
|
|
- // 把标记点存储起来,方便后面清除
|
|
|
- markerList.value.push(marker);
|
|
|
- }
|
|
|
- })
|
|
|
- .catch((e) => {
|
|
|
- console.error(e);
|
|
|
- });
|
|
|
- }
|
|
|
-);
|
|
|
+ // 把标记点存储起来,方便后面清除
|
|
|
+ markerList.value.push(marker);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ console.error(e);
|
|
|
+ });
|
|
|
+});
|
|
|
|
|
|
// 获取标记点数据
|
|
|
const getData = () => {
|