hookehuyr

fix 导航路线兼容多条显示

1 <!-- 1 <!--
2 * @Date: 2023-05-19 14:54:27 2 * @Date: 2023-05-19 14:54:27
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-08-19 17:42:32 4 + * @LastEditTime: 2024-08-20 16:58:48
5 * @FilePath: /map-demo/src/views/index.vue 5 * @FilePath: /map-demo/src/views/index.vue
6 * @Description: 公众地图主体页面 6 * @Description: 公众地图主体页面
7 --> 7 -->
...@@ -48,12 +48,12 @@ ...@@ -48,12 +48,12 @@
48 <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A%E4%BD%8Dloc@2x.png" size="1.5rem" 48 <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A%E4%BD%8Dloc@2x.png" size="1.5rem"
49 style="vertical-align: middle;" /> 49 style="vertical-align: middle;" />
50 </div> --> 50 </div> -->
51 - <div v-if="Object.keys(data_paths)?.length"> 51 + <div v-for="(item, index) in data_path_list" :key="index">
52 - <div v-if="open_safe_route" class="item" @click="handleSafeRoute(true)"> 52 + <div v-if="item.status" class="item" @click="handleSafeRoute(true, item)">
53 <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF01.png" size="1.5rem" 53 <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF01.png" size="1.5rem"
54 style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);" /> 54 style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);" />
55 </div> 55 </div>
56 - <div v-else class="item" @click="handleSafeRoute(false)"> 56 + <div v-else class="item" @click="handleSafeRoute(false, item)">
57 <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF02.png" size="1.5rem" 57 <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF02.png" size="1.5rem"
58 style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);" /> 58 style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);" />
59 </div> 59 </div>
...@@ -201,7 +201,7 @@ export default { ...@@ -201,7 +201,7 @@ export default {
201 current_lng: '', 201 current_lng: '',
202 current_lat: '', 202 current_lat: '',
203 current_route: '', 203 current_route: '',
204 - current_safe_route: '', 204 + current_safe_route: [],
205 // show_popup: false, 205 // show_popup: false,
206 dialog_show: false, 206 dialog_show: false,
207 dialog_text: '', 207 dialog_text: '',
...@@ -247,6 +247,7 @@ export default { ...@@ -247,6 +247,7 @@ export default {
247 data_zooms: '', // 接口获取-地图默认缩放范围 247 data_zooms: '', // 接口获取-地图默认缩放范围
248 data_rotation: 0, // 接口获取-地图旋转角度 248 data_rotation: 0, // 接口获取-地图旋转角度
249 data_paths: {}, // 接口获取-地图导航路径 249 data_paths: {}, // 接口获取-地图导航路径
250 + data_path_list: [], // 接口获取-地图导航路径
250 } 251 }
251 }, 252 },
252 async mounted() { 253 async mounted() {
...@@ -263,6 +264,16 @@ export default { ...@@ -263,6 +264,16 @@ export default {
263 this.data_rotation = data.map.rotation; // 地图旋转角度 264 this.data_rotation = data.map.rotation; // 地图旋转角度
264 this.data_zooms = data.map.zooms.map(item => Number(item)); // 地图默认缩放范围 265 this.data_zooms = data.map.zooms.map(item => Number(item)); // 地图默认缩放范围
265 this.data_paths = data.map.path ? data.map.path : {}; // 地图默认导航路径 266 this.data_paths = data.map.path ? data.map.path : {}; // 地图默认导航路径
267 + if (data.map.path) {
268 + for (const key in data.map.path) {
269 + const element = data.map.path[key];
270 + this.data_path_list.push({
271 + name: key,
272 + path: element,
273 + status: true
274 + })
275 + }
276 + }
266 // 初始化地图 277 // 初始化地图
267 this.initMap(); 278 this.initMap();
268 // this.setMapBoundary(); 279 // this.setMapBoundary();
...@@ -598,10 +609,10 @@ export default { ...@@ -598,10 +609,10 @@ export default {
598 this.map.setZoom(zoom - 1) 609 this.map.setZoom(zoom - 1)
599 } 610 }
600 }, 611 },
601 - addSafeRoute() { // 新增路径 612 + addSafeRoute({name, path}) { // 新增路径
602 // 获取对象的第一个键和值 613 // 获取对象的第一个键和值
603 - let firstKey = Object.keys(this.data_paths)[0]; 614 + // let firstKey = Object.keys(this.data_paths)[0];
604 - let firstValue = this.data_paths[firstKey]; 615 + // let firstValue = this.data_paths[firstKey];
605 // 行动路线 616 // 行动路线
606 // var path = [ 617 // var path = [
607 // [120.587645, 31.314833], 618 // [120.587645, 31.314833],
...@@ -609,9 +620,9 @@ export default { ...@@ -609,9 +620,9 @@ export default {
609 // [120.588211, 31.314377], 620 // [120.588211, 31.314377],
610 // ]; 621 // ];
611 // console.warn(firstValue); 622 // console.warn(firstValue);
612 - var path = firstValue; 623 + // var path = firstValue;
613 // 生成折线地图路径 624 // 生成折线地图路径
614 - this.current_safe_route = new AMap.Polyline({ 625 + let current_safe_route = new AMap.Polyline({
615 path, 626 path,
616 isOutline: true, 627 isOutline: true,
617 outlineColor: '#fba601', 628 outlineColor: '#fba601',
...@@ -627,7 +638,11 @@ export default { ...@@ -627,7 +638,11 @@ export default {
627 lineCap: 'round', 638 lineCap: 'round',
628 zIndex: 50 639 zIndex: 50
629 }) 640 })
630 - this.map.add([this.current_safe_route]); 641 + this.map.add([current_safe_route]);
642 + this.current_safe_route.push({
643 + key: name,
644 + path: current_safe_route
645 + })
631 // 设置起始点标记 646 // 设置起始点标记
632 var marker1 = new AMap.Marker({ 647 var marker1 = new AMap.Marker({
633 icon: new AMap.Icon({ 648 icon: new AMap.Icon({
...@@ -666,12 +681,28 @@ export default { ...@@ -666,12 +681,28 @@ export default {
666 content: "<div class='info'>终点</div>", //设置文本标注内容 681 content: "<div class='info'>终点</div>", //设置文本标注内容
667 }); 682 });
668 // 新增逃生路线标记 683 // 新增逃生路线标记
669 - this.route_safe_marker = [marker1, marker2] 684 + // this.route_safe_marker = [marker1, marker2]
670 - this.map.add(this.route_safe_marker); 685 + // this.map.add(this.route_safe_marker);
686 + // 新增逃生路线标记
687 + let route_safe_marker = [marker1, marker2]
688 + this.map.add(route_safe_marker);
689 + this.route_safe_marker.push({
690 + key: name,
691 + path: route_safe_marker
692 + })
671 }, 693 },
672 - removeSafeRoute() { // 移除地图路线 694 + removeSafeRoute({name}) { // 移除地图路线
673 - this.map.remove([this.current_safe_route]); // 删除地图折线 695 + this.current_safe_route.forEach(item => {
674 - this.map.remove(this.route_safe_marker); // 删除起始点标记 696 + if (item.key === name) {
697 + this.map.remove([item.path]); // 删除地图折线
698 + }
699 + });
700 + // this.map.remove(this.route_safe_marker); // 删除起始点标记
701 + this.route_safe_marker.forEach(item => {
702 + if (item.key === name) {
703 + this.map.remove(item.path); // 删除起始点标记
704 + }
705 + });
675 }, 706 },
676 // addNavRoute (path) { // 新增导航路径 707 // addNavRoute (path) { // 新增导航路径
677 // // 生成折线地图路径 708 // // 生成折线地图路径
...@@ -1026,14 +1057,15 @@ export default { ...@@ -1026,14 +1057,15 @@ export default {
1026 this.dialog_text = '内部设施'; 1057 this.dialog_text = '内部设施';
1027 } 1058 }
1028 }, 1059 },
1029 - handleSafeRoute(status) { // 打开/关闭逃生路线线 1060 + handleSafeRoute(status, item) { // 打开/关闭逃生路线线
1030 if (status) { 1061 if (status) {
1031 - this.addSafeRoute() 1062 + this.addSafeRoute(item)
1032 - this.open_safe_route = false; 1063 + // this.open_safe_route = false;
1033 } else { 1064 } else {
1034 - this.removeSafeRoute() 1065 + this.removeSafeRoute(item)
1035 - this.open_safe_route = true; 1066 + // this.open_safe_route = true;
1036 } 1067 }
1068 + item.status = !status;
1037 }, 1069 },
1038 handleNavPopup() { 1070 handleNavPopup() {
1039 this.show_nav_popup = !this.show_nav_popup 1071 this.show_nav_popup = !this.show_nav_popup
......