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 +1 -1
- package/src/index.js +2 -0
- package/src/layers/Line.js +24 -2
- package/src/layers/Point.js +24 -0
- package/src/layers/Polygon.js +27 -3
- package/src/layers/index.js +9 -0
- package/src/util/mapEvent.js +4 -1
- package/src/util/mapTools.js +2 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/layers/Line.js
CHANGED
|
@@ -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
|
}
|
package/src/layers/Point.js
CHANGED
|
@@ -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)
|
package/src/layers/Polygon.js
CHANGED
|
@@ -38,18 +38,18 @@ export const addLayerPolygon = (option, layerId) => {
|
|
|
38
38
|
return
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
let 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 =
|
|
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 =
|
|
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
|
}
|
package/src/layers/index.js
CHANGED
package/src/util/mapEvent.js
CHANGED
|
@@ -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
|
+
}
|
package/src/util/mapTools.js
CHANGED
|
@@ -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
|
+
}
|