xy-map 1.0.32 → 1.0.34

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xy-map",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "地图组件",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/map.js CHANGED
@@ -182,7 +182,7 @@ class mapSdk {
182
182
  addBuildings(show = true) {
183
183
  let map = this.map
184
184
  const layers = map.getStyle().layers
185
- const labelLayerId = layers.find((layer) => layer.type === 'symbol' && layer.layout['text-field']).id
185
+ const labelLayerId = layers.find((layer) => layer.type === 'symbol' && layer.layout && layer.layout['text-field']).id
186
186
  if (show) {
187
187
  map.addLayer({
188
188
  '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: {
@@ -115,8 +116,18 @@ export default {
115
116
  console.log('修改结束')
116
117
  this.$emit('update', data)
117
118
  },
119
+ drawEdit (geometry) { // 修改回填元素
120
+ // let geometry = {
121
+ // type: 'Point',
122
+ // coordinates: [this.lng, this.lat]
123
+ // }
124
+ this.draw.add(geometry)
125
+ },
118
126
  drawDelete () {
119
- this.draw.deleteAll()
127
+ if (this.draw) {
128
+ this.draw.deleteAll()
129
+ this.$emit('clear')
130
+ }
120
131
  },
121
132
  }
122
133
  }
@@ -5,13 +5,14 @@
5
5
 
6
6
  <draw-tools ref="draw"
7
7
  :list="['line']"
8
+ :single="single"
8
9
  @update="drawUpdate"
9
10
  @end="drawUpdate">
10
11
  <div class="mt-15 ">
11
12
  <el-input :value="position.toString()"
12
13
  size="small"
13
14
  placeholder="点击地图获取坐标"
14
- readonly
15
+ :readonly="readonly"
15
16
  style="width: 300px; margin-right: 10px;"></el-input>
16
17
  <el-button type="primary"
17
18
  size="small"
@@ -33,7 +34,23 @@ export default {
33
34
  config: {
34
35
  type: Object,
35
36
  default: () => { }
36
- }
37
+ },
38
+ readonly: {
39
+ type: Boolean,
40
+ default: true
41
+ },
42
+ single: {
43
+ type: Boolean,
44
+ default: false
45
+ },
46
+ geoData: {
47
+ type: [Object, String],
48
+ default: ''
49
+ },
50
+ pointList: {
51
+ type: [Array, String],
52
+ default: ''
53
+ },
37
54
  },
38
55
  data () {
39
56
  return {
@@ -41,6 +58,14 @@ export default {
41
58
  position: '',
42
59
  }
43
60
  },
61
+ watch: {
62
+ pointList () {
63
+ this.draw()
64
+ },
65
+ geoData () {
66
+ this.draw()
67
+ }
68
+ },
44
69
  mounted () {
45
70
  this.init()
46
71
  },
@@ -48,20 +73,49 @@ export default {
48
73
  init () {
49
74
  let config = Object.assign({}, {
50
75
  accessToken: 'pk.eyJ1IjoiaGo0NjI3NzEzOTYiLCJhIjoiY2w5YzNjOTZvMDF6NDNwb2d6YmJkYWRpMCJ9.-fW-OChGB1oY2DCMO_c8sg',
51
- container: 'map',
52
76
  zoom: 14,
53
77
  center: [102.83643451528434, 24.81972792178513],
54
78
  is3d: false,
55
79
  }, this.config)
56
80
  mapSdk.initMap(config).then(map => {
57
81
  this.$refs.draw.initDraw(map)
82
+ this.draw()
83
+ })
84
+ },
85
+ draw () {
86
+ if (this.pointList) {
87
+ let features = this.pointList.map(item => {
88
+ return {
89
+ 'type': 'Feature',
90
+ 'geometry': {
91
+ 'type': 'LineString',
92
+ 'coordinates': item
93
+ },
94
+ 'properties': {}
95
+ }
96
+ })
97
+ this.geoJson = {
98
+ 'type': 'FeatureCollection',
99
+ 'features': features
100
+ }
101
+ } else {
102
+ this.geoJson = this.geoData
103
+ }
104
+ this.drawUpdate(this.geoJson)
105
+
106
+ // 开启编辑
107
+ this.geoJson.features.forEach(item => {
108
+ this.$refs.draw.drawEdit(item.geometry)
58
109
  })
59
110
  },
60
111
  drawUpdate (data) {
61
112
  this.geoJson = data
62
- this.position = data.features[0].geometry.coordinates
113
+ this.position = data.features.map(item => item.geometry.coordinates)
63
114
  this.$nextTick(() => {
64
- mapSdk.fitLineBounds(this.position, {
115
+ // 二维数组转一维数组
116
+ // const bounds = this.position.reduce((a, b) => a.concat(b))
117
+ const bounds = this.position.flat()
118
+ mapSdk.fitLineBounds(bounds, {
65
119
  padding: 100
66
120
  })
67
121
  })
@@ -71,6 +125,7 @@ export default {
71
125
  geoJson: this.geoJson,
72
126
  position: this.position
73
127
  }
128
+ console.log(data)
74
129
  this.$emit('save', data)
75
130
  }
76
131
  }
@@ -39,13 +39,33 @@ export default {
39
39
  config: {
40
40
  type: Object,
41
41
  default: () => { }
42
- }
42
+ },
43
+ geoData: {
44
+ type: [Object, String],
45
+ default: ''
46
+ },
47
+ lng: {
48
+ type: [Number, String],
49
+ default: ''
50
+ },
51
+ lat: {
52
+ type: [Number, String],
53
+ default: ''
54
+ },
43
55
  },
44
56
  data () {
45
57
  return {
46
58
  geoJson: '',
47
59
  position: '',
48
- address: ''
60
+ address: '',
61
+ }
62
+ },
63
+ watch: {
64
+ lng () {
65
+ this.draw()
66
+ },
67
+ geoData () {
68
+ this.draw()
49
69
  }
50
70
  },
51
71
  mounted () {
@@ -55,13 +75,38 @@ export default {
55
75
  init () {
56
76
  let config = Object.assign({}, {
57
77
  accessToken: 'pk.eyJ1IjoiaGo0NjI3NzEzOTYiLCJhIjoiY2w5YzNjOTZvMDF6NDNwb2d6YmJkYWRpMCJ9.-fW-OChGB1oY2DCMO_c8sg',
58
- container: 'map',
59
78
  zoom: 14,
60
79
  center: [102.83643451528434, 24.81972792178513],
61
80
  is3d: false,
62
81
  }, this.config)
63
82
  mapSdk.initMap(config).then(map => {
64
83
  this.$refs.draw.initDraw(map)
84
+ this.draw()
85
+ })
86
+ },
87
+ draw () {
88
+ if (this.lng && this.lat) {
89
+ this.geoJson = {
90
+ 'type': 'FeatureCollection',
91
+ 'features': [
92
+ {
93
+ 'type': 'Feature',
94
+ 'geometry': {
95
+ 'type': 'Point',
96
+ 'coordinates': [this.lng, this.lat]
97
+ },
98
+ 'properties': {}
99
+ }
100
+ ]
101
+ }
102
+ } else {
103
+ this.geoJson = this.geoData
104
+ }
105
+ this.drawUpdate(this.geoJson)
106
+
107
+ // 开启编辑
108
+ this.geoJson.features.forEach(item => {
109
+ this.$refs.draw.drawEdit(item.geometry)
65
110
  })
66
111
  },
67
112
  drawUpdate (data) {
@@ -72,15 +117,17 @@ export default {
72
117
  GeoAddress(this.position).then(data => {
73
118
  this.address = data
74
119
  })
75
-
76
120
  })
77
121
  },
78
122
  save () {
79
123
  let data = {
80
124
  geoJson: this.geoJson,
81
125
  position: this.position,
126
+ lng: this.position[0],
127
+ lat: this.position[1],
82
128
  address: this.address
83
129
  }
130
+ console.log(data)
84
131
  this.$emit('save', data)
85
132
  }
86
133
  }
@@ -5,13 +5,14 @@
5
5
 
6
6
  <draw-tools ref="draw"
7
7
  :list="['polygon']"
8
+ :single="single"
8
9
  @update="drawUpdate"
9
10
  @end="drawUpdate">
10
11
  <div class="mt-15 ">
11
12
  <el-input :value="position.toString()"
12
13
  size="small"
13
14
  placeholder="点击地图获取坐标"
14
- readonly
15
+ :readonly="readonly"
15
16
  style="width: 300px; margin-right: 10px;"></el-input>
16
17
  <el-button type="primary"
17
18
  size="small"
@@ -33,7 +34,23 @@ export default {
33
34
  config: {
34
35
  type: Object,
35
36
  default: () => { }
36
- }
37
+ },
38
+ single: {
39
+ type: Boolean,
40
+ default: false
41
+ },
42
+ readonly: {
43
+ type: Boolean,
44
+ default: true
45
+ },
46
+ geoData: {
47
+ type: [Object, String],
48
+ default: ''
49
+ },
50
+ pointList: {
51
+ type: [Array, String],
52
+ default: ''
53
+ },
37
54
  },
38
55
  data () {
39
56
  return {
@@ -41,6 +58,14 @@ export default {
41
58
  position: '',
42
59
  }
43
60
  },
61
+ watch: {
62
+ pointList () {
63
+ this.draw()
64
+ },
65
+ geoData () {
66
+ this.draw()
67
+ }
68
+ },
44
69
  mounted () {
45
70
  this.init()
46
71
  },
@@ -48,20 +73,49 @@ export default {
48
73
  init () {
49
74
  let config = Object.assign({}, {
50
75
  accessToken: 'pk.eyJ1IjoiaGo0NjI3NzEzOTYiLCJhIjoiY2w5YzNjOTZvMDF6NDNwb2d6YmJkYWRpMCJ9.-fW-OChGB1oY2DCMO_c8sg',
51
- container: 'map',
52
76
  zoom: 14,
53
77
  center: [102.83643451528434, 24.81972792178513],
54
78
  is3d: false,
55
79
  }, this.config)
56
80
  mapSdk.initMap(config).then(map => {
57
81
  this.$refs.draw.initDraw(map)
82
+ this.draw()
83
+ })
84
+ },
85
+ draw () {
86
+ if (this.pointList) {
87
+ let features = this.pointList.map(item => {
88
+ return {
89
+ 'type': 'Feature',
90
+ 'geometry': {
91
+ 'type': 'Polygon',
92
+ 'coordinates': [item]
93
+ },
94
+ 'properties': {}
95
+ }
96
+ })
97
+ this.geoJson = {
98
+ 'type': 'FeatureCollection',
99
+ 'features': features
100
+ }
101
+ } else {
102
+ this.geoJson = this.geoData
103
+ }
104
+ this.drawUpdate(this.geoJson)
105
+
106
+ // 开启编辑
107
+ this.geoJson.features.forEach(item => {
108
+ this.$refs.draw.drawEdit(item.geometry)
58
109
  })
59
110
  },
60
111
  drawUpdate (data) {
61
112
  this.geoJson = data
62
- this.position = data.features[0].geometry.coordinates
113
+ this.position = data.features.map(item => item.geometry.coordinates[0])
63
114
  this.$nextTick(() => {
64
- mapSdk.fitLineBounds(this.position[0], {
115
+ // 二维数组转一维数组
116
+ // const bounds = this.position.reduce((a, b) => a.concat(b))
117
+ const bounds = this.position.flat()
118
+ mapSdk.fitLineBounds(bounds, {
65
119
  padding: 100
66
120
  })
67
121
  })
@@ -71,6 +125,7 @@ export default {
71
125
  geoJson: this.geoJson,
72
126
  position: this.position
73
127
  }
128
+ console.log(data)
74
129
  this.$emit('save', data)
75
130
  }
76
131
  }
@@ -1,12 +0,0 @@
1
- import Vue from 'vue'
2
- import Vuex from 'vuex'
3
-
4
- Vue.use(Vuex)
5
-
6
- export default new Vuex.Store({
7
- state: {},
8
- getters: {},
9
- mutations: {},
10
- actions: {},
11
- modules: {},
12
- })