@antv/l7-layers 2.9.23 → 2.9.25

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.
Files changed (166) hide show
  1. package/es/Geometry/models/plane.d.ts +1 -0
  2. package/es/citybuliding/building.js +1 -1
  3. package/es/core/BaseLayer.js +10 -3
  4. package/es/core/interface.d.ts +26 -48
  5. package/es/core/interface.js +3 -0
  6. package/es/core/schema.d.ts +3 -3
  7. package/es/core/triangulation.d.ts +4 -3
  8. package/es/core/triangulation.js +54 -39
  9. package/es/heatmap/models/heatmap.js +1 -1
  10. package/es/image/models/image.js +7 -1
  11. package/es/line/index.js +4 -1
  12. package/es/line/models/arc.js +1 -1
  13. package/es/line/models/simpleLine.js +1 -1
  14. package/es/line/shaders/line_arc_vert.glsl +5 -3
  15. package/es/line/shaders/simple/simpleline_vert.glsl +1 -0
  16. package/es/plugins/FeatureScalePlugin.js +0 -1
  17. package/es/point/index.js +3 -1
  18. package/es/point/models/fill.js +5 -2
  19. package/es/point/models/fillmage.js +9 -3
  20. package/es/point/models/image.js +8 -2
  21. package/es/point/models/radar.js +2 -3
  22. package/es/point/models/tile.js +1 -1
  23. package/es/point/shaders/fill_vert.glsl +13 -6
  24. package/es/point/shaders/image/fillImage_vert.glsl +13 -5
  25. package/es/point/shaders/image_vert.glsl +17 -8
  26. package/es/polygon/index.js +4 -1
  27. package/es/raster/index.js +3 -1
  28. package/es/tile/manager/tileLayerManager.d.ts +3 -2
  29. package/es/tile/manager/tileLayerManager.js +5 -2
  30. package/es/tile/models/tileModel.js +4 -3
  31. package/es/tile/tileFactory/base.d.ts +1 -1
  32. package/es/tile/tileFactory/base.js +32 -5
  33. package/es/tile/tileFactory/vectorLayer.d.ts +3 -1
  34. package/es/tile/tileFactory/vectorLayer.js +22 -1
  35. package/es/tile/tileLayer/baseTileLayer.d.ts +1 -1
  36. package/es/tile/tileLayer/baseTileLayer.js +3 -2
  37. package/es/tile/utils.d.ts +2 -0
  38. package/es/tile/utils.js +5 -1
  39. package/lib/Geometry/index.js +114 -77
  40. package/lib/Geometry/models/billboard.js +232 -181
  41. package/lib/Geometry/models/index.js +18 -34
  42. package/lib/Geometry/models/plane.js +407 -278
  43. package/lib/Geometry/models/sprite.js +291 -189
  44. package/lib/canvas/index.js +101 -66
  45. package/lib/canvas/models/canvas.js +207 -140
  46. package/lib/canvas/models/index.js +12 -30
  47. package/lib/citybuliding/building.js +98 -63
  48. package/lib/citybuliding/models/build.js +192 -146
  49. package/lib/core/BaseLayer.js +1331 -809
  50. package/lib/core/BaseModel.js +457 -279
  51. package/lib/core/interface.js +40 -53
  52. package/lib/core/schema.js +21 -39
  53. package/lib/core/shape/Path.js +67 -79
  54. package/lib/core/shape/extrude.js +132 -91
  55. package/lib/core/triangulation.js +412 -213
  56. package/lib/earth/index.js +100 -62
  57. package/lib/earth/models/atmosphere.js +146 -112
  58. package/lib/earth/models/base.js +210 -150
  59. package/lib/earth/models/bloomsphere.js +146 -112
  60. package/lib/earth/utils.js +111 -91
  61. package/lib/heatmap/index.js +149 -92
  62. package/lib/heatmap/models/grid.js +118 -91
  63. package/lib/heatmap/models/grid3d.js +155 -123
  64. package/lib/heatmap/models/heatmap.js +475 -338
  65. package/lib/heatmap/models/hexagon.js +121 -92
  66. package/lib/heatmap/models/index.js +22 -37
  67. package/lib/heatmap/triangulation.js +31 -47
  68. package/lib/image/index.js +111 -74
  69. package/lib/image/models/dataImage.js +232 -174
  70. package/lib/image/models/image.js +175 -123
  71. package/lib/image/models/index.js +15 -32
  72. package/lib/index.js +263 -97
  73. package/lib/line/index.js +131 -83
  74. package/lib/line/models/arc.js +352 -237
  75. package/lib/line/models/arc_3d.js +334 -228
  76. package/lib/line/models/earthArc_3d.js +336 -228
  77. package/lib/line/models/great_circle.js +291 -200
  78. package/lib/line/models/half.js +286 -201
  79. package/lib/line/models/index.js +42 -50
  80. package/lib/line/models/line.js +428 -299
  81. package/lib/line/models/linearline.js +277 -203
  82. package/lib/line/models/simpleLine.js +239 -175
  83. package/lib/line/models/tile.js +348 -237
  84. package/lib/line/models/wall.js +327 -235
  85. package/lib/line/shaders/line_arc_vert.glsl +5 -3
  86. package/lib/line/shaders/simple/simpleline_vert.glsl +1 -0
  87. package/lib/mask/index.js +92 -59
  88. package/lib/mask/models/fill.js +134 -82
  89. package/lib/mask/models/index.js +12 -30
  90. package/lib/plugins/DataMappingPlugin.js +342 -224
  91. package/lib/plugins/DataSourcePlugin.js +102 -87
  92. package/lib/plugins/FeatureScalePlugin.js +330 -241
  93. package/lib/plugins/LayerAnimateStylePlugin.js +61 -55
  94. package/lib/plugins/LayerModelPlugin.js +80 -73
  95. package/lib/plugins/LayerStylePlugin.js +48 -51
  96. package/lib/plugins/LightingPlugin.js +80 -68
  97. package/lib/plugins/MultiPassRendererPlugin.js +91 -65
  98. package/lib/plugins/PixelPickingPlugin.js +150 -109
  99. package/lib/plugins/RegisterStyleAttributePlugin.js +110 -110
  100. package/lib/plugins/ShaderUniformPlugin.js +118 -99
  101. package/lib/plugins/UpdateModelPlugin.js +40 -47
  102. package/lib/plugins/UpdateStyleAttributePlugin.js +93 -75
  103. package/lib/point/index.js +226 -148
  104. package/lib/point/models/earthExtrude.js +279 -201
  105. package/lib/point/models/earthFill.js +287 -202
  106. package/lib/point/models/extrude.js +299 -203
  107. package/lib/point/models/fill.js +406 -273
  108. package/lib/point/models/fillmage.js +365 -252
  109. package/lib/point/models/image.js +241 -164
  110. package/lib/point/models/index.js +46 -52
  111. package/lib/point/models/normal.js +183 -134
  112. package/lib/point/models/radar.js +304 -212
  113. package/lib/point/models/simplePoint.js +194 -142
  114. package/lib/point/models/text.js +608 -385
  115. package/lib/point/models/tile.js +314 -223
  116. package/lib/point/shaders/fill_vert.glsl +13 -6
  117. package/lib/point/shaders/image/fillImage_vert.glsl +13 -5
  118. package/lib/point/shaders/image_vert.glsl +17 -8
  119. package/lib/point/shape/extrude.js +56 -52
  120. package/lib/polygon/index.js +154 -100
  121. package/lib/polygon/models/extrude.js +311 -223
  122. package/lib/polygon/models/fill.js +215 -153
  123. package/lib/polygon/models/index.js +46 -52
  124. package/lib/polygon/models/ocean.js +244 -173
  125. package/lib/polygon/models/tile.js +144 -100
  126. package/lib/polygon/models/water.js +222 -153
  127. package/lib/raster/buffers/triangulation.js +27 -40
  128. package/lib/raster/index.js +115 -74
  129. package/lib/raster/models/index.js +16 -33
  130. package/lib/raster/models/raster.js +178 -135
  131. package/lib/raster/raster.js +187 -132
  132. package/lib/tile/interface.js +4 -16
  133. package/lib/tile/manager/tileConfigManager.js +125 -86
  134. package/lib/tile/manager/tileLayerManager.js +314 -227
  135. package/lib/tile/manager/tilePickerManager.js +192 -123
  136. package/lib/tile/models/tileModel.js +71 -51
  137. package/lib/tile/tileFactory/base.js +433 -292
  138. package/lib/tile/tileFactory/index.js +51 -49
  139. package/lib/tile/tileFactory/line.js +65 -50
  140. package/lib/tile/tileFactory/point.js +65 -50
  141. package/lib/tile/tileFactory/polygon.js +65 -50
  142. package/lib/tile/tileFactory/raster.js +66 -54
  143. package/lib/tile/tileFactory/rasterData.js +88 -76
  144. package/lib/tile/tileFactory/rasterDataLayer.js +97 -62
  145. package/lib/tile/tileFactory/vectorLayer.js +169 -95
  146. package/lib/tile/tileLayer/baseTileLayer.js +420 -220
  147. package/lib/tile/tmsTileLayer.js +110 -67
  148. package/lib/tile/utils.js +113 -87
  149. package/lib/utils/blend.js +59 -79
  150. package/lib/utils/collision-index.js +107 -64
  151. package/lib/utils/dataMappingStyle.js +105 -60
  152. package/lib/utils/extrude_polyline.js +600 -398
  153. package/lib/utils/grid-index.js +163 -111
  154. package/lib/utils/layerData.js +130 -99
  155. package/lib/utils/multiPassRender.js +49 -41
  156. package/lib/utils/polylineNormal.js +148 -96
  157. package/lib/utils/simpleLine.js +100 -85
  158. package/lib/utils/symbol-layout.js +219 -116
  159. package/lib/utils/updateShape.js +15 -41
  160. package/lib/wind/index.js +109 -71
  161. package/lib/wind/models/index.js +12 -30
  162. package/lib/wind/models/utils.js +144 -105
  163. package/lib/wind/models/wind.js +333 -224
  164. package/lib/wind/models/windRender.js +329 -218
  165. package/lib/wind/models/windShader.js +23 -181
  166. package/package.json +7 -6
@@ -1,53 +1,61 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/utils/multiPassRender.ts
20
- var multiPassRender_exports = {};
21
- __export(multiPassRender_exports, {
22
- createMultiPassRenderer: () => createMultiPassRenderer,
23
- normalizePasses: () => normalizePasses
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
24
7
  });
25
- module.exports = __toCommonJS(multiPassRender_exports);
8
+ exports.createMultiPassRenderer = createMultiPassRenderer;
9
+ exports.normalizePasses = normalizePasses;
10
+
11
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
+
13
+ /**
14
+ * 'blurH' -> ['blurH', {}]
15
+ */
26
16
  function normalizePasses(passes) {
27
- return passes.map((pass) => {
28
- if (typeof pass === "string") {
17
+ return passes.map(function (pass) {
18
+ if (typeof pass === 'string') {
29
19
  pass = [pass, {}];
30
20
  }
21
+
31
22
  return pass;
32
23
  });
33
24
  }
25
+ /**
26
+ * 默认添加 ClearPass、RenderPass
27
+ * 以及 PostProcessing 中的最后一个 CopyPass
28
+ */
29
+
30
+
34
31
  function createMultiPassRenderer(layer, passes, postProcessingPassFactory, normalPassFactory) {
35
- const multiPassRenderer = layer.multiPassRenderer;
36
- const { enablePicking, enableTAA } = layer.getLayerConfig();
32
+ var multiPassRenderer = layer.multiPassRenderer;
33
+
34
+ var _layer$getLayerConfig = layer.getLayerConfig(),
35
+ enablePicking = _layer$getLayerConfig.enablePicking,
36
+ enableTAA = _layer$getLayerConfig.enableTAA; // picking pass if enabled
37
+ // if (enablePicking) {
38
+ // multiPassRenderer.add(normalPassFactory('pixelPicking'));
39
+ // }
40
+ // use TAA pass if enabled instead of render pass
41
+
42
+
37
43
  if (enableTAA) {
38
- multiPassRenderer.add(normalPassFactory("taa"));
44
+ multiPassRenderer.add(normalPassFactory('taa'));
39
45
  } else {
40
- multiPassRenderer.add(normalPassFactory("render"));
41
- }
42
- normalizePasses(passes).forEach((pass) => {
43
- const [passName, initializationOptions] = pass;
46
+ // render all layers in this pass
47
+ multiPassRenderer.add(normalPassFactory('render'));
48
+ } // post processing
49
+
50
+
51
+ normalizePasses(passes).forEach(function (pass) {
52
+ var _pass = (0, _slicedToArray2.default)(pass, 2),
53
+ passName = _pass[0],
54
+ initializationOptions = _pass[1];
55
+
44
56
  multiPassRenderer.add(postProcessingPassFactory(passName), initializationOptions);
45
- });
46
- multiPassRenderer.add(postProcessingPassFactory("copy"));
57
+ }); // 末尾为固定的 CopyPass
58
+
59
+ multiPassRenderer.add(postProcessingPassFactory('copy'));
47
60
  return multiPassRenderer;
48
- }
49
- // Annotate the CommonJS export names for ESM import in node:
50
- 0 && (module.exports = {
51
- createMultiPassRenderer,
52
- normalizePasses
53
- });
61
+ }
@@ -1,178 +1,230 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/utils/polylineNormal.ts
20
- var polylineNormal_exports = {};
21
- __export(polylineNormal_exports, {
22
- computeMiter: () => computeMiter,
23
- computeNormal: () => computeNormal,
24
- default: () => polylineNormal_default,
25
- direction: () => direction
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
26
7
  });
27
- module.exports = __toCommonJS(polylineNormal_exports);
28
- var import_l7_utils = require("@antv/l7-utils");
29
- var import_gl_matrix = require("gl-matrix");
8
+ exports.computeMiter = computeMiter;
9
+ exports.computeNormal = computeNormal;
10
+ exports.default = _default;
11
+ exports.direction = direction;
12
+
13
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
14
+
15
+ var _l7Utils = require("@antv/l7-utils");
16
+
17
+ var _glMatrix = require("gl-matrix");
18
+
30
19
  function computeMiter(tangent, miter, lineA, lineB, halfThick) {
31
- import_gl_matrix.vec2.add(tangent, lineA, lineB);
32
- import_gl_matrix.vec2.normalize(tangent, tangent);
33
- miter = import_gl_matrix.vec2.fromValues(-tangent[1], tangent[0]);
34
- const tmp = import_gl_matrix.vec2.fromValues(-lineA[1], lineA[0]);
35
- return halfThick / import_gl_matrix.vec2.dot(miter, tmp);
20
+ _glMatrix.vec2.add(tangent, lineA, lineB);
21
+
22
+ _glMatrix.vec2.normalize(tangent, tangent);
23
+
24
+ miter = _glMatrix.vec2.fromValues(-tangent[1], tangent[0]);
25
+
26
+ var tmp = _glMatrix.vec2.fromValues(-lineA[1], lineA[0]);
27
+
28
+ return halfThick / _glMatrix.vec2.dot(miter, tmp);
36
29
  }
30
+
37
31
  function computeNormal(out, dir) {
38
- return import_gl_matrix.vec2.set(out, -dir[1], dir[0]);
32
+ return _glMatrix.vec2.set(out, -dir[1], dir[0]);
39
33
  }
34
+
40
35
  function direction(out, a, b) {
41
- import_gl_matrix.vec2.sub(out, a, b);
42
- import_gl_matrix.vec2.normalize(out, out);
36
+ // const a1 = aProjectFlat([a[0], a[1]]) as [number, number];
37
+ // const b1 = aProjectFlat([b[0], b[1]]) as [number, number];
38
+ _glMatrix.vec2.sub(out, a, b);
39
+
40
+ _glMatrix.vec2.normalize(out, out);
41
+
43
42
  return out;
44
43
  }
44
+
45
45
  function extrusions(positions, out, miters, point, normal, scale) {
46
46
  addNext(out, miters, normal, -scale);
47
47
  addNext(out, miters, normal, scale);
48
48
  positions.push(point[0], point[1], 0);
49
49
  positions.push(point[0], point[1], 0);
50
50
  }
51
+
51
52
  function addNext(out, miters, normal, length) {
52
53
  out.push(normal[0], normal[1], 0);
53
54
  miters.push(length);
54
55
  }
56
+
55
57
  function lineSegmentDistance(b1, a1) {
56
- const dx = a1[0] - b1[0];
57
- const dy = a1[1] - b1[1];
58
+ var dx = a1[0] - b1[0];
59
+ var dy = a1[1] - b1[1];
58
60
  return Math.sqrt(dx * dx + dy * dy);
59
61
  }
62
+
60
63
  function isPointEqual(a, b) {
61
64
  return a[0] === b[0] && a[1] === b[1];
62
65
  }
63
- function polylineNormal_default(points, closed, indexOffset, isDash = true) {
64
- const lineA = import_gl_matrix.vec2.fromValues(0, 0);
65
- const lineB = import_gl_matrix.vec2.fromValues(0, 0);
66
- const tangent = import_gl_matrix.vec2.fromValues(0, 0);
67
- const miter = import_gl_matrix.vec2.create();
68
- let started = false;
69
- let lineNormal = null;
70
- const tmp = import_gl_matrix.vec2.create();
71
- let count = indexOffset || 0;
72
- const miterLimit = 4;
73
- const out = [];
74
- const attrPos = [];
75
- const attrIndex = [];
76
- const miters = [];
77
- const attrDistance = [0, 0];
66
+
67
+ function _default(points, closed, indexOffset) {
68
+ var isDash = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
69
+
70
+ var lineA = _glMatrix.vec2.fromValues(0, 0);
71
+
72
+ var lineB = _glMatrix.vec2.fromValues(0, 0);
73
+
74
+ var tangent = _glMatrix.vec2.fromValues(0, 0);
75
+
76
+ var miter = _glMatrix.vec2.create();
77
+
78
+ var started = false;
79
+ var lineNormal = null;
80
+
81
+ var tmp = _glMatrix.vec2.create();
82
+
83
+ var count = indexOffset || 0;
84
+ var miterLimit = 4;
85
+ var out = [];
86
+ var attrPos = [];
87
+ var attrIndex = [];
88
+ var miters = [];
89
+ var attrDistance = [0, 0];
90
+
78
91
  if (closed) {
79
92
  points = points.slice();
80
93
  points.push(points[0]);
81
94
  }
82
- const total = points.length;
83
- for (let i = 1; i < total; i++) {
84
- const index = count;
85
- const last = import_gl_matrix.vec2.fromValues(points[i - 1][0], points[i - 1][1]);
86
- const cur = import_gl_matrix.vec2.fromValues(points[i][0], points[i][1]);
87
- let next = i < points.length - 1 ? import_gl_matrix.vec2.fromValues(points[i + 1][0], points[i + 1][1]) : null;
95
+
96
+ var total = points.length;
97
+
98
+ for (var i = 1; i < total; i++) {
99
+ var index = count;
100
+
101
+ var last = _glMatrix.vec2.fromValues(points[i - 1][0], points[i - 1][1]);
102
+
103
+ var cur = _glMatrix.vec2.fromValues(points[i][0], points[i][1]);
104
+
105
+ var next = i < points.length - 1 ? _glMatrix.vec2.fromValues(points[i + 1][0], points[i + 1][1]) : null; // 如果当前点和前一点相同,跳过
106
+
88
107
  if (isPointEqual(last, cur)) {
89
108
  continue;
90
109
  }
110
+
91
111
  if (next) {
92
- let nextIndex = i + 1;
112
+ var nextIndex = i + 1; // 找到不相同的下一点
113
+
93
114
  while (next && isPointEqual(cur, next)) {
94
- next = nextIndex < points.length - 1 ? import_gl_matrix.vec2.fromValues(points[++nextIndex][0], points[nextIndex][1]) : null;
115
+ next = nextIndex < points.length - 1 ? _glMatrix.vec2.fromValues(points[++nextIndex][0], points[nextIndex][1]) : null;
95
116
  }
96
117
  }
97
- let d = 0;
98
- const flatCur = (0, import_l7_utils.aProjectFlat)([cur[0], cur[1]]);
99
- const flatLast = (0, import_l7_utils.aProjectFlat)([last[0], last[1]]);
118
+
119
+ var d = 0;
120
+ var flatCur = (0, _l7Utils.aProjectFlat)([cur[0], cur[1]]);
121
+ var flatLast = (0, _l7Utils.aProjectFlat)([last[0], last[1]]);
122
+
100
123
  if (isDash) {
101
- const lineDistance = lineSegmentDistance(flatCur, flatLast);
124
+ var lineDistance = lineSegmentDistance(flatCur, flatLast);
102
125
  d = lineDistance + attrDistance[attrDistance.length - 1];
103
126
  }
127
+
104
128
  direction(lineA, flatCur, flatLast);
129
+
105
130
  if (!lineNormal) {
106
- lineNormal = import_gl_matrix.vec2.create();
131
+ lineNormal = _glMatrix.vec2.create();
107
132
  computeNormal(lineNormal, lineA);
108
133
  }
134
+
109
135
  if (!started) {
110
136
  started = true;
111
137
  extrusions(attrPos, out, miters, last, lineNormal, 1);
112
138
  }
113
- attrIndex.push(index + 0, index + 2, index + 1);
139
+
140
+ attrIndex.push(index + 0, index + 2, index + 1); // no miter, simple segment
141
+
114
142
  if (!next) {
143
+ // reset normal
115
144
  computeNormal(lineNormal, lineA);
116
145
  extrusions(attrPos, out, miters, cur, lineNormal, 1);
117
146
  attrDistance.push(d, d);
118
147
  attrIndex.push(index + 1, index + 2, index + 3);
119
148
  count += 2;
120
149
  } else {
121
- const flatNext = (0, import_l7_utils.aProjectFlat)([next[0], next[1]]);
122
- direction(lineB, flatNext, flatCur);
123
- let miterLen = computeMiter(tangent, import_gl_matrix.vec2.fromValues(miter[0], miter[1]), lineA, lineB, 1);
124
- const flip = import_gl_matrix.vec2.dot(tangent, lineNormal) < 0 ? -1 : 1;
125
- const bevel = Math.abs(miterLen) > miterLimit;
126
- if (Math.abs(miterLen) > 1e3) {
150
+ var flatNext = (0, _l7Utils.aProjectFlat)([next[0], next[1]]); // get unit dir of next line
151
+
152
+ direction(lineB, flatNext, flatCur); // stores tangent & miter
153
+
154
+ var miterLen = computeMiter(tangent, _glMatrix.vec2.fromValues(miter[0], miter[1]), lineA, lineB, 1); // get orientation
155
+
156
+ var flip = _glMatrix.vec2.dot(tangent, lineNormal) < 0 ? -1 : 1;
157
+ var bevel = Math.abs(miterLen) > miterLimit; // 处理前后两条线段重合的情况,这种情况不需要使用任何接头(miter/bevel)。
158
+ // 理论上这种情况下 miterLen = Infinity,本应通过 isFinite(miterLen) 判断,
159
+ // 但是 AMap 投影变换后丢失精度,只能通过一个阈值(1000)判断。
160
+
161
+ if (Math.abs(miterLen) > 1000) {
127
162
  extrusions(attrPos, out, miters, cur, lineNormal, 1);
128
163
  attrIndex.push(index + 1, index + 2, index + 3);
129
164
  attrIndex.push(index + 2, index + 4, index + 3);
130
165
  computeNormal(tmp, lineB);
131
- import_gl_matrix.vec2.copy(lineNormal, tmp);
166
+
167
+ _glMatrix.vec2.copy(lineNormal, tmp); // store normal for next round
168
+
169
+
132
170
  extrusions(attrPos, out, miters, cur, lineNormal, 1);
133
- attrDistance.push(d, d, d, d);
171
+ attrDistance.push(d, d, d, d); // the miter is now the normal for our next join
172
+
134
173
  count += 4;
135
174
  continue;
136
175
  }
176
+
137
177
  if (bevel) {
138
- miterLen = miterLimit;
178
+ miterLen = miterLimit; // next two points in our first segment
179
+
139
180
  extrusions(attrPos, out, miters, cur, lineNormal, 1);
140
- attrIndex.push(index + 1, index + 2, index + 3);
141
- attrIndex.push(...flip === 1 ? [index + 2, index + 4, index + 5] : [index + 4, index + 5, index + 3]);
181
+ attrIndex.push(index + 1, index + 2, index + 3); // now add the bevel triangle
182
+
183
+ attrIndex.push.apply(attrIndex, (0, _toConsumableArray2.default)(flip === 1 ? [index + 2, index + 4, index + 5] : [index + 4, index + 5, index + 3]));
142
184
  computeNormal(tmp, lineB);
143
- import_gl_matrix.vec2.copy(lineNormal, tmp);
185
+
186
+ _glMatrix.vec2.copy(lineNormal, tmp); // store normal for next round
187
+
188
+
144
189
  extrusions(attrPos, out, miters, cur, lineNormal, 1);
145
- attrDistance.push(d, d, d, d);
190
+ attrDistance.push(d, d, d, d); // the miter is now the normal for our next join
191
+
146
192
  count += 4;
147
193
  } else {
194
+ // next two points in our first segment
148
195
  extrusions(attrPos, out, miters, cur, lineNormal, 1);
149
- attrIndex.push(index + 1, index + 2, index + 3);
196
+ attrIndex.push(index + 1, index + 2, index + 3); // now add the miter triangles
197
+
150
198
  addNext(out, miters, lineNormal, miterLen * -flip);
151
199
  attrPos.push(cur[0], cur[1], 0);
152
200
  attrIndex.push(index + 2, index + 4, index + 3);
153
201
  attrIndex.push(index + 4, index + 5, index + 6);
154
202
  computeNormal(tmp, lineB);
155
- import_gl_matrix.vec2.copy(lineNormal, tmp);
203
+
204
+ _glMatrix.vec2.copy(lineNormal, tmp); // store normal for next round
205
+
206
+
156
207
  extrusions(attrPos, out, miters, cur, lineNormal, 1);
157
- attrDistance.push(d, d, d, d, d);
208
+ attrDistance.push(d, d, d, d, d); // the miter is now the normal for our next join
209
+
158
210
  count += 5;
159
211
  }
160
212
  }
161
213
  }
162
- const pickData = [];
163
- for (let i = 0; i < miters.length; i++) {
164
- const totalDistance = attrDistance[attrDistance.length - 1];
165
- pickData.push(attrPos[i * 3], attrPos[i * 3 + 1], attrPos[i * 3 + 2], attrDistance[i], miters[i], totalDistance);
214
+
215
+ var pickData = [];
216
+
217
+ for (var _i = 0; _i < miters.length; _i++) {
218
+ var totalDistance = attrDistance[attrDistance.length - 1];
219
+ pickData.push(attrPos[_i * 3], attrPos[_i * 3 + 1], attrPos[_i * 3 + 2], attrDistance[_i], // dash
220
+ miters[_i], totalDistance // dash
221
+ );
166
222
  }
223
+
167
224
  return {
168
225
  normals: out,
169
- attrIndex,
170
- attrPos: pickData
226
+ attrIndex: attrIndex,
227
+ attrPos: pickData // [x,y,z, distance, miter ,t0tal ]
228
+
171
229
  };
172
- }
173
- // Annotate the CommonJS export names for ESM import in node:
174
- 0 && (module.exports = {
175
- computeMiter,
176
- computeNormal,
177
- direction
178
- });
230
+ } // [x,y,z, distance, miter ]
@@ -1,41 +1,39 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/utils/simpleLine.ts
20
- var simpleLine_exports = {};
21
- __export(simpleLine_exports, {
22
- default: () => ExtrudePolyline,
23
- direction: () => direction
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
24
7
  });
25
- module.exports = __toCommonJS(simpleLine_exports);
26
- var import_l7_utils = require("@antv/l7-utils");
27
- var import_gl_matrix = require("gl-matrix");
28
- var lineA = import_gl_matrix.vec2.create();
8
+ exports.default = void 0;
9
+ exports.direction = direction;
10
+
11
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
+
13
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
14
+
15
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+
17
+ var _l7Utils = require("@antv/l7-utils");
18
+
19
+ var _glMatrix = require("gl-matrix");
20
+
21
+ var lineA = _glMatrix.vec2.create();
22
+
29
23
  function direction(out, a, b) {
30
- import_gl_matrix.vec2.sub(out, a, b);
31
- import_gl_matrix.vec2.normalize(out, out);
24
+ _glMatrix.vec2.sub(out, a, b);
25
+
26
+ _glMatrix.vec2.normalize(out, out);
27
+
32
28
  return out;
33
29
  }
34
- var ExtrudePolyline = class {
35
- constructor() {
36
- this.started = false;
37
- this.totalDistance = 0;
38
- this.currentIndex = 0;
30
+
31
+ var ExtrudePolyline = /*#__PURE__*/function () {
32
+ function ExtrudePolyline() {
33
+ (0, _classCallCheck2.default)(this, ExtrudePolyline);
34
+ (0, _defineProperty2.default)(this, "started", false);
35
+ (0, _defineProperty2.default)(this, "totalDistance", 0);
36
+ (0, _defineProperty2.default)(this, "currentIndex", 0);
39
37
  this.complex = {
40
38
  positions: [],
41
39
  indices: [],
@@ -43,59 +41,76 @@ var ExtrudePolyline = class {
43
41
  indexes: []
44
42
  };
45
43
  }
46
- simpleExtrude(points) {
47
- const complex = this.complex;
48
- if (points.length <= 1) {
44
+
45
+ (0, _createClass2.default)(ExtrudePolyline, [{
46
+ key: "simpleExtrude",
47
+ value: function simpleExtrude(points) {
48
+ var complex = this.complex;
49
+
50
+ if (points.length <= 1) {
51
+ return complex;
52
+ }
53
+
54
+ this.started = false;
55
+ this.totalDistance = 0;
56
+ var total = points.length;
57
+ var count = complex.startIndex;
58
+
59
+ for (var i = 1; i < total; i++) {
60
+ var last = points[i - 1];
61
+ var cur = points[i];
62
+ var amt = this.simpleSegment(complex, count, last, cur);
63
+ count += amt;
64
+ }
65
+
66
+ for (var _i = 0; _i < complex.positions.length / 6; _i++) {
67
+ complex.positions[_i * 6 + 5] = this.totalDistance;
68
+ }
69
+
49
70
  return complex;
50
71
  }
51
- this.started = false;
52
- this.totalDistance = 0;
53
- const total = points.length;
54
- let count = complex.startIndex;
55
- for (let i = 1; i < total; i++) {
56
- const last = points[i - 1];
57
- const cur = points[i];
58
- const amt = this.simpleSegment(complex, count, last, cur);
59
- count += amt;
72
+ }, {
73
+ key: "simpleSegment",
74
+ value: function simpleSegment(complex, index, last, cur) {
75
+ var count = 0;
76
+ var indices = complex.indices;
77
+ var positions = complex.positions;
78
+ var flatCur = (0, _l7Utils.aProjectFlat)([cur[0], cur[1]]);
79
+ var flatLast = (0, _l7Utils.aProjectFlat)([last[0], last[1]]);
80
+ direction(lineA, flatCur, flatLast);
81
+ var segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
82
+ this.totalDistance += segmentDistance;
83
+
84
+ if (!this.started) {
85
+ this.started = true;
86
+ this.extrusions(positions, last, this.totalDistance - segmentDistance);
87
+ }
88
+
89
+ this.extrusions(positions, cur, this.totalDistance);
90
+ indices.push(index + 0, index + 1, index + 2);
91
+ indices.push(index + 2, index + 1, index + 3);
92
+ count += 2;
93
+ return count;
60
94
  }
61
- for (let i = 0; i < complex.positions.length / 6; i++) {
62
- complex.positions[i * 6 + 5] = this.totalDistance;
95
+ }, {
96
+ key: "extrusions",
97
+ value: function extrusions(positions, point, // 顶点
98
+ distanceRadio) {
99
+ positions.push(point[0], point[1], point[2] | 0, distanceRadio, 0, point[2] | 0);
100
+ this.complex.indexes.push(this.currentIndex);
101
+ positions.push(point[0], point[1], point[2] | 0, distanceRadio, 0, point[2] | 0);
102
+ this.complex.indexes.push(this.currentIndex);
103
+ this.currentIndex++;
63
104
  }
64
- return complex;
65
- }
66
- simpleSegment(complex, index, last, cur) {
67
- let count = 0;
68
- const indices = complex.indices;
69
- const positions = complex.positions;
70
- const flatCur = (0, import_l7_utils.aProjectFlat)([cur[0], cur[1]]);
71
- const flatLast = (0, import_l7_utils.aProjectFlat)([last[0], last[1]]);
72
- direction(lineA, flatCur, flatLast);
73
- const segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
74
- this.totalDistance += segmentDistance;
75
- if (!this.started) {
76
- this.started = true;
77
- this.extrusions(positions, last, this.totalDistance - segmentDistance);
105
+ }, {
106
+ key: "lineSegmentDistance",
107
+ value: function lineSegmentDistance(b1, a1) {
108
+ var dx = a1[0] - b1[0];
109
+ var dy = a1[1] - b1[1];
110
+ return Math.sqrt(dx * dx + dy * dy);
78
111
  }
79
- this.extrusions(positions, cur, this.totalDistance);
80
- indices.push(index + 0, index + 1, index + 2);
81
- indices.push(index + 2, index + 1, index + 3);
82
- count += 2;
83
- return count;
84
- }
85
- extrusions(positions, point, distanceRadio) {
86
- positions.push(point[0], point[1], point[2] | 0, distanceRadio, 0, point[2] | 0);
87
- this.complex.indexes.push(this.currentIndex);
88
- positions.push(point[0], point[1], point[2] | 0, distanceRadio, 0, point[2] | 0);
89
- this.complex.indexes.push(this.currentIndex);
90
- this.currentIndex++;
91
- }
92
- lineSegmentDistance(b1, a1) {
93
- const dx = a1[0] - b1[0];
94
- const dy = a1[1] - b1[1];
95
- return Math.sqrt(dx * dx + dy * dy);
96
- }
97
- };
98
- // Annotate the CommonJS export names for ESM import in node:
99
- 0 && (module.exports = {
100
- direction
101
- });
112
+ }]);
113
+ return ExtrudePolyline;
114
+ }();
115
+
116
+ exports.default = ExtrudePolyline;