@antv/l7-layers 2.15.5 → 2.16.1
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/Geometry/index.js +31 -9
- package/es/Geometry/models/billboard.js +89 -51
- package/es/Geometry/models/plane.js +143 -81
- package/es/Geometry/models/sprite.js +118 -60
- package/es/canvas/index.js +33 -10
- package/es/canvas/models/canvas.js +97 -41
- package/es/citybuliding/building.js +27 -8
- package/es/citybuliding/models/build.js +82 -57
- package/es/core/BaseLayer.js +486 -321
- package/es/core/BaseModel.js +126 -97
- package/es/core/LayerPickService.js +32 -21
- package/es/core/TextureService.js +13 -0
- package/es/core/interface.js +24 -17
- package/es/core/shape/Path.js +20 -13
- package/es/core/shape/extrude.js +31 -10
- package/es/core/triangulation.js +114 -54
- package/es/earth/index.js +33 -9
- package/es/earth/models/atmosphere.js +54 -30
- package/es/earth/models/base.js +85 -47
- package/es/earth/models/bloomsphere.js +54 -30
- package/es/earth/utils.js +13 -9
- package/es/heatmap/index.js +40 -10
- package/es/heatmap/models/grid.js +52 -28
- package/es/heatmap/models/grid3d.js +52 -28
- package/es/heatmap/models/heatmap.js +146 -91
- package/es/heatmap/models/hexagon.js +52 -28
- package/es/heatmap/triangulation.js +4 -0
- package/es/image/index.js +28 -9
- package/es/image/models/image.js +100 -66
- package/es/index.js +17 -9
- package/es/line/index.js +34 -9
- package/es/line/models/arc.js +118 -66
- package/es/line/models/arc_3d.js +108 -60
- package/es/line/models/earthArc_3d.js +111 -63
- package/es/line/models/great_circle.js +100 -56
- package/es/line/models/half.js +77 -46
- package/es/line/models/line.js +148 -94
- package/es/line/models/linearline.js +80 -45
- package/es/line/models/simpleLine.js +74 -41
- package/es/line/models/wall.js +92 -52
- package/es/mask/index.js +28 -9
- package/es/mask/models/fill.js +54 -29
- package/es/plugins/DataMappingPlugin.js +117 -80
- package/es/plugins/DataSourcePlugin.js +68 -45
- package/es/plugins/FeatureScalePlugin.js +122 -67
- package/es/plugins/LayerAnimateStylePlugin.js +5 -0
- package/es/plugins/LayerMaskPlugin.js +11 -3
- package/es/plugins/LayerModelPlugin.js +104 -67
- package/es/plugins/LayerStylePlugin.js +9 -3
- package/es/plugins/LightingPlugin.js +18 -12
- package/es/plugins/MultiPassRendererPlugin.js +16 -11
- package/es/plugins/PixelPickingPlugin.js +21 -12
- package/es/plugins/RegisterStyleAttributePlugin.js +12 -5
- package/es/plugins/ShaderUniformPlugin.js +27 -13
- package/es/plugins/UpdateModelPlugin.js +5 -0
- package/es/plugins/UpdateStyleAttributePlugin.js +11 -5
- package/es/point/index.js +77 -26
- package/es/point/models/earthExtrude.js +102 -61
- package/es/point/models/earthFill.js +87 -57
- package/es/point/models/extrude.js +101 -60
- package/es/point/models/fill.js +100 -70
- package/es/point/models/fillmage.js +107 -63
- package/es/point/models/image.js +88 -48
- package/es/point/models/index.js +2 -2
- package/es/point/models/normal.js +54 -30
- package/es/point/models/radar.js +64 -40
- package/es/point/models/simplePoint.js +69 -41
- package/es/point/models/text.d.ts +2 -1
- package/es/point/models/text.js +305 -201
- package/es/point/shape/extrude.js +13 -4
- package/es/polygon/index.js +40 -11
- package/es/polygon/models/extrude.js +92 -48
- package/es/polygon/models/fill.js +88 -54
- package/es/polygon/models/index.js +2 -3
- package/es/polygon/models/ocean.js +76 -42
- package/es/polygon/models/water.js +71 -37
- package/es/raster/buffers/triangulation.js +4 -2
- package/es/raster/index.js +32 -9
- package/es/raster/models/raster.js +116 -80
- package/es/raster/models/rasterRgb.js +127 -84
- package/es/raster/models/rasterTerrainRgb.js +84 -56
- package/es/tile/interaction/getRasterData.js +20 -14
- package/es/tile/interaction/utils.js +9 -7
- package/es/tile/manager/base.js +96 -63
- package/es/tile/service/TileLayerService.js +55 -33
- package/es/tile/service/TilePickService.js +40 -26
- package/es/tile/service/TileSourceService.js +7 -3
- package/es/tile/tileFactory/DebugTile.js +46 -29
- package/es/tile/tileFactory/ImageTile.js +38 -20
- package/es/tile/tileFactory/MaskTile.js +43 -22
- package/es/tile/tileFactory/RasterRGBTile.js +42 -22
- package/es/tile/tileFactory/RasterTerrainRGBTile.js +38 -20
- package/es/tile/tileFactory/RasterTile.js +53 -30
- package/es/tile/tileFactory/Tile.js +97 -63
- package/es/tile/tileFactory/VectorTile.js +68 -41
- package/es/tile/tileFactory/index.js +11 -0
- package/es/tile/tileFactory/layers/TileDebugLayer.js +27 -6
- package/es/tile/tileFactory/util.js +3 -0
- package/es/tile/tileLayer/BaseLayer.js +146 -105
- package/es/tile/utils.js +1 -1
- package/es/utils/blend.js +2 -0
- package/es/utils/collision-index.js +16 -9
- package/es/utils/dataMappingStyle.js +18 -8
- package/es/utils/extrude_polyline.js +149 -101
- package/es/utils/grid-index.js +27 -2
- package/es/utils/identityScale.js +8 -0
- package/es/utils/layerData.js +44 -30
- package/es/utils/multiPassRender.js +13 -11
- package/es/utils/polylineNormal.js +37 -31
- package/es/utils/simpleLine.js +16 -2
- package/es/utils/stencil.js +3 -2
- package/es/utils/symbol-layout.js +53 -27
- package/es/wind/index.js +29 -9
- package/es/wind/models/utils.js +51 -26
- package/es/wind/models/wind.js +147 -101
- package/es/wind/models/windRender.js +66 -53
- package/lib/Geometry/index.js +38 -9
- package/lib/Geometry/models/billboard.js +97 -51
- package/lib/Geometry/models/index.js +5 -0
- package/lib/Geometry/models/plane.js +151 -79
- package/lib/Geometry/models/sprite.js +127 -60
- package/lib/canvas/index.js +40 -10
- package/lib/canvas/models/canvas.js +101 -41
- package/lib/canvas/models/index.js +3 -0
- package/lib/citybuliding/building.js +35 -8
- package/lib/citybuliding/models/build.js +92 -57
- package/lib/core/BaseLayer.js +480 -321
- package/lib/core/BaseModel.js +139 -97
- package/lib/core/LayerPickService.js +37 -21
- package/lib/core/TextureService.js +16 -0
- package/lib/core/interface.js +31 -21
- package/lib/core/schema.js +1 -0
- package/lib/core/shape/Path.js +31 -14
- package/lib/core/shape/extrude.js +54 -10
- package/lib/core/triangulation.js +153 -53
- package/lib/earth/index.js +43 -9
- package/lib/earth/models/atmosphere.js +63 -30
- package/lib/earth/models/base.js +90 -47
- package/lib/earth/models/bloomsphere.js +63 -30
- package/lib/earth/utils.js +31 -7
- package/lib/heatmap/index.js +48 -10
- package/lib/heatmap/models/grid.js +60 -28
- package/lib/heatmap/models/grid3d.js +60 -28
- package/lib/heatmap/models/heatmap.js +162 -91
- package/lib/heatmap/models/hexagon.js +60 -28
- package/lib/heatmap/models/index.js +6 -0
- package/lib/heatmap/triangulation.js +5 -0
- package/lib/image/index.js +36 -9
- package/lib/image/models/image.js +109 -66
- package/lib/image/models/index.js +3 -0
- package/lib/index.js +61 -7
- package/lib/line/index.js +40 -9
- package/lib/line/models/arc.js +128 -64
- package/lib/line/models/arc_3d.js +119 -58
- package/lib/line/models/earthArc_3d.js +122 -61
- package/lib/line/models/great_circle.js +111 -56
- package/lib/line/models/half.js +87 -46
- package/lib/line/models/index.js +11 -0
- package/lib/line/models/line.js +156 -92
- package/lib/line/models/linearline.js +92 -45
- package/lib/line/models/simpleLine.js +84 -41
- package/lib/line/models/wall.js +103 -52
- package/lib/mask/index.js +36 -9
- package/lib/mask/models/fill.js +63 -29
- package/lib/mask/models/index.js +3 -0
- package/lib/plugins/DataMappingPlugin.js +128 -80
- package/lib/plugins/DataSourcePlugin.js +76 -45
- package/lib/plugins/FeatureScalePlugin.js +138 -67
- package/lib/plugins/LayerAnimateStylePlugin.js +10 -0
- package/lib/plugins/LayerMaskPlugin.js +17 -4
- package/lib/plugins/LayerModelPlugin.js +113 -68
- package/lib/plugins/LayerStylePlugin.js +14 -4
- package/lib/plugins/LightingPlugin.js +25 -12
- package/lib/plugins/MultiPassRendererPlugin.js +22 -11
- package/lib/plugins/PixelPickingPlugin.js +27 -12
- package/lib/plugins/RegisterStyleAttributePlugin.js +19 -5
- package/lib/plugins/ShaderUniformPlugin.js +34 -13
- package/lib/plugins/UpdateModelPlugin.js +10 -1
- package/lib/plugins/UpdateStyleAttributePlugin.js +16 -5
- package/lib/point/index.js +83 -26
- package/lib/point/models/earthExtrude.js +113 -61
- package/lib/point/models/earthFill.js +117 -57
- package/lib/point/models/extrude.js +111 -60
- package/lib/point/models/fill.js +109 -68
- package/lib/point/models/fillmage.js +115 -61
- package/lib/point/models/image.js +98 -48
- package/lib/point/models/index.js +12 -1
- package/lib/point/models/normal.js +64 -30
- package/lib/point/models/radar.js +74 -40
- package/lib/point/models/simplePoint.js +79 -41
- package/lib/point/models/text.js +314 -202
- package/lib/point/shape/extrude.js +20 -4
- package/lib/polygon/index.js +48 -11
- package/lib/polygon/models/extrude.js +103 -48
- package/lib/polygon/models/fill.js +98 -54
- package/lib/polygon/models/index.js +14 -2
- package/lib/polygon/models/ocean.js +88 -42
- package/lib/polygon/models/water.js +82 -37
- package/lib/raster/buffers/triangulation.js +7 -3
- package/lib/raster/index.js +40 -9
- package/lib/raster/models/index.js +5 -0
- package/lib/raster/models/raster.js +125 -80
- package/lib/raster/models/rasterRgb.js +139 -84
- package/lib/raster/models/rasterTerrainRgb.js +93 -56
- package/lib/tile/interaction/getRasterData.js +25 -14
- package/lib/tile/interaction/utils.js +19 -7
- package/lib/tile/manager/base.js +104 -63
- package/lib/tile/service/TileLayerService.js +60 -33
- package/lib/tile/service/TilePickService.js +48 -26
- package/lib/tile/service/TileSourceService.js +16 -2
- package/lib/tile/style/utils.js +3 -0
- package/lib/tile/tileFactory/DebugTile.js +54 -29
- package/lib/tile/tileFactory/ImageTile.js +46 -20
- package/lib/tile/tileFactory/MaskTile.js +51 -22
- package/lib/tile/tileFactory/RasterRGBTile.js +50 -22
- package/lib/tile/tileFactory/RasterTerrainRGBTile.js +46 -20
- package/lib/tile/tileFactory/RasterTile.js +63 -30
- package/lib/tile/tileFactory/Tile.js +102 -63
- package/lib/tile/tileFactory/VectorTile.js +76 -41
- package/lib/tile/tileFactory/index.js +25 -0
- package/lib/tile/tileFactory/layers/TileDebugLayer.js +32 -6
- package/lib/tile/tileFactory/util.js +9 -0
- package/lib/tile/tileLayer/BaseLayer.js +153 -105
- package/lib/tile/utils.js +5 -1
- package/lib/utils/blend.js +5 -0
- package/lib/utils/collision-index.js +25 -9
- package/lib/utils/dataMappingStyle.js +19 -8
- package/lib/utils/extrude_polyline.js +181 -101
- package/lib/utils/grid-index.js +28 -2
- package/lib/utils/identityScale.js +9 -0
- package/lib/utils/layerData.js +49 -30
- package/lib/utils/multiPassRender.js +16 -11
- package/lib/utils/polylineNormal.js +66 -31
- package/lib/utils/simpleLine.js +21 -2
- package/lib/utils/stencil.js +4 -0
- package/lib/utils/symbol-layout.js +55 -27
- package/lib/wind/index.js +37 -9
- package/lib/wind/models/index.js +3 -0
- package/lib/wind/models/utils.js +62 -26
- package/lib/wind/models/wind.js +157 -101
- package/lib/wind/models/windRender.js +71 -53
- package/lib/wind/models/windShader.js +1 -0
- package/package.json +7 -7
package/es/utils/stencil.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { gl, MaskOperation, StencilType } from '@antv/l7-core';
|
|
2
|
-
|
|
1
|
+
import { gl, MaskOperation, StencilType } from '@antv/l7-core'; // 掩膜配置
|
|
2
|
+
|
|
3
3
|
export function getStencil(mask, maskInside) {
|
|
4
4
|
return {
|
|
5
5
|
enable: mask,
|
|
@@ -30,6 +30,7 @@ export function getStencilMask(option) {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
+
|
|
33
34
|
return {
|
|
34
35
|
enable: true,
|
|
35
36
|
mask: 0xff,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
|
|
2
3
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
8
|
* 返回文本相对锚点位置
|
|
6
9
|
* @param {string} anchor 锚点位置
|
|
@@ -9,64 +12,76 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
9
12
|
function getAnchorAlignment(anchor) {
|
|
10
13
|
var horizontalAlign = 0.5;
|
|
11
14
|
var verticalAlign = 0.5;
|
|
15
|
+
|
|
12
16
|
switch (anchor) {
|
|
13
17
|
case 'right':
|
|
14
18
|
case 'top-right':
|
|
15
19
|
case 'bottom-right':
|
|
16
20
|
horizontalAlign = 1;
|
|
17
21
|
break;
|
|
22
|
+
|
|
18
23
|
case 'left':
|
|
19
24
|
case 'top-left':
|
|
20
25
|
case 'bottom-left':
|
|
21
26
|
horizontalAlign = 0;
|
|
22
27
|
break;
|
|
28
|
+
|
|
23
29
|
default:
|
|
24
30
|
horizontalAlign = 0.5;
|
|
25
31
|
}
|
|
32
|
+
|
|
26
33
|
switch (anchor) {
|
|
27
34
|
case 'bottom':
|
|
28
35
|
case 'bottom-right':
|
|
29
36
|
case 'bottom-left':
|
|
30
37
|
verticalAlign = 1;
|
|
31
38
|
break;
|
|
39
|
+
|
|
32
40
|
case 'top':
|
|
33
41
|
case 'top-right':
|
|
34
42
|
case 'top-left':
|
|
35
43
|
verticalAlign = 0;
|
|
36
44
|
break;
|
|
45
|
+
|
|
37
46
|
default:
|
|
38
47
|
verticalAlign = 0.5;
|
|
39
48
|
}
|
|
49
|
+
|
|
40
50
|
return {
|
|
41
51
|
horizontalAlign: horizontalAlign,
|
|
42
52
|
verticalAlign: verticalAlign
|
|
43
53
|
};
|
|
44
|
-
}
|
|
54
|
+
} // justify right = 1, left = 0, center = 0.5
|
|
55
|
+
|
|
45
56
|
|
|
46
|
-
// justify right = 1, left = 0, center = 0.5
|
|
47
57
|
function justifyLine(positionedGlyphs, glyphMap, start, end, justify) {
|
|
48
58
|
if (!justify) {
|
|
49
59
|
return;
|
|
50
60
|
}
|
|
61
|
+
|
|
51
62
|
var lastPositionedGlyph = positionedGlyphs[end];
|
|
52
63
|
var glyph = lastPositionedGlyph.glyph;
|
|
64
|
+
|
|
53
65
|
if (glyph) {
|
|
54
66
|
var lastAdvance = glyphMap[glyph].advance * lastPositionedGlyph.scale;
|
|
55
67
|
var lineIndent = (positionedGlyphs[end].x + lastAdvance) * justify;
|
|
68
|
+
|
|
56
69
|
for (var j = start; j <= end; j++) {
|
|
57
70
|
positionedGlyphs[j].x -= lineIndent;
|
|
58
71
|
}
|
|
59
72
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// justify right=1 left=0 center=0.5
|
|
73
|
+
} // justify right=1 left=0 center=0.5
|
|
63
74
|
// horizontalAlign right=1 left=0 center=0.5
|
|
64
75
|
// verticalAlign right=1 left=0 center=0.5
|
|
76
|
+
|
|
77
|
+
|
|
65
78
|
function align(positionedGlyphs, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight, lineCount) {
|
|
66
79
|
var shiftX = (justify - horizontalAlign) * maxLineLength;
|
|
67
80
|
var shiftY = (-verticalAlign * lineCount + 0.5) * lineHeight;
|
|
81
|
+
|
|
68
82
|
var _iterator = _createForOfIteratorHelper(positionedGlyphs),
|
|
69
|
-
|
|
83
|
+
_step;
|
|
84
|
+
|
|
70
85
|
try {
|
|
71
86
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
72
87
|
var glyphs = _step.value;
|
|
@@ -79,6 +94,7 @@ function align(positionedGlyphs, justify, horizontalAlign, verticalAlign, maxLin
|
|
|
79
94
|
_iterator.f();
|
|
80
95
|
}
|
|
81
96
|
}
|
|
97
|
+
|
|
82
98
|
function shapeLines(shaping, glyphMap, lines, lineHeight, textAnchor, textJustify, spacing) {
|
|
83
99
|
// buffer 为 4
|
|
84
100
|
var yOffset = -8;
|
|
@@ -92,6 +108,7 @@ function shapeLines(shaping, glyphMap, lines, lineHeight, textAnchor, textJustif
|
|
|
92
108
|
line.split('').forEach(function (char) {
|
|
93
109
|
var glyph = glyphMap[char];
|
|
94
110
|
var baselineOffset = 0;
|
|
111
|
+
|
|
95
112
|
if (glyph) {
|
|
96
113
|
positionedGlyphs.push({
|
|
97
114
|
glyph: char,
|
|
@@ -104,29 +121,31 @@ function shapeLines(shaping, glyphMap, lines, lineHeight, textAnchor, textJustif
|
|
|
104
121
|
});
|
|
105
122
|
x += glyph.advance + spacing;
|
|
106
123
|
}
|
|
107
|
-
});
|
|
124
|
+
}); // 左右对齐
|
|
108
125
|
|
|
109
|
-
// 左右对齐
|
|
110
126
|
if (positionedGlyphs.length !== lineStartIndex) {
|
|
111
127
|
var lineLength = x - spacing;
|
|
112
128
|
maxLineLength = Math.max(lineLength, maxLineLength);
|
|
113
129
|
justifyLine(positionedGlyphs, glyphMap, lineStartIndex, positionedGlyphs.length - 1, justify);
|
|
114
130
|
}
|
|
131
|
+
|
|
115
132
|
x = 0;
|
|
116
133
|
y -= lineHeight + 5;
|
|
117
134
|
});
|
|
135
|
+
|
|
118
136
|
var _getAnchorAlignment = getAnchorAlignment(textAnchor),
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
137
|
+
horizontalAlign = _getAnchorAlignment.horizontalAlign,
|
|
138
|
+
verticalAlign = _getAnchorAlignment.verticalAlign;
|
|
139
|
+
|
|
140
|
+
align(positionedGlyphs, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight, lines.length); // 计算包围盒
|
|
122
141
|
|
|
123
|
-
// 计算包围盒
|
|
124
142
|
var height = y - yOffset;
|
|
125
143
|
shaping.top += -verticalAlign * height;
|
|
126
144
|
shaping.bottom = shaping.top - height;
|
|
127
145
|
shaping.left += -horizontalAlign * maxLineLength;
|
|
128
146
|
shaping.right = shaping.left + maxLineLength;
|
|
129
147
|
}
|
|
148
|
+
|
|
130
149
|
function shapeIconFont(shaping, glyphMap, iconfonts, lineHeight, textAnchor, textJustify, spacing) {
|
|
131
150
|
// buffer 为 4
|
|
132
151
|
var yOffset = -8;
|
|
@@ -139,10 +158,12 @@ function shapeIconFont(shaping, glyphMap, iconfonts, lineHeight, textAnchor, tex
|
|
|
139
158
|
iconfonts.forEach(function (iconfont) {
|
|
140
159
|
var glyph = glyphMap[iconfont];
|
|
141
160
|
var baselineOffset = 0;
|
|
161
|
+
|
|
142
162
|
if (glyph) {
|
|
143
163
|
positionedGlyphs.push({
|
|
144
164
|
glyph: iconfont,
|
|
145
165
|
// x,
|
|
166
|
+
|
|
146
167
|
/**
|
|
147
168
|
* iconfont
|
|
148
169
|
* 在计算大小的时候计算的是 unicode 字符 如 
|
|
@@ -156,30 +177,31 @@ function shapeIconFont(shaping, glyphMap, iconfonts, lineHeight, textAnchor, tex
|
|
|
156
177
|
metrics: glyph
|
|
157
178
|
});
|
|
158
179
|
x += glyph.advance + spacing;
|
|
159
|
-
}
|
|
180
|
+
} // 左右对齐
|
|
181
|
+
|
|
160
182
|
|
|
161
|
-
// 左右对齐
|
|
162
183
|
if (positionedGlyphs.length !== lineStartIndex) {
|
|
163
184
|
var lineLength = x - spacing;
|
|
164
185
|
maxLineLength = Math.max(lineLength, maxLineLength);
|
|
165
186
|
justifyLine(positionedGlyphs, glyphMap, lineStartIndex, positionedGlyphs.length - 1, justify);
|
|
166
187
|
}
|
|
188
|
+
|
|
167
189
|
x = 0;
|
|
168
190
|
y -= lineHeight + 5;
|
|
169
191
|
});
|
|
192
|
+
|
|
170
193
|
var _getAnchorAlignment2 = getAnchorAlignment(textAnchor),
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
194
|
+
horizontalAlign = _getAnchorAlignment2.horizontalAlign,
|
|
195
|
+
verticalAlign = _getAnchorAlignment2.verticalAlign;
|
|
196
|
+
|
|
197
|
+
align(positionedGlyphs, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight, iconfonts.length); // 计算包围盒
|
|
174
198
|
|
|
175
|
-
// 计算包围盒
|
|
176
199
|
var height = y - yOffset;
|
|
177
200
|
shaping.top += -verticalAlign * height;
|
|
178
201
|
shaping.bottom = shaping.top - height;
|
|
179
202
|
shaping.left += -horizontalAlign * maxLineLength;
|
|
180
203
|
shaping.right = shaping.left + maxLineLength;
|
|
181
204
|
}
|
|
182
|
-
|
|
183
205
|
/**
|
|
184
206
|
* 计算文本中每个独立字符相对锚点的位置
|
|
185
207
|
*
|
|
@@ -193,6 +215,8 @@ function shapeIconFont(shaping, glyphMap, iconfonts, lineHeight, textAnchor, tex
|
|
|
193
215
|
* @param {[boolean]} isIconFont 是否是 iconfont
|
|
194
216
|
* @return {boolean|shaping} 每个字符相对于锚点的位置
|
|
195
217
|
*/
|
|
218
|
+
|
|
219
|
+
|
|
196
220
|
export function shapeText(text, glyphs, lineHeight, textAnchor, textJustify, spacing) {
|
|
197
221
|
var translate = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : [0, 0];
|
|
198
222
|
var isIconFont = arguments.length > 7 ? arguments[7] : undefined;
|
|
@@ -209,25 +233,28 @@ export function shapeText(text, glyphs, lineHeight, textAnchor, textJustify, spa
|
|
|
209
233
|
text: text
|
|
210
234
|
};
|
|
211
235
|
isIconFont ? shapeIconFont(shaping, glyphs, lines, lineHeight, textAnchor, textJustify, spacing) : shapeLines(shaping, glyphs, lines, lineHeight, textAnchor, textJustify, spacing);
|
|
236
|
+
|
|
212
237
|
if (!positionedGlyphs.length) {
|
|
213
238
|
return false;
|
|
214
239
|
}
|
|
240
|
+
|
|
215
241
|
return shaping;
|
|
216
242
|
}
|
|
217
243
|
export function getGlyphQuads(shaping) {
|
|
218
244
|
var textOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0];
|
|
219
245
|
var alongLine = arguments.length > 2 ? arguments[2] : undefined;
|
|
220
246
|
var _shaping$positionedGl = shaping.positionedGlyphs,
|
|
221
|
-
|
|
247
|
+
positionedGlyphs = _shaping$positionedGl === void 0 ? [] : _shaping$positionedGl;
|
|
222
248
|
var quads = [];
|
|
249
|
+
|
|
223
250
|
var _iterator2 = _createForOfIteratorHelper(positionedGlyphs),
|
|
224
|
-
|
|
251
|
+
_step2;
|
|
252
|
+
|
|
225
253
|
try {
|
|
226
254
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
227
255
|
var positionedGlyph = _step2.value;
|
|
228
|
-
var rect = positionedGlyph.metrics;
|
|
256
|
+
var rect = positionedGlyph.metrics; // The rects have an addditional buffer that is not included in their size.
|
|
229
257
|
|
|
230
|
-
// The rects have an addditional buffer that is not included in their size.
|
|
231
258
|
var rectBuffer = 4;
|
|
232
259
|
var halfAdvance = rect.advance * positionedGlyph.scale / 2;
|
|
233
260
|
var glyphOffset = alongLine ? [positionedGlyph.x + halfAdvance, positionedGlyph.y] : [0, 0];
|
|
@@ -251,9 +278,7 @@ export function getGlyphQuads(shaping) {
|
|
|
251
278
|
var br = {
|
|
252
279
|
x: x2,
|
|
253
280
|
y: y2
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
// TODO:处理字符旋转的情况
|
|
281
|
+
}; // TODO:处理字符旋转的情况
|
|
257
282
|
|
|
258
283
|
quads.push({
|
|
259
284
|
tl: tl,
|
|
@@ -269,5 +294,6 @@ export function getGlyphQuads(shaping) {
|
|
|
269
294
|
} finally {
|
|
270
295
|
_iterator2.f();
|
|
271
296
|
}
|
|
297
|
+
|
|
272
298
|
return quads;
|
|
273
299
|
}
|
package/es/wind/index.js
CHANGED
|
@@ -7,50 +7,68 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConst
|
|
|
7
7
|
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
8
8
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
9
9
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
10
|
+
|
|
10
11
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
12
|
+
|
|
11
13
|
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; } }
|
|
14
|
+
|
|
12
15
|
import BaseLayer from "../core/BaseLayer";
|
|
13
16
|
import WindModels from "./models";
|
|
17
|
+
|
|
14
18
|
var WindLayer = /*#__PURE__*/function (_BaseLayer) {
|
|
15
19
|
_inherits(WindLayer, _BaseLayer);
|
|
20
|
+
|
|
16
21
|
var _super = _createSuper(WindLayer);
|
|
22
|
+
|
|
17
23
|
function WindLayer() {
|
|
18
24
|
var _this;
|
|
25
|
+
|
|
19
26
|
_classCallCheck(this, WindLayer);
|
|
27
|
+
|
|
20
28
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
21
29
|
args[_key] = arguments[_key];
|
|
22
30
|
}
|
|
31
|
+
|
|
23
32
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
33
|
+
|
|
24
34
|
_defineProperty(_assertThisInitialized(_this), "type", 'WindLayer');
|
|
35
|
+
|
|
25
36
|
return _this;
|
|
26
37
|
}
|
|
38
|
+
|
|
27
39
|
_createClass(WindLayer, [{
|
|
28
40
|
key: "buildModels",
|
|
29
41
|
value: function () {
|
|
30
42
|
var _buildModels = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
31
43
|
var modelType;
|
|
32
44
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
33
|
-
while (1)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
while (1) {
|
|
46
|
+
switch (_context.prev = _context.next) {
|
|
47
|
+
case 0:
|
|
48
|
+
modelType = this.getModelType();
|
|
49
|
+
this.layerModel = new WindModels[modelType](this);
|
|
50
|
+
_context.next = 4;
|
|
51
|
+
return this.initLayerModels();
|
|
52
|
+
|
|
53
|
+
case 4:
|
|
54
|
+
case "end":
|
|
55
|
+
return _context.stop();
|
|
56
|
+
}
|
|
42
57
|
}
|
|
43
58
|
}, _callee, this);
|
|
44
59
|
}));
|
|
60
|
+
|
|
45
61
|
function buildModels() {
|
|
46
62
|
return _buildModels.apply(this, arguments);
|
|
47
63
|
}
|
|
64
|
+
|
|
48
65
|
return buildModels;
|
|
49
66
|
}()
|
|
50
67
|
}, {
|
|
51
68
|
key: "renderModels",
|
|
52
69
|
value: function renderModels() {
|
|
53
70
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
|
+
|
|
54
72
|
if (this.layerModel) {
|
|
55
73
|
this.layerModel.render(options); // 独立的渲染流程
|
|
56
74
|
}
|
|
@@ -72,6 +90,8 @@ var WindLayer = /*#__PURE__*/function (_BaseLayer) {
|
|
|
72
90
|
return 'wind';
|
|
73
91
|
}
|
|
74
92
|
}]);
|
|
93
|
+
|
|
75
94
|
return WindLayer;
|
|
76
95
|
}(BaseLayer);
|
|
96
|
+
|
|
77
97
|
export { WindLayer as default };
|
package/es/wind/models/utils.js
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
export function createProgram(gl, vshader, fshader) {
|
|
2
2
|
// Create shader object
|
|
3
3
|
var vertexShader = loadShader(gl, gl.VERTEX_SHADER, vshader); // 创建顶点着色器对象
|
|
4
|
+
|
|
4
5
|
var fragmentShader = loadShader(gl, gl.FRAGMENT_SHADER, fshader); // 创建片元着色器对象
|
|
6
|
+
|
|
5
7
|
if (!vertexShader || !fragmentShader) {
|
|
6
8
|
return null;
|
|
7
|
-
}
|
|
9
|
+
} // Create a program object
|
|
10
|
+
|
|
8
11
|
|
|
9
|
-
// Create a program object
|
|
10
12
|
var program = gl.createProgram(); // 创建程序对象
|
|
13
|
+
|
|
11
14
|
if (!program) {
|
|
12
15
|
return null;
|
|
13
|
-
}
|
|
16
|
+
} // Attach the shader objects
|
|
17
|
+
|
|
14
18
|
|
|
15
|
-
// Attach the shader objects
|
|
16
19
|
gl.attachShader(program, vertexShader); // 绑定着色器对象
|
|
17
|
-
gl.attachShader(program, fragmentShader);
|
|
18
20
|
|
|
19
|
-
// Link the program object
|
|
20
|
-
gl.linkProgram(program); // 链接着色器对象
|
|
21
|
+
gl.attachShader(program, fragmentShader); // Link the program object
|
|
21
22
|
|
|
23
|
+
gl.linkProgram(program); // 链接着色器对象
|
|
22
24
|
// Check the result of linking
|
|
25
|
+
|
|
23
26
|
var linked = gl.getProgramParameter(program, gl.LINK_STATUS); // 判断着色器对象是否链接成功
|
|
27
|
+
|
|
24
28
|
if (!linked) {
|
|
25
29
|
var error = gl.getProgramInfoLog(program);
|
|
26
30
|
console.warn('Failed to link program: ' + error);
|
|
@@ -29,48 +33,55 @@ export function createProgram(gl, vshader, fshader) {
|
|
|
29
33
|
gl.deleteShader(vertexShader);
|
|
30
34
|
return null;
|
|
31
35
|
}
|
|
36
|
+
|
|
32
37
|
var numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
|
|
38
|
+
|
|
33
39
|
for (var i = 0; i < numAttributes; i++) {
|
|
34
|
-
var attribute = gl.getActiveAttrib(program, i);
|
|
35
|
-
|
|
40
|
+
var attribute = gl.getActiveAttrib(program, i); // @ts-ignore
|
|
41
|
+
|
|
36
42
|
program[attribute.name] = gl.getAttribLocation(program, attribute.name);
|
|
37
43
|
}
|
|
44
|
+
|
|
38
45
|
var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
|
46
|
+
|
|
39
47
|
for (var i$1 = 0; i$1 < numUniforms; i$1++) {
|
|
40
|
-
var uniform = gl.getActiveUniform(program, i$1);
|
|
41
|
-
|
|
48
|
+
var uniform = gl.getActiveUniform(program, i$1); // @ts-ignore
|
|
49
|
+
|
|
42
50
|
program[uniform.name] = gl.getUniformLocation(program, uniform.name);
|
|
43
|
-
}
|
|
51
|
+
} // @ts-ignore
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
program.vertexShader = vertexShader; // @ts-ignore
|
|
44
55
|
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
program.vertexShader = vertexShader;
|
|
47
|
-
// @ts-ignore
|
|
48
56
|
program.fragmentShader = fragmentShader;
|
|
49
57
|
return program;
|
|
50
58
|
}
|
|
51
59
|
export function loadShader(gl, type, source) {
|
|
52
60
|
// Create shader object
|
|
53
61
|
var shader = gl.createShader(type); // 生成着色器对象
|
|
62
|
+
|
|
54
63
|
if (shader == null) {
|
|
55
64
|
console.warn('unable to create shader');
|
|
56
65
|
return null;
|
|
57
|
-
}
|
|
66
|
+
} // Set the shader program
|
|
58
67
|
|
|
59
|
-
// Set the shader program
|
|
60
|
-
gl.shaderSource(shader, source); // 载入着色器
|
|
61
68
|
|
|
69
|
+
gl.shaderSource(shader, source); // 载入着色器
|
|
62
70
|
// Compile the shader
|
|
63
|
-
gl.compileShader(shader); // 编译着色器代码
|
|
64
71
|
|
|
72
|
+
gl.compileShader(shader); // 编译着色器代码
|
|
65
73
|
// Check the result of compilation
|
|
74
|
+
|
|
66
75
|
var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS); // 判断着色器对象是否生成成功
|
|
67
76
|
// gl.SHADER_TYPE、gl.DELETE_STATUS、gl.COMPILE_STATUS
|
|
77
|
+
|
|
68
78
|
if (!compiled) {
|
|
69
79
|
var error = gl.getShaderInfoLog(shader);
|
|
70
80
|
console.warn('Failed to compile shader: ' + error);
|
|
71
81
|
gl.deleteShader(shader);
|
|
72
82
|
return null;
|
|
73
83
|
}
|
|
84
|
+
|
|
74
85
|
return shader;
|
|
75
86
|
}
|
|
76
87
|
export function createTexture(gl, filter, data, width, height) {
|
|
@@ -107,10 +118,13 @@ export function createBuffer(gl, data) {
|
|
|
107
118
|
}
|
|
108
119
|
export function bindAttriBuffer(gl, attrName, vertices, count, program) {
|
|
109
120
|
var buffer = gl.createBuffer();
|
|
121
|
+
|
|
110
122
|
if (!buffer) {
|
|
111
123
|
console.warn('failed create vertex buffer');
|
|
112
124
|
}
|
|
125
|
+
|
|
113
126
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 将缓冲区对象绑定到目标
|
|
127
|
+
|
|
114
128
|
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); // 向缓冲区对象中写入数据
|
|
115
129
|
|
|
116
130
|
var attr = gl.getAttribLocation(program, attrName);
|
|
@@ -125,21 +139,25 @@ export function bindAttriBuffer(gl, attrName, vertices, count, program) {
|
|
|
125
139
|
}
|
|
126
140
|
export function bindAttriIndicesBuffer(gl, indices) {
|
|
127
141
|
var buffer = gl.createBuffer();
|
|
142
|
+
|
|
128
143
|
if (!buffer) {
|
|
129
144
|
console.warn('failed create vertex buffer');
|
|
130
145
|
} else {
|
|
131
146
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer);
|
|
132
147
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
|
|
133
148
|
}
|
|
149
|
+
|
|
134
150
|
return buffer;
|
|
135
151
|
}
|
|
136
152
|
export function bindUnifrom(gl, unifromName, data, program, vec) {
|
|
137
153
|
var uniform = gl.getUniformLocation(program, unifromName);
|
|
154
|
+
|
|
138
155
|
if (uniform === null || uniform < 0) {
|
|
139
156
|
console.warn('无法获取 uniform 变量的存储位置');
|
|
140
157
|
} else {
|
|
141
158
|
setUnifrom(gl, uniform, data, vec);
|
|
142
159
|
}
|
|
160
|
+
|
|
143
161
|
return uniform;
|
|
144
162
|
}
|
|
145
163
|
export function setUnifrom(gl, location, data, vec) {
|
|
@@ -147,20 +165,27 @@ export function setUnifrom(gl, location, data, vec) {
|
|
|
147
165
|
case 'float':
|
|
148
166
|
gl.uniform1f(location, data);
|
|
149
167
|
break;
|
|
168
|
+
|
|
150
169
|
case 'vec2':
|
|
151
170
|
gl.uniform2fv(location, data);
|
|
152
171
|
break;
|
|
172
|
+
|
|
153
173
|
case 'vec3':
|
|
154
174
|
gl.uniform3fv(location, data);
|
|
155
175
|
break;
|
|
176
|
+
|
|
156
177
|
case 'vec4':
|
|
157
178
|
gl.uniform4fv(location, data);
|
|
158
179
|
break;
|
|
180
|
+
|
|
159
181
|
case 'bool':
|
|
160
182
|
gl.uniform1i(location, data); // 1 - true 0 - false
|
|
183
|
+
|
|
161
184
|
break;
|
|
185
|
+
|
|
162
186
|
case 'sampler2d':
|
|
163
187
|
break;
|
|
188
|
+
|
|
164
189
|
case 'mat4':
|
|
165
190
|
gl.uniformMatrix4fv(location, false, data);
|
|
166
191
|
break;
|
|
@@ -168,7 +193,7 @@ export function setUnifrom(gl, location, data, vec) {
|
|
|
168
193
|
}
|
|
169
194
|
export function initFramebuffer(gl) {
|
|
170
195
|
var drawingBufferWidth = gl.drawingBufferWidth,
|
|
171
|
-
|
|
196
|
+
drawingBufferHeight = gl.drawingBufferHeight;
|
|
172
197
|
var OFFER_SCREEN_WIDTH = drawingBufferWidth;
|
|
173
198
|
var OFFER_SCREEN_HEIGHT = drawingBufferHeight;
|
|
174
199
|
var FRAMEBUFFER = gl.createFramebuffer();
|
|
@@ -177,12 +202,12 @@ export function initFramebuffer(gl) {
|
|
|
177
202
|
gl.bindRenderbuffer(gl.RENDERBUFFER, depthbuffer);
|
|
178
203
|
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, OFFER_SCREEN_WIDTH, OFFER_SCREEN_HEIGHT);
|
|
179
204
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthbuffer);
|
|
180
|
-
var texture = gl.createTexture();
|
|
181
|
-
|
|
182
|
-
FRAMEBUFFER.texture = texture;
|
|
183
|
-
|
|
184
|
-
FRAMEBUFFER.width = OFFER_SCREEN_WIDTH;
|
|
185
|
-
|
|
205
|
+
var texture = gl.createTexture(); // @ts-ignore
|
|
206
|
+
|
|
207
|
+
FRAMEBUFFER.texture = texture; // @ts-ignore
|
|
208
|
+
|
|
209
|
+
FRAMEBUFFER.width = OFFER_SCREEN_WIDTH; // @ts-ignore
|
|
210
|
+
|
|
186
211
|
FRAMEBUFFER.height = OFFER_SCREEN_HEIGHT;
|
|
187
212
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
188
213
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|