hookehuyr

地图样式新增

1 <!-- 1 <!--
2 * @Date: 2023-01-09 15:22:38 2 * @Date: 2023-01-09 15:22:38
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-05-26 16:14:24 4 + * @LastEditTime: 2023-05-29 14:18:36
5 - * @FilePath: /tswj/index.html 5 + * @FilePath: /map-demo/index.html
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <!DOCTYPE html> 8 <!DOCTYPE html>
...@@ -22,6 +22,6 @@ ...@@ -22,6 +22,6 @@
22 securityJsCode:'8602057c4c8dae5bed9a240c0582c46f', 22 securityJsCode:'8602057c4c8dae5bed9a240c0582c46f',
23 } 23 }
24 </script> 24 </script>
25 - <script src="https://webapi.amap.com/maps?v=2.0&key=381c6763e1fefd810fbab697f470149c&plugin=AMap.ElasticMarker,AMap.ImageLayer"></script> 25 + <script src="https://webapi.amap.com/maps?v=2.0&key=381c6763e1fefd810fbab697f470149c&plugin=AMap.ElasticMarker,AMap.ImageLayer,AMap.ToolBar"></script>
26 </body> 26 </body>
27 </html> 27 </html>
......
...@@ -119,9 +119,18 @@ var toiletInfo = [ ...@@ -119,9 +119,18 @@ var toiletInfo = [
119 }, 119 },
120 ]; 120 ];
121 121
122 +var activityInfo = [
123 + {
124 + name: '素食',
125 + position: [120.587152, 31.314396],
126 + icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
127 + },
128 +];
129 +
122 export default { 130 export default {
123 sheshi, 131 sheshi,
124 touristSpots, 132 touristSpots,
125 spotInfo, 133 spotInfo,
126 toiletInfo, 134 toiletInfo,
135 + activityInfo,
127 }; 136 };
......
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-05-29 06:15:20 4 + * @LastEditTime: 2023-05-29 17:21:49
5 - * @FilePath: /tswj/src/views/Map.vue 5 + * @FilePath: /map-demo/src/views/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <template> 8 <template>
9 - <div class=""> 9 + <div style="height: 100vh; position: relative;">
10 <div id="container"></div> 10 <div id="container"></div>
11 <div class="input-card"> 11 <div class="input-card">
12 - <div class="input-item"> 12 + <!-- <div class="input-item">
13 <span @click="showPublic" class="btn">显示公共设施</span> 13 <span @click="showPublic" class="btn">显示公共设施</span>
14 <span @click="hidePublic" class="btn">隐藏公共设施</span> 14 <span @click="hidePublic" class="btn">隐藏公共设施</span>
15 - </div> 15 + </div> -->
16 - <div class="input-item"> 16 + <!-- <div class="input-item">
17 <button class="btn" @click="addLayer" style="margin-right:1rem;">添加图层</button> 17 <button class="btn" @click="addLayer" style="margin-right:1rem;">添加图层</button>
18 <button class="btn" @click="removeLayer">删除图层</button> 18 <button class="btn" @click="removeLayer">删除图层</button>
19 - </div> 19 + </div> -->
20 <div class="input-item"> 20 <div class="input-item">
21 - <button class="btn" @click="setLocation" style="margin-right:1rem;">定位服务</button> 21 + <!-- <button class="btn" @click="setLocation" style="margin-right:1rem;">定位服务</button>
22 <button class="btn" @click="addLocation" style="margin-right:1rem;">添加定位路线</button> 22 <button class="btn" @click="addLocation" style="margin-right:1rem;">添加定位路线</button>
23 - <button class="btn" @click="removeLocation" style="margin-right:1rem;">删除定位路线</button> 23 + <button class="btn" @click="removeLocation" style="margin-right:1rem;">删除定位路线</button> -->
24 <button class="btn" @click="setTitleLayer" style="margin-right:1rem;">添加贴片</button> 24 <button class="btn" @click="setTitleLayer" style="margin-right:1rem;">添加贴片</button>
25 </div> 25 </div>
26 <div class="input-item"> 26 <div class="input-item">
27 - <button class="btn" @click="setSpotLayer" style="margin-right:1rem;">景点信息</button>
28 - <button class="btn" @click="setToiletLayer" style="margin-right:1rem;">卫生间</button>
29 - </div>
30 - <div class="input-item">
31 <button class="btn" @click="setWalkRoute" style="margin-right:1rem;">步行导航</button> 27 <button class="btn" @click="setWalkRoute" style="margin-right:1rem;">步行导航</button>
32 <button class="btn" @click="removeWalkRoute" style="margin-right:1rem;">移除步行导航</button> 28 <button class="btn" @click="removeWalkRoute" style="margin-right:1rem;">移除步行导航</button>
33 </div> 29 </div>
34 </div> 30 </div>
31 + <div class="nav-bar-wrapper">
32 + <van-row>
33 + <van-col span="8" :class="[isActive === 0 ? 'checked' : '', 'item']" @click="setNavLayer(0)">
34 + <van-icon name="shop-o" size="1.25rem" /><br/>
35 + <span style="font-size: 0.85rem;">景区信息</span>
36 + </van-col>
37 + <van-col span="8" :class="[isActive === 1 ? 'checked' : '', 'item']" @click="setNavLayer(1)">
38 + <van-icon name="shop-o" size="1.25rem" /><br/>
39 + <span style="font-size: 0.85rem;">卫生间</span>
40 + </van-col>
41 + <van-col span="8" :class="[isActive === 2 ? 'checked' : '', 'item']" @click="setNavLayer(2)">
42 + <van-icon name="shop-o" size="1.25rem" /><br/>
43 + <span style="font-size: 0.85rem;">活动中心</span>
44 + </van-col>
45 + </van-row>
46 + </div>
47 + <div class="safe-route-wrapper">
48 + <span v-if="open_safe_route" @click="handleSafeRoute(true)">打开安全路线</span>
49 + <span v-else @click="handleSafeRoute(false)">关闭安全路线</span>
50 + </div>
51 + <div class="tool-bar-wrapper">
52 + <van-icon name="plus" style="margin-bottom: 1rem;" @click="setZoom('plus')" />
53 + <van-icon name="minus" style="margin-bottom: 1rem;" @click="setZoom('minus')" />
54 + <van-icon name="aim" @click="setLocation" />
55 + </div>
35 <van-popup v-model:show="show_popup" position="bottom" :overlay="false" closeable 56 <van-popup v-model:show="show_popup" position="bottom" :overlay="false" closeable
36 :style="{ padding: '64px' }">内容</van-popup> 57 :style="{ padding: '64px' }">内容</van-popup>
37 58
...@@ -139,22 +160,29 @@ export default { ...@@ -139,22 +160,29 @@ export default {
139 current_route: '', 160 current_route: '',
140 spotInfo: [], // 景点信息实体 161 spotInfo: [], // 景点信息实体
141 toiletInfo: [], // 厕所信息实体 162 toiletInfo: [], // 厕所信息实体
163 + activityInfo: [], // 活动场所信息实体
142 show_popup: false, 164 show_popup: false,
143 dialog_show: false, 165 dialog_show: false,
144 xys_lng: '', 166 xys_lng: '',
145 xys_lat: '', 167 xys_lat: '',
146 walk_route: '', 168 walk_route: '',
169 + toolBar: '',
170 + isActive: 0,
171 + safe_route: [],
172 + open_safe_route: true
147 } 173 }
148 }, 174 },
149 mounted() { 175 mounted() {
150 // 初始化地图 176 // 初始化地图
151 this.initMap(); 177 this.initMap();
152 - this.loadPublicEquipment(); 178 + // this.loadPublicEquipment();
153 - this.loadScenicSpot(); 179 + // this.loadScenicSpot();
154 - this.loadPlant(); 180 + // this.loadPlant();
155 // this.setMapBoundary(); 181 // this.setMapBoundary();
156 // 使用之前都要再获取一下地址 182 // 使用之前都要再获取一下地址
157 this.getLocation() 183 this.getLocation()
184 + // 打开贴片地图
185 + // this.setTitleLayer()
158 }, 186 },
159 methods: { 187 methods: {
160 // addMarker () { 188 // addMarker () {
...@@ -190,7 +218,7 @@ export default { ...@@ -190,7 +218,7 @@ export default {
190 showIndoorMap: false, 218 showIndoorMap: false,
191 defaultCursor: 'pointer', // 地图默认鼠标样式 219 defaultCursor: 'pointer', // 地图默认鼠标样式
192 showBuildingBlock: false, // 是否展示地图 3D 楼块 220 showBuildingBlock: false, // 是否展示地图 3D 楼块
193 - zooms: [17, 19], // 地图显示的缩放级别范围, 默认为 [2, 20] ,取值范围 [2 ~ 30] 221 + zooms: [17, 18], // 地图显示的缩放级别范围, 默认为 [2, 20] ,取值范围 [2 ~ 30]
194 showLabel: true, // 是否展示地图文字和 POI 信息 222 showLabel: true, // 是否展示地图文字和 POI 信息
195 zoom: 18, // 设置地图显示的缩放级别 223 zoom: 18, // 设置地图显示的缩放级别
196 pitch: 0, // 俯仰角度,默认 0,最大值根据地图当前 zoom 级别不断增大,2D地图下无效 。 224 pitch: 0, // 俯仰角度,默认 0,最大值根据地图当前 zoom 级别不断增大,2D地图下无效 。
...@@ -204,6 +232,8 @@ export default { ...@@ -204,6 +232,8 @@ export default {
204 }); 232 });
205 // 添加地图点击事件 233 // 添加地图点击事件
206 this.map.on("click", this.showInfoClick); 234 this.map.on("click", this.showInfoClick);
235 + //
236 + this.setSpotLayer()
207 }, 237 },
208 layerMap() { 238 layerMap() {
209 // 图层地图 239 // 图层地图
...@@ -508,6 +538,56 @@ export default { ...@@ -508,6 +538,56 @@ export default {
508 }) 538 })
509 this.map.add(this.toiletInfo); 539 this.map.add(this.toiletInfo);
510 }, 540 },
541 + loadActivityMaker() { // 加载活动标记
542 + var zoomStyleMapping = { 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0, 20: 0 };
543 + _.each(coord.activityInfo, (x, i) => {
544 + var marker = new AMap.ElasticMarker({
545 + position: coord.activityInfo[i].position,
546 + zooms: [17, 19],
547 + styles: [{
548 + icon: {
549 + img: coord.activityInfo[i].icon,
550 + size: [16, 16], // 可见区域的大小
551 + anchor: 'bottom-center', // 锚点
552 + fitZoom: 14, // 最合适的级别
553 + scaleFactor: 2, // 地图放大一级的缩放比例系数
554 + maxScale: 1.4, // 最大放大比例
555 + minScale: 0.8 // 最小放大比例
556 + },
557 + label: {
558 + content: coord.activityInfo[i].name,
559 + position: 'TM',
560 + minZoom: 18
561 + }
562 + }],
563 + zoomStyleMapping
564 + });
565 + // let infoWindowContent =
566 + // '<div className="custom-infowindow input-card">' +
567 + // '<label style="color:grey">公共厕所</label>' +
568 + // // 为 infowindow 添加自定义事件
569 + // '<div id="lnglat2container" class="btn">我要走过去</div>' +
570 + // '</div>';
571 + // // 创建一个自定义内容的 infowindow 实例
572 + // let infoWindow = new AMap.InfoWindow({
573 + // position: coord.spotInfo[i].position,
574 + // offset: new AMap.Pixel(0, -30),
575 + // content: infoWindowContent
576 + // });
577 + if (clickListener) {
578 + marker.off('click', clickListener)
579 + }
580 + // 绑定景点的点击事件 - 文字出现才能触发
581 + var clickListener = marker.on('click', (e) => {
582 + // infoWindow.open(this.map);
583 + this.show_popup = true;
584 + })
585 + //
586 + this.activityInfo.push(marker);
587 +
588 + })
589 + this.map.add(this.activityInfo);
590 + },
511 setMapBoundary() { // 地图描边 591 setMapBoundary() { // 地图描边
512 new AMap.Polygon({ 592 new AMap.Polygon({
513 cursor: 'pointer', 593 cursor: 'pointer',
...@@ -543,19 +623,23 @@ export default { ...@@ -543,19 +623,23 @@ export default {
543 }, 623 },
544 setLocation() { // 开启定位服务 624 setLocation() { // 开启定位服务
545 // this.map.addControl(this.geolocation); // 添加定位图标 自动跳转当前位置 625 // this.map.addControl(this.geolocation); // 添加定位图标 自动跳转当前位置
546 - // 使用纠正偏移后的地址,打一个定位标记 626 + if (!this.current_lng || !this.current_lat) {
547 - var marker = new AMap.Marker({ 627 + this.getLocation()
548 - position: new AMap.LngLat(this.current_lng, this.current_lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] 628 + } else {
549 - }); 629 + // 使用纠正偏移后的地址,打一个定位标记
550 - this.map.add(marker); 630 + var marker = new AMap.Marker({
551 - // 定位到地图中心-西园寺 631 + position: new AMap.LngLat(this.current_lng, this.current_lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
552 - this.map.setCenter([120.587334, 31.314823]); 632 + });
553 - // 判断是否在范围内 633 + this.map.add(marker);
554 - let isPointInRing = AMap.GeometryUtil.isPointInRing([this.current_lng, this.current_lat], [ 634 + // 定位到地图中心-西园寺
555 - [120.585111, 31.316084], [120.585111, 31.316084], [120.589488, 31.313197], [120.585422, 31.313005] 635 + this.map.setCenter([120.587334, 31.314823]);
556 - ]); 636 + // 判断是否在范围内
557 - if (!isPointInRing) { 637 + let isPointInRing = AMap.GeometryUtil.isPointInRing([this.current_lng, this.current_lat], [
558 - this.dialog_show = true; 638 + [120.585111, 31.316084], [120.585111, 31.316084], [120.589488, 31.313197], [120.585422, 31.313005]
639 + ]);
640 + if (!isPointInRing) {
641 + this.dialog_show = true;
642 + }
559 } 643 }
560 }, 644 },
561 getLocation() { 645 getLocation() {
...@@ -577,13 +661,22 @@ export default { ...@@ -577,13 +661,22 @@ export default {
577 }) 661 })
578 }); 662 });
579 }, 663 },
664 + setZoom (type) { // 设置放大缩小地图
665 + const zoom = this.map.getZoom();
666 + if (type === 'plus') {
667 + this.map.setZoom(zoom + 1)
668 + }
669 + if (type === 'minus') {
670 + this.map.setZoom(zoom - 1)
671 + }
672 + },
580 setRoute() { // 生成路径 673 setRoute() { // 生成路径
581 // 行动路线 674 // 行动路线
582 var path = [ 675 var path = [
583 - [116.413384, 39.874071], 676 + [120.587512, 31.313796],
584 - [116.413141, 39.877934], 677 + [120.587495, 31.314204],
585 - [116.411469, 39.878175], 678 + [120.586862, 31.314304],
586 - [this.current_lng, this.current_lat] 679 + [120.586841, 31.314543]
587 ]; 680 ];
588 681
589 this.current_route = new AMap.Polyline({ 682 this.current_route = new AMap.Polyline({
...@@ -603,12 +696,23 @@ export default { ...@@ -603,12 +696,23 @@ export default {
603 zIndex: 50 696 zIndex: 50
604 }) 697 })
605 }, 698 },
606 - addLocation() { // 新增路径 699 + addSafeRoute() { // 新增路径
607 this.setRoute(); 700 this.setRoute();
608 this.map.add([this.current_route]); 701 this.map.add([this.current_route]);
702 + //
703 + var marker1 = new AMap.Marker({
704 + position: new AMap.LngLat(120.587506, 31.313787), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
705 + });
706 + var marker2 = new AMap.Marker({
707 + position: new AMap.LngLat(120.586825, 31.314543), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
708 + });
709 + // 新增逃生路线标记
710 + this.safe_route = [marker1, marker2]
711 + this.map.add(this.safe_route);
609 }, 712 },
610 - removeLocation() { // 删除路径 713 + removeSafeRoute() { // 删除路径
611 this.map.remove([this.current_route]); 714 this.map.remove([this.current_route]);
715 + this.map.remove(this.safe_route);
612 }, 716 },
613 setTitleLayer() { 717 setTitleLayer() {
614 //该demo可模拟水印效果 718 //该demo可模拟水印效果
...@@ -662,25 +766,36 @@ export default { ...@@ -662,25 +766,36 @@ export default {
662 layer.setMap(this.map); 766 layer.setMap(this.map);
663 767
664 // 只显示相应区域,移动会回到选定范围 768 // 只显示相应区域,移动会回到选定范围
665 - this.lockMapBounds() 769 + // this.lockMapBounds()
666 770
667 }, 771 },
668 setSpotLayer() { // 设置景点图层 772 setSpotLayer() { // 设置景点图层
669 this.removeToiletLayer() 773 this.removeToiletLayer()
774 + this.removeActivityLayer()
670 // 加载地图标记 775 // 加载地图标记
671 this.loadSpotMaker() 776 this.loadSpotMaker()
672 }, 777 },
673 setToiletLayer() { // 设置景点图层 778 setToiletLayer() { // 设置景点图层
674 this.removeSpotLayer() 779 this.removeSpotLayer()
780 + this.removeActivityLayer()
675 // 加载厕所标记 781 // 加载厕所标记
676 this.loadToiletMaker() 782 this.loadToiletMaker()
677 }, 783 },
784 + setActivityLayer() { // 设置活动图层
785 + this.removeSpotLayer();
786 + this.removeToiletLayer()
787 + // 加载活动标记
788 + this.loadActivityMaker()
789 + },
678 removeSpotLayer() { // 删除景点标记 790 removeSpotLayer() { // 删除景点标记
679 this.map.remove(this.spotInfo); 791 this.map.remove(this.spotInfo);
680 }, 792 },
681 removeToiletLayer() { // 删除景点标记 793 removeToiletLayer() { // 删除景点标记
682 this.map.remove(this.toiletInfo); 794 this.map.remove(this.toiletInfo);
683 }, 795 },
796 + removeActivityLayer() { // 删除活动标记
797 + this.map.remove(this.activityInfo);
798 + },
684 // 限制地图范围 799 // 限制地图范围
685 lockMapBounds() { 800 lockMapBounds() {
686 // var bounds = this.map.getBounds(); 801 // var bounds = this.map.getBounds();
...@@ -724,6 +839,27 @@ export default { ...@@ -724,6 +839,27 @@ export default {
724 }, 839 },
725 removeWalkRoute () { 840 removeWalkRoute () {
726 this.walk_route.clear() 841 this.walk_route.clear()
842 + },
843 + setNavLayer (index) { // 选择地图图层显示
844 + this.isActive = index;
845 + if (index === 0) {
846 + this.setSpotLayer()
847 + }
848 + if (index === 1) {
849 + this.setToiletLayer()
850 + }
851 + if (index === 2) {
852 + this.setActivityLayer()
853 + }
854 + },
855 + handleSafeRoute (status) { // 打开/关闭逃生路线线
856 + if (status) {
857 + this.addSafeRoute()
858 + this.open_safe_route = false;
859 + } else {
860 + this.removeSafeRoute()
861 + this.open_safe_route = true;
862 + }
727 } 863 }
728 } 864 }
729 } 865 }
...@@ -768,10 +904,39 @@ export default { ...@@ -768,10 +904,39 @@ export default {
768 border-radius: 0.4rem; 904 border-radius: 0.4rem;
769 box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5); 905 box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
770 position: fixed; 906 position: fixed;
771 - top: 1rem; 907 + top: 4rem;
772 right: 1rem; 908 right: 1rem;
773 -ms-flex: 1 1 auto; 909 -ms-flex: 1 1 auto;
774 flex: 1 1 auto; 910 flex: 1 1 auto;
775 padding: 0.75rem 1.25rem; 911 padding: 0.75rem 1.25rem;
776 } 912 }
913 +
914 +.tool-bar-wrapper {
915 + position: absolute;
916 + left: 20px;
917 + bottom: 40px;
918 + width: 20px;
919 +}
920 +.nav-bar-wrapper {
921 + position: absolute;
922 + top: 0;
923 + left: 0;
924 + right: 0;
925 + height: 3.5rem;
926 + background-color: white;
927 + text-align: center;
928 + box-shadow: 0 2px 2px rgba(0, 0, 0, .2);
929 + .item {
930 + padding-top: 0.5rem;
931 + }
932 + .checked {
933 + color: red;
934 + }
935 +}
936 +.safe-route-wrapper {
937 + position: absolute;
938 + bottom: 1rem;
939 + right: 1rem;
940 + background-color: white;
941 +}
777 </style> 942 </style>
......