Showing
4 changed files
with
112 additions
and
25 deletions
| ... | @@ -118,6 +118,13 @@ var spotInfo = [ | ... | @@ -118,6 +118,13 @@ var spotInfo = [ |
| 118 | ], | 118 | ], |
| 119 | // zoom: { 17: 0, 18: 0, 19: 0, 20: 0 }, | 119 | // zoom: { 17: 0, 18: 0, 19: 0, 20: 0 }, |
| 120 | window_type: 'normal', | 120 | window_type: 'normal', |
| 121 | + path: [ | ||
| 122 | + [120.58769, 31.313319], | ||
| 123 | + [120.587631, 31.313058], | ||
| 124 | + [120.587575, 31.312943], | ||
| 125 | + [120.587538, 31.312777], | ||
| 126 | + [120.587894, 31.312779], | ||
| 127 | + ], | ||
| 121 | }, | 128 | }, |
| 122 | { | 129 | { |
| 123 | name: '福德智慧二桥', | 130 | name: '福德智慧二桥', |
| ... | @@ -132,6 +139,11 @@ var spotInfo = [ | ... | @@ -132,6 +139,11 @@ var spotInfo = [ |
| 132 | ], | 139 | ], |
| 133 | // zoom: { 17: 1, 18: 1, 19: 0, 20: 0 }, | 140 | // zoom: { 17: 1, 18: 1, 19: 0, 20: 0 }, |
| 134 | window_type: 'normal', | 141 | window_type: 'normal', |
| 142 | + path: [ | ||
| 143 | + [120.588046, 31.313359], | ||
| 144 | + [120.588138, 31.313203], | ||
| 145 | + [120.588168, 31.313004], | ||
| 146 | + ], | ||
| 135 | }, | 147 | }, |
| 136 | { | 148 | { |
| 137 | name: '御赐牌楼', | 149 | name: '御赐牌楼', | ... | ... |
| ... | @@ -249,7 +249,8 @@ export default { | ... | @@ -249,7 +249,8 @@ export default { |
| 249 | } | 249 | } |
| 250 | }, | 250 | }, |
| 251 | goToLocation () { | 251 | goToLocation () { |
| 252 | - this.$emit('onLocation', this.info.position) | 252 | + // this.$emit('onLocation', this.info.position) |
| 253 | + this.$emit('onLocation', this.info.path) | ||
| 253 | } | 254 | } |
| 254 | } | 255 | } |
| 255 | } | 256 | } | ... | ... |
| ... | @@ -97,7 +97,8 @@ export default { | ... | @@ -97,7 +97,8 @@ export default { |
| 97 | location.href = this.info.details[this.isActive].url; | 97 | location.href = this.info.details[this.isActive].url; |
| 98 | }, | 98 | }, |
| 99 | goToLocation() { | 99 | goToLocation() { |
| 100 | - this.$emit('onLocation', this.info.position) | 100 | + // this.$emit('onLocation', this.info.position) |
| 101 | + this.$emit('onLocation', this.info.path) | ||
| 101 | } | 102 | } |
| 102 | } | 103 | } |
| 103 | } | 104 | } | ... | ... |
| 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-28 11:02:03 | 4 | + * @LastEditTime: 2023-06-28 14:13:45 |
| 5 | * @FilePath: /map-demo/src/views/index.vue | 5 | * @FilePath: /map-demo/src/views/index.vue |
| 6 | * @Description: 地图主体页面 | 6 | * @Description: 地图主体页面 |
| 7 | --> | 7 | --> |
| ... | @@ -36,10 +36,10 @@ | ... | @@ -36,10 +36,10 @@ |
| 36 | </div> | 36 | </div> |
| 37 | <div class="operate-bar-wrapper"> | 37 | <div class="operate-bar-wrapper"> |
| 38 | <div class="box-wrapper"> | 38 | <div class="box-wrapper"> |
| 39 | - <div class="item" @click="setLocation"> | 39 | + <!-- <div class="item" @click="setLocation"> |
| 40 | <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A%E4%BD%8Dloc@2x.png" size="1.5rem" | 40 | <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A%E4%BD%8Dloc@2x.png" size="1.5rem" |
| 41 | style="vertical-align: middle;" /> | 41 | style="vertical-align: middle;" /> |
| 42 | - </div> | 42 | + </div> --> |
| 43 | <div v-if="open_safe_route" class="item" @click="handleSafeRoute(true)"> | 43 | <div v-if="open_safe_route" class="item" @click="handleSafeRoute(true)"> |
| 44 | <van-icon name="https://cdn.ipadbiz.cn/xys/map/%E7%BA%BF%E8%B7%AF@2x.png" size="1.25rem" | 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;" /> | 45 | style="vertical-align: middle;" /> |
| ... | @@ -51,7 +51,10 @@ | ... | @@ -51,7 +51,10 @@ |
| 51 | </div> | 51 | </div> |
| 52 | </div> | 52 | </div> |
| 53 | 53 | ||
| 54 | - <div v-if="!show_walk_route" @click="removeWalkRoute" class="walk-nav-text"> | 54 | + <!-- <div v-if="!show_walk_route" @click="removeWalkRoute" class="walk-nav-text"> |
| 55 | + 关闭步行导航 | ||
| 56 | + </div> --> | ||
| 57 | + <div v-if="!show_walk_route" @click="removeNavRoute" class="walk-nav-text"> | ||
| 55 | 关闭步行导航 | 58 | 关闭步行导航 |
| 56 | </div> | 59 | </div> |
| 57 | 60 | ||
| ... | @@ -195,7 +198,7 @@ export default { | ... | @@ -195,7 +198,7 @@ export default { |
| 195 | walk_route: '', | 198 | walk_route: '', |
| 196 | toolBar: '', | 199 | toolBar: '', |
| 197 | isActive: 0, | 200 | isActive: 0, |
| 198 | - safe_route: [], | 201 | + route_marker: [], |
| 199 | open_safe_route: true, | 202 | open_safe_route: true, |
| 200 | show_walk_route: true, | 203 | show_walk_route: true, |
| 201 | popup_title: '', | 204 | popup_title: '', |
| ... | @@ -555,7 +558,7 @@ export default { | ... | @@ -555,7 +558,7 @@ export default { |
| 555 | this.map.setZoom(zoom - 1) | 558 | this.map.setZoom(zoom - 1) |
| 556 | } | 559 | } |
| 557 | }, | 560 | }, |
| 558 | - setRoute() { // 生成路径 | 561 | + addSafeRoute() { // 新增路径 |
| 559 | // 行动路线 | 562 | // 行动路线 |
| 560 | var path = [ | 563 | var path = [ |
| 561 | [120.587512, 31.313796], | 564 | [120.587512, 31.313796], |
| ... | @@ -563,9 +566,9 @@ export default { | ... | @@ -563,9 +566,9 @@ export default { |
| 563 | [120.586862, 31.314304], | 566 | [120.586862, 31.314304], |
| 564 | [120.586841, 31.314543] | 567 | [120.586841, 31.314543] |
| 565 | ]; | 568 | ]; |
| 566 | - | 569 | + // 生成折线地图路径 |
| 567 | this.current_route = new AMap.Polyline({ | 570 | this.current_route = new AMap.Polyline({ |
| 568 | - path: path, | 571 | + path, |
| 569 | isOutline: true, | 572 | isOutline: true, |
| 570 | outlineColor: '#7F7F7F', | 573 | outlineColor: '#7F7F7F', |
| 571 | borderWeight: 1, | 574 | borderWeight: 1, |
| ... | @@ -580,11 +583,72 @@ export default { | ... | @@ -580,11 +583,72 @@ export default { |
| 580 | lineCap: 'round', | 583 | lineCap: 'round', |
| 581 | zIndex: 50 | 584 | zIndex: 50 |
| 582 | }) | 585 | }) |
| 586 | + this.map.add([this.current_route]); | ||
| 587 | + // 设置起始点标记 | ||
| 588 | + var marker1 = new AMap.Marker({ | ||
| 589 | + icon: new AMap.Icon({ | ||
| 590 | + image: 'https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A%E4%BD%8D-%E5%B0%8F1@2x.png', | ||
| 591 | + size: new AMap.Size(40, 40), | ||
| 592 | + // 图标所用图片大小 | ||
| 593 | + imageSize: new AMap.Size(40, 40), | ||
| 594 | + // 图标取图偏移量 | ||
| 595 | + imageOffset: new AMap.Pixel(0, 0) | ||
| 596 | + }), | ||
| 597 | + position: new AMap.LngLat(path[0][0], path[0][1]), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] | ||
| 598 | + anchor: 'bottom-center', | ||
| 599 | + offset: new AMap.Pixel(0, 0) | ||
| 600 | + }); | ||
| 601 | + marker1.setLabel({ | ||
| 602 | + direction: 'right', | ||
| 603 | + offset: new AMap.Pixel(0, -10), //设置文本标注偏移量 | ||
| 604 | + content: "<div class='info'>起点</div>", //设置文本标注内容 | ||
| 605 | + }); | ||
| 606 | + var marker2 = new AMap.Marker({ | ||
| 607 | + icon: new AMap.Icon({ | ||
| 608 | + image: 'https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A%E4%BD%8D-%E5%B0%8F1@2x.png', | ||
| 609 | + size: new AMap.Size(40, 40), | ||
| 610 | + // 图标所用图片大小 | ||
| 611 | + imageSize: new AMap.Size(40, 40), | ||
| 612 | + // 图标取图偏移量 | ||
| 613 | + imageOffset: new AMap.Pixel(0, 0) | ||
| 614 | + }), | ||
| 615 | + position: new AMap.LngLat(path[path.length - 1][0], path[path.length - 1][1]), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] | ||
| 616 | + anchor: 'bottom-center', | ||
| 617 | + offset: new AMap.Pixel(0, 0) | ||
| 618 | + }); | ||
| 619 | + marker2.setLabel({ | ||
| 620 | + direction: 'right', | ||
| 621 | + offset: new AMap.Pixel(0, -10), //设置文本标注偏移量 | ||
| 622 | + content: "<div class='info'>终点</div>", //设置文本标注内容 | ||
| 623 | + }); | ||
| 624 | + // 新增逃生路线标记 | ||
| 625 | + this.route_marker = [marker1, marker2] | ||
| 626 | + this.map.add(this.route_marker); | ||
| 583 | }, | 627 | }, |
| 584 | - addSafeRoute() { // 新增路径 | 628 | + removeSafeRoute() { // 移除地图路线 |
| 585 | - this.setRoute(); | 629 | + this.map.remove([this.current_route]); // 删除地图折线 |
| 630 | + this.map.remove(this.route_marker); // 删除起始点标记 | ||
| 631 | + }, | ||
| 632 | + addNavRoute (path) { // 新增导航路径 | ||
| 633 | + // 生成折线地图路径 | ||
| 634 | + this.current_route = new AMap.Polyline({ | ||
| 635 | + path, | ||
| 636 | + isOutline: true, | ||
| 637 | + outlineColor: '#7F7F7F', | ||
| 638 | + borderWeight: 1, | ||
| 639 | + strokeColor: '#7F7F7F', | ||
| 640 | + strokeOpacity: 1, | ||
| 641 | + strokeWeight: 1, | ||
| 642 | + // 折线样式还支持 'dashed' | ||
| 643 | + strokeStyle: 'solid', | ||
| 644 | + // strokeStyle是dashed时有效 | ||
| 645 | + strokeDasharray: [10, 5], | ||
| 646 | + lineJoin: 'round', | ||
| 647 | + lineCap: 'round', | ||
| 648 | + zIndex: 50 | ||
| 649 | + }) | ||
| 586 | this.map.add([this.current_route]); | 650 | this.map.add([this.current_route]); |
| 587 | - // | 651 | + // 设置起始点标记 |
| 588 | var marker1 = new AMap.Marker({ | 652 | var marker1 = new AMap.Marker({ |
| 589 | icon: new AMap.Icon({ | 653 | icon: new AMap.Icon({ |
| 590 | image: 'https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A%E4%BD%8D-%E5%B0%8F1@2x.png', | 654 | image: 'https://cdn.ipadbiz.cn/xys/map/%E5%AE%9A%E4%BD%8D-%E5%B0%8F1@2x.png', |
| ... | @@ -594,7 +658,7 @@ export default { | ... | @@ -594,7 +658,7 @@ export default { |
| 594 | // 图标取图偏移量 | 658 | // 图标取图偏移量 |
| 595 | imageOffset: new AMap.Pixel(0, 0) | 659 | imageOffset: new AMap.Pixel(0, 0) |
| 596 | }), | 660 | }), |
| 597 | - position: new AMap.LngLat(120.587506, 31.313787), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] | 661 | + position: new AMap.LngLat(path[0][0], path[0][1]), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] |
| 598 | anchor: 'bottom-center', | 662 | anchor: 'bottom-center', |
| 599 | offset: new AMap.Pixel(0, 0) | 663 | offset: new AMap.Pixel(0, 0) |
| 600 | }); | 664 | }); |
| ... | @@ -612,7 +676,7 @@ export default { | ... | @@ -612,7 +676,7 @@ export default { |
| 612 | // 图标取图偏移量 | 676 | // 图标取图偏移量 |
| 613 | imageOffset: new AMap.Pixel(0, 0) | 677 | imageOffset: new AMap.Pixel(0, 0) |
| 614 | }), | 678 | }), |
| 615 | - position: new AMap.LngLat(120.586825, 31.314543), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] | 679 | + position: new AMap.LngLat(path[path.length - 1][0], path[path.length - 1][1]), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] |
| 616 | anchor: 'bottom-center', | 680 | anchor: 'bottom-center', |
| 617 | offset: new AMap.Pixel(0, 0) | 681 | offset: new AMap.Pixel(0, 0) |
| 618 | }); | 682 | }); |
| ... | @@ -622,12 +686,16 @@ export default { | ... | @@ -622,12 +686,16 @@ export default { |
| 622 | content: "<div class='info'>终点</div>", //设置文本标注内容 | 686 | content: "<div class='info'>终点</div>", //设置文本标注内容 |
| 623 | }); | 687 | }); |
| 624 | // 新增逃生路线标记 | 688 | // 新增逃生路线标记 |
| 625 | - this.safe_route = [marker1, marker2] | 689 | + this.route_marker = [marker1, marker2] |
| 626 | - this.map.add(this.safe_route); | 690 | + this.map.add(this.route_marker); |
| 691 | + // 关闭导航提示 | ||
| 692 | + this.show_walk_route = false; | ||
| 627 | }, | 693 | }, |
| 628 | - removeSafeRoute() { // 删除路径 | 694 | + removeNavRoute() { // 移除地图路线 |
| 629 | - this.map.remove([this.current_route]); | 695 | + this.map.remove([this.current_route]); // 删除地图折线 |
| 630 | - this.map.remove(this.safe_route); | 696 | + this.map.remove(this.route_marker); // 删除起始点标记 |
| 697 | + // 关闭导航提示 | ||
| 698 | + this.show_walk_route = true; | ||
| 631 | }, | 699 | }, |
| 632 | setTitleLayer() { // 生成瓦片图 | 700 | setTitleLayer() { // 生成瓦片图 |
| 633 | var layer = new AMap.TileLayer.Flexible({ | 701 | var layer = new AMap.TileLayer.Flexible({ |
| ... | @@ -806,7 +874,7 @@ export default { | ... | @@ -806,7 +874,7 @@ export default { |
| 806 | this.walk_route.clear(); | 874 | this.walk_route.clear(); |
| 807 | this.show_walk_route = true; | 875 | this.show_walk_route = true; |
| 808 | }, | 876 | }, |
| 809 | - infoWindowLocation(position) { // 监听前往按钮回调 | 877 | + infoWindowLocation(path) { // 监听前往按钮回调 |
| 810 | // TODO: 实际获取精确定位后导航到位置 | 878 | // TODO: 实际获取精确定位后导航到位置 |
| 811 | // // 判断是否在范围内 | 879 | // // 判断是否在范围内 |
| 812 | // if (!this.isPointInRing()) { | 880 | // if (!this.isPointInRing()) { |
| ... | @@ -814,12 +882,17 @@ export default { | ... | @@ -814,12 +882,17 @@ export default { |
| 814 | // } else { | 882 | // } else { |
| 815 | // this.setWalkRoute({ lng: this.current_lng, lat: this.current_lat }, { lng: position[0], lat: position[1] }) | 883 | // this.setWalkRoute({ lng: this.current_lng, lat: this.current_lat }, { lng: position[0], lat: position[1] }) |
| 816 | // } | 884 | // } |
| 817 | - if (this.walk_route) { // 清除前一条步行导航 | 885 | + // if (this.walk_route) { // 清除前一条步行导航 |
| 818 | - this.walk_route.clear(); | 886 | + // this.walk_route.clear(); |
| 819 | - } | 887 | + // } |
| 820 | // 测试 | 888 | // 测试 |
| 821 | this.closeInfoWindow(); // 关闭弹框 | 889 | this.closeInfoWindow(); // 关闭弹框 |
| 822 | - this.setWalkRoute({ lng: 120.59014, lat: 31.310306 }, { lng: position[0], lat: position[1] }); | 890 | + // this.setWalkRoute({ lng: 120.59014, lat: 31.310306 }, { lng: position[0], lat: position[1] }); |
| 891 | + if (this.current_route) { // 清除前一条步行导航 | ||
| 892 | + this.map.remove([this.current_route]); // 删除地图折线 | ||
| 893 | + this.map.remove(this.route_marker); // 删除起始点标记 | ||
| 894 | + } | ||
| 895 | + this.addNavRoute(path) | ||
| 823 | }, | 896 | }, |
| 824 | setNavLayer({ key }, index) { // 选择地图图层显示 | 897 | setNavLayer({ key }, index) { // 选择地图图层显示 |
| 825 | this.isActive = index; | 898 | this.isActive = index; | ... | ... |
-
Please register or login to post a comment