xy-map 1.0.28 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/index.html +8 -0
- package/src/map.js +1 -1
- package/src/package/draw/index.vue +5 -4
- package/src/package/mapMarker.vue +5 -3
- package/src/util/gaodeApi.js +71 -0
package/package.json
CHANGED
package/public/index.html
CHANGED
|
@@ -17,5 +17,13 @@
|
|
|
17
17
|
<div id="app"></div>
|
|
18
18
|
<!-- built files will be auto injected -->
|
|
19
19
|
</body>
|
|
20
|
+
<script type="text/javascript">
|
|
21
|
+
window._AMapSecurityConfig = {
|
|
22
|
+
securityJsCode: '261f789527e95a030aee9155590ff24c',
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
25
|
+
<script
|
|
26
|
+
src="https://webapi.amap.com/maps?v=2.0&key=dbd721a5a7d1276483505b5b821aa9e9&plugin=AMap.DistrictSearch&plugin=AMap.Geocoder&plugin=AMap.MouseTool&plugin=AMap.DistrictLayer&plugin=AMap.MarkerClusterer&plugin=Map3D"
|
|
27
|
+
charset="utf-8"></script>
|
|
20
28
|
|
|
21
29
|
</html>
|
package/src/map.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
</div>
|
|
24
24
|
</div>
|
|
25
25
|
|
|
26
|
+
<slot></slot>
|
|
26
27
|
</div>
|
|
27
28
|
</template>
|
|
28
29
|
|
|
@@ -57,7 +58,7 @@ export default {
|
|
|
57
58
|
{ id: 'polygon', type: 'draw_polygon', name: '绘制面', icon: 'el-icon-house' },
|
|
58
59
|
// { id: 'circle', type: 'draw_circle', name: '绘制圆', icon: 'el-icon-pie-chart' },
|
|
59
60
|
]
|
|
60
|
-
let filter = this.list.length > 0 ? arr.filter(item => this.list.includes(item.
|
|
61
|
+
let filter = this.list.length > 0 ? arr.filter(item => this.list.includes(item.id)) : arr
|
|
61
62
|
return filter
|
|
62
63
|
}
|
|
63
64
|
},
|
|
@@ -127,11 +128,11 @@ export default {
|
|
|
127
128
|
left: 0;
|
|
128
129
|
top: 0;
|
|
129
130
|
margin: 15px;
|
|
131
|
+
background-color: rgba(255, 255, 255, 0.9);
|
|
132
|
+
padding: 14px;
|
|
133
|
+
border-radius: 5px;
|
|
130
134
|
|
|
131
135
|
.tools-bar {
|
|
132
|
-
background-color: rgba(255, 255, 255, 0.9);
|
|
133
|
-
padding: 14px;
|
|
134
|
-
border-radius: 5px;
|
|
135
136
|
cursor: pointer;
|
|
136
137
|
}
|
|
137
138
|
}
|
|
@@ -23,19 +23,21 @@ export default {
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
data () {
|
|
26
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
marker: ''
|
|
28
|
+
}
|
|
27
29
|
},
|
|
28
30
|
watch: {
|
|
29
31
|
map () {
|
|
30
32
|
let el = this.$refs.dom
|
|
31
|
-
const marker = new mapBoxGl.Marker(el, { draggable: this.drag }).setLngLat(this.position).addTo(this.map)
|
|
33
|
+
const marker = this.marker = new mapBoxGl.Marker(el, { draggable: this.drag }).setLngLat(this.position).addTo(this.map)
|
|
32
34
|
if (this.drag) {
|
|
33
35
|
marker.on('dragend', () => {
|
|
34
36
|
const lngLat = marker.getLngLat()
|
|
35
37
|
this.$emit('dragEnd', lngLat)
|
|
36
38
|
})
|
|
37
39
|
}
|
|
38
|
-
}
|
|
40
|
+
},
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
</script>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// 获取浏览器定位
|
|
2
|
+
export function GeoAddress(lnglat) {
|
|
3
|
+
return new Promise((resolve) => {
|
|
4
|
+
// eslint-disable-next-line no-undef
|
|
5
|
+
AMap.plugin('AMap.Geocoder', () => {
|
|
6
|
+
// eslint-disable-next-line no-undef
|
|
7
|
+
const geocoder = new AMap.Geocoder()
|
|
8
|
+
|
|
9
|
+
geocoder.getAddress(lnglat, (status, result) => {
|
|
10
|
+
let address = {}
|
|
11
|
+
if (status === 'complete' && result.info === 'OK') {
|
|
12
|
+
console.log(result)
|
|
13
|
+
// result为对应的地理位置详细信息
|
|
14
|
+
address = {
|
|
15
|
+
formattedAddress: result.regeocode.formattedAddress,
|
|
16
|
+
...result.regeocode.addressComponent
|
|
17
|
+
}
|
|
18
|
+
// console.log(address)
|
|
19
|
+
resolve(address)
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// 获取浏览器定位
|
|
28
|
+
export function Geolocation() {
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
// eslint-disable-next-line no-undef
|
|
31
|
+
new AMap.plugin('AMap.Geolocation', () => {
|
|
32
|
+
// eslint-disable-next-line no-undef
|
|
33
|
+
const geolocation = new AMap.Geolocation({
|
|
34
|
+
// 是否使用高精度定位,默认:true
|
|
35
|
+
enableHighAccuracy: true,
|
|
36
|
+
// 设置定位超时时间,默认:无穷大
|
|
37
|
+
timeout: 10000,
|
|
38
|
+
// 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20)
|
|
39
|
+
// eslint-disable-next-line no-undef
|
|
40
|
+
buttonOffset: new AMap.Pixel(10, 20),
|
|
41
|
+
// 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
|
|
42
|
+
zoomToAccuracy: true,
|
|
43
|
+
// 定位按钮的排放位置, RB表示右下
|
|
44
|
+
buttonPosition: 'RB'
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
geolocation.getCurrentPosition((status, result) => {
|
|
48
|
+
if (status === 'complete') {
|
|
49
|
+
onComplete(result)
|
|
50
|
+
} else {
|
|
51
|
+
onError(result)
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
function onComplete(data) {
|
|
56
|
+
// data是具体的定位信息
|
|
57
|
+
const info = {
|
|
58
|
+
lng: data.position.lng,
|
|
59
|
+
lat: data.position.lat,
|
|
60
|
+
formattedAddress: data.formattedAddress,
|
|
61
|
+
...data.addressComponent
|
|
62
|
+
}
|
|
63
|
+
resolve(info)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function onError(data) {
|
|
67
|
+
// 定位出错
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
}
|