xy-map 1.0.33 → 1.0.35
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/src/map.js +2 -1
- package/src/package/draw/index.vue +6 -3
- package/src/package/draw/line.vue +56 -20
- package/src/package/draw/point.vue +9 -5
- package/src/package/draw/polygon.vue +43 -12
- package/src/package/draw/shpFile.vue +49 -0
- package/src/package/mapMarker.vue +9 -5
package/package.json
CHANGED
package/src/map.js
CHANGED
|
@@ -182,7 +182,8 @@ class mapSdk {
|
|
|
182
182
|
addBuildings(show = true) {
|
|
183
183
|
let map = this.map
|
|
184
184
|
const layers = map.getStyle().layers
|
|
185
|
-
const
|
|
185
|
+
const failed = layers.find((layer) => layer.type === 'symbol' && (layer.layout && layer.layout['text-field']))
|
|
186
|
+
const labelLayerId = failed ? failed.id : ''
|
|
186
187
|
if (show) {
|
|
187
188
|
map.addLayer({
|
|
188
189
|
'id': 'add-3d-buildings',
|
|
@@ -47,7 +47,7 @@ export default {
|
|
|
47
47
|
return {
|
|
48
48
|
type: 'move',
|
|
49
49
|
isEdit: false, //是否编辑模式
|
|
50
|
-
draw: ''
|
|
50
|
+
draw: '',
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
computed: {
|
|
@@ -64,6 +64,7 @@ export default {
|
|
|
64
64
|
},
|
|
65
65
|
methods: {
|
|
66
66
|
initDraw (map) {
|
|
67
|
+
this.map = map
|
|
67
68
|
const draw = this.draw = new MapboxDraw({
|
|
68
69
|
displayControlsDefault: false,
|
|
69
70
|
controls: {
|
|
@@ -123,8 +124,10 @@ export default {
|
|
|
123
124
|
this.draw.add(geometry)
|
|
124
125
|
},
|
|
125
126
|
drawDelete () {
|
|
126
|
-
this.draw
|
|
127
|
-
|
|
127
|
+
if (this.draw) {
|
|
128
|
+
this.draw.deleteAll()
|
|
129
|
+
this.$emit('clear')
|
|
130
|
+
}
|
|
128
131
|
},
|
|
129
132
|
}
|
|
130
133
|
}
|
|
@@ -5,14 +5,20 @@
|
|
|
5
5
|
|
|
6
6
|
<draw-tools ref="draw"
|
|
7
7
|
:list="['line']"
|
|
8
|
+
:single="single"
|
|
8
9
|
@update="drawUpdate"
|
|
9
|
-
@end="drawUpdate"
|
|
10
|
-
|
|
10
|
+
@end="drawUpdate"
|
|
11
|
+
@clear="clear">
|
|
12
|
+
<div class="mt-15 flex">
|
|
11
13
|
<el-input :value="position.toString()"
|
|
12
14
|
size="small"
|
|
13
15
|
placeholder="点击地图获取坐标"
|
|
14
16
|
:readonly="readonly"
|
|
15
17
|
style="width: 300px; margin-right: 10px;"></el-input>
|
|
18
|
+
|
|
19
|
+
<shp-file v-if="upload"
|
|
20
|
+
@upload="getShp"></shp-file>
|
|
21
|
+
|
|
16
22
|
<el-button type="primary"
|
|
17
23
|
size="small"
|
|
18
24
|
@click="save">保存</el-button>
|
|
@@ -24,10 +30,12 @@
|
|
|
24
30
|
<script>
|
|
25
31
|
import { mapSdk } from '../../index.js'
|
|
26
32
|
import drawTools from './index.vue'
|
|
33
|
+
import shpFile from './shpFile.vue'
|
|
27
34
|
|
|
28
35
|
export default {
|
|
29
36
|
components: {
|
|
30
|
-
drawTools
|
|
37
|
+
drawTools,
|
|
38
|
+
shpFile
|
|
31
39
|
},
|
|
32
40
|
props: {
|
|
33
41
|
config: {
|
|
@@ -35,9 +43,21 @@ export default {
|
|
|
35
43
|
default: () => { }
|
|
36
44
|
},
|
|
37
45
|
readonly: {
|
|
46
|
+
type: Boolean,
|
|
47
|
+
default: false
|
|
48
|
+
},
|
|
49
|
+
upload: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: false
|
|
52
|
+
},
|
|
53
|
+
autoZoom: { // 自动缩放适应边界
|
|
38
54
|
type: Boolean,
|
|
39
55
|
default: true
|
|
40
56
|
},
|
|
57
|
+
single: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: false
|
|
60
|
+
},
|
|
41
61
|
geoData: {
|
|
42
62
|
type: [Object, String],
|
|
43
63
|
default: ''
|
|
@@ -79,37 +99,44 @@ export default {
|
|
|
79
99
|
},
|
|
80
100
|
draw () {
|
|
81
101
|
if (this.pointList) {
|
|
102
|
+
let features = this.pointList.map(item => {
|
|
103
|
+
return {
|
|
104
|
+
'type': 'Feature',
|
|
105
|
+
'geometry': {
|
|
106
|
+
'type': 'LineString',
|
|
107
|
+
'coordinates': item
|
|
108
|
+
},
|
|
109
|
+
'properties': {}
|
|
110
|
+
}
|
|
111
|
+
})
|
|
82
112
|
this.geoJson = {
|
|
83
113
|
'type': 'FeatureCollection',
|
|
84
|
-
'features':
|
|
85
|
-
{
|
|
86
|
-
'type': 'Feature',
|
|
87
|
-
'geometry': {
|
|
88
|
-
'type': 'LineString',
|
|
89
|
-
'coordinates': this.pointList
|
|
90
|
-
},
|
|
91
|
-
'properties': {}
|
|
92
|
-
}
|
|
93
|
-
]
|
|
114
|
+
'features': features
|
|
94
115
|
}
|
|
95
116
|
} else {
|
|
96
117
|
this.geoJson = this.geoData
|
|
97
118
|
}
|
|
98
119
|
this.drawUpdate(this.geoJson)
|
|
99
|
-
|
|
120
|
+
this.edit()
|
|
121
|
+
},
|
|
122
|
+
edit () {
|
|
100
123
|
// 开启编辑
|
|
101
124
|
this.geoJson.features.forEach(item => {
|
|
102
125
|
this.$refs.draw.drawEdit(item.geometry)
|
|
103
126
|
})
|
|
104
127
|
},
|
|
105
|
-
drawUpdate (data) {
|
|
128
|
+
drawUpdate (data, autoZoom = false) {
|
|
106
129
|
this.geoJson = data
|
|
107
|
-
this.position =
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
130
|
+
this.position = this.geoJson.features.map(item => item.geometry.coordinates)
|
|
131
|
+
|
|
132
|
+
if (this.autoZoom || autoZoom) { // 开启缩放动画
|
|
133
|
+
this.$nextTick(() => {
|
|
134
|
+
const bounds = this.position.flat() // 二维数组转一维数组
|
|
135
|
+
mapSdk.fitLineBounds(bounds, {
|
|
136
|
+
padding: 100
|
|
137
|
+
})
|
|
111
138
|
})
|
|
112
|
-
}
|
|
139
|
+
}
|
|
113
140
|
},
|
|
114
141
|
save () {
|
|
115
142
|
let data = {
|
|
@@ -118,6 +145,15 @@ export default {
|
|
|
118
145
|
}
|
|
119
146
|
console.log(data)
|
|
120
147
|
this.$emit('save', data)
|
|
148
|
+
},
|
|
149
|
+
clear () {
|
|
150
|
+
this.geoJson = ''
|
|
151
|
+
this.position = ''
|
|
152
|
+
},
|
|
153
|
+
getShp (shp) {
|
|
154
|
+
this.$refs.draw.drawDelete() // 先清空画布
|
|
155
|
+
this.drawUpdate(shp, true)
|
|
156
|
+
this.edit()
|
|
121
157
|
}
|
|
122
158
|
}
|
|
123
159
|
}
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
<draw-tools ref="draw"
|
|
7
7
|
:list="['point']"
|
|
8
8
|
@update="drawUpdate"
|
|
9
|
-
@end="drawUpdate"
|
|
9
|
+
@end="drawUpdate"
|
|
10
|
+
@clear="clear">
|
|
10
11
|
<div class="mt-15"
|
|
11
12
|
style="width: 380px;">
|
|
12
13
|
<div class="flex">
|
|
@@ -58,7 +59,6 @@ export default {
|
|
|
58
59
|
geoJson: '',
|
|
59
60
|
position: '',
|
|
60
61
|
address: '',
|
|
61
|
-
map: ''
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
watch: {
|
|
@@ -81,7 +81,6 @@ export default {
|
|
|
81
81
|
is3d: false,
|
|
82
82
|
}, this.config)
|
|
83
83
|
mapSdk.initMap(config).then(map => {
|
|
84
|
-
this.map = map
|
|
85
84
|
this.$refs.draw.initDraw(map)
|
|
86
85
|
this.draw()
|
|
87
86
|
})
|
|
@@ -95,7 +94,7 @@ export default {
|
|
|
95
94
|
'type': 'Feature',
|
|
96
95
|
'geometry': {
|
|
97
96
|
'type': 'Point',
|
|
98
|
-
'coordinates': [this.lng, this.lat]
|
|
97
|
+
'coordinates': [this.lng * 1, this.lat * 1]
|
|
99
98
|
},
|
|
100
99
|
'properties': {}
|
|
101
100
|
}
|
|
@@ -131,7 +130,12 @@ export default {
|
|
|
131
130
|
}
|
|
132
131
|
console.log(data)
|
|
133
132
|
this.$emit('save', data)
|
|
134
|
-
}
|
|
133
|
+
},
|
|
134
|
+
clear () {
|
|
135
|
+
this.geoJson = ''
|
|
136
|
+
this.position = ''
|
|
137
|
+
this.address = ''
|
|
138
|
+
},
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
141
|
</script>
|
|
@@ -5,15 +5,20 @@
|
|
|
5
5
|
|
|
6
6
|
<draw-tools ref="draw"
|
|
7
7
|
:list="['polygon']"
|
|
8
|
-
:single="
|
|
8
|
+
:single="single"
|
|
9
9
|
@update="drawUpdate"
|
|
10
|
-
@end="drawUpdate"
|
|
10
|
+
@end="drawUpdate"
|
|
11
|
+
@clear="clear">
|
|
11
12
|
<div class="mt-15 ">
|
|
12
13
|
<el-input :value="position.toString()"
|
|
13
14
|
size="small"
|
|
14
15
|
placeholder="点击地图获取坐标"
|
|
15
16
|
:readonly="readonly"
|
|
16
17
|
style="width: 300px; margin-right: 10px;"></el-input>
|
|
18
|
+
|
|
19
|
+
<shp-file @upload="getShp"
|
|
20
|
+
v-if="upload"></shp-file>
|
|
21
|
+
|
|
17
22
|
<el-button type="primary"
|
|
18
23
|
size="small"
|
|
19
24
|
@click="save">保存</el-button>
|
|
@@ -25,20 +30,34 @@
|
|
|
25
30
|
<script>
|
|
26
31
|
import { mapSdk } from '../../index.js'
|
|
27
32
|
import drawTools from './index.vue'
|
|
33
|
+
import shpFile from './shpFile.vue'
|
|
28
34
|
|
|
29
35
|
export default {
|
|
30
36
|
components: {
|
|
31
|
-
drawTools
|
|
37
|
+
drawTools,
|
|
38
|
+
shpFile
|
|
32
39
|
},
|
|
33
40
|
props: {
|
|
34
41
|
config: {
|
|
35
42
|
type: Object,
|
|
36
43
|
default: () => { }
|
|
37
44
|
},
|
|
45
|
+
single: {
|
|
46
|
+
type: Boolean,
|
|
47
|
+
default: false
|
|
48
|
+
},
|
|
49
|
+
autoZoom: { // 自动缩放适应边界
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: true
|
|
52
|
+
},
|
|
38
53
|
readonly: {
|
|
39
54
|
type: Boolean,
|
|
40
55
|
default: true
|
|
41
56
|
},
|
|
57
|
+
upload: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: false
|
|
60
|
+
},
|
|
42
61
|
geoData: {
|
|
43
62
|
type: [Object, String],
|
|
44
63
|
default: ''
|
|
@@ -98,23 +117,26 @@ export default {
|
|
|
98
117
|
this.geoJson = this.geoData
|
|
99
118
|
}
|
|
100
119
|
this.drawUpdate(this.geoJson)
|
|
101
|
-
|
|
120
|
+
this.edit()
|
|
121
|
+
},
|
|
122
|
+
edit () {
|
|
102
123
|
// 开启编辑
|
|
103
124
|
this.geoJson.features.forEach(item => {
|
|
104
125
|
this.$refs.draw.drawEdit(item.geometry)
|
|
105
126
|
})
|
|
106
127
|
},
|
|
107
|
-
drawUpdate (data) {
|
|
128
|
+
drawUpdate (data, autoZoom = false) {
|
|
108
129
|
this.geoJson = data
|
|
109
130
|
this.position = data.features.map(item => item.geometry.coordinates[0])
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
131
|
+
|
|
132
|
+
if (this.autoZoom || autoZoom) {
|
|
133
|
+
this.$nextTick(() => {
|
|
134
|
+
const bounds = this.position.flat() // 二维数组转一维数组
|
|
135
|
+
mapSdk.fitLineBounds(bounds, {
|
|
136
|
+
padding: 100
|
|
137
|
+
})
|
|
116
138
|
})
|
|
117
|
-
}
|
|
139
|
+
}
|
|
118
140
|
},
|
|
119
141
|
save () {
|
|
120
142
|
let data = {
|
|
@@ -123,6 +145,15 @@ export default {
|
|
|
123
145
|
}
|
|
124
146
|
console.log(data)
|
|
125
147
|
this.$emit('save', data)
|
|
148
|
+
},
|
|
149
|
+
clear () {
|
|
150
|
+
this.geoJson = ''
|
|
151
|
+
this.position = ''
|
|
152
|
+
},
|
|
153
|
+
getShp (shp) {
|
|
154
|
+
this.$refs.draw.drawDelete() // 先清空画布
|
|
155
|
+
this.drawUpdate(shp, true)
|
|
156
|
+
this.edit()
|
|
126
157
|
}
|
|
127
158
|
}
|
|
128
159
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-button size="small"
|
|
3
|
+
class="upload"
|
|
4
|
+
type="warning">
|
|
5
|
+
shp上传
|
|
6
|
+
<input class="file"
|
|
7
|
+
type="file"
|
|
8
|
+
accept=".json"
|
|
9
|
+
@change="getFile" />
|
|
10
|
+
</el-button>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
export default {
|
|
15
|
+
data () {
|
|
16
|
+
return {}
|
|
17
|
+
},
|
|
18
|
+
methods: {
|
|
19
|
+
getFile (e) {
|
|
20
|
+
const file = e.target.files ? e.target.files[0] : ''
|
|
21
|
+
if (file) {
|
|
22
|
+
let reader = new FileReader()
|
|
23
|
+
reader.readAsText(file, 'UTF-8')
|
|
24
|
+
reader.onload = (f) => {
|
|
25
|
+
let json = f.target.result
|
|
26
|
+
if (json) {
|
|
27
|
+
json = JSON.parse(json)
|
|
28
|
+
this.$emit('upload', json)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<style lang="scss" scoped>
|
|
38
|
+
.upload {
|
|
39
|
+
position: relative;
|
|
40
|
+
input {
|
|
41
|
+
position: absolute;
|
|
42
|
+
width: 100%;
|
|
43
|
+
height: 100%;
|
|
44
|
+
left: 0;
|
|
45
|
+
top: 0;
|
|
46
|
+
opacity: 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
</style>
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
<script>
|
|
8
8
|
import mapBoxGl from 'mapbox-gl'
|
|
9
|
+
import { mapSdk } from '../index.js'
|
|
9
10
|
|
|
10
11
|
export default {
|
|
11
12
|
props: {
|
|
@@ -24,20 +25,23 @@ export default {
|
|
|
24
25
|
},
|
|
25
26
|
data () {
|
|
26
27
|
return {
|
|
27
|
-
marker: ''
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
mounted () {
|
|
31
|
+
this.createdMarker()
|
|
32
|
+
},
|
|
33
|
+
methods: {
|
|
34
|
+
createdMarker () {
|
|
35
|
+
let { map } = mapSdk
|
|
32
36
|
let el = this.$refs.dom
|
|
33
|
-
const marker =
|
|
37
|
+
const marker = new mapBoxGl.Marker(el, { draggable: this.drag }).setLngLat(this.position).addTo(map)
|
|
34
38
|
if (this.drag) {
|
|
35
39
|
marker.on('dragend', () => {
|
|
36
40
|
const lngLat = marker.getLngLat()
|
|
37
41
|
this.$emit('dragEnd', lngLat)
|
|
38
42
|
})
|
|
39
43
|
}
|
|
40
|
-
}
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
</script>
|