@antv/l7-layers 2.16.0 → 2.16.2
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/es/core/BaseLayer.d.ts +3 -0
- package/es/core/BaseLayer.js +76 -80
- package/es/core/BaseModel.d.ts +9 -71
- package/es/core/BaseModel.js +75 -357
- package/es/core/CommonStyleAttribute.d.ts +2 -0
- package/es/core/CommonStyleAttribute.js +66 -0
- package/es/core/interface.d.ts +13 -3
- package/es/core/shape/extrude.js +18 -6
- package/es/core/triangulation.d.ts +12 -0
- package/es/core/triangulation.js +70 -0
- package/es/heatmap/models/grid.js +1 -1
- package/es/heatmap/models/grid3d.js +1 -1
- package/es/heatmap/models/heatmap.d.ts +1 -0
- package/es/heatmap/models/heatmap.js +17 -13
- package/es/heatmap/models/hexagon.js +1 -1
- package/es/heatmap/shaders/grid_vert.glsl +2 -2
- package/es/heatmap/shaders/hexagon_3d_vert.glsl +2 -2
- package/es/heatmap/shaders/hexagon_vert.glsl +2 -2
- package/es/line/index.d.ts +1 -0
- package/es/line/index.js +3 -2
- package/es/line/models/arc.js +9 -45
- package/es/line/models/arc_3d.js +12 -45
- package/es/line/models/earthArc_3d.js +6 -40
- package/es/line/models/{half.d.ts → flow.d.ts} +1 -11
- package/es/line/models/flow.js +167 -0
- package/es/line/models/great_circle.js +4 -38
- package/es/line/models/index.d.ts +1 -1
- package/es/line/models/index.js +3 -3
- package/es/line/models/line.js +7 -41
- package/es/line/models/linearline.js +4 -38
- package/es/line/models/simpleLine.d.ts +0 -1
- package/es/line/models/simpleLine.js +4 -43
- package/es/line/shaders/dash/arc_dash_frag.glsl +3 -6
- package/es/line/shaders/dash/arc_dash_vert.glsl +6 -46
- package/es/line/shaders/dash/line_dash_frag.glsl +4 -7
- package/es/line/shaders/dash/line_dash_vert.glsl +3 -33
- package/es/line/shaders/flow/flow_line_frag.glsl +13 -0
- package/es/line/shaders/flow/flow_line_vert.glsl +83 -0
- package/es/line/shaders/line_arc_3d_frag.glsl +6 -6
- package/es/line/shaders/line_arc_3d_vert.glsl +4 -34
- package/es/line/shaders/line_arc_frag.glsl +7 -11
- package/es/line/shaders/line_arc_great_circle_frag.glsl +5 -6
- package/es/line/shaders/line_arc_great_circle_vert.glsl +4 -32
- package/es/line/shaders/line_arc_vert.glsl +9 -45
- package/es/line/shaders/line_frag.glsl +15 -17
- package/es/line/shaders/line_vert.glsl +3 -34
- package/es/line/shaders/linear/arc3d_linear_frag.glsl +5 -19
- package/es/line/shaders/linear/arc3d_linear_vert.glsl +9 -48
- package/es/line/shaders/linear/arc_linear_frag.glsl +2 -30
- package/es/line/shaders/linear/arc_linear_vert.glsl +9 -45
- package/es/line/shaders/linear/line_linear_frag.glsl +5 -6
- package/es/line/shaders/linearLine/line_linear_frag.glsl +2 -14
- package/es/line/shaders/linearLine/line_linear_vert.glsl +14 -32
- package/es/line/shaders/simple/simpleline_frag.glsl +1 -5
- package/es/line/shaders/simple/simpleline_linear_frag.glsl +2 -6
- package/es/line/shaders/simple/simpleline_vert.glsl +7 -33
- package/es/plugins/DataMappingPlugin.js +20 -34
- package/es/plugins/LayerModelPlugin.js +13 -1
- package/es/plugins/ShaderUniformPlugin.js +3 -3
- package/es/point/index.d.ts +1 -0
- package/es/point/index.js +1 -0
- package/es/point/models/earthExtrude.d.ts +0 -3
- package/es/point/models/earthExtrude.js +2 -40
- package/es/point/models/earthFill.d.ts +0 -1
- package/es/point/models/earthFill.js +9 -60
- package/es/point/models/extrude.d.ts +0 -3
- package/es/point/models/extrude.js +3 -42
- package/es/point/models/fill.d.ts +0 -1
- package/es/point/models/fill.js +15 -76
- package/es/point/models/fillmage.js +6 -43
- package/es/point/models/image.js +7 -41
- package/es/point/models/normal.js +2 -2
- package/es/point/models/radar.d.ts +0 -1
- package/es/point/models/radar.js +4 -13
- package/es/point/models/simplePoint.d.ts +0 -1
- package/es/point/models/simplePoint.js +8 -49
- package/es/point/models/text.js +17 -47
- package/es/point/shaders/animate/wave_frag.glsl +1 -11
- package/es/point/shaders/earth/extrude_frag.glsl +5 -17
- package/es/point/shaders/earth/extrude_vert.glsl +14 -29
- package/es/point/shaders/earth/fill_frag.glsl +5 -14
- package/es/point/shaders/earth/fill_vert.glsl +1 -75
- package/es/point/shaders/extrude/extrude_frag.glsl +3 -29
- package/es/point/shaders/extrude/extrude_vert.glsl +27 -35
- package/es/point/shaders/fill_frag.glsl +9 -20
- package/es/point/shaders/fill_vert.glsl +16 -101
- package/es/point/shaders/image/fillImage_frag.glsl +2 -5
- package/es/point/shaders/image/fillImage_vert.glsl +4 -47
- package/es/point/shaders/image_frag.glsl +1 -5
- package/es/point/shaders/image_vert.glsl +1 -44
- package/es/point/shaders/normal_frag.glsl +0 -2
- package/es/point/shaders/normal_vert.glsl +2 -1
- package/es/point/shaders/radar/radar_vert.glsl +2 -2
- package/es/point/shaders/simplePoint_frag.glsl +0 -7
- package/es/point/shaders/simplePoint_vert.glsl +3 -45
- package/es/point/shaders/text_frag.glsl +6 -19
- package/es/point/shaders/text_vert.glsl +5 -66
- package/es/polygon/index.d.ts +1 -0
- package/es/polygon/index.js +1 -0
- package/es/polygon/models/extrude.d.ts +0 -3
- package/es/polygon/models/extrude.js +86 -82
- package/es/polygon/models/fill.d.ts +0 -4
- package/es/polygon/models/fill.js +8 -47
- package/es/polygon/shaders/extrude/polygon_extrude_frag.glsl +2 -23
- package/es/polygon/shaders/extrude/polygon_extrude_picklight_frag.glsl +7 -5
- package/es/polygon/shaders/extrude/polygon_extrude_picklight_vert.glsl +7 -32
- package/es/polygon/shaders/extrude/polygon_extrude_vert.glsl +33 -38
- package/es/polygon/shaders/extrude/polygon_extrudetex_frag.glsl +12 -9
- package/es/polygon/shaders/extrude/polygon_extrudetex_vert.glsl +16 -44
- package/es/polygon/shaders/polygon_frag.glsl +0 -5
- package/es/polygon/shaders/polygon_linear_frag.glsl +0 -8
- package/es/polygon/shaders/polygon_linear_vert.glsl +0 -32
- package/es/polygon/shaders/polygon_vert.glsl +1 -27
- package/es/utils/layerData.js +2 -2
- package/lib/core/BaseLayer.js +74 -78
- package/lib/core/BaseModel.js +74 -356
- package/lib/core/CommonStyleAttribute.js +72 -0
- package/lib/core/shape/extrude.js +18 -6
- package/lib/core/triangulation.js +72 -0
- package/lib/heatmap/models/grid.js +1 -1
- package/lib/heatmap/models/grid3d.js +1 -1
- package/lib/heatmap/models/heatmap.js +17 -13
- package/lib/heatmap/models/hexagon.js +1 -1
- package/lib/heatmap/shaders/grid_vert.glsl +2 -2
- package/lib/heatmap/shaders/hexagon_3d_vert.glsl +2 -2
- package/lib/heatmap/shaders/hexagon_vert.glsl +2 -2
- package/lib/line/index.js +3 -2
- package/lib/line/models/arc.js +9 -45
- package/lib/line/models/arc_3d.js +12 -45
- package/lib/line/models/earthArc_3d.js +6 -40
- package/lib/line/models/flow.js +174 -0
- package/lib/line/models/great_circle.js +4 -38
- package/lib/line/models/index.js +3 -3
- package/lib/line/models/line.js +7 -41
- package/lib/line/models/linearline.js +4 -38
- package/lib/line/models/simpleLine.js +4 -43
- package/lib/line/shaders/dash/arc_dash_frag.glsl +3 -6
- package/lib/line/shaders/dash/arc_dash_vert.glsl +6 -46
- package/lib/line/shaders/dash/line_dash_frag.glsl +4 -7
- package/lib/line/shaders/dash/line_dash_vert.glsl +3 -33
- package/lib/line/shaders/flow/flow_line_frag.glsl +13 -0
- package/lib/line/shaders/flow/flow_line_vert.glsl +83 -0
- package/lib/line/shaders/line_arc_3d_frag.glsl +6 -6
- package/lib/line/shaders/line_arc_3d_vert.glsl +4 -34
- package/lib/line/shaders/line_arc_frag.glsl +7 -11
- package/lib/line/shaders/line_arc_great_circle_frag.glsl +5 -6
- package/lib/line/shaders/line_arc_great_circle_vert.glsl +4 -32
- package/lib/line/shaders/line_arc_vert.glsl +9 -45
- package/lib/line/shaders/line_frag.glsl +15 -17
- package/lib/line/shaders/line_vert.glsl +3 -34
- package/lib/line/shaders/linear/arc3d_linear_frag.glsl +5 -19
- package/lib/line/shaders/linear/arc3d_linear_vert.glsl +9 -48
- package/lib/line/shaders/linear/arc_linear_frag.glsl +2 -30
- package/lib/line/shaders/linear/arc_linear_vert.glsl +9 -45
- package/lib/line/shaders/linear/line_linear_frag.glsl +5 -6
- package/lib/line/shaders/linearLine/line_linear_frag.glsl +2 -14
- package/lib/line/shaders/linearLine/line_linear_vert.glsl +14 -32
- package/lib/line/shaders/simple/simpleline_frag.glsl +1 -5
- package/lib/line/shaders/simple/simpleline_linear_frag.glsl +2 -6
- package/lib/line/shaders/simple/simpleline_vert.glsl +7 -33
- package/lib/plugins/DataMappingPlugin.js +20 -34
- package/lib/plugins/LayerModelPlugin.js +13 -1
- package/lib/plugins/ShaderUniformPlugin.js +3 -3
- package/lib/point/index.js +1 -0
- package/lib/point/models/earthExtrude.js +2 -40
- package/lib/point/models/earthFill.js +9 -60
- package/lib/point/models/extrude.js +3 -42
- package/lib/point/models/fill.js +15 -76
- package/lib/point/models/fillmage.js +6 -43
- package/lib/point/models/image.js +7 -41
- package/lib/point/models/normal.js +2 -2
- package/lib/point/models/radar.js +4 -13
- package/lib/point/models/simplePoint.js +8 -49
- package/lib/point/models/text.js +15 -45
- package/lib/point/shaders/animate/wave_frag.glsl +1 -11
- package/lib/point/shaders/earth/extrude_frag.glsl +5 -17
- package/lib/point/shaders/earth/extrude_vert.glsl +14 -29
- package/lib/point/shaders/earth/fill_frag.glsl +5 -14
- package/lib/point/shaders/earth/fill_vert.glsl +1 -75
- package/lib/point/shaders/extrude/extrude_frag.glsl +3 -29
- package/lib/point/shaders/extrude/extrude_vert.glsl +27 -35
- package/lib/point/shaders/fill_frag.glsl +9 -20
- package/lib/point/shaders/fill_vert.glsl +16 -101
- package/lib/point/shaders/image/fillImage_frag.glsl +2 -5
- package/lib/point/shaders/image/fillImage_vert.glsl +4 -47
- package/lib/point/shaders/image_frag.glsl +1 -5
- package/lib/point/shaders/image_vert.glsl +1 -44
- package/lib/point/shaders/normal_frag.glsl +0 -2
- package/lib/point/shaders/normal_vert.glsl +2 -1
- package/lib/point/shaders/radar/radar_vert.glsl +2 -2
- package/lib/point/shaders/simplePoint_frag.glsl +0 -7
- package/lib/point/shaders/simplePoint_vert.glsl +3 -45
- package/lib/point/shaders/text_frag.glsl +6 -19
- package/lib/point/shaders/text_vert.glsl +5 -66
- package/lib/polygon/index.js +1 -0
- package/lib/polygon/models/extrude.js +86 -82
- package/lib/polygon/models/fill.js +8 -47
- package/lib/polygon/shaders/extrude/polygon_extrude_frag.glsl +2 -23
- package/lib/polygon/shaders/extrude/polygon_extrude_picklight_frag.glsl +7 -5
- package/lib/polygon/shaders/extrude/polygon_extrude_picklight_vert.glsl +7 -32
- package/lib/polygon/shaders/extrude/polygon_extrude_vert.glsl +33 -38
- package/lib/polygon/shaders/extrude/polygon_extrudetex_frag.glsl +12 -9
- package/lib/polygon/shaders/extrude/polygon_extrudetex_vert.glsl +16 -44
- package/lib/polygon/shaders/polygon_frag.glsl +0 -5
- package/lib/polygon/shaders/polygon_linear_frag.glsl +0 -8
- package/lib/polygon/shaders/polygon_linear_vert.glsl +0 -32
- package/lib/polygon/shaders/polygon_vert.glsl +1 -27
- package/lib/utils/layerData.js +2 -2
- package/package.json +7 -7
- package/es/line/models/half.js +0 -267
- package/es/line/shaders/half/line_half_frag.glsl +0 -53
- package/es/line/shaders/half/line_half_vert.glsl +0 -169
- package/es/utils/dataMappingStyle.d.ts +0 -31
- package/es/utils/dataMappingStyle.js +0 -137
- package/lib/line/models/half.js +0 -274
- package/lib/line/shaders/half/line_half_frag.glsl +0 -53
- package/lib/line/shaders/half/line_half_vert.glsl +0 -169
- package/lib/utils/dataMappingStyle.js +0 -140
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { isFunction, isNumber, isString } from 'lodash';
|
|
2
|
-
/**
|
|
3
|
-
* 该文件中的工具方法主要用于对 style 中的属性进行 数据映射
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 当 style 中使用的 opacity 不是常数的时候根据数据进行映射
|
|
8
|
-
* @param field
|
|
9
|
-
* @param values
|
|
10
|
-
* @param updateOptions
|
|
11
|
-
*/
|
|
12
|
-
function registerStyleAttribute(fieldName, layer, field, values, updateOptions) {
|
|
13
|
-
layer.updateStyleAttribute(fieldName, field, values, updateOptions);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 当样式发生变化时判断是否需要进行数据映射
|
|
18
|
-
* @param configToUpdate
|
|
19
|
-
* @param layer
|
|
20
|
-
*/
|
|
21
|
-
function styleDataMapping(configToUpdate, layer) {
|
|
22
|
-
// 瓦片图层不需要进行样式数据映射
|
|
23
|
-
if (layer.tileLayer || layer.isTileLayer) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (configToUpdate.opacity) {
|
|
27
|
-
// 处理 style 中 opacity 属性的数据映射
|
|
28
|
-
floatStyleMapping('opacity', layer, configToUpdate.opacity);
|
|
29
|
-
}
|
|
30
|
-
if (configToUpdate.strokeWidth) {
|
|
31
|
-
// 处理 style 中 strokeWidth 属性的数据映射
|
|
32
|
-
|
|
33
|
-
floatStyleMapping('strokeWidth', layer, configToUpdate.strokeWidth);
|
|
34
|
-
}
|
|
35
|
-
if (configToUpdate.strokeOpacity) {
|
|
36
|
-
// 处理 style 中 strokeOpacity 属性的数据映射
|
|
37
|
-
floatStyleMapping('strokeOpacity', layer, configToUpdate.strokeOpacity);
|
|
38
|
-
}
|
|
39
|
-
if (configToUpdate.stroke) {
|
|
40
|
-
// 处理 style 中 stroke (strokeColor) 属性的数据映射
|
|
41
|
-
colorStyleMapping('stroke', layer, configToUpdate.stroke);
|
|
42
|
-
}
|
|
43
|
-
if (configToUpdate.offsets) {
|
|
44
|
-
// 处理 style 中 offsets 属性的数据映射
|
|
45
|
-
offsetStyleMapping('offsets', layer, configToUpdate.offsets);
|
|
46
|
-
}
|
|
47
|
-
if (configToUpdate.textOffset) {
|
|
48
|
-
// 处理 style 中 textOffset 属性的数据映射
|
|
49
|
-
offsetStyleMapping('textOffset', layer, configToUpdate.textOffset);
|
|
50
|
-
}
|
|
51
|
-
if (configToUpdate.thetaOffset) {
|
|
52
|
-
// 处理 style 中 thetaOffset 属性的数据映射
|
|
53
|
-
floatStyleMapping('thetaOffset', layer, configToUpdate.thetaOffset);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 根据传入参数 float 的类型和值做相应的操作
|
|
59
|
-
*/
|
|
60
|
-
function floatStyleMapping(fieldName, layer, styleFloat) {
|
|
61
|
-
if (isString(styleFloat)) {
|
|
62
|
-
// 如果传入的 styleFloat 是 string 类型,那么就认为其对应的是传入数据的字段
|
|
63
|
-
registerStyleAttribute(fieldName, layer, styleFloat, function (value) {
|
|
64
|
-
return value;
|
|
65
|
-
});
|
|
66
|
-
} else if (isNumber(styleFloat)) {
|
|
67
|
-
// 传入 number、默认值处理
|
|
68
|
-
// registerStyleAttribute(fieldName, layer, [styleFloat], undefined);
|
|
69
|
-
} else if (Array.isArray(styleFloat) && styleFloat.length === 2) {
|
|
70
|
-
// 传入的 styleFloat 是长度为 2 的数组
|
|
71
|
-
if (isString(styleFloat[0]) && isFunction(styleFloat[1])) {
|
|
72
|
-
// 字段回调函数 [string, callback]
|
|
73
|
-
registerStyleAttribute(fieldName, layer, styleFloat[0], styleFloat[1]);
|
|
74
|
-
} else if (isString(styleFloat[0]) && Array.isArray(styleFloat[1]) && isNumber(styleFloat[1][0]) && isNumber(styleFloat[1][1])) {
|
|
75
|
-
// 字段映射 [string, [start: number, end: number]]
|
|
76
|
-
registerStyleAttribute(fieldName, layer, styleFloat[0], styleFloat[1]);
|
|
77
|
-
} else {
|
|
78
|
-
// 兼容
|
|
79
|
-
registerStyleAttribute(fieldName, layer, [1.0], undefined);
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
// 兼容
|
|
83
|
-
registerStyleAttribute(fieldName, layer, [1.0], undefined);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* 根据传入参数 offsets 的类型和值做相应的操作
|
|
88
|
-
* @param fieldName
|
|
89
|
-
* @param layer
|
|
90
|
-
* @param styleOffsets
|
|
91
|
-
*/
|
|
92
|
-
function offsetStyleMapping(fieldName, layer, styleOffsets) {
|
|
93
|
-
if (isString(styleOffsets)) {
|
|
94
|
-
// 如果传入的 styleOffsets 是 string 类型,那么就认为其对应的是传入数据的字段
|
|
95
|
-
registerStyleAttribute(fieldName, layer, styleOffsets, function (value) {
|
|
96
|
-
return value;
|
|
97
|
-
});
|
|
98
|
-
} else if (Array.isArray(styleOffsets) && styleOffsets.length === 2 && isString(styleOffsets[0]) && isFunction(styleOffsets[1])) {
|
|
99
|
-
// 字段回调函数 [string, callback]
|
|
100
|
-
registerStyleAttribute(fieldName, layer, styleOffsets[0], styleOffsets[1]);
|
|
101
|
-
} else if (Array.isArray(styleOffsets) && styleOffsets.length === 2 && isNumber(styleOffsets[0]) && isNumber(styleOffsets[1])) {
|
|
102
|
-
// 字段映射 [string, [start: number, end: number]]
|
|
103
|
-
registerStyleAttribute(fieldName, layer, styleOffsets, undefined);
|
|
104
|
-
} else {
|
|
105
|
-
// 兼容
|
|
106
|
-
registerStyleAttribute(fieldName, layer, [0, 0], undefined);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 根据传入参数 stroke / color 的类型和值做相应的操作
|
|
112
|
-
* @param fieldName
|
|
113
|
-
* @param layer
|
|
114
|
-
* @param styleColor
|
|
115
|
-
*/
|
|
116
|
-
function colorStyleMapping(fieldName, layer, styleColor) {
|
|
117
|
-
if (isString(styleColor)) {
|
|
118
|
-
// 如果传入的 styleColor 是 string 类型,那么就认为其是颜色值
|
|
119
|
-
// registerStyleAttribute(fieldName, layer, styleColor, undefined);
|
|
120
|
-
} else if (Array.isArray(styleColor) && styleColor.length === 2) {
|
|
121
|
-
// 传入的 styleColor 是长度为 2 的数组
|
|
122
|
-
if (isString(styleColor[0]) && isFunction(styleColor[1])) {
|
|
123
|
-
// 字段回调函数 [string, callback]
|
|
124
|
-
registerStyleAttribute(fieldName, layer, styleColor[0], styleColor[1]);
|
|
125
|
-
} else if (isString(styleColor[0]) && Array.isArray(styleColor[1]) && styleColor[1].length > 0) {
|
|
126
|
-
// 字段映射 [string, [start: string, end: string]]
|
|
127
|
-
registerStyleAttribute(fieldName, layer, styleColor[0], styleColor[1]);
|
|
128
|
-
} else {
|
|
129
|
-
// 兼容
|
|
130
|
-
registerStyleAttribute(fieldName, layer, '#fff', undefined);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
// 兼容
|
|
134
|
-
registerStyleAttribute(fieldName, layer, '#fff', undefined);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
export { styleDataMapping, floatStyleMapping, colorStyleMapping };
|
package/lib/line/models/half.js
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
14
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
15
|
-
var _l7Core = require("@antv/l7-core");
|
|
16
|
-
var _l7Utils = require("@antv/l7-utils");
|
|
17
|
-
var _lodash = require("lodash");
|
|
18
|
-
var _BaseModel2 = _interopRequireDefault(require("../../core/BaseModel"));
|
|
19
|
-
var _triangulation = require("../../core/triangulation");
|
|
20
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
21
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
22
|
-
/* babel-plugin-inline-import '../shaders/half/line_half_frag.glsl' */
|
|
23
|
-
var line_half_frag = "#define COORDINATE_SYSTEM_LNGLAT 1.0 // mapbox\n#define COORDINATE_SYSTEM_LNGLAT_OFFSET 2.0 // mapbox offset\n#define COORDINATE_SYSTEM_VECTOR_TILE 3.0\n#define COORDINATE_SYSTEM_IDENTITY 4.0\n#define COORDINATE_SYSTEM_P20 5.0 // amap\n#define COORDINATE_SYSTEM_P20_OFFSET 6.0 // amap offset\n#define COORDINATE_SYSTEM_METER_OFFSET 7.0\n\n#define COORDINATE_SYSTEM_P20_2 8.0 // amap2.0\nuniform float u_CoordinateSystem;\nvarying vec4 v_color;\nuniform float u_arrow: 0.0;\nuniform float u_linearColor: 0;\nuniform vec4 u_sourceColor;\nuniform vec4 u_targetColor;\n\n#pragma include \"picking\"\n\nvarying mat4 styleMappingMat;\nvoid main() {\n float distanceAndIndex = styleMappingMat[0][3];\n float miter = styleMappingMat[0][2];\n\n float opacity = styleMappingMat[0][0];\n float d_distance_ratio = styleMappingMat[3].r; // \u5F53\u524D\u70B9\u4F4D\u8DDD\u79BB\u5360\u7EBF\u603B\u957F\u7684\u6BD4\u4F8B\n\n\n if(u_arrow > 0.0 && distanceAndIndex < 2.0) { // arrow\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20 || u_CoordinateSystem == COORDINATE_SYSTEM_P20_OFFSET) { \n if(cross(vec3(styleMappingMat[1].rg, 0.0), vec3(styleMappingMat[1].ba, 0.0)).z < 0.0) { // amap\n discard;\n }\n } else { // amap2 mapbox map\n if(cross(vec3(styleMappingMat[1].rg, 0.0), vec3(styleMappingMat[1].ba, 0.0)).z > 0.0) { \n discard;\n }\n }\n } else { // line body\n if(miter < 0.0) {\n discard;\n }\n }\n\n\n if(u_linearColor == 1.0) { // \u4F7F\u7528\u6E10\u53D8\u989C\u8272\n gl_FragColor = mix(u_sourceColor, u_targetColor, d_distance_ratio);\n } else { // \u4F7F\u7528 color \u65B9\u6CD5\u4F20\u5165\u7684\u989C\u8272\n gl_FragColor = v_color;\n }\n\n gl_FragColor.a *= opacity; // \u5168\u5C40\u900F\u660E\u5EA6\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
|
|
24
|
-
/* babel-plugin-inline-import '../shaders/half/line_half_vert.glsl' */
|
|
25
|
-
var line_half_vert = "attribute float a_Miter;\nattribute vec4 a_Color;\nattribute vec2 a_Size;\nattribute vec3 a_Normal;\nattribute vec3 a_Position;\n\n// dash line\nattribute vec4 a_dirPoints;\nattribute vec3 a_DistanceAndIndex;\n\nuniform vec4 u_lineDir;\n\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvarying vec4 v_color;\n\nuniform float u_linearColor: 0;\nuniform float u_arrow: 0.0;\nuniform float u_arrowHeight: 3.0;\nuniform float u_arrowWidth: 2.0;\nuniform float u_tailWidth: 1.0;\n\nuniform float u_opacity: 1.0;\nvarying mat4 styleMappingMat; // \u7528\u4E8E\u5C06\u5728\u9876\u70B9\u7740\u8272\u5668\u4E2D\u8BA1\u7B97\u597D\u7684\u6837\u5F0F\u503C\u4F20\u9012\u7ED9\u7247\u5143\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n\nvec2 calculateArrow(vec2 offset) {\n /*\n * \u5728\u652F\u6301\u7BAD\u5934\u7684\u65F6\u5019\uFF0C\u7B2C\u4E8C\u3001\u7B2C\u4E09\u7EC4\u9876\u70B9\u662F\u989D\u5916\u63D2\u5165\u7528\u4E8E\u6784\u5EFA\u9876\u70B9\u7684\n */\n float arrowFlag = -1.0;\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) {\n // \u9AD8\u5FB7 2.0 \u7684\u65CB\u8F6C\u89D2\u5EA6\u4E0D\u540C\n arrowFlag = 1.0;\n }\n float pi = arrowFlag * 3.1415926/2.;\n if(a_Miter < 0.) {\n // \u6839\u636E\u7EBF\u7684\u4E24\u4FA7\u504F\u79FB\u4E0D\u540C\u3001\u65CB\u8F6C\u7684\u65B9\u5411\u76F8\u53CD\n pi = -pi;\n }\n highp float angle_sin = sin(pi);\n highp float angle_cos = cos(pi);\n // \u8BA1\u7B97\u5782\u76F4\u4E0E\u7EBF\u65B9\u5411\u7684\u65CB\u8F6C\u77E9\u9635\n mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);\n float arrowWidth = u_arrowWidth;\n float arrowHeight = u_arrowHeight;\n\n vec2 arrowOffset = vec2(0.0);\n /*\n * a_DistanceAndIndex.y \u7528\u4E8E\u6807\u8BB0\u5F53\u524D\u9876\u70B9\u5C5E\u4E8E\u54EA\u4E00\u7EC4\uFF08\u4E24\u4E2A\u9876\u70B9\u4E00\u7EC4\uFF0C\u6784\u6210\u7EBF\u7684\u5176\u5B9E\u662F\u77E9\u5F62\uFF0C\u6700\u7B80\u9700\u8981\u56DB\u4E2A\u9876\u70B9\u3001\u4E24\u7EC4\u9876\u70B9\u6784\u6210\uFF09\n */\n if(a_DistanceAndIndex.y == 0.0) {\n // \u7BAD\u5934\u5C16\u90E8\n offset = vec2(0.0);\n } else if(a_DistanceAndIndex.y == 1.0) {\n // \u7BAD\u5934\u4E24\u4FA7\n arrowOffset = rotation_matrix*(offset * arrowHeight);\n offset += arrowOffset; // \u6CBF\u7EBF\u504F\u79FB\n offset = offset * arrowWidth; // \u5782\u76F4\u7EBF\u5411\u5916\u504F\u79FB\uFF08\u662F\u6784\u5EFA\u7BAD\u5934\u4E24\u4FA7\u7684\u9876\u70B9\uFF09\n } else if(a_DistanceAndIndex.y == 2.0 || a_DistanceAndIndex.y == 3.0 || a_DistanceAndIndex.y == 4.0) {\n // \u504F\u79FB\u5176\u4F59\u7684\u70B9\u4F4D\uFF08\u5C06\u957F\u5EA6\u8BA9\u4F4D\u7ED9\u7BAD\u5934\uFF09\n arrowOffset = rotation_matrix*(offset * arrowHeight) * arrowWidth;\n offset += arrowOffset;// \u6CBF\u7EBF\u504F\u79FB\n }\n\n return offset;\n}\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n styleMappingMat = mat4(\n 0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - a_Miter - a_DistanceAndIndex\n 0.0, 0.0, 0.0, 0.0, // originX - originY - vectorX - vectorY\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1]\n 0.0, 0.0, 0.0, 0.0 // distance_ratio/distance/pixelLen/texV\n );\n styleMappingMat[0][3] = a_DistanceAndIndex.y;\n styleMappingMat[0][2] = a_Miter;\n\n float rowCount = u_cellTypeLayout[0][0]; // \u5F53\u524D\u7684\u6570\u636E\u7EB9\u7406\u6709\u51E0\u884C\n float columnCount = u_cellTypeLayout[0][1]; // \u5F53\u770B\u5230\u6570\u636E\u7EB9\u7406\u6709\u51E0\u5217\n float columnWidth = 1.0/columnCount; // \u5217\u5BBD\n float rowHeight = 1.0/rowCount; // \u884C\u9AD8\n float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets\n float id = a_vertexId; // \u7B2Cn\u4E2A\u9876\u70B9\n float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u884C\n float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u5217\n \n // cell \u56FA\u5B9A\u987A\u5E8F opacity -> strokeOpacity -> strokeWidth -> stroke ... \n // \u6309\u987A\u5E8F\u4ECE cell \u4E2D\u53D6\u503C\u3001\u82E5\u6CA1\u6709\u5219\u81EA\u52A8\u5F80\u4E0B\u53D6\u503C\n float textureOffset = 0.0; // \u5728 cell \u4E2D\u53D6\u503C\u7684\u504F\u79FB\u91CF\n\n vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][0] = opacityAndOffset.r;\n textureOffset = opacityAndOffset.g;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n\n v_color = a_Color;\n\n vec3 size = a_Miter * setPickingSize(a_Size.x) * reverse_offset_normal(a_Normal);\n \n vec2 offset = project_pixel(size.xy);\n\n // styleMappingMat[1].rg = a_Position.xy + offset;\n\n vec2 copyOffset = vec2(offset.x, offset.y);\n\n float lineDistance = a_DistanceAndIndex.x;\n float total_Distance = a_DistanceAndIndex.z;\n float currentLinePointRatio = lineDistance / total_Distance;\n \n if(u_arrow > 0.0) {\n // \u8BA1\u7B97\u7BAD\u5934\n offset = calculateArrow(offset);\n\n if(a_DistanceAndIndex.y > 4.0) {\n offset *= mix(1.0, u_tailWidth, currentLinePointRatio);\n }\n }\n\n float lineOffsetWidth = length(offset + offset * sign(a_Miter)); // \u7EBF\u6A2A\u5411\u504F\u79FB\u7684\u8DDD\u79BB\uFF08\u5411\u4E24\u4FA7\u504F\u79FB\u7684\u548C\uFF09\n float linePixelSize = project_pixel(a_Size.x) * 2.0; // \u5B9A\u70B9\u4F4D\u7F6E\u504F\u79FB\uFF0C\u6309\u5730\u56FE\u7B49\u7EA7\u7F29\u653E\u540E\u7684\u8DDD\u79BB \u5355\u4FA7 * 2\n\n // \u8BBE\u7F6E\u6570\u636E\u96C6\u7684\u53C2\u6570\n styleMappingMat[3][0] = currentLinePointRatio; // \u5F53\u524D\u70B9\u4F4D\u8DDD\u79BB\u5360\u7EBF\u603B\u957F\u7684\u6BD4\u4F8B\n styleMappingMat[3][1] = lineDistance; // \u5F53\u524D\u9876\u70B9\u7684\u8DDD\u79BB\n\n vec4 project_pos = project_position(vec4(a_Position.xy, 0, 1.0));\n\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, a_Size.y, 1.0));\n\n float h = float(a_Position.z); // \u7EBF\u9876\u70B9\u7684\u9AD8\u5EA6 - \u517C\u5BB9\u4E0D\u5B58\u5728\u7B2C\u4E09\u4E2A\u6570\u503C\u7684\u60C5\u51B5 vertex height\n float lineHeight = a_Size.y; // size \u7B2C\u4E8C\u4E2A\u53C2\u6570\u4EE3\u8868\u7684\u9AD8\u5EA6 [linewidth, lineheight]\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n lineHeight *= 0.2; // \u4FDD\u6301\u548C amap/mapbox \u4E00\u81F4\u7684\u6548\u679C\n gl_Position = u_Mvp * (vec4(project_pos.xy + offset, lineHeight, 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, lineHeight, 1.0));\n }\n \n if(u_arrow > 0.0 && a_DistanceAndIndex.y < 2.0) {\n vec2 startPoint = a_dirPoints.rg;\n vec2 endPoint = a_dirPoints.ba;\n vec4 t1 = project_position(vec4(startPoint, 0, 1.0));\n vec4 t2 = project_position(vec4(endPoint, 0, 1.0));\n // TODO\uFF1A \u540E\u7EED\u4F18\u5316\u53EF\u4EE5\u628A\u4F4D\u7F6E\u8BA1\u7B97\u653E\u5728 cpu \u4E2D\u5B8C\u6210\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n vec2 p1 = (u_Mvp * vec4(t1.xy, 0.0, 1.0)).xy;\n vec2 p2 = (u_Mvp * vec4(t2.xy, 0.0, 1.0)).xy;\n styleMappingMat[1].rg = normalize(p1 - p2);\n styleMappingMat[1].ba = normalize(gl_Position.xy - p2);\n } else {\n vec2 p1 = project_common_position_to_clipspace(vec4(t1.xy, 0.0, 1.0)).xy;\n vec2 p2 = project_common_position_to_clipspace(vec4(t2.xy, 0.0, 1.0)).xy;\n styleMappingMat[1].rg = normalize(p1 - p2);\n styleMappingMat[1].ba = normalize(gl_Position.xy - p2);\n }\n }\n\n setPickingColor(a_PickingColor);\n}\n";
|
|
26
|
-
var LineModel = /*#__PURE__*/function (_BaseModel) {
|
|
27
|
-
(0, _inherits2.default)(LineModel, _BaseModel);
|
|
28
|
-
var _super = _createSuper(LineModel);
|
|
29
|
-
function LineModel() {
|
|
30
|
-
(0, _classCallCheck2.default)(this, LineModel);
|
|
31
|
-
return _super.apply(this, arguments);
|
|
32
|
-
}
|
|
33
|
-
(0, _createClass2.default)(LineModel, [{
|
|
34
|
-
key: "getUninforms",
|
|
35
|
-
value: function getUninforms() {
|
|
36
|
-
var _ref = this.layer.getLayerConfig(),
|
|
37
|
-
_ref$opacity = _ref.opacity,
|
|
38
|
-
opacity = _ref$opacity === void 0 ? 1 : _ref$opacity,
|
|
39
|
-
sourceColor = _ref.sourceColor,
|
|
40
|
-
targetColor = _ref.targetColor,
|
|
41
|
-
_ref$arrow = _ref.arrow,
|
|
42
|
-
arrow = _ref$arrow === void 0 ? {
|
|
43
|
-
enable: false,
|
|
44
|
-
arrowWidth: 2,
|
|
45
|
-
arrowHeight: 3,
|
|
46
|
-
tailWidth: 1
|
|
47
|
-
} : _ref$arrow;
|
|
48
|
-
|
|
49
|
-
// 转化渐变色
|
|
50
|
-
var useLinearColor = 0; // 默认不生效
|
|
51
|
-
var sourceColorArr = [0, 0, 0, 0];
|
|
52
|
-
var targetColorArr = [0, 0, 0, 0];
|
|
53
|
-
if (sourceColor && targetColor) {
|
|
54
|
-
sourceColorArr = (0, _l7Utils.rgb2arr)(sourceColor);
|
|
55
|
-
targetColorArr = (0, _l7Utils.rgb2arr)(targetColor);
|
|
56
|
-
useLinearColor = 1;
|
|
57
|
-
}
|
|
58
|
-
if (this.dataTextureTest && this.dataTextureNeedUpdate({
|
|
59
|
-
opacity: opacity
|
|
60
|
-
})) {
|
|
61
|
-
this.judgeStyleAttributes({
|
|
62
|
-
opacity: opacity
|
|
63
|
-
});
|
|
64
|
-
var encodeData = this.layer.getEncodedData();
|
|
65
|
-
var _this$calDataFrame = this.calDataFrame(this.cellLength, encodeData, this.cellProperties),
|
|
66
|
-
data = _this$calDataFrame.data,
|
|
67
|
-
width = _this$calDataFrame.width,
|
|
68
|
-
height = _this$calDataFrame.height;
|
|
69
|
-
this.rowCount = height; // 当前数据纹理有多少行
|
|
70
|
-
|
|
71
|
-
this.dataTexture = this.cellLength > 0 && data.length > 0 ? this.createTexture2D({
|
|
72
|
-
flipY: true,
|
|
73
|
-
data: data,
|
|
74
|
-
format: _l7Core.gl.LUMINANCE,
|
|
75
|
-
type: _l7Core.gl.FLOAT,
|
|
76
|
-
width: width,
|
|
77
|
-
height: height
|
|
78
|
-
}) : this.createTexture2D({
|
|
79
|
-
flipY: true,
|
|
80
|
-
data: [1],
|
|
81
|
-
format: _l7Core.gl.LUMINANCE,
|
|
82
|
-
type: _l7Core.gl.FLOAT,
|
|
83
|
-
width: 1,
|
|
84
|
-
height: 1
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
u_dataTexture: this.dataTexture,
|
|
89
|
-
// 数据纹理 - 有数据映射的时候纹理中带数据,若没有任何数据映射时纹理是 [1]
|
|
90
|
-
u_cellTypeLayout: this.getCellTypeLayout(),
|
|
91
|
-
u_opacity: (0, _lodash.isNumber)(opacity) ? opacity : 1.0,
|
|
92
|
-
// 渐变色支持参数
|
|
93
|
-
u_linearColor: useLinearColor,
|
|
94
|
-
u_sourceColor: sourceColorArr,
|
|
95
|
-
u_targetColor: targetColorArr,
|
|
96
|
-
// arrow
|
|
97
|
-
u_arrow: Number(arrow.enable),
|
|
98
|
-
u_arrowHeight: arrow.arrowHeight || 3,
|
|
99
|
-
u_arrowWidth: arrow.arrowWidth || 2,
|
|
100
|
-
u_tailWidth: arrow.tailWidth === undefined ? 1 : arrow.tailWidth
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}, {
|
|
104
|
-
key: "initModels",
|
|
105
|
-
value: function () {
|
|
106
|
-
var _initModels = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
107
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
108
|
-
while (1) switch (_context.prev = _context.next) {
|
|
109
|
-
case 0:
|
|
110
|
-
return _context.abrupt("return", this.buildModels());
|
|
111
|
-
case 1:
|
|
112
|
-
case "end":
|
|
113
|
-
return _context.stop();
|
|
114
|
-
}
|
|
115
|
-
}, _callee, this);
|
|
116
|
-
}));
|
|
117
|
-
function initModels() {
|
|
118
|
-
return _initModels.apply(this, arguments);
|
|
119
|
-
}
|
|
120
|
-
return initModels;
|
|
121
|
-
}()
|
|
122
|
-
}, {
|
|
123
|
-
key: "clearModels",
|
|
124
|
-
value: function clearModels() {
|
|
125
|
-
var _this$dataTexture;
|
|
126
|
-
(_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy();
|
|
127
|
-
}
|
|
128
|
-
}, {
|
|
129
|
-
key: "buildModels",
|
|
130
|
-
value: function () {
|
|
131
|
-
var _buildModels = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
132
|
-
var _ref2, _ref2$depth, depth, _this$getShaders, frag, vert, model;
|
|
133
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
134
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
135
|
-
case 0:
|
|
136
|
-
_ref2 = this.layer.getLayerConfig(), _ref2$depth = _ref2.depth, depth = _ref2$depth === void 0 ? false : _ref2$depth;
|
|
137
|
-
_this$getShaders = this.getShaders(), frag = _this$getShaders.frag, vert = _this$getShaders.vert;
|
|
138
|
-
this.layer.triangulation = _triangulation.LineTriangulation;
|
|
139
|
-
_context2.next = 5;
|
|
140
|
-
return this.layer.buildLayerModel({
|
|
141
|
-
moduleName: 'lineHalf',
|
|
142
|
-
vertexShader: vert,
|
|
143
|
-
fragmentShader: frag,
|
|
144
|
-
triangulation: _triangulation.LineTriangulation,
|
|
145
|
-
depth: {
|
|
146
|
-
enable: depth
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
case 5:
|
|
150
|
-
model = _context2.sent;
|
|
151
|
-
return _context2.abrupt("return", [model]);
|
|
152
|
-
case 7:
|
|
153
|
-
case "end":
|
|
154
|
-
return _context2.stop();
|
|
155
|
-
}
|
|
156
|
-
}, _callee2, this);
|
|
157
|
-
}));
|
|
158
|
-
function buildModels() {
|
|
159
|
-
return _buildModels.apply(this, arguments);
|
|
160
|
-
}
|
|
161
|
-
return buildModels;
|
|
162
|
-
}()
|
|
163
|
-
/**
|
|
164
|
-
* 根据参数获取不同的 shader 代码
|
|
165
|
-
* @returns
|
|
166
|
-
*/
|
|
167
|
-
}, {
|
|
168
|
-
key: "getShaders",
|
|
169
|
-
value: function getShaders() {
|
|
170
|
-
return {
|
|
171
|
-
frag: line_half_frag,
|
|
172
|
-
vert: line_half_vert,
|
|
173
|
-
type: 'normal'
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
}, {
|
|
177
|
-
key: "registerBuiltinAttributes",
|
|
178
|
-
value: function registerBuiltinAttributes() {
|
|
179
|
-
this.styleAttributeService.registerStyleAttribute({
|
|
180
|
-
name: 'distanceAndIndex',
|
|
181
|
-
type: _l7Core.AttributeType.Attribute,
|
|
182
|
-
descriptor: {
|
|
183
|
-
name: 'a_DistanceAndIndex',
|
|
184
|
-
buffer: {
|
|
185
|
-
// give the WebGL driver a hint that this buffer may change
|
|
186
|
-
usage: _l7Core.gl.STATIC_DRAW,
|
|
187
|
-
data: [],
|
|
188
|
-
type: _l7Core.gl.FLOAT
|
|
189
|
-
},
|
|
190
|
-
size: 3,
|
|
191
|
-
update: function update(feature, featureIdx, vertex, attributeIdx, normal, vertexIndex) {
|
|
192
|
-
return vertexIndex === undefined ? [vertex[3], 10, vertex[5]] : [vertex[3], vertexIndex, vertex[5]];
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
this.styleAttributeService.registerStyleAttribute({
|
|
197
|
-
name: 'dirPoints',
|
|
198
|
-
type: _l7Core.AttributeType.Attribute,
|
|
199
|
-
descriptor: {
|
|
200
|
-
name: 'a_dirPoints',
|
|
201
|
-
buffer: {
|
|
202
|
-
// give the WebGL driver a hint that this buffer may change
|
|
203
|
-
usage: _l7Core.gl.STATIC_DRAW,
|
|
204
|
-
data: [],
|
|
205
|
-
type: _l7Core.gl.FLOAT
|
|
206
|
-
},
|
|
207
|
-
size: 4,
|
|
208
|
-
update: function update(feature) {
|
|
209
|
-
var startPoint = feature.coordinates[0] || [0, 0];
|
|
210
|
-
var endPoint = feature.coordinates[3] || [0, 0];
|
|
211
|
-
return [startPoint[0], startPoint[1], endPoint[0], endPoint[1]];
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
this.styleAttributeService.registerStyleAttribute({
|
|
216
|
-
name: 'size',
|
|
217
|
-
type: _l7Core.AttributeType.Attribute,
|
|
218
|
-
descriptor: {
|
|
219
|
-
name: 'a_Size',
|
|
220
|
-
buffer: {
|
|
221
|
-
// give the WebGL driver a hint that this buffer may change
|
|
222
|
-
usage: _l7Core.gl.DYNAMIC_DRAW,
|
|
223
|
-
data: [],
|
|
224
|
-
type: _l7Core.gl.FLOAT
|
|
225
|
-
},
|
|
226
|
-
size: 2,
|
|
227
|
-
update: function update(feature) {
|
|
228
|
-
var _feature$size = feature.size,
|
|
229
|
-
size = _feature$size === void 0 ? 1 : _feature$size;
|
|
230
|
-
return Array.isArray(size) ? [size[0], size[1]] : [size, 0];
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
// point layer size;
|
|
236
|
-
this.styleAttributeService.registerStyleAttribute({
|
|
237
|
-
name: 'normal',
|
|
238
|
-
type: _l7Core.AttributeType.Attribute,
|
|
239
|
-
descriptor: {
|
|
240
|
-
name: 'a_Normal',
|
|
241
|
-
buffer: {
|
|
242
|
-
// give the WebGL driver a hint that this buffer may change
|
|
243
|
-
usage: _l7Core.gl.STATIC_DRAW,
|
|
244
|
-
data: [],
|
|
245
|
-
type: _l7Core.gl.FLOAT
|
|
246
|
-
},
|
|
247
|
-
size: 3,
|
|
248
|
-
update: function update(feature, featureIdx, vertex, attributeIdx, normal) {
|
|
249
|
-
return normal;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
this.styleAttributeService.registerStyleAttribute({
|
|
254
|
-
name: 'miter',
|
|
255
|
-
type: _l7Core.AttributeType.Attribute,
|
|
256
|
-
descriptor: {
|
|
257
|
-
name: 'a_Miter',
|
|
258
|
-
buffer: {
|
|
259
|
-
// give the WebGL driver a hint that this buffer may change
|
|
260
|
-
usage: _l7Core.gl.STATIC_DRAW,
|
|
261
|
-
data: [],
|
|
262
|
-
type: _l7Core.gl.FLOAT
|
|
263
|
-
},
|
|
264
|
-
size: 1,
|
|
265
|
-
update: function update(feature, featureIdx, vertex) {
|
|
266
|
-
return [vertex[4]];
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}]);
|
|
272
|
-
return LineModel;
|
|
273
|
-
}(_BaseModel2.default);
|
|
274
|
-
exports.default = LineModel;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
#define COORDINATE_SYSTEM_LNGLAT 1.0 // mapbox
|
|
2
|
-
#define COORDINATE_SYSTEM_LNGLAT_OFFSET 2.0 // mapbox offset
|
|
3
|
-
#define COORDINATE_SYSTEM_VECTOR_TILE 3.0
|
|
4
|
-
#define COORDINATE_SYSTEM_IDENTITY 4.0
|
|
5
|
-
#define COORDINATE_SYSTEM_P20 5.0 // amap
|
|
6
|
-
#define COORDINATE_SYSTEM_P20_OFFSET 6.0 // amap offset
|
|
7
|
-
#define COORDINATE_SYSTEM_METER_OFFSET 7.0
|
|
8
|
-
|
|
9
|
-
#define COORDINATE_SYSTEM_P20_2 8.0 // amap2.0
|
|
10
|
-
uniform float u_CoordinateSystem;
|
|
11
|
-
varying vec4 v_color;
|
|
12
|
-
uniform float u_arrow: 0.0;
|
|
13
|
-
uniform float u_linearColor: 0;
|
|
14
|
-
uniform vec4 u_sourceColor;
|
|
15
|
-
uniform vec4 u_targetColor;
|
|
16
|
-
|
|
17
|
-
#pragma include "picking"
|
|
18
|
-
|
|
19
|
-
varying mat4 styleMappingMat;
|
|
20
|
-
void main() {
|
|
21
|
-
float distanceAndIndex = styleMappingMat[0][3];
|
|
22
|
-
float miter = styleMappingMat[0][2];
|
|
23
|
-
|
|
24
|
-
float opacity = styleMappingMat[0][0];
|
|
25
|
-
float d_distance_ratio = styleMappingMat[3].r; // 当前点位距离占线总长的比例
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if(u_arrow > 0.0 && distanceAndIndex < 2.0) { // arrow
|
|
29
|
-
if(u_CoordinateSystem == COORDINATE_SYSTEM_P20 || u_CoordinateSystem == COORDINATE_SYSTEM_P20_OFFSET) {
|
|
30
|
-
if(cross(vec3(styleMappingMat[1].rg, 0.0), vec3(styleMappingMat[1].ba, 0.0)).z < 0.0) { // amap
|
|
31
|
-
discard;
|
|
32
|
-
}
|
|
33
|
-
} else { // amap2 mapbox map
|
|
34
|
-
if(cross(vec3(styleMappingMat[1].rg, 0.0), vec3(styleMappingMat[1].ba, 0.0)).z > 0.0) {
|
|
35
|
-
discard;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
} else { // line body
|
|
39
|
-
if(miter < 0.0) {
|
|
40
|
-
discard;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if(u_linearColor == 1.0) { // 使用渐变颜色
|
|
46
|
-
gl_FragColor = mix(u_sourceColor, u_targetColor, d_distance_ratio);
|
|
47
|
-
} else { // 使用 color 方法传入的颜色
|
|
48
|
-
gl_FragColor = v_color;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
gl_FragColor.a *= opacity; // 全局透明度
|
|
52
|
-
gl_FragColor = filterColor(gl_FragColor);
|
|
53
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
attribute float a_Miter;
|
|
2
|
-
attribute vec4 a_Color;
|
|
3
|
-
attribute vec2 a_Size;
|
|
4
|
-
attribute vec3 a_Normal;
|
|
5
|
-
attribute vec3 a_Position;
|
|
6
|
-
|
|
7
|
-
// dash line
|
|
8
|
-
attribute vec4 a_dirPoints;
|
|
9
|
-
attribute vec3 a_DistanceAndIndex;
|
|
10
|
-
|
|
11
|
-
uniform vec4 u_lineDir;
|
|
12
|
-
|
|
13
|
-
uniform mat4 u_ModelMatrix;
|
|
14
|
-
uniform mat4 u_Mvp;
|
|
15
|
-
|
|
16
|
-
#pragma include "projection"
|
|
17
|
-
#pragma include "picking"
|
|
18
|
-
|
|
19
|
-
varying vec4 v_color;
|
|
20
|
-
|
|
21
|
-
uniform float u_linearColor: 0;
|
|
22
|
-
uniform float u_arrow: 0.0;
|
|
23
|
-
uniform float u_arrowHeight: 3.0;
|
|
24
|
-
uniform float u_arrowWidth: 2.0;
|
|
25
|
-
uniform float u_tailWidth: 1.0;
|
|
26
|
-
|
|
27
|
-
uniform float u_opacity: 1.0;
|
|
28
|
-
varying mat4 styleMappingMat; // 用于将在顶点着色器中计算好的样式值传递给片元
|
|
29
|
-
|
|
30
|
-
#pragma include "styleMapping"
|
|
31
|
-
#pragma include "styleMappingCalOpacity"
|
|
32
|
-
|
|
33
|
-
vec2 calculateArrow(vec2 offset) {
|
|
34
|
-
/*
|
|
35
|
-
* 在支持箭头的时候,第二、第三组顶点是额外插入用于构建顶点的
|
|
36
|
-
*/
|
|
37
|
-
float arrowFlag = -1.0;
|
|
38
|
-
if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) {
|
|
39
|
-
// 高德 2.0 的旋转角度不同
|
|
40
|
-
arrowFlag = 1.0;
|
|
41
|
-
}
|
|
42
|
-
float pi = arrowFlag * 3.1415926/2.;
|
|
43
|
-
if(a_Miter < 0.) {
|
|
44
|
-
// 根据线的两侧偏移不同、旋转的方向相反
|
|
45
|
-
pi = -pi;
|
|
46
|
-
}
|
|
47
|
-
highp float angle_sin = sin(pi);
|
|
48
|
-
highp float angle_cos = cos(pi);
|
|
49
|
-
// 计算垂直与线方向的旋转矩阵
|
|
50
|
-
mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);
|
|
51
|
-
float arrowWidth = u_arrowWidth;
|
|
52
|
-
float arrowHeight = u_arrowHeight;
|
|
53
|
-
|
|
54
|
-
vec2 arrowOffset = vec2(0.0);
|
|
55
|
-
/*
|
|
56
|
-
* a_DistanceAndIndex.y 用于标记当前顶点属于哪一组(两个顶点一组,构成线的其实是矩形,最简需要四个顶点、两组顶点构成)
|
|
57
|
-
*/
|
|
58
|
-
if(a_DistanceAndIndex.y == 0.0) {
|
|
59
|
-
// 箭头尖部
|
|
60
|
-
offset = vec2(0.0);
|
|
61
|
-
} else if(a_DistanceAndIndex.y == 1.0) {
|
|
62
|
-
// 箭头两侧
|
|
63
|
-
arrowOffset = rotation_matrix*(offset * arrowHeight);
|
|
64
|
-
offset += arrowOffset; // 沿线偏移
|
|
65
|
-
offset = offset * arrowWidth; // 垂直线向外偏移(是构建箭头两侧的顶点)
|
|
66
|
-
} else if(a_DistanceAndIndex.y == 2.0 || a_DistanceAndIndex.y == 3.0 || a_DistanceAndIndex.y == 4.0) {
|
|
67
|
-
// 偏移其余的点位(将长度让位给箭头)
|
|
68
|
-
arrowOffset = rotation_matrix*(offset * arrowHeight) * arrowWidth;
|
|
69
|
-
offset += arrowOffset;// 沿线偏移
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return offset;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
void main() {
|
|
76
|
-
// cal style mapping - 数据纹理映射部分的计算
|
|
77
|
-
styleMappingMat = mat4(
|
|
78
|
-
0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - a_Miter - a_DistanceAndIndex
|
|
79
|
-
0.0, 0.0, 0.0, 0.0, // originX - originY - vectorX - vectorY
|
|
80
|
-
0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1]
|
|
81
|
-
0.0, 0.0, 0.0, 0.0 // distance_ratio/distance/pixelLen/texV
|
|
82
|
-
);
|
|
83
|
-
styleMappingMat[0][3] = a_DistanceAndIndex.y;
|
|
84
|
-
styleMappingMat[0][2] = a_Miter;
|
|
85
|
-
|
|
86
|
-
float rowCount = u_cellTypeLayout[0][0]; // 当前的数据纹理有几行
|
|
87
|
-
float columnCount = u_cellTypeLayout[0][1]; // 当看到数据纹理有几列
|
|
88
|
-
float columnWidth = 1.0/columnCount; // 列宽
|
|
89
|
-
float rowHeight = 1.0/rowCount; // 行高
|
|
90
|
-
float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets
|
|
91
|
-
float id = a_vertexId; // 第n个顶点
|
|
92
|
-
float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // 起始点在第几行
|
|
93
|
-
float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // 起始点在第几列
|
|
94
|
-
|
|
95
|
-
// cell 固定顺序 opacity -> strokeOpacity -> strokeWidth -> stroke ...
|
|
96
|
-
// 按顺序从 cell 中取值、若没有则自动往下取值
|
|
97
|
-
float textureOffset = 0.0; // 在 cell 中取值的偏移量
|
|
98
|
-
|
|
99
|
-
vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);
|
|
100
|
-
styleMappingMat[0][0] = opacityAndOffset.r;
|
|
101
|
-
textureOffset = opacityAndOffset.g;
|
|
102
|
-
// cal style mapping - 数据纹理映射部分的计算
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
v_color = a_Color;
|
|
106
|
-
|
|
107
|
-
vec3 size = a_Miter * setPickingSize(a_Size.x) * reverse_offset_normal(a_Normal);
|
|
108
|
-
|
|
109
|
-
vec2 offset = project_pixel(size.xy);
|
|
110
|
-
|
|
111
|
-
// styleMappingMat[1].rg = a_Position.xy + offset;
|
|
112
|
-
|
|
113
|
-
vec2 copyOffset = vec2(offset.x, offset.y);
|
|
114
|
-
|
|
115
|
-
float lineDistance = a_DistanceAndIndex.x;
|
|
116
|
-
float total_Distance = a_DistanceAndIndex.z;
|
|
117
|
-
float currentLinePointRatio = lineDistance / total_Distance;
|
|
118
|
-
|
|
119
|
-
if(u_arrow > 0.0) {
|
|
120
|
-
// 计算箭头
|
|
121
|
-
offset = calculateArrow(offset);
|
|
122
|
-
|
|
123
|
-
if(a_DistanceAndIndex.y > 4.0) {
|
|
124
|
-
offset *= mix(1.0, u_tailWidth, currentLinePointRatio);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
float lineOffsetWidth = length(offset + offset * sign(a_Miter)); // 线横向偏移的距离(向两侧偏移的和)
|
|
129
|
-
float linePixelSize = project_pixel(a_Size.x) * 2.0; // 定点位置偏移,按地图等级缩放后的距离 单侧 * 2
|
|
130
|
-
|
|
131
|
-
// 设置数据集的参数
|
|
132
|
-
styleMappingMat[3][0] = currentLinePointRatio; // 当前点位距离占线总长的比例
|
|
133
|
-
styleMappingMat[3][1] = lineDistance; // 当前顶点的距离
|
|
134
|
-
|
|
135
|
-
vec4 project_pos = project_position(vec4(a_Position.xy, 0, 1.0));
|
|
136
|
-
|
|
137
|
-
// gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, a_Size.y, 1.0));
|
|
138
|
-
|
|
139
|
-
float h = float(a_Position.z); // 线顶点的高度 - 兼容不存在第三个数值的情况 vertex height
|
|
140
|
-
float lineHeight = a_Size.y; // size 第二个参数代表的高度 [linewidth, lineheight]
|
|
141
|
-
|
|
142
|
-
if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x
|
|
143
|
-
lineHeight *= 0.2; // 保持和 amap/mapbox 一致的效果
|
|
144
|
-
gl_Position = u_Mvp * (vec4(project_pos.xy + offset, lineHeight, 1.0));
|
|
145
|
-
} else {
|
|
146
|
-
gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, lineHeight, 1.0));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if(u_arrow > 0.0 && a_DistanceAndIndex.y < 2.0) {
|
|
150
|
-
vec2 startPoint = a_dirPoints.rg;
|
|
151
|
-
vec2 endPoint = a_dirPoints.ba;
|
|
152
|
-
vec4 t1 = project_position(vec4(startPoint, 0, 1.0));
|
|
153
|
-
vec4 t2 = project_position(vec4(endPoint, 0, 1.0));
|
|
154
|
-
// TODO: 后续优化可以把位置计算放在 cpu 中完成
|
|
155
|
-
if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x
|
|
156
|
-
vec2 p1 = (u_Mvp * vec4(t1.xy, 0.0, 1.0)).xy;
|
|
157
|
-
vec2 p2 = (u_Mvp * vec4(t2.xy, 0.0, 1.0)).xy;
|
|
158
|
-
styleMappingMat[1].rg = normalize(p1 - p2);
|
|
159
|
-
styleMappingMat[1].ba = normalize(gl_Position.xy - p2);
|
|
160
|
-
} else {
|
|
161
|
-
vec2 p1 = project_common_position_to_clipspace(vec4(t1.xy, 0.0, 1.0)).xy;
|
|
162
|
-
vec2 p2 = project_common_position_to_clipspace(vec4(t2.xy, 0.0, 1.0)).xy;
|
|
163
|
-
styleMappingMat[1].rg = normalize(p1 - p2);
|
|
164
|
-
styleMappingMat[1].ba = normalize(gl_Position.xy - p2);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
setPickingColor(a_PickingColor);
|
|
169
|
-
}
|