惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
Forbes - Security
Forbes - Security
The Last Watchdog
The Last Watchdog
TaoSecurity Blog
TaoSecurity Blog
Schneier on Security
Schneier on Security
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
Project Zero
Project Zero
O
OpenAI News
W
WeLiveSecurity
Security Archives - TechRepublic
Security Archives - TechRepublic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Hacker News: Front Page
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
Help Net Security
Help Net Security
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
S
Security @ Cisco Blogs
Latest news
Latest news
AWS News Blog
AWS News Blog
U
Unit 42
Martin Fowler
Martin Fowler
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Know Your Adversary
Know Your Adversary
Scott Helme
Scott Helme
博客园 - 司徒正美
B
Blog RSS Feed
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker
Google Online Security Blog
Google Online Security Blog
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Last Week in AI
Last Week in AI
月光博客
月光博客
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
SegmentFault 最新的问题
NISL@THU
NISL@THU
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
小众软件
小众软件

Xiaobin's Notes

Mac本地快速部署DeepSeek Electron的原理 如何让大语言模型输出JSON格式 webstorm 的 cpu 占用高 修改Joplin主题样式 ECMAScript 历代版本 新一代包管理器 PNPM React useEffect() Hook 家庭用电插座 MacOS 14.4 引发Java 应用崩溃 重定向广告 Pyenv工具 ElasticSearch集群原理 ElasticSearch集群节点 Elasticsearch Mapping 参数 Elasticsearch元数据 Elasticsearch的数据类型 Go语言的向后兼容和toolchain规则 Go 1.21 新增特性
Vue 2.x 使用高德地图JS API 2.0加载起点终点路径轨迹
xbl · 2024-05-01 · via Xiaobin's Notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// index.vue
<template>
<div class="index">
<template >
<v-map :data="dataList"></v-map>
<v-detail :statrLocation="statrLocation" :endLocation="endLocation"/>
</template>
</div>
</template>

<script>
import Map from './mMap.vue' // 地图
import Detail from './detail.vue'

export default {
name: 'index',
data() {
return {
dataList: [],
statrLocation: {},
endLocation: {},
}
},
components: {
"v-map": Map,
"v-detail": Detail
},
mounted() {
this.dataList = [
{
longitude: 116.478346,
latitude: 39.997361
},
{
longitude: 116.402796,
latitude: 39.936915
}
]
this.statrLocation = this.dataList[0]
this.endLocation = this.dataList[this.dataList.length-1]
},
methods: {

}
};
</script>
<style scoped lang="scss">
.index {
position: relative;
width: 100%;
height: 100%;
background: #fcf9f2;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// mMap.vue
<template>
<div class="m-map">
<div id="map-box"></div>
</div>
</template>
<script>

export default {
props: ['data'],
data() {
return {
map: {},
lineArr: [],
};
},
created() {
this.initMap()
},
methods: {
initMap() {
this.$nextTick(() => {
this.map = new AMap.Map('map-box', {
resizeEnable: true, //是否监控地图容器尺寸变化
zoom: 14, //初始化地图层级
center: [116.397428, 39.90923], //初始化地图中心点
animateEnable: true// 地图平移过程中是否使用动画
});

if(this.lineArr.length) {
this.drawLine() //绘制路线
}
});
},
drawLine(){
AMap.convertFrom(this.lineArr, 'gps', (status, result) => {
if (result.info === 'ok') {
const paths = result.locations;

this.map.clearMap()

this.startMarker = new AMap.Marker({
map: this.map,
position: paths[0], //起点经纬度
icon: new AMap.Icon({
image: require('@/assets/img/icon/icon-start.png'),
size: new AMap.Size(120, 120), //图标所处区域大小
imageSize: new AMap.Size(120,120) //图标大小
}), //起点ico
offset: new AMap.Pixel(-60, -60),
autoRotation: true,
// angle:-90,
});

this.endMarker = new AMap.Marker({
map: this.map,
position: paths[paths.length-1], //终点经纬度
icon: new AMap.Icon({
image: require('@/assets/img/icon/icon-end.png'),
size: new AMap.Size(60, 60), //图标所处区域大小
imageSize: new AMap.Size(60,60) //图标大小
}), //终点ico
offset: new AMap.Pixel(-30, -30),
autoRotation: true,
});

// 绘制轨迹
var polyline = new AMap.Polyline({
map: this.map,
path: paths,
showDir: true,
strokeColor: '#28F', //线颜色
// strokeOpacity: 1, //线透明度
strokeWeight: 6, //线宽
// strokeStyle: "solid" //线样式
});
this.map.add([this.startMarker, this.endMarker]);
this.map.setFitView(); //自适应缩放级别
}
})

}
},
watch: {
data: {
handler(newValue, oldValue) {
this.lineArr = [];
if(newValue.length) {
newValue.map((item, index) => {
if( item.longitude != null && item.latitude != null ) {
this.lineArr.push(new AMap.LngLat(item.longitude,item.latitude));
}
});
this.drawLine();
}
},
immediate: true
},
},
};
</script>
<style scoped lang ="scss">
@import '@/assets/scss/mixin.scss';
.m-map {
width: 100%;
height: 100vh;
#map-box {
width: 100%;
height: 100%;
}
}
</style>

