hookehuyr

调整导航功能

...@@ -28,13 +28,13 @@ ...@@ -28,13 +28,13 @@
28 </div> 28 </div>
29 </div> 29 </div>
30 <div class="van-hairline--top" style="margin: 1rem 0;"> 30 <div class="van-hairline--top" style="margin: 1rem 0;">
31 - <div @click="goTo()" style="width: 50%; float: left; text-align: center; margin-top: 1rem;" 31 + <div @click="goToUrl()" style="width: 50%; float: left; text-align: center; margin-top: 1rem;"
32 class="van-hairline--right"> 32 class="van-hairline--right">
33 <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E5%89%8D%E5%BE%80@2x.png" size="1.5rem" color="#FFF" 33 <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E5%89%8D%E5%BE%80@2x.png" size="1.5rem" color="#FFF"
34 style="vertical-align: bottom;" />&nbsp; 34 style="vertical-align: bottom;" />&nbsp;
35 <span style="color: #AB8F57; font-size: 1.1rem;">详情</span> 35 <span style="color: #AB8F57; font-size: 1.1rem;">详情</span>
36 </div> 36 </div>
37 - <div style="width: 50%; float: left; text-align: center; margin-top: 1rem;"> 37 + <div @click="goToLocation()" style="width: 50%; float: left; text-align: center; margin-top: 1rem;">
38 <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E5%89%8D%E5%BE%80@2x.png" size="1.5rem" color="#FFF" 38 <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E5%89%8D%E5%BE%80@2x.png" size="1.5rem" color="#FFF"
39 style="vertical-align: bottom;" />&nbsp; 39 style="vertical-align: bottom;" />&nbsp;
40 <span style="color: #AB8F57; font-size: 1.1rem;">前往</span> 40 <span style="color: #AB8F57; font-size: 1.1rem;">前往</span>
...@@ -200,7 +200,7 @@ export default { ...@@ -200,7 +200,7 @@ export default {
200 this.audio.pause(); 200 this.audio.pause();
201 this.is_play = false; 201 this.is_play = false;
202 }, 202 },
203 - goTo(url) { 203 + goToUrl(url) {
204 location.href = this.info.details[this.isActive].url; 204 location.href = this.info.details[this.isActive].url;
205 }, 205 },
206 handleTitle (index) { 206 handleTitle (index) {
...@@ -226,6 +226,9 @@ export default { ...@@ -226,6 +226,9 @@ export default {
226 }, 1000); 226 }, 1000);
227 }, 100); 227 }, 100);
228 } 228 }
229 + },
230 + goToLocation () {
231 + this.$emit('onLocation', this.info.position)
229 } 232 }
230 } 233 }
231 } 234 }
......
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: 2023-06-06 17:19:52 4 + * @LastEditTime: 2023-06-07 10:34:46
5 * @FilePath: /map-demo/src/views/index.vue 5 * @FilePath: /map-demo/src/views/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -27,44 +27,33 @@ ...@@ -27,44 +27,33 @@
27 <van-popup v-model:show="show_nav_popup" position="bottom" duration="0" :overlay="false" 27 <van-popup v-model:show="show_nav_popup" position="bottom" duration="0" :overlay="false"
28 :style="{ padding: '1rem', bottom: '4.5rem' }"> 28 :style="{ padding: '1rem', bottom: '4.5rem' }">
29 <div style="text-align: left;"> 29 <div style="text-align: left;">
30 - <div v-for="(item, index) in navList[navName]" :key="index" @click="positionMarker(item)" style="margin-bottom: 1rem; font-size: 1.15rem;"> 30 + <div v-for="(item, index) in navList[navName]" :key="index" @click="positionMarker(item)"
31 + style="margin-bottom: 1rem; font-size: 1.15rem;">
31 <van-icon name="fire-o" color="red" />&nbsp;&nbsp;{{ item.name }} 32 <van-icon name="fire-o" color="red" />&nbsp;&nbsp;{{ item.name }}
32 </div> 33 </div>
33 </div> 34 </div>
34 </van-popup> 35 </van-popup>
35 </div> 36 </div>
36 - <!-- <div class="safe-route-wrapper">
37 - <span v-if="open_safe_route" @click="handleSafeRoute(true)">打开安全路线</span>
38 - <span v-else @click="handleSafeRoute(false)">关闭安全路线</span>
39 - </div> -->
40 - <!-- <div class="tool-bar-wrapper">
41 - <div style="display: flex; flex-direction: column;align-items: center;justify-content: center;">
42 - <van-icon name="plus" style="margin-bottom: 1rem;" @click="setZoom('plus')" />
43 - <van-icon name="minus" style="margin-bottom: 1rem;" @click="setZoom('minus')" />
44 - <van-icon name="aim" @click="setLocation" />
45 - </div>
46 - </div> -->
47 <div class="operate-bar-wrapper"> 37 <div class="operate-bar-wrapper">
48 <div class="box-wrapper"> 38 <div class="box-wrapper">
49 <div class="item" @click="setLocation"> 39 <div class="item" @click="setLocation">
50 - <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A%E4%BD%8Dloc@2x.png" size="1.5rem" style="vertical-align: middle;" /> 40 + <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A%E4%BD%8Dloc@2x.png" size="1.5rem"
51 - </div> 41 + style="vertical-align: middle;" />
52 - <div v-if="show_walk_route" class="item" @click="setWalkRoute">
53 - <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF@2x.png" size="1.25rem" style="vertical-align: middle;" />
54 - </div>
55 - <div v-else class="item" @click="removeWalkRoute">
56 - <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF@2x.png" size="1.25rem" style="vertical-align: middle;" />
57 </div> 42 </div>
58 <div v-if="open_safe_route" class="item" @click="handleSafeRoute(true)"> 43 <div v-if="open_safe_route" class="item" @click="handleSafeRoute(true)">
59 - <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF@2x.png" size="1.25rem" style="vertical-align: middle;" /> 44 + <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF@2x.png" size="1.25rem"
45 + style="vertical-align: middle;" />
60 </div> 46 </div>
61 <div v-else class="item" @click="handleSafeRoute(false)"> 47 <div v-else class="item" @click="handleSafeRoute(false)">
62 - <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF@2x.png" size="1.25rem" style="vertical-align: middle;" /> 48 + <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF@2x.png" size="1.25rem"
49 + style="vertical-align: middle;" />
63 </div> 50 </div>
64 </div> 51 </div>
65 </div> 52 </div>
66 53
67 - <!-- <div style="position: fixed; bottom: 0; height: 2rem; width: 100%; background-color: white; z-index: 999;"></div> --> 54 + <div v-if="!show_walk_route" @click="removeWalkRoute" style="position: fixed; bottom: 8rem; left: 48%; z-index: 999; background: rgba(86, 65, 23, 0.8); color: white; border-radius: 10px; padding: 5px 12px; font-size: 0.8rem;">
55 + 关闭步行导航
56 + </div>
68 57
69 <van-popup v-model:show="show_popup" position="bottom" :overlay="true" :style="{ padding: '1rem', height: '100%' }"> 58 <van-popup v-model:show="show_popup" position="bottom" :overlay="true" :style="{ padding: '1rem', height: '100%' }">
70 <van-icon name="cross" size="1.35rem" @click="show_popup = false" style="float: right; color: gray;" /> 59 <van-icon name="cross" size="1.35rem" @click="show_popup = false" style="float: right; color: gray;" />
...@@ -85,9 +74,12 @@ ...@@ -85,9 +74,12 @@
85 74
86 <!-- 自定义组件InfoWindow,初始时需要隐藏 --> 75 <!-- 自定义组件InfoWindow,初始时需要隐藏 -->
87 <!-- 隐藏不要使用v-if,因为我们需要渲染完成后的原生html结构作为信息框的dom对象使用 --> 76 <!-- 隐藏不要使用v-if,因为我们需要渲染完成后的原生html结构作为信息框的dom对象使用 -->
88 - <InfoWindow v-show="showInfoWindow" ref="infoWindow" :info-window="infoWindow" :info="itemInfo" :rect="rect"></InfoWindow> 77 + <InfoWindow v-show="showInfoWindow" ref="infoWindow" :info-window="infoWindow" :info="itemInfo" :rect="rect"
89 - <InfoWindowLite v-show="showInfoWindowLite" ref="infoWindowLite" :info-window="infoWindowLite" :info="itemInfo" :rect="rect"></InfoWindowLite> 78 + @onLocation="infoWindowLocation"></InfoWindow>
90 - <InfoWindowWarn v-show="showInfoWindowWarn" ref="infoWindowWarn" :info-window="infoWindowWarn" :info="itemInfo" :rect="rect"></InfoWindowWarn> 79 + <InfoWindowLite v-show="showInfoWindowLite" ref="infoWindowLite" :info-window="infoWindowLite" :info="itemInfo"
80 + :rect="rect"></InfoWindowLite>
81 + <InfoWindowWarn v-show="showInfoWindowWarn" ref="infoWindowWarn" :info-window="infoWindowWarn" :info="itemInfo"
82 + :rect="rect"></InfoWindowWarn>
91 </div> 83 </div>
92 </template> 84 </template>
93 85
...@@ -259,21 +251,21 @@ export default { ...@@ -259,21 +251,21 @@ export default {
259 }) 251 })
260 } 252 }
261 }, 253 },
262 - showInfoWindow (val) { 254 + showInfoWindow(val) {
263 if (val) { 255 if (val) {
264 // 元素的大小及其相对于视口的位置 256 // 元素的大小及其相对于视口的位置
265 const rect = useRect(this.$refs.root); 257 const rect = useRect(this.$refs.root);
266 this.rect = rect; 258 this.rect = rect;
267 } 259 }
268 }, 260 },
269 - showInfoWindowLite (val) { 261 + showInfoWindowLite(val) {
270 if (val) { 262 if (val) {
271 // 元素的大小及其相对于视口的位置 263 // 元素的大小及其相对于视口的位置
272 const rect = useRect(this.$refs.root); 264 const rect = useRect(this.$refs.root);
273 this.rect = rect; 265 this.rect = rect;
274 } 266 }
275 }, 267 },
276 - showInfoWindowWarn (val) { 268 + showInfoWindowWarn(val) {
277 if (val) { 269 if (val) {
278 // 元素的大小及其相对于视口的位置 270 // 元素的大小及其相对于视口的位置
279 const rect = useRect(this.$refs.root); 271 const rect = useRect(this.$refs.root);
...@@ -627,6 +619,12 @@ export default { ...@@ -627,6 +619,12 @@ export default {
627 hidePublic() { 619 hidePublic() {
628 this.map.remove(this.facilities); 620 this.map.remove(this.facilities);
629 }, 621 },
622 + isPointInRing () { // 是否在景区范围
623 + let isPointInRing = AMap.GeometryUtil.isPointInRing([this.current_lng, this.current_lat], [
624 + [120.585111, 31.316084], [120.585111, 31.316084], [120.589488, 31.313197], [120.585422, 31.313005]
625 + ]);
626 + return isPointInRing
627 + },
630 setLocation() { // 开启定位服务 628 setLocation() { // 开启定位服务
631 // this.map.addControl(this.geolocation); // 添加定位图标 自动跳转当前位置 629 // this.map.addControl(this.geolocation); // 添加定位图标 自动跳转当前位置
632 if (!this.current_lng || !this.current_lat) { 630 if (!this.current_lng || !this.current_lat) {
...@@ -640,10 +638,7 @@ export default { ...@@ -640,10 +638,7 @@ export default {
640 // 定位到地图中心-西园寺 638 // 定位到地图中心-西园寺
641 this.map.setCenter([120.587334, 31.314823]); 639 this.map.setCenter([120.587334, 31.314823]);
642 // 判断是否在范围内 640 // 判断是否在范围内
643 - let isPointInRing = AMap.GeometryUtil.isPointInRing([this.current_lng, this.current_lat], [ 641 + if (!this.isPointInRing()) {
644 - [120.585111, 31.316084], [120.585111, 31.316084], [120.589488, 31.313197], [120.585422, 31.313005]
645 - ]);
646 - if (!isPointInRing) {
647 this.dialog_show = true; 642 this.dialog_show = true;
648 } 643 }
649 } 644 }
...@@ -716,11 +711,11 @@ export default { ...@@ -716,11 +711,11 @@ export default {
716 imageOffset: new AMap.Pixel(0, 0) 711 imageOffset: new AMap.Pixel(0, 0)
717 }), 712 }),
718 position: new AMap.LngLat(120.587506, 31.313787), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] 713 position: new AMap.LngLat(120.587506, 31.313787), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
719 - anchor:'bottom-center', 714 + anchor: 'bottom-center',
720 offset: new AMap.Pixel(0, 0) 715 offset: new AMap.Pixel(0, 0)
721 }); 716 });
722 marker1.setLabel({ 717 marker1.setLabel({
723 - direction:'right', 718 + direction: 'right',
724 offset: new AMap.Pixel(0, -10), //设置文本标注偏移量 719 offset: new AMap.Pixel(0, -10), //设置文本标注偏移量
725 content: "<div class='info'>起点</div>", //设置文本标注内容 720 content: "<div class='info'>起点</div>", //设置文本标注内容
726 }); 721 });
...@@ -734,11 +729,11 @@ export default { ...@@ -734,11 +729,11 @@ export default {
734 imageOffset: new AMap.Pixel(0, 0) 729 imageOffset: new AMap.Pixel(0, 0)
735 }), 730 }),
736 position: new AMap.LngLat(120.586825, 31.314543), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] 731 position: new AMap.LngLat(120.586825, 31.314543), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
737 - anchor:'bottom-center', 732 + anchor: 'bottom-center',
738 offset: new AMap.Pixel(0, 0) 733 offset: new AMap.Pixel(0, 0)
739 }); 734 });
740 marker2.setLabel({ 735 marker2.setLabel({
741 - direction:'right', 736 + direction: 'right',
742 offset: new AMap.Pixel(0, -10), //设置文本标注偏移量 737 offset: new AMap.Pixel(0, -10), //设置文本标注偏移量
743 content: "<div class='info'>终点</div>", //设置文本标注内容 738 content: "<div class='info'>终点</div>", //设置文本标注内容
744 }); 739 });
...@@ -883,7 +878,7 @@ export default { ...@@ -883,7 +878,7 @@ export default {
883 // 点击空白处 关闭弹框 878 // 点击空白处 关闭弹框
884 this.closeInfoWindow() 879 this.closeInfoWindow()
885 }, 880 },
886 - setWalkRoute() { 881 + setWalkRoute(start = { lng: 120.587799, lat: 31.313276 }, end = { lng: 120.587912, lat: 31.315169 }) {
887 //步行导航 882 //步行导航
888 let walking_CallBack = (result) => { 883 let walking_CallBack = (result) => {
889 if (result.type === 'complete') { 884 if (result.type === 'complete') {
...@@ -899,7 +894,7 @@ export default { ...@@ -899,7 +894,7 @@ export default {
899 }); //构造步行导航类 894 }); //构造步行导航类
900 AMap.Event.addListener(this.walk_route, "complete", walking_CallBack); //返回导航查询结果 895 AMap.Event.addListener(this.walk_route, "complete", walking_CallBack); //返回导航查询结果
901 //根据起、终点坐标规划步行路线 896 //根据起、终点坐标规划步行路线
902 - this.walk_route.search(new AMap.LngLat(120.587799, 31.313276), new AMap.LngLat(120.587912, 31.315169)); 897 + this.walk_route.search(new AMap.LngLat(start.lng, start.lat), new AMap.LngLat(end.lng, end.lat));
903 }); 898 });
904 this.show_walk_route = false; 899 this.show_walk_route = false;
905 }, 900 },
...@@ -907,6 +902,17 @@ export default { ...@@ -907,6 +902,17 @@ export default {
907 this.walk_route.clear(); 902 this.walk_route.clear();
908 this.show_walk_route = true; 903 this.show_walk_route = true;
909 }, 904 },
905 + infoWindowLocation(position) { // 监听前往按钮回调
906 + // // 判断是否在范围内
907 + // if (!this.isPointInRing()) {
908 + // this.dialog_show = true;
909 + // } else {
910 + // this.setWalkRoute({ lng: this.current_lng, lat: this.current_lat }, { lng: position[0], lat: position[1] })
911 + // }
912 + // 测试
913 + this.closeInfoWindow(); // 关闭弹框
914 + this.setWalkRoute({ lng: 120.59014, lat: 31.310306 }, { lng: position[0], lat: position[1] });
915 + },
910 setNavLayer({ key }, index) { // 选择地图图层显示 916 setNavLayer({ key }, index) { // 选择地图图层显示
911 this.isActive = index; 917 this.isActive = index;
912 if (key === 'spot') { 918 if (key === 'spot') {
...@@ -988,7 +994,12 @@ export default { ...@@ -988,7 +994,12 @@ export default {
988 offset: new AMap.Pixel(0, -30), 994 offset: new AMap.Pixel(0, -30),
989 }) 995 })
990 this.infoWindow = infoWindow; 996 this.infoWindow = infoWindow;
991 - this.itemInfo = item 997 + this.itemInfo = item;
998 + this.itemInfo.map = this.map;
999 + this.itemInfo.LngLat = {
1000 + lng: this.current_lng,
1001 + lat: this.current_lat,
1002 + }
992 // 信息窗口打开 1003 // 信息窗口打开
993 infoWindow.open(this.map, item.position) 1004 infoWindow.open(this.map, item.position)
994 }, 1005 },
...@@ -1005,7 +1016,12 @@ export default { ...@@ -1005,7 +1016,12 @@ export default {
1005 offset: new AMap.Pixel(0, -30), 1016 offset: new AMap.Pixel(0, -30),
1006 }) 1017 })
1007 this.infoWindowLite = infoWindowLite; 1018 this.infoWindowLite = infoWindowLite;
1008 - this.itemInfo = item 1019 + this.itemInfo = item;
1020 + this.itemInfo.map = this.map;
1021 + this.itemInfo.LngLat = {
1022 + lng: this.current_lng,
1023 + lat: this.current_lat,
1024 + }
1009 // 信息窗口打开 1025 // 信息窗口打开
1010 infoWindowLite.open(this.map, item.position) 1026 infoWindowLite.open(this.map, item.position)
1011 }, 1027 },
...@@ -1022,11 +1038,16 @@ export default { ...@@ -1022,11 +1038,16 @@ export default {
1022 offset: new AMap.Pixel(0, -30), 1038 offset: new AMap.Pixel(0, -30),
1023 }) 1039 })
1024 this.infoWindowWarn = infoWindowWarn; 1040 this.infoWindowWarn = infoWindowWarn;
1025 - this.itemInfo = item 1041 + this.itemInfo = item;
1042 + this.itemInfo.map = this.map;
1043 + this.itemInfo.LngLat = {
1044 + lng: this.current_lng,
1045 + lat: this.current_lat,
1046 + }
1026 // 信息窗口打开 1047 // 信息窗口打开
1027 - infoWindowWarn.open(this.map, item.position) 1048 + infoWindowWarn.open(this.map, item.position);
1028 }, 1049 },
1029 - closeInfoWindow () { 1050 + closeInfoWindow() {
1030 if (this.showInfoWindow) { 1051 if (this.showInfoWindow) {
1031 this.$refs['infoWindow'].close(); 1052 this.$refs['infoWindow'].close();
1032 // 打开缩放 1053 // 打开缩放
...@@ -1120,13 +1141,21 @@ export default { ...@@ -1120,13 +1141,21 @@ export default {
1120 z-index: 999; 1141 z-index: 999;
1121 // padding: 0.5rem 0; 1142 // padding: 0.5rem 0;
1122 padding-bottom: 0.5rem; 1143 padding-bottom: 0.5rem;
1144 +
1123 .nav-bar-content { 1145 .nav-bar-content {
1124 - display: flex; overflow-x: scroll; overflow-y: hidden; -webkit-overflow-scrolling: touch; position: relative; 1146 + display: flex;
1147 + overflow-x: scroll;
1148 + overflow-y: hidden;
1149 + -webkit-overflow-scrolling: touch;
1150 + position: relative;
1125 } 1151 }
1152 +
1126 .item { 1153 .item {
1127 padding-top: 0.5rem; 1154 padding-top: 0.5rem;
1128 color: #888; 1155 color: #888;
1129 - width: 21.5%; flex-shrink: 0; padding-top: 1rem; 1156 + width: 21.5%;
1157 + flex-shrink: 0;
1158 + padding-top: 1rem;
1130 } 1159 }
1131 1160
1132 .checked { 1161 .checked {
...@@ -1193,7 +1222,8 @@ export default { ...@@ -1193,7 +1222,8 @@ export default {
1193 overflow: -moz-scrollbars-none; 1222 overflow: -moz-scrollbars-none;
1194 } 1223 }
1195 1224
1196 -.van-dialog__confirm, .van-dialog__confirm:active { 1225 +.van-dialog__confirm,
1226 +.van-dialog__confirm:active {
1197 color: #AB8F57; 1227 color: #AB8F57;
1198 } 1228 }
1199 </style> 1229 </style>
......