xy-map 1.0.21 → 1.0.22
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 +5 -0
- package/src/layers/Text.js +25 -19
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -15,6 +15,10 @@ import {
|
|
|
15
15
|
getLayerAll
|
|
16
16
|
} from './layers/index.js'
|
|
17
17
|
|
|
18
|
+
import {
|
|
19
|
+
addLayerText
|
|
20
|
+
} from './layers/Text.js'
|
|
21
|
+
|
|
18
22
|
import {
|
|
19
23
|
addLayerLine,
|
|
20
24
|
addLayerLineAnimation
|
|
@@ -80,6 +84,7 @@ const mapLayers = {
|
|
|
80
84
|
|
|
81
85
|
// 绘制
|
|
82
86
|
const mapDraw = {
|
|
87
|
+
addLayerText,
|
|
83
88
|
addLayerLine,
|
|
84
89
|
addLayerLineAnimation,
|
|
85
90
|
addLayerPoint,
|
package/src/layers/Text.js
CHANGED
|
@@ -20,28 +20,34 @@ export const addLayerText = (placement = 'point', option, layerId) => { // 文
|
|
|
20
20
|
return
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
let layout = opt.text ? opt.text.layout : {}
|
|
24
|
+
let layoutOpt = Object.assign({
|
|
25
|
+
'symbol-placement': placement,
|
|
26
|
+
'text-field': ['get', 'name'],
|
|
27
|
+
/* 使用text标签显示的值,Feature属性使用{域名}格式*/
|
|
28
|
+
'text-font': ['Open Sans Semibold'],
|
|
29
|
+
/* 文本字体 */
|
|
30
|
+
'text-size': 10,
|
|
31
|
+
'text-offset': [0, 0], // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
|
|
32
|
+
// 'text-anchor': 'top',
|
|
33
|
+
'text-ignore-placement': false, // 是否忽略文本位置
|
|
34
|
+
'visibility': 'visible'
|
|
35
|
+
}, layout)
|
|
36
|
+
|
|
37
|
+
let paint = opt.text ? opt.text.paint : {}
|
|
38
|
+
let paintOpt = Object.assign({
|
|
39
|
+
'text-color': '#ffffff',
|
|
40
|
+
'text-halo-color': 'rgba(0, 0, 0, .5)',
|
|
41
|
+
'text-halo-width': 0.8,
|
|
42
|
+
'text-opacity': 1
|
|
43
|
+
}, paint)
|
|
44
|
+
|
|
23
45
|
map.addLayer({
|
|
24
46
|
id: id,
|
|
25
47
|
type: 'symbol',
|
|
26
|
-
source: parentId,
|
|
27
|
-
layout:
|
|
28
|
-
|
|
29
|
-
'text-field': ['get', 'name'],
|
|
30
|
-
/* 使用text标签显示的值,Feature属性使用{域名}格式*/
|
|
31
|
-
'text-font': ['Open Sans Semibold'],
|
|
32
|
-
/* 文本字体 */
|
|
33
|
-
'text-size': 10,
|
|
34
|
-
'text-offset': [0, 0], // 该属性表示文本偏移锚点的距离,正值表示向右和向下,负值表示向左和向上
|
|
35
|
-
// 'text-anchor': 'top',
|
|
36
|
-
'text-ignore-placement': false, // 是否忽略文本位置
|
|
37
|
-
'visibility': 'visible'
|
|
38
|
-
}, opt.text.layout),
|
|
39
|
-
paint: Object.assign({
|
|
40
|
-
'text-color': '#ffffff',
|
|
41
|
-
'text-halo-color': 'rgba(0, 0, 0, .5)',
|
|
42
|
-
'text-halo-width': 0.8,
|
|
43
|
-
'text-opacity': 1
|
|
44
|
-
}, opt.text.paint),
|
|
48
|
+
source: opt.source || parentId,
|
|
49
|
+
layout: layoutOpt,
|
|
50
|
+
paint: paintOpt,
|
|
45
51
|
...opt.other
|
|
46
52
|
}, layerId)
|
|
47
53
|
}
|