在使用中发现标记点位置显示不对,存在一定的偏移,需要将其他坐标转为高德坐标方法. 在绘制轨迹之前先转换为高德坐标,然后再删除地图上所有的覆盖物,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// detail.vue
<template>
<div class="m-detail-box">
<div class="m-btn-wrapper">
<van-button class="open-btn" round @click="openShow = true">导航至车辆当前位置</van-button>
</div>
<van-action-sheet
class="m-sheet-box"
v-model="openShow"
:actions="actions"
cancel-text="取消"
close-on-click-action
@select="onSelect"
/>
</div>
</template>

<script>
import {
Toast
} from 'vant';

export default {
props: {
statrLocation: {
type: Object,
default: () => ({})
},
endLocation: {
type: Object,
default: () => ({})
},
},
data() {
return {
openShow: false,
actions: [
{ name: '使用苹果地图导航', value: 'iosamap', color: '#007AFF' },
{ name: '使用百度地图导航', value: 'bmap', color: '#007AFF' },
{ name: '使用高德地图导航', value: 'amap', color: '#007AFF' }
],
}
},
filters: {

},
mounted() {

},
methods: {
onSelect(item) {
this.openShow = false;
let startLocation = this.startLocation
let endLocation = this.endLocation

if (endLocation.longitude && endLocation.latitude) {
let url = ''
switch (item.value) {
case 'iosamap':
url = `iosamap://navi?sourceApplication=applicationName&backScheme=applicationScheme&poiname=${location}&poiid=BGVIS&lat=${endLocation.latitude}&lon=${endLocation.longitude}&dev=1&style=2`
break;
case 'bmap':
// 单点标注
url = `http://api.map.baidu.com/marker?location=${endLocation.latitude},${endLocation.longitude}&title=车辆位置&content=实时定位&output=html&coord_type=wgs84&src=webapp.baidu.openAPIdemo`

// 路径规划
// url = `http://api.map.baidu.com/direction?origin=latlng:${startLocation.latitude},${startLocation.longitude}|name:我的位置&destination=latlng:${endLocation.latitude},${endLocation.longitude}|name:实时定位&mode=driving&coord_type=wgs84&src=webapp.baidu.openAPIdemo`
break;
case 'amap':
// 单点标注
url = `https://uri.amap.com/marker?position=${endLocation.longitude},${endLocation.latitude}&name=实时定位&src=mypage&coordinate=wgs84&callnative=1`

// 路径规划
// url = `https://uri.amap.com/navigation?from=${startLocation.longitude},${startLocation.latitude},我的位置&to=${endLocation.longitude},${endLocation.latitude},实时定位&mode=car&policy=1&coordinate=wgs84&callnative=1`
break;
}
window.open(url)
} else {
Toast({
message: '暂无车辆定位',
type: 'fail',
})
}
},
},
beforeDestroy() {
clearInterval(this.timer)
}
}
</script>
<style scoped lang="scss">
@import "@/assets/scss/mixin.scss";

.m-detail-box {
position: absolute;
bottom: 0;
padding: 20px 0 0;
border-radius: 20px 20px 0px 0px;
width: 100%;
background: #FEFFFE;
box-shadow: 0 4px 40px 4px rgba(135, 119, 145, 0.36);
z-index: 160;

.van-cell-group {
&::after {
border: none;
}
}

.van-cell {
padding: 12px 24px;
font-size: 16px;
font-weight: 600;

&::after {
left: 24px;
right: 24px;
}

.van-cell__title {
flex: none;
color: #757AB5;
}

.van-cell__value {
color: #292929;
}
}

.m-btn-wrapper {
border-top: 1px solid #EFF2F9;
background: #FFF;

.open-btn {
display: block;
margin: 10px auto;
padding: 14px;
width: 90%;
font-size: 18px;
color: #FEFFFE;
background: #85D4D9;
}
}

/deep/.van-overlay {
background: rgba(33, 34, 51, 0.5);
}

.m-sheet-box {
padding: 0 8px;
background: transparent;

.van-action-sheet__content {
border-radius: 14px;
background: rgba(255, 255, 255, 0.92);
}

.van-action-sheet__gap {
height: 20px;
background: transparent;
}

.van-action-sheet__cancel {
margin-bottom: 20px;
border-radius: 14px;
font-size: 20px;
color: #007AFF;
background: rgba(255, 255, 255, 0.92);
}
}
}
</style>