xy-map 1.0.13 → 1.0.15
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 +7 -1
- package/src/layers/Line.js +24 -2
- package/src/layers/Point.js +27 -13
- 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 +14 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -10,11 +10,13 @@ import {
|
|
|
10
10
|
setLayout,
|
|
11
11
|
setPaint,
|
|
12
12
|
setFilter,
|
|
13
|
+
setHigh,
|
|
13
14
|
getLayerAll
|
|
14
15
|
} from './layers/index.js'
|
|
15
16
|
|
|
16
17
|
import {
|
|
17
|
-
addLayerLine
|
|
18
|
+
addLayerLine,
|
|
19
|
+
addLayerLineAnimation
|
|
18
20
|
} from './layers/Line.js'
|
|
19
21
|
|
|
20
22
|
import {
|
|
@@ -29,6 +31,7 @@ import {
|
|
|
29
31
|
|
|
30
32
|
import {
|
|
31
33
|
toGeoJson,
|
|
34
|
+
loadImage,
|
|
32
35
|
ranging,
|
|
33
36
|
drawArea,
|
|
34
37
|
clearDraw,
|
|
@@ -58,12 +61,14 @@ const mapLayers = {
|
|
|
58
61
|
setLayout,
|
|
59
62
|
setPaint,
|
|
60
63
|
setFilter,
|
|
64
|
+
setHigh,
|
|
61
65
|
getLayerAll
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
// 绘制
|
|
65
69
|
const mapDraw = {
|
|
66
70
|
addLayerLine,
|
|
71
|
+
addLayerLineAnimation,
|
|
67
72
|
addLayerPoint,
|
|
68
73
|
addDiyPoint,
|
|
69
74
|
addLayerImagePoint,
|
|
@@ -73,6 +78,7 @@ const mapDraw = {
|
|
|
73
78
|
// 地图工具
|
|
74
79
|
const mapTools = {
|
|
75
80
|
toGeoJson,
|
|
81
|
+
loadImage,
|
|
76
82
|
ranging,
|
|
77
83
|
drawArea,
|
|
78
84
|
clearDraw,
|
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
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
addLayerText
|
|
9
9
|
} from './Text'
|
|
10
|
+
import {
|
|
11
|
+
loadImage
|
|
12
|
+
} from '../util/mapTools'
|
|
10
13
|
import {
|
|
11
14
|
mapClick
|
|
12
15
|
} from '../util/mapEvent'
|
|
@@ -218,6 +221,30 @@ export const addLayerImagePoint = async (option, layerId) => { // 点
|
|
|
218
221
|
paint: paintOpt
|
|
219
222
|
}, layerId)
|
|
220
223
|
|
|
224
|
+
// 高亮样式
|
|
225
|
+
if (opt.high) {
|
|
226
|
+
let highLayout = opt.high.layout ? opt.high.layout : {}
|
|
227
|
+
let highLayoutOpt = Object.assign({
|
|
228
|
+
...layoutOpt,
|
|
229
|
+
}, highLayout)
|
|
230
|
+
|
|
231
|
+
let highPaint = opt.high.paint ? opt.high.paint : {
|
|
232
|
+
'text-color': '#ff0'
|
|
233
|
+
}
|
|
234
|
+
let highPaintOpt = Object.assign({
|
|
235
|
+
...paintOpt,
|
|
236
|
+
}, highPaint)
|
|
237
|
+
|
|
238
|
+
map.addLayer({
|
|
239
|
+
id: id + '-high',
|
|
240
|
+
type: 'symbol',
|
|
241
|
+
source: id,
|
|
242
|
+
layout: highLayoutOpt,
|
|
243
|
+
paint: highPaintOpt,
|
|
244
|
+
filter: ['==', ['boolean', ['get', 'high']], true]
|
|
245
|
+
}, layerId)
|
|
246
|
+
}
|
|
247
|
+
|
|
221
248
|
if (opt.cluster.cluster) {
|
|
222
249
|
let style = opt.style || {}
|
|
223
250
|
clusterLayer(id, style)
|
|
@@ -250,19 +277,6 @@ export const addLayerImagePoint = async (option, layerId) => { // 点
|
|
|
250
277
|
}
|
|
251
278
|
}
|
|
252
279
|
|
|
253
|
-
/**
|
|
254
|
-
* 加载图片
|
|
255
|
-
*/
|
|
256
|
-
export const loadImage = (src, width = 24, height = 24) => {
|
|
257
|
-
return new Promise((resolve) => {
|
|
258
|
-
let image = new Image(width, height)
|
|
259
|
-
image.src = src
|
|
260
|
-
image.onload = () => {
|
|
261
|
-
resolve(image)
|
|
262
|
-
}
|
|
263
|
-
})
|
|
264
|
-
}
|
|
265
|
-
|
|
266
280
|
/**
|
|
267
281
|
* 点聚合图层
|
|
268
282
|
*/
|
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,
|
|
@@ -115,3 +116,16 @@ export const polygonCenter = (area) => {
|
|
|
115
116
|
let center = turf.centerOfMass(polygon)
|
|
116
117
|
return center
|
|
117
118
|
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 加载图片
|
|
122
|
+
*/
|
|
123
|
+
export const loadImage = (src, width = 24, height = 24) => {
|
|
124
|
+
return new Promise((resolve) => {
|
|
125
|
+
let image = new Image(width, height)
|
|
126
|
+
image.src = src
|
|
127
|
+
image.onload = () => {
|
|
128
|
+
resolve(image)
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
}
|