xy-map 1.0.13 → 1.0.14

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.13",
3
+ "version": "1.0.14",
4
4
  "description": "地图组件",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  setLayout,
11
11
  setPaint,
12
12
  setFilter,
13
+ setHigh,
13
14
  getLayerAll
14
15
  } from './layers/index.js'
15
16
 
@@ -58,6 +59,7 @@ const mapLayers = {
58
59
  setLayout,
59
60
  setPaint,
60
61
  setFilter,
62
+ setHigh,
61
63
  getLayerAll
62
64
  }
63
65
 
@@ -21,7 +21,10 @@ const defaultOptions = {
21
21
  layout: {},
22
22
  paint: {}
23
23
  },
24
- style: {},
24
+ style: {
25
+ layout: {},
26
+ paint: {},
27
+ },
25
28
  hover: null,
26
29
  click: null,
27
30
  }
@@ -62,7 +65,6 @@ export const addLayerLine = (option, layerId) => {
62
65
  })
63
66
  }
64
67
 
65
-
66
68
  map.addLayer({
67
69
  id: id,
68
70
  type: 'line',
@@ -71,6 +73,26 @@ export const addLayerLine = (option, layerId) => {
71
73
  paint: paintOpt
72
74
  }, layerId)
73
75
 
76
+ // 高亮样式
77
+ if (opt.high) {
78
+ let highPaint = opt.high.paint ? opt.high.paint : {
79
+ 'line-color': '#ff0'
80
+ }
81
+ let highPaintOpt = Object.assign({
82
+ ...paintOpt
83
+ }, highPaint)
84
+
85
+ map.addLayer({
86
+ id: id + '-high',
87
+ type: 'line',
88
+ source: id,
89
+ layout: layoutOpt,
90
+ paint: highPaintOpt,
91
+ filter: ['==', ['boolean', ['get', 'high']], true]
92
+ }, layerId)
93
+ }
94
+
95
+
74
96
  if (opt.click) {
75
97
  mapClick(opt.id, opt.click)
76
98
  }
@@ -218,6 +218,30 @@ export const addLayerImagePoint = async (option, layerId) => { // 点
218
218
  paint: paintOpt
219
219
  }, layerId)
220
220
 
221
+ // 高亮样式
222
+ if (opt.high) {
223
+ let highLayout = opt.high.layout ? opt.high.layout : {}
224
+ let highLayoutOpt = Object.assign({
225
+ ...layoutOpt,
226
+ }, highLayout)
227
+
228
+ let highPaint = opt.high.paint ? opt.high.paint : {
229
+ 'text-color': '#ff0'
230
+ }
231
+ let highPaintOpt = Object.assign({
232
+ ...paintOpt,
233
+ }, highPaint)
234
+
235
+ map.addLayer({
236
+ id: id + '-high',
237
+ type: 'symbol',
238
+ source: id,
239
+ layout: highLayoutOpt,
240
+ paint: highPaintOpt,
241
+ filter: ['==', ['boolean', ['get', 'high']], true]
242
+ }, layerId)
243
+ }
244
+
221
245
  if (opt.cluster.cluster) {
222
246
  let style = opt.style || {}
223
247
  clusterLayer(id, style)
@@ -38,18 +38,18 @@ export const addLayerPolygon = (option, layerId) => {
38
38
  return
39
39
  }
40
40
 
41
- let layout = option.style ? option.style.layout : {}
41
+ let layout = opt.style ? opt.style.layout : {}
42
42
  let layoutOpt = Object.assign({
43
43
  'visibility': 'visible',
44
44
  }, layout)
45
45
 
46
- let paint = option.style ? option.style.paint : {}
46
+ let paint = opt.style ? opt.style.paint : {}
47
47
  let paintOpt = Object.assign({
48
48
  'fill-color': '#28b2ff',
49
49
  'fill-opacity': 0.3
50
50
  }, paint)
51
51
 
52
- let line = option.style ? option.style.line : {}
52
+ let line = opt.style ? opt.style.line : {}
53
53
  let lineOpt = Object.assign({
54
54
  'line-color': '#fff',
55
55
  'line-width': 1,
@@ -82,6 +82,30 @@ export const addLayerPolygon = (option, layerId) => {
82
82
  paint: lineOpt
83
83
  }, layerId)
84
84
 
85
+ // 高亮样式
86
+ if (opt.high) {
87
+ let highLayout = opt.high.layout ? opt.high.layout : {}
88
+ let highLayoutOpt = Object.assign({
89
+ ...layoutOpt,
90
+ }, highLayout)
91
+
92
+ let highPaint = opt.high.paint ? opt.high.paint : {
93
+ 'fill-opacity': 0.5
94
+ }
95
+ let highPaintOpt = Object.assign({
96
+ ...paintOpt,
97
+ }, highPaint)
98
+
99
+ map.addLayer({
100
+ id: id + '-high',
101
+ type: 'fill',
102
+ source: id,
103
+ layout: highLayoutOpt,
104
+ paint: highPaintOpt,
105
+ filter: ['==', ['boolean', ['get', 'high']], true]
106
+ }, layerId)
107
+ }
108
+
85
109
  if (opt.click) {
86
110
  mapClick(id, opt.click)
87
111
  }
@@ -118,4 +118,13 @@ export const setFilter = (key, filter) => {
118
118
  } = mapSdk
119
119
 
120
120
  map.setFilter(key, filter)
121
+ }
122
+
123
+ // 设置高亮
124
+ export const setHigh = (id, filter) => {
125
+ let {
126
+ map
127
+ } = mapSdk
128
+
129
+ map.setFilter(id + '-high', filter)
121
130
  }
@@ -16,6 +16,7 @@ export const mapClick = (id, callback) => {
16
16
  // if (callback) {
17
17
  // e.preventDefault()
18
18
  // } else {
19
+
19
20
  if (e.defaultPrevented) return
20
21
  e.preventDefault()
21
22
 
@@ -31,10 +32,12 @@ export const mapClick = (id, callback) => {
31
32
  coordinates = [e.lngLat.lng, e.lngLat.lat]
32
33
  }
33
34
  const properties = e.features[0].properties
35
+ const features = map.queryRenderedFeatures(e.point)
34
36
 
35
37
  const event = {
36
38
  coordinates,
37
39
  properties,
40
+ features,
38
41
  e,
39
42
  position: [e.lngLat.lng, e.lngLat.lat]
40
43
  }
@@ -105,4 +108,4 @@ export const changeMapCursor = (id) => {
105
108
  })
106
109
  }
107
110
  })
108
- }
111
+ }
@@ -15,6 +15,7 @@ import {
15
15
  export const toGeoJson = (list, type, props = 'position') => {
16
16
  let pointsData = list.map((item, index) => {
17
17
  return {
18
+ id: item.id || '',
18
19
  type: 'Feature',
19
20
  geometry: {
20
21
  type: type,
@@ -114,4 +115,4 @@ export const polygonCenter = (area) => {
114
115
  let polygon = turf.polygon(area)
115
116
  let center = turf.centerOfMass(polygon)
116
117
  return center
117
- }
118
+ }