@antv/l7-layers 2.9.25-alpha.0 → 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 (125) hide show
  1. package/es/heatmap/models/heatmap.js +1 -1
  2. package/es/tile/utils.js +1 -1
  3. package/lib/Geometry/index.js +114 -77
  4. package/lib/Geometry/models/billboard.js +232 -181
  5. package/lib/Geometry/models/index.js +18 -34
  6. package/lib/Geometry/models/plane.js +407 -278
  7. package/lib/Geometry/models/sprite.js +291 -189
  8. package/lib/canvas/index.js +101 -66
  9. package/lib/canvas/models/canvas.js +207 -140
  10. package/lib/canvas/models/index.js +12 -30
  11. package/lib/citybuliding/building.js +98 -63
  12. package/lib/citybuliding/models/build.js +192 -146
  13. package/lib/core/BaseLayer.js +1331 -814
  14. package/lib/core/BaseModel.js +457 -279
  15. package/lib/core/interface.js +40 -53
  16. package/lib/core/schema.js +21 -39
  17. package/lib/core/shape/Path.js +67 -79
  18. package/lib/core/shape/extrude.js +132 -91
  19. package/lib/core/triangulation.js +378 -196
  20. package/lib/earth/index.js +100 -62
  21. package/lib/earth/models/atmosphere.js +146 -112
  22. package/lib/earth/models/base.js +210 -150
  23. package/lib/earth/models/bloomsphere.js +146 -112
  24. package/lib/earth/utils.js +111 -91
  25. package/lib/heatmap/index.js +149 -92
  26. package/lib/heatmap/models/grid.js +118 -91
  27. package/lib/heatmap/models/grid3d.js +155 -123
  28. package/lib/heatmap/models/heatmap.js +475 -338
  29. package/lib/heatmap/models/hexagon.js +121 -92
  30. package/lib/heatmap/models/index.js +22 -37
  31. package/lib/heatmap/triangulation.js +31 -47
  32. package/lib/image/index.js +111 -74
  33. package/lib/image/models/dataImage.js +232 -174
  34. package/lib/image/models/image.js +175 -128
  35. package/lib/image/models/index.js +15 -32
  36. package/lib/index.js +263 -97
  37. package/lib/line/index.js +131 -85
  38. package/lib/line/models/arc.js +352 -237
  39. package/lib/line/models/arc_3d.js +334 -228
  40. package/lib/line/models/earthArc_3d.js +336 -228
  41. package/lib/line/models/great_circle.js +291 -200
  42. package/lib/line/models/half.js +286 -201
  43. package/lib/line/models/index.js +42 -50
  44. package/lib/line/models/line.js +428 -299
  45. package/lib/line/models/linearline.js +277 -203
  46. package/lib/line/models/simpleLine.js +239 -175
  47. package/lib/line/models/tile.js +348 -237
  48. package/lib/line/models/wall.js +327 -235
  49. package/lib/mask/index.js +92 -59
  50. package/lib/mask/models/fill.js +134 -82
  51. package/lib/mask/models/index.js +12 -30
  52. package/lib/plugins/DataMappingPlugin.js +342 -224
  53. package/lib/plugins/DataSourcePlugin.js +102 -87
  54. package/lib/plugins/FeatureScalePlugin.js +330 -240
  55. package/lib/plugins/LayerAnimateStylePlugin.js +61 -55
  56. package/lib/plugins/LayerModelPlugin.js +80 -73
  57. package/lib/plugins/LayerStylePlugin.js +48 -51
  58. package/lib/plugins/LightingPlugin.js +80 -68
  59. package/lib/plugins/MultiPassRendererPlugin.js +91 -65
  60. package/lib/plugins/PixelPickingPlugin.js +150 -109
  61. package/lib/plugins/RegisterStyleAttributePlugin.js +110 -110
  62. package/lib/plugins/ShaderUniformPlugin.js +118 -99
  63. package/lib/plugins/UpdateModelPlugin.js +40 -47
  64. package/lib/plugins/UpdateStyleAttributePlugin.js +93 -75
  65. package/lib/point/index.js +226 -150
  66. package/lib/point/models/earthExtrude.js +279 -201
  67. package/lib/point/models/earthFill.js +287 -202
  68. package/lib/point/models/extrude.js +299 -203
  69. package/lib/point/models/fill.js +406 -275
  70. package/lib/point/models/fillmage.js +365 -256
  71. package/lib/point/models/image.js +241 -168
  72. package/lib/point/models/index.js +46 -52
  73. package/lib/point/models/normal.js +183 -134
  74. package/lib/point/models/radar.js +304 -211
  75. package/lib/point/models/simplePoint.js +194 -142
  76. package/lib/point/models/text.js +608 -385
  77. package/lib/point/models/tile.js +314 -223
  78. package/lib/point/shape/extrude.js +56 -52
  79. package/lib/polygon/index.js +154 -102
  80. package/lib/polygon/models/extrude.js +311 -223
  81. package/lib/polygon/models/fill.js +215 -153
  82. package/lib/polygon/models/index.js +46 -52
  83. package/lib/polygon/models/ocean.js +244 -173
  84. package/lib/polygon/models/tile.js +144 -100
  85. package/lib/polygon/models/water.js +222 -153
  86. package/lib/raster/buffers/triangulation.js +27 -40
  87. package/lib/raster/index.js +115 -75
  88. package/lib/raster/models/index.js +16 -33
  89. package/lib/raster/models/raster.js +178 -135
  90. package/lib/raster/raster.js +187 -132
  91. package/lib/tile/interface.js +4 -16
  92. package/lib/tile/manager/tileConfigManager.js +125 -86
  93. package/lib/tile/manager/tileLayerManager.js +313 -229
  94. package/lib/tile/manager/tilePickerManager.js +192 -123
  95. package/lib/tile/models/tileModel.js +71 -52
  96. package/lib/tile/tileFactory/base.js +432 -309
  97. package/lib/tile/tileFactory/index.js +51 -49
  98. package/lib/tile/tileFactory/line.js +65 -50
  99. package/lib/tile/tileFactory/point.js +65 -50
  100. package/lib/tile/tileFactory/polygon.js +65 -50
  101. package/lib/tile/tileFactory/raster.js +66 -54
  102. package/lib/tile/tileFactory/rasterData.js +88 -76
  103. package/lib/tile/tileFactory/rasterDataLayer.js +97 -62
  104. package/lib/tile/tileFactory/vectorLayer.js +168 -109
  105. package/lib/tile/tileLayer/baseTileLayer.js +420 -221
  106. package/lib/tile/tmsTileLayer.js +110 -67
  107. package/lib/tile/utils.js +110 -92
  108. package/lib/utils/blend.js +59 -79
  109. package/lib/utils/collision-index.js +107 -64
  110. package/lib/utils/dataMappingStyle.js +105 -60
  111. package/lib/utils/extrude_polyline.js +600 -398
  112. package/lib/utils/grid-index.js +163 -111
  113. package/lib/utils/layerData.js +130 -99
  114. package/lib/utils/multiPassRender.js +49 -41
  115. package/lib/utils/polylineNormal.js +148 -96
  116. package/lib/utils/simpleLine.js +100 -85
  117. package/lib/utils/symbol-layout.js +219 -116
  118. package/lib/utils/updateShape.js +15 -41
  119. package/lib/wind/index.js +109 -71
  120. package/lib/wind/models/index.js +12 -30
  121. package/lib/wind/models/utils.js +144 -105
  122. package/lib/wind/models/wind.js +333 -224
  123. package/lib/wind/models/windRender.js +329 -218
  124. package/lib/wind/models/windShader.js +23 -181
  125. package/package.json +6 -6
@@ -1,414 +1,637 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
-
22
- // src/point/models/text.ts
23
- var text_exports = {};
24
- __export(text_exports, {
25
- TextTriangulation: () => TextTriangulation,
26
- default: () => TextModel
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
27
7
  });
28
- module.exports = __toCommonJS(text_exports);
29
- var import_l7_core = require("@antv/l7-core");
30
- var import_l7_utils = require("@antv/l7-utils");
31
- var import_lodash = require("lodash");
32
- var import_BaseModel = __toESM(require("../../core/BaseModel"));
33
- var import_collision_index = __toESM(require("../../utils/collision-index"));
34
- var import_symbol_layout = require("../../utils/symbol-layout");
35
- var import_text_frag = __toESM(require("../shaders/text_frag.glsl"));
36
- var import_text_vert = __toESM(require("../shaders/text_vert.glsl"));
8
+ exports.TextTriangulation = TextTriangulation;
9
+ exports.default = void 0;
10
+
11
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
12
+
13
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
+
15
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
16
+
17
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
18
+
19
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
20
+
21
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
22
+
23
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
24
+
25
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
26
+
27
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
28
+
29
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
30
+
31
+ var _l7Core = require("@antv/l7-core");
32
+
33
+ var _l7Utils = require("@antv/l7-utils");
34
+
35
+ var _lodash = require("lodash");
36
+
37
+ var _BaseModel2 = _interopRequireDefault(require("../../core/BaseModel"));
38
+
39
+ var _collisionIndex = _interopRequireDefault(require("../../utils/collision-index"));
40
+
41
+ var _symbolLayout = require("../../utils/symbol-layout");
42
+
43
+ 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; } } }; }
44
+
45
+ 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); }
46
+
47
+ 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; }
48
+
49
+ 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); }; }
50
+
51
+ 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; } }
52
+
53
+ /* babel-plugin-inline-import '../shaders/text_frag.glsl' */
54
+ var textFrag = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 48.0\nuniform sampler2D u_sdf_map;\nuniform float u_gamma_scale : 0.5;\n// uniform float u_font_size : 24.0;\nuniform float u_opacity : 1.0;\nuniform vec4 u_stroke_color : [0, 0, 0, 1];\nuniform float u_stroke_width : 2.0;\nuniform float u_halo_blur : 0.5;\nuniform float u_DevicePixelRatio;\n\nvarying vec4 v_color;\nvarying vec2 v_uv;\nvarying float v_gamma_scale;\nvarying float v_fontScale;\n\nvarying mat4 styleMappingMat; // \u4F20\u9012\u4ECE\u7247\u5143\u4E2D\u4F20\u9012\u7684\u6620\u5C04\u6570\u636E\n\n#pragma include \"picking\"\nvoid main() {\n // get style data mapping\n float opacity = styleMappingMat[0][0];\n float strokeWidth = styleMappingMat[0][2];\n vec4 textrueStroke = vec4(\n styleMappingMat[1][0],\n styleMappingMat[1][1],\n styleMappingMat[1][2],\n styleMappingMat[1][3]\n );\n\n // get sdf from atlas\n float dist = texture2D(u_sdf_map, v_uv).a;\n\n // float fontScale = u_font_size / FONT_SIZE;\n\n // lowp float buff = (6.0 - u_stroke_width / v_fontScale) / SDF_PX;\n lowp float buff = (6.0 - strokeWidth / v_fontScale) / SDF_PX;\n highp float gamma = (u_halo_blur * 1.19 / SDF_PX + EDGE_GAMMA) / (v_fontScale * u_gamma_scale) / 1.0;\n\n highp float gamma_scaled = gamma * v_gamma_scale;\n\n highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);\n // gl_FragColor = mix(vec4(v_color.rgb, v_color.a * u_opacity), vec4(u_stroke_color.rgb, u_stroke_color.a * u_opacity), smoothstep(0., 0.5, 1. - dist));\n gl_FragColor = mix(vec4(v_color.rgb, v_color.a * opacity), vec4(textrueStroke.rgb, textrueStroke.a * opacity), smoothstep(0., 0.5, 1. - dist));\n gl_FragColor.a= gl_FragColor.a * alpha;\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
55
+
56
+ /* babel-plugin-inline-import '../shaders/text_vert.glsl' */
57
+ var textVert = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 24.0\nattribute vec3 a_Position;\nattribute vec2 a_tex;\nattribute vec2 a_textOffsets;\nattribute vec4 a_Color;\nattribute float a_Size;\nattribute float a_Rotate;\n\nuniform vec2 u_sdf_map_size;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\nuniform float u_raisingHeight: 0.0;\n\nvarying vec2 v_uv;\nvarying float v_gamma_scale;\nvarying vec4 v_color;\nvarying float v_fontScale;\n\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\nuniform float u_opacity : 1;\nuniform float u_stroke_width : 2;\nuniform vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n#pragma include \"styleMappingCalStrokeWidth\"\n\n#pragma include \"projection\"\n#pragma include \"picking\"\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 - strokeWidth - empty\n 0.0, 0.0, 0.0, 0.0, // strokeR - strokeG - strokeB - strokeA\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1]\n 0.0, 0.0, 0.0, 0.0\n );\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\n vec2 strokeWidthAndOffset = calStrokeWidthAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][2] = strokeWidthAndOffset.r;\n textureOffset = strokeWidthAndOffset.g;\n\n vec4 textrueStroke = vec4(-1.0, -1.0, -1.0, -1.0);\n if(hasStroke()) {\n vec2 valueRPos = nextPos(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset);\n styleMappingMat[1][0] = pos2value(valueRPos, columnWidth, rowHeight); // R\n textureOffset += 1.0;\n\n vec2 valueGPos = nextPos(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset);\n styleMappingMat[1][1] = pos2value(valueGPos, columnWidth, rowHeight); // G\n textureOffset += 1.0;\n\n vec2 valueBPos = nextPos(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset);\n styleMappingMat[1][2] = pos2value(valueBPos, columnWidth, rowHeight); // B\n textureOffset += 1.0;\n\n vec2 valueAPos = nextPos(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset);\n styleMappingMat[1][3] = pos2value(valueAPos, columnWidth, rowHeight); // A\n textureOffset += 1.0;\n } else {\n if(u_stroke_color == vec4(0.0)) {\n styleMappingMat[1][0] = v_color.r;\n styleMappingMat[1][1] = v_color.g;\n styleMappingMat[1][2] = v_color.b;\n styleMappingMat[1][3] = v_color.a;\n } else {\n styleMappingMat[1][0] = u_stroke_color.r;\n styleMappingMat[1][1] = u_stroke_color.g;\n styleMappingMat[1][2] = u_stroke_color.b;\n styleMappingMat[1][3] = u_stroke_color.a;\n }\n }\n \n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n v_color = a_Color;\n v_uv = a_tex / u_sdf_map_size;\n\n // \u6587\u672C\u7F29\u653E\u6BD4\u4F8B\n float fontScale = a_Size / FONT_SIZE;\n v_fontScale = fontScale;\n\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n // vec4 projected_position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n highp float angle_sin = sin(a_Rotate);\n highp float angle_cos = cos(a_Rotate);\n mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);\n \n // gl_Position = vec4(projected_position.xy / projected_position.w + rotation_matrix * a_textOffsets * fontScale / u_ViewportSize * 2.0 * u_DevicePixelRatio, 0.0, 1.0);\n\n float raiseHeight = u_raisingHeight;\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n raiseHeight = u_raisingHeight * mapboxZoomScale;\n }\n\n vec4 projected_position;\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n projected_position = u_Mvp * (vec4(a_Position.xyz + vec3(0.0, 0.0, raiseHeight), 1.0));\n } else { // else\n projected_position = project_common_position_to_clipspace(vec4(project_pos.xyz + vec3(0.0, 0.0, raiseHeight), 1.0));\n }\n\n gl_Position = vec4(\n projected_position.xy / projected_position.w + rotation_matrix * a_textOffsets * fontScale / u_ViewportSize * 2.0 * u_DevicePixelRatio, 0.0, 1.0);\n v_gamma_scale = gl_Position.w;\n setPickingColor(a_PickingColor);\n\n}\n";
58
+
37
59
  function TextTriangulation(feature) {
38
- const that = this;
39
- const id = feature.id;
40
- const vertices = [];
41
- const indices = [];
60
+ // @ts-ignore
61
+ var that = this;
62
+ var id = feature.id;
63
+ var vertices = [];
64
+ var indices = [];
65
+
42
66
  if (!that.glyphInfoMap || !that.glyphInfoMap[id]) {
43
67
  return {
44
68
  vertices: [],
69
+ // [ x, y, z, tex.x,tex.y, offset.x. offset.y]
45
70
  indices: [],
46
71
  size: 7
47
72
  };
48
73
  }
49
- const centroid = that.glyphInfoMap[id].centroid;
50
- const coord = centroid.length === 2 ? [centroid[0], centroid[1], 0] : centroid;
51
- that.glyphInfoMap[id].glyphQuads.forEach((quad, index) => {
52
- vertices.push(...coord, quad.tex.x, quad.tex.y + quad.tex.height, quad.tl.x, quad.tl.y, ...coord, quad.tex.x + quad.tex.width, quad.tex.y + quad.tex.height, quad.tr.x, quad.tr.y, ...coord, quad.tex.x + quad.tex.width, quad.tex.y, quad.br.x, quad.br.y, ...coord, quad.tex.x, quad.tex.y, quad.bl.x, quad.bl.y);
74
+
75
+ var centroid = that.glyphInfoMap[id].centroid; // 计算中心点
76
+
77
+ var coord = centroid.length === 2 ? [centroid[0], centroid[1], 0] : centroid;
78
+ that.glyphInfoMap[id].glyphQuads.forEach(function (quad, index) {
79
+ vertices.push.apply(vertices, (0, _toConsumableArray2.default)(coord).concat([quad.tex.x, quad.tex.y + quad.tex.height, quad.tl.x, quad.tl.y], (0, _toConsumableArray2.default)(coord), [quad.tex.x + quad.tex.width, quad.tex.y + quad.tex.height, quad.tr.x, quad.tr.y], (0, _toConsumableArray2.default)(coord), [quad.tex.x + quad.tex.width, quad.tex.y, quad.br.x, quad.br.y], (0, _toConsumableArray2.default)(coord), [quad.tex.x, quad.tex.y, quad.bl.x, quad.bl.y]));
53
80
  indices.push(0 + index * 4, 1 + index * 4, 2 + index * 4, 2 + index * 4, 3 + index * 4, 0 + index * 4);
54
81
  });
55
82
  return {
56
- vertices,
57
- indices,
83
+ vertices: vertices,
84
+ // [ x, y, z, tex.x,tex.y, offset.x. offset.y]
85
+ indices: indices,
58
86
  size: 7
59
87
  };
60
88
  }
61
- var TextModel = class extends import_BaseModel.default {
62
- constructor() {
63
- super(...arguments);
64
- this.glyphInfoMap = {};
65
- this.currentZoom = -1;
66
- this.textureHeight = 0;
67
- this.textCount = 0;
68
- this.preTextStyle = {};
69
- this.buildModels = async (callbackModel) => {
70
- const {
71
- mask = false,
72
- maskInside = true
73
- } = this.layer.getLayerConfig();
74
- this.mapping();
75
- this.layer.buildLayerModel({
76
- moduleName: "pointText",
77
- vertexShader: import_text_vert.default,
78
- fragmentShader: import_text_frag.default,
79
- triangulation: TextTriangulation.bind(this),
80
- depth: { enable: false },
81
- blend: this.getBlend(),
82
- stencil: (0, import_l7_utils.getMask)(mask, maskInside)
83
- }).then((model) => {
84
- callbackModel([model]);
85
- }).catch((err) => {
86
- console.warn(err);
87
- callbackModel([]);
88
- });
89
- };
90
- this.mapping = () => {
91
- this.initGlyph();
92
- this.updateTexture();
93
- this.filterGlyphs();
94
- this.reBuildModel();
95
- };
89
+
90
+ var TextModel = /*#__PURE__*/function (_BaseModel) {
91
+ (0, _inherits2.default)(TextModel, _BaseModel);
92
+
93
+ var _super = _createSuper(TextModel);
94
+
95
+ function TextModel() {
96
+ var _this;
97
+
98
+ (0, _classCallCheck2.default)(this, TextModel);
99
+
100
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
101
+ args[_key] = arguments[_key];
102
+ }
103
+
104
+ _this = _super.call.apply(_super, [this].concat(args));
105
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "glyphInfoMap", {});
106
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "currentZoom", -1);
107
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "textureHeight", 0);
108
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "textCount", 0);
109
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "preTextStyle", {});
110
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "buildModels", /*#__PURE__*/function () {
111
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(callbackModel) {
112
+ var _ref2, _ref2$mask, mask, _ref2$maskInside, maskInside;
113
+
114
+ return _regenerator.default.wrap(function _callee$(_context) {
115
+ while (1) {
116
+ switch (_context.prev = _context.next) {
117
+ case 0:
118
+ _ref2 = _this.layer.getLayerConfig(), _ref2$mask = _ref2.mask, mask = _ref2$mask === void 0 ? false : _ref2$mask, _ref2$maskInside = _ref2.maskInside, maskInside = _ref2$maskInside === void 0 ? true : _ref2$maskInside;
119
+
120
+ _this.mapping();
121
+
122
+ _this.layer.buildLayerModel({
123
+ moduleName: 'pointText',
124
+ vertexShader: textVert,
125
+ fragmentShader: textFrag,
126
+ triangulation: TextTriangulation.bind((0, _assertThisInitialized2.default)(_this)),
127
+ depth: {
128
+ enable: false
129
+ },
130
+ blend: _this.getBlend(),
131
+ stencil: (0, _l7Utils.getMask)(mask, maskInside)
132
+ }).then(function (model) {
133
+ callbackModel([model]);
134
+ }).catch(function (err) {
135
+ console.warn(err);
136
+ callbackModel([]);
137
+ });
138
+
139
+ case 3:
140
+ case "end":
141
+ return _context.stop();
142
+ }
143
+ }
144
+ }, _callee);
145
+ }));
146
+
147
+ return function (_x) {
148
+ return _ref.apply(this, arguments);
149
+ };
150
+ }());
151
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "mapping", function () {
152
+ _this.initGlyph();
153
+
154
+ _this.updateTexture();
155
+
156
+ _this.filterGlyphs();
157
+
158
+ _this.reBuildModel();
159
+ });
160
+ return _this;
96
161
  }
97
- getUninforms() {
98
- const {
99
- opacity = 1,
100
- stroke = "#fff",
101
- strokeWidth = 0,
102
- textAnchor = "center",
103
- textAllowOverlap = false,
104
- halo = 0.5,
105
- gamma = 2,
106
- raisingHeight = 0
107
- } = this.layer.getLayerConfig();
108
- const { canvas, mapping } = this.fontService;
109
- if (Object.keys(mapping).length !== this.textCount) {
110
- this.updateTexture();
111
- this.textCount = Object.keys(mapping).length;
162
+
163
+ (0, _createClass2.default)(TextModel, [{
164
+ key: "getUninforms",
165
+ value: function getUninforms() {
166
+ var _ref3 = this.layer.getLayerConfig(),
167
+ _ref3$opacity = _ref3.opacity,
168
+ opacity = _ref3$opacity === void 0 ? 1.0 : _ref3$opacity,
169
+ _ref3$stroke = _ref3.stroke,
170
+ stroke = _ref3$stroke === void 0 ? '#fff' : _ref3$stroke,
171
+ _ref3$strokeWidth = _ref3.strokeWidth,
172
+ strokeWidth = _ref3$strokeWidth === void 0 ? 0 : _ref3$strokeWidth,
173
+ _ref3$textAnchor = _ref3.textAnchor,
174
+ textAnchor = _ref3$textAnchor === void 0 ? 'center' : _ref3$textAnchor,
175
+ _ref3$textAllowOverla = _ref3.textAllowOverlap,
176
+ textAllowOverlap = _ref3$textAllowOverla === void 0 ? false : _ref3$textAllowOverla,
177
+ _ref3$halo = _ref3.halo,
178
+ halo = _ref3$halo === void 0 ? 0.5 : _ref3$halo,
179
+ _ref3$gamma = _ref3.gamma,
180
+ gamma = _ref3$gamma === void 0 ? 2.0 : _ref3$gamma,
181
+ _ref3$raisingHeight = _ref3.raisingHeight,
182
+ raisingHeight = _ref3$raisingHeight === void 0 ? 0 : _ref3$raisingHeight;
183
+
184
+ var _this$fontService = this.fontService,
185
+ canvas = _this$fontService.canvas,
186
+ mapping = _this$fontService.mapping;
187
+
188
+ if (Object.keys(mapping).length !== this.textCount) {
189
+ this.updateTexture();
190
+ this.textCount = Object.keys(mapping).length;
191
+ }
192
+
193
+ this.preTextStyle = {
194
+ textAnchor: textAnchor,
195
+ textAllowOverlap: textAllowOverlap
196
+ };
197
+
198
+ if (this.dataTextureTest && this.dataTextureNeedUpdate({
199
+ opacity: opacity,
200
+ strokeWidth: strokeWidth,
201
+ stroke: stroke
202
+ })) {
203
+ this.judgeStyleAttributes({
204
+ opacity: opacity,
205
+ strokeWidth: strokeWidth,
206
+ stroke: stroke
207
+ });
208
+ var encodeData = this.layer.getEncodedData();
209
+
210
+ var _this$calDataFrame = this.calDataFrame(this.cellLength, encodeData, this.cellProperties),
211
+ data = _this$calDataFrame.data,
212
+ width = _this$calDataFrame.width,
213
+ height = _this$calDataFrame.height;
214
+
215
+ this.rowCount = height; // 当前数据纹理有多少行
216
+
217
+ this.dataTexture = this.cellLength > 0 && data.length > 0 ? this.createTexture2D({
218
+ flipY: true,
219
+ data: data,
220
+ format: _l7Core.gl.LUMINANCE,
221
+ type: _l7Core.gl.FLOAT,
222
+ width: width,
223
+ height: height
224
+ }) : this.createTexture2D({
225
+ flipY: true,
226
+ data: [1],
227
+ format: _l7Core.gl.LUMINANCE,
228
+ type: _l7Core.gl.FLOAT,
229
+ width: 1,
230
+ height: 1
231
+ });
232
+ }
233
+
234
+ return {
235
+ u_dataTexture: this.dataTexture,
236
+ // 数据纹理 - 有数据映射的时候纹理中带数据,若没有任何数据映射时纹理是 [1]
237
+ u_cellTypeLayout: this.getCellTypeLayout(),
238
+ u_raisingHeight: Number(raisingHeight),
239
+ u_opacity: (0, _lodash.isNumber)(opacity) ? opacity : 1.0,
240
+ u_stroke_width: (0, _lodash.isNumber)(strokeWidth) ? strokeWidth : 1.0,
241
+ u_stroke_color: this.getStrokeColor(stroke),
242
+ u_sdf_map: this.texture,
243
+ u_halo_blur: halo,
244
+ u_gamma_scale: gamma,
245
+ u_sdf_map_size: [canvas.width, canvas.height]
246
+ };
112
247
  }
113
- this.preTextStyle = {
114
- textAnchor,
115
- textAllowOverlap
116
- };
117
- if (this.dataTextureTest && this.dataTextureNeedUpdate({
118
- opacity,
119
- strokeWidth,
120
- stroke
121
- })) {
122
- this.judgeStyleAttributes({
123
- opacity,
124
- strokeWidth,
125
- stroke
126
- });
127
- const encodeData = this.layer.getEncodedData();
128
- const { data, width, height } = this.calDataFrame(this.cellLength, encodeData, this.cellProperties);
129
- this.rowCount = height;
130
- this.dataTexture = this.cellLength > 0 && data.length > 0 ? this.createTexture2D({
131
- flipY: true,
132
- data,
133
- format: import_l7_core.gl.LUMINANCE,
134
- type: import_l7_core.gl.FLOAT,
135
- width,
136
- height
137
- }) : this.createTexture2D({
138
- flipY: true,
139
- data: [1],
140
- format: import_l7_core.gl.LUMINANCE,
141
- type: import_l7_core.gl.FLOAT,
142
- width: 1,
143
- height: 1
144
- });
248
+ }, {
249
+ key: "initModels",
250
+ value: function initModels(callbackModel) {
251
+ this.layer.on('remapping', this.mapping);
252
+ this.extent = this.textExtent();
253
+
254
+ var _ref4 = this.layer.getLayerConfig(),
255
+ _ref4$textAnchor = _ref4.textAnchor,
256
+ textAnchor = _ref4$textAnchor === void 0 ? 'center' : _ref4$textAnchor,
257
+ _ref4$textAllowOverla = _ref4.textAllowOverlap,
258
+ textAllowOverlap = _ref4$textAllowOverla === void 0 ? true : _ref4$textAllowOverla;
259
+
260
+ this.preTextStyle = {
261
+ textAnchor: textAnchor,
262
+ textAllowOverlap: textAllowOverlap
263
+ };
264
+ this.buildModels(callbackModel);
145
265
  }
146
- return {
147
- u_dataTexture: this.dataTexture,
148
- u_cellTypeLayout: this.getCellTypeLayout(),
149
- u_raisingHeight: Number(raisingHeight),
150
- u_opacity: (0, import_lodash.isNumber)(opacity) ? opacity : 1,
151
- u_stroke_width: (0, import_lodash.isNumber)(strokeWidth) ? strokeWidth : 1,
152
- u_stroke_color: this.getStrokeColor(stroke),
153
- u_sdf_map: this.texture,
154
- u_halo_blur: halo,
155
- u_gamma_scale: gamma,
156
- u_sdf_map_size: [canvas.width, canvas.height]
157
- };
158
- }
159
- initModels(callbackModel) {
160
- this.layer.on("remapping", this.mapping);
161
- this.extent = this.textExtent();
162
- const {
163
- textAnchor = "center",
164
- textAllowOverlap = true
165
- } = this.layer.getLayerConfig();
166
- this.preTextStyle = {
167
- textAnchor,
168
- textAllowOverlap
169
- };
170
- this.buildModels(callbackModel);
171
- }
172
- needUpdate() {
173
- const {
174
- textAllowOverlap = false
175
- } = this.layer.getLayerConfig();
176
- const zoom = this.mapService.getZoom();
177
- const extent = this.mapService.getBounds();
178
- const flag = (0, import_l7_utils.boundsContains)(this.extent, extent);
179
- if (!textAllowOverlap && (Math.abs(this.currentZoom - zoom) > 1 || !flag) || textAllowOverlap !== this.preTextStyle.textAllowOverlap) {
180
- this.reBuildModel();
181
- return true;
266
+ }, {
267
+ key: "needUpdate",
268
+ value: function needUpdate() {
269
+ var _ref5 = this.layer.getLayerConfig(),
270
+ _ref5$textAllowOverla = _ref5.textAllowOverlap,
271
+ textAllowOverlap = _ref5$textAllowOverla === void 0 ? false : _ref5$textAllowOverla; // textAllowOverlap 发生改变
272
+
273
+
274
+ var zoom = this.mapService.getZoom();
275
+ var extent = this.mapService.getBounds();
276
+ var flag = (0, _l7Utils.boundsContains)(this.extent, extent); // 文本不能压盖则进行过滤
277
+
278
+ if (!textAllowOverlap && (Math.abs(this.currentZoom - zoom) > 1 || !flag) || textAllowOverlap !== this.preTextStyle.textAllowOverlap) {
279
+ this.reBuildModel();
280
+ return true;
281
+ }
282
+
283
+ return false;
182
284
  }
183
- return false;
184
- }
185
- clearModels() {
186
- var _a, _b;
187
- (_a = this.texture) == null ? void 0 : _a.destroy();
188
- (_b = this.dataTexture) == null ? void 0 : _b.destroy();
189
- this.layer.off("remapping", this.mapping);
190
- }
191
- registerBuiltinAttributes() {
192
- this.styleAttributeService.registerStyleAttribute({
193
- name: "rotate",
194
- type: import_l7_core.AttributeType.Attribute,
195
- descriptor: {
196
- name: "a_Rotate",
197
- buffer: {
198
- usage: import_l7_core.gl.DYNAMIC_DRAW,
199
- data: [],
200
- type: import_l7_core.gl.FLOAT
201
- },
202
- size: 1,
203
- update: (feature, featureIdx, vertex, attributeIdx) => {
204
- const { rotate = 0 } = feature;
205
- return Array.isArray(rotate) ? [rotate[0]] : [rotate];
285
+ }, {
286
+ key: "clearModels",
287
+ value: function clearModels() {
288
+ var _this$texture, _this$dataTexture;
289
+
290
+ (_this$texture = this.texture) === null || _this$texture === void 0 ? void 0 : _this$texture.destroy();
291
+ (_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy();
292
+ this.layer.off('remapping', this.mapping);
293
+ }
294
+ }, {
295
+ key: "registerBuiltinAttributes",
296
+ value: function registerBuiltinAttributes() {
297
+ this.styleAttributeService.registerStyleAttribute({
298
+ name: 'rotate',
299
+ type: _l7Core.AttributeType.Attribute,
300
+ descriptor: {
301
+ name: 'a_Rotate',
302
+ buffer: {
303
+ usage: _l7Core.gl.DYNAMIC_DRAW,
304
+ data: [],
305
+ type: _l7Core.gl.FLOAT
306
+ },
307
+ size: 1,
308
+ update: function update(feature, featureIdx, vertex, attributeIdx) {
309
+ var _feature$rotate = feature.rotate,
310
+ rotate = _feature$rotate === void 0 ? 0 : _feature$rotate;
311
+ return Array.isArray(rotate) ? [rotate[0]] : [rotate];
312
+ }
206
313
  }
207
- }
208
- });
209
- this.styleAttributeService.registerStyleAttribute({
210
- name: "textOffsets",
211
- type: import_l7_core.AttributeType.Attribute,
212
- descriptor: {
213
- name: "a_textOffsets",
214
- buffer: {
215
- usage: import_l7_core.gl.STATIC_DRAW,
216
- data: [],
217
- type: import_l7_core.gl.FLOAT
218
- },
219
- size: 2,
220
- update: (feature, featureIdx, vertex, attributeIdx) => {
221
- return [vertex[5], vertex[6]];
314
+ });
315
+ this.styleAttributeService.registerStyleAttribute({
316
+ name: 'textOffsets',
317
+ type: _l7Core.AttributeType.Attribute,
318
+ descriptor: {
319
+ name: 'a_textOffsets',
320
+ buffer: {
321
+ // give the WebGL driver a hint that this buffer may change
322
+ usage: _l7Core.gl.STATIC_DRAW,
323
+ data: [],
324
+ type: _l7Core.gl.FLOAT
325
+ },
326
+ size: 2,
327
+ update: function update(feature, featureIdx, vertex, attributeIdx) {
328
+ return [vertex[5], vertex[6]];
329
+ }
222
330
  }
223
- }
224
- });
225
- this.styleAttributeService.registerStyleAttribute({
226
- name: "size",
227
- type: import_l7_core.AttributeType.Attribute,
228
- descriptor: {
229
- name: "a_Size",
230
- buffer: {
231
- usage: import_l7_core.gl.DYNAMIC_DRAW,
232
- data: [],
233
- type: import_l7_core.gl.FLOAT
234
- },
235
- size: 1,
236
- update: (feature, featureIdx, vertex, attributeIdx) => {
237
- const { size = 12 } = feature;
238
- return Array.isArray(size) ? [size[0]] : [size];
331
+ }); // point layer size;
332
+
333
+ this.styleAttributeService.registerStyleAttribute({
334
+ name: 'size',
335
+ type: _l7Core.AttributeType.Attribute,
336
+ descriptor: {
337
+ name: 'a_Size',
338
+ buffer: {
339
+ // give the WebGL driver a hint that this buffer may change
340
+ usage: _l7Core.gl.DYNAMIC_DRAW,
341
+ data: [],
342
+ type: _l7Core.gl.FLOAT
343
+ },
344
+ size: 1,
345
+ update: function update(feature, featureIdx, vertex, attributeIdx) {
346
+ var _feature$size = feature.size,
347
+ size = _feature$size === void 0 ? 12 : _feature$size;
348
+ return Array.isArray(size) ? [size[0]] : [size];
349
+ }
239
350
  }
240
- }
241
- });
242
- this.styleAttributeService.registerStyleAttribute({
243
- name: "textUv",
244
- type: import_l7_core.AttributeType.Attribute,
245
- descriptor: {
246
- name: "a_tex",
247
- buffer: {
248
- usage: import_l7_core.gl.DYNAMIC_DRAW,
249
- data: [],
250
- type: import_l7_core.gl.FLOAT
251
- },
252
- size: 2,
253
- update: (feature, featureIdx, vertex, attributeIdx) => {
254
- return [vertex[3], vertex[4]];
351
+ }); // point layer size;
352
+
353
+ this.styleAttributeService.registerStyleAttribute({
354
+ name: 'textUv',
355
+ type: _l7Core.AttributeType.Attribute,
356
+ descriptor: {
357
+ name: 'a_tex',
358
+ buffer: {
359
+ // give the WebGL driver a hint that this buffer may change
360
+ usage: _l7Core.gl.DYNAMIC_DRAW,
361
+ data: [],
362
+ type: _l7Core.gl.FLOAT
363
+ },
364
+ size: 2,
365
+ update: function update(feature, featureIdx, vertex, attributeIdx) {
366
+ return [vertex[3], vertex[4]];
367
+ }
255
368
  }
256
- }
257
- });
258
- }
259
- textExtent() {
260
- const bounds = this.mapService.getBounds();
261
- return (0, import_l7_utils.padBounds)(bounds, 0.5);
262
- }
263
- initTextFont() {
264
- const {
265
- fontWeight = "400",
266
- fontFamily = "sans-serif"
267
- } = this.layer.getLayerConfig();
268
- const data = this.layer.getEncodedData();
269
- const characterSet = [];
270
- data.forEach((item) => {
271
- let { shape = "" } = item;
272
- shape = shape.toString();
273
- for (const char of shape) {
274
- if (characterSet.indexOf(char) === -1) {
275
- characterSet.push(char);
369
+ });
370
+ }
371
+ }, {
372
+ key: "textExtent",
373
+ value: function textExtent() {
374
+ var bounds = this.mapService.getBounds();
375
+ return (0, _l7Utils.padBounds)(bounds, 0.5);
376
+ }
377
+ /**
378
+ * 生成文字纹理(生成文字纹理字典)
379
+ */
380
+
381
+ }, {
382
+ key: "initTextFont",
383
+ value: function initTextFont() {
384
+ var _ref6 = this.layer.getLayerConfig(),
385
+ _ref6$fontWeight = _ref6.fontWeight,
386
+ fontWeight = _ref6$fontWeight === void 0 ? '400' : _ref6$fontWeight,
387
+ _ref6$fontFamily = _ref6.fontFamily,
388
+ fontFamily = _ref6$fontFamily === void 0 ? 'sans-serif' : _ref6$fontFamily;
389
+
390
+ var data = this.layer.getEncodedData();
391
+ var characterSet = [];
392
+ data.forEach(function (item) {
393
+ var _item$shape = item.shape,
394
+ shape = _item$shape === void 0 ? '' : _item$shape;
395
+ shape = shape.toString();
396
+
397
+ var _iterator = _createForOfIteratorHelper(shape),
398
+ _step;
399
+
400
+ try {
401
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
402
+ var char = _step.value;
403
+
404
+ // 去重
405
+ if (characterSet.indexOf(char) === -1) {
406
+ characterSet.push(char);
407
+ }
408
+ }
409
+ } catch (err) {
410
+ _iterator.e(err);
411
+ } finally {
412
+ _iterator.f();
413
+ }
414
+ });
415
+ this.fontService.setFontOptions({
416
+ characterSet: characterSet,
417
+ fontWeight: fontWeight,
418
+ fontFamily: fontFamily,
419
+ iconfont: false
420
+ });
421
+ }
422
+ /**
423
+ * 生成 iconfont 纹理字典
424
+ */
425
+
426
+ }, {
427
+ key: "initIconFontTex",
428
+ value: function initIconFontTex() {
429
+ var _ref7 = this.layer.getLayerConfig(),
430
+ _ref7$fontWeight = _ref7.fontWeight,
431
+ fontWeight = _ref7$fontWeight === void 0 ? '400' : _ref7$fontWeight,
432
+ _ref7$fontFamily = _ref7.fontFamily,
433
+ fontFamily = _ref7$fontFamily === void 0 ? 'sans-serif' : _ref7$fontFamily;
434
+
435
+ var data = this.layer.getEncodedData();
436
+ var characterSet = [];
437
+ data.forEach(function (item) {
438
+ var _item$shape2 = item.shape,
439
+ shape = _item$shape2 === void 0 ? '' : _item$shape2;
440
+ shape = "".concat(shape);
441
+
442
+ if (characterSet.indexOf(shape) === -1) {
443
+ characterSet.push(shape);
276
444
  }
445
+ });
446
+ this.fontService.setFontOptions({
447
+ characterSet: characterSet,
448
+ fontWeight: fontWeight,
449
+ fontFamily: fontFamily,
450
+ iconfont: true
451
+ });
452
+ }
453
+ /**
454
+ * 生成文字布局(对照文字纹理字典提取对应文字的位置很好信息)
455
+ */
456
+
457
+ }, {
458
+ key: "generateGlyphLayout",
459
+ value: function generateGlyphLayout(iconfont) {
460
+ var _this2 = this;
461
+
462
+ // TODO:更新文字布局
463
+ var mapping = this.fontService.mapping;
464
+
465
+ var _ref8 = this.layer.getLayerConfig(),
466
+ _ref8$spacing = _ref8.spacing,
467
+ spacing = _ref8$spacing === void 0 ? 2 : _ref8$spacing,
468
+ _ref8$textAnchor = _ref8.textAnchor,
469
+ textAnchor = _ref8$textAnchor === void 0 ? 'center' : _ref8$textAnchor;
470
+
471
+ var data = this.layer.getEncodedData();
472
+ this.glyphInfo = data.map(function (feature) {
473
+ var _feature$shape = feature.shape,
474
+ shape = _feature$shape === void 0 ? '' : _feature$shape,
475
+ id = feature.id,
476
+ _feature$size2 = feature.size,
477
+ size = _feature$size2 === void 0 ? 1 : _feature$size2,
478
+ _feature$textOffset = feature.textOffset,
479
+ textOffset = _feature$textOffset === void 0 ? [0, 0] : _feature$textOffset;
480
+ var shaping = (0, _symbolLayout.shapeText)(shape.toString(), mapping, // @ts-ignore
481
+ size, textAnchor, 'left', spacing, textOffset, iconfont);
482
+ var glyphQuads = (0, _symbolLayout.getGlyphQuads)(shaping, textOffset, false);
483
+ feature.shaping = shaping;
484
+ feature.glyphQuads = glyphQuads; // feature.centroid = calculteCentroid(coordinates);
485
+
486
+ feature.centroid = (0, _l7Utils.calculateCentroid)(feature.coordinates); // 此时地图高德2.0 originCentroid == centroid
487
+
488
+ feature.originCentroid = feature.version === 'GAODE2.x' ? (0, _l7Utils.calculateCentroid)(feature.originCoordinates) : feature.originCentroid = feature.centroid;
489
+ _this2.glyphInfoMap[id] = {
490
+ shaping: shaping,
491
+ glyphQuads: glyphQuads,
492
+ centroid: (0, _l7Utils.calculateCentroid)(feature.coordinates)
493
+ };
494
+ return feature;
495
+ });
496
+ }
497
+ /**
498
+ * 文字避让 depend on originCentorid
499
+ */
500
+
501
+ }, {
502
+ key: "filterGlyphs",
503
+ value: function filterGlyphs() {
504
+ var _this3 = this;
505
+
506
+ var _ref9 = this.layer.getLayerConfig(),
507
+ _ref9$padding = _ref9.padding,
508
+ padding = _ref9$padding === void 0 ? [4, 4] : _ref9$padding,
509
+ _ref9$textAllowOverla = _ref9.textAllowOverlap,
510
+ textAllowOverlap = _ref9$textAllowOverla === void 0 ? false : _ref9$textAllowOverla;
511
+
512
+ if (textAllowOverlap) {
513
+ // 如果允许文本覆盖
514
+ // this.layer.setEncodedData(this.glyphInfo);
515
+ return;
277
516
  }
278
- });
279
- this.fontService.setFontOptions({
280
- characterSet,
281
- fontWeight,
282
- fontFamily,
283
- iconfont: false
284
- });
285
- }
286
- initIconFontTex() {
287
- const {
288
- fontWeight = "400",
289
- fontFamily = "sans-serif"
290
- } = this.layer.getLayerConfig();
291
- const data = this.layer.getEncodedData();
292
- const characterSet = [];
293
- data.forEach((item) => {
294
- let { shape = "" } = item;
295
- shape = `${shape}`;
296
- if (characterSet.indexOf(shape) === -1) {
297
- characterSet.push(shape);
517
+
518
+ this.glyphInfoMap = {};
519
+ this.currentZoom = this.mapService.getZoom();
520
+ this.extent = this.textExtent();
521
+
522
+ var _this$rendererService = this.rendererService.getViewportSize(),
523
+ width = _this$rendererService.width,
524
+ height = _this$rendererService.height;
525
+
526
+ var collisionIndex = new _collisionIndex.default(width, height);
527
+ var filterData = this.glyphInfo.filter(function (feature) {
528
+ var shaping = feature.shaping,
529
+ _feature$id = feature.id,
530
+ id = _feature$id === void 0 ? 0 : _feature$id; // const centroid = feature.centroid as [number, number];
531
+ // const centroid = feature.originCentroid as [number, number];
532
+
533
+ var centroid = feature.version === 'GAODE2.x' ? feature.originCentroid : feature.centroid;
534
+ var size = feature.size;
535
+ var fontScale = size / 24;
536
+
537
+ var pixels = _this3.mapService.lngLatToContainer(centroid);
538
+
539
+ var _collisionIndex$place = collisionIndex.placeCollisionBox({
540
+ x1: shaping.left * fontScale - padding[0],
541
+ x2: shaping.right * fontScale + padding[0],
542
+ y1: shaping.top * fontScale - padding[1],
543
+ y2: shaping.bottom * fontScale + padding[1],
544
+ anchorPointX: pixels.x,
545
+ anchorPointY: pixels.y
546
+ }),
547
+ box = _collisionIndex$place.box;
548
+
549
+ if (box && box.length) {
550
+ // TODO:featureIndex
551
+ collisionIndex.insertCollisionBox(box, id);
552
+ return true;
553
+ } else {
554
+ return false;
555
+ }
556
+ });
557
+ filterData.forEach(function (item) {
558
+ // @ts-ignore
559
+ _this3.glyphInfoMap[item.id] = item;
560
+ }); // this.layer.setEncodedData(filterData);
561
+ }
562
+ /**
563
+ * 初始化文字布局
564
+ */
565
+
566
+ }, {
567
+ key: "initGlyph",
568
+ value: function initGlyph() {
569
+ var _this$layer$getLayerC = this.layer.getLayerConfig(),
570
+ _this$layer$getLayerC2 = _this$layer$getLayerC.iconfont,
571
+ iconfont = _this$layer$getLayerC2 === void 0 ? false : _this$layer$getLayerC2; // 1.生成文字纹理(或是生成 iconfont)
572
+
573
+
574
+ iconfont ? this.initIconFontTex() : this.initTextFont(); // this.initTextFont();
575
+ // 2.生成文字布局
576
+
577
+ this.generateGlyphLayout(iconfont);
578
+ }
579
+ /**
580
+ * 更新文字纹理
581
+ */
582
+
583
+ }, {
584
+ key: "updateTexture",
585
+ value: function updateTexture() {
586
+ var createTexture2D = this.rendererService.createTexture2D;
587
+ var canvas = this.fontService.canvas;
588
+ this.textureHeight = canvas.height;
589
+
590
+ if (this.texture) {
591
+ this.texture.destroy();
298
592
  }
299
- });
300
- this.fontService.setFontOptions({
301
- characterSet,
302
- fontWeight,
303
- fontFamily,
304
- iconfont: true
305
- });
306
- }
307
- generateGlyphLayout(iconfont) {
308
- const { mapping } = this.fontService;
309
- const {
310
- spacing = 2,
311
- textAnchor = "center"
312
- } = this.layer.getLayerConfig();
313
- const data = this.layer.getEncodedData();
314
- this.glyphInfo = data.map((feature) => {
315
- const { shape = "", id, size = 1, textOffset = [0, 0] } = feature;
316
- const shaping = (0, import_symbol_layout.shapeText)(shape.toString(), mapping, size, textAnchor, "left", spacing, textOffset, iconfont);
317
- const glyphQuads = (0, import_symbol_layout.getGlyphQuads)(shaping, textOffset, false);
318
- feature.shaping = shaping;
319
- feature.glyphQuads = glyphQuads;
320
- feature.centroid = (0, import_l7_utils.calculateCentroid)(feature.coordinates);
321
- feature.originCentroid = feature.version === "GAODE2.x" ? (0, import_l7_utils.calculateCentroid)(feature.originCoordinates) : feature.originCentroid = feature.centroid;
322
- this.glyphInfoMap[id] = {
323
- shaping,
324
- glyphQuads,
325
- centroid: (0, import_l7_utils.calculateCentroid)(feature.coordinates)
326
- };
327
- return feature;
328
- });
329
- }
330
- filterGlyphs() {
331
- const {
332
- padding = [4, 4],
333
- textAllowOverlap = false
334
- } = this.layer.getLayerConfig();
335
- if (textAllowOverlap) {
336
- return;
593
+
594
+ this.texture = createTexture2D({
595
+ data: canvas,
596
+ mag: _l7Core.gl.LINEAR,
597
+ min: _l7Core.gl.LINEAR,
598
+ width: canvas.width,
599
+ height: canvas.height
600
+ });
337
601
  }
338
- this.glyphInfoMap = {};
339
- this.currentZoom = this.mapService.getZoom();
340
- this.extent = this.textExtent();
341
- const { width, height } = this.rendererService.getViewportSize();
342
- const collisionIndex = new import_collision_index.default(width, height);
343
- const filterData = this.glyphInfo.filter((feature) => {
344
- const { shaping, id = 0 } = feature;
345
- const centroid = feature.version === "GAODE2.x" ? feature.originCentroid : feature.centroid;
346
- const size = feature.size;
347
- const fontScale = size / 24;
348
- const pixels = this.mapService.lngLatToContainer(centroid);
349
- const { box } = collisionIndex.placeCollisionBox({
350
- x1: shaping.left * fontScale - padding[0],
351
- x2: shaping.right * fontScale + padding[0],
352
- y1: shaping.top * fontScale - padding[1],
353
- y2: shaping.bottom * fontScale + padding[1],
354
- anchorPointX: pixels.x,
355
- anchorPointY: pixels.y
602
+ }, {
603
+ key: "reBuildModel",
604
+ value: function reBuildModel() {
605
+ var _this4 = this;
606
+
607
+ var _ref10 = this.layer.getLayerConfig(),
608
+ _ref10$mask = _ref10.mask,
609
+ mask = _ref10$mask === void 0 ? false : _ref10$mask,
610
+ _ref10$maskInside = _ref10.maskInside,
611
+ maskInside = _ref10$maskInside === void 0 ? true : _ref10$maskInside;
612
+
613
+ this.filterGlyphs();
614
+ this.layer.buildLayerModel({
615
+ moduleName: 'pointText',
616
+ vertexShader: textVert,
617
+ fragmentShader: textFrag,
618
+ triangulation: TextTriangulation.bind(this),
619
+ depth: {
620
+ enable: false
621
+ },
622
+ blend: this.getBlend(),
623
+ stencil: (0, _l7Utils.getMask)(mask, maskInside)
624
+ }).then(function (model) {
625
+ _this4.layer.models = [model];
626
+
627
+ _this4.layer.renderLayers();
628
+ }).catch(function (err) {
629
+ console.warn(err);
630
+ _this4.layer.models = [];
356
631
  });
357
- if (box && box.length) {
358
- collisionIndex.insertCollisionBox(box, id);
359
- return true;
360
- } else {
361
- return false;
362
- }
363
- });
364
- filterData.forEach((item) => {
365
- this.glyphInfoMap[item.id] = item;
366
- });
367
- }
368
- initGlyph() {
369
- const { iconfont = false } = this.layer.getLayerConfig();
370
- iconfont ? this.initIconFontTex() : this.initTextFont();
371
- this.generateGlyphLayout(iconfont);
372
- }
373
- updateTexture() {
374
- const { createTexture2D } = this.rendererService;
375
- const { canvas } = this.fontService;
376
- this.textureHeight = canvas.height;
377
- if (this.texture) {
378
- this.texture.destroy();
379
632
  }
380
- this.texture = createTexture2D({
381
- data: canvas,
382
- mag: import_l7_core.gl.LINEAR,
383
- min: import_l7_core.gl.LINEAR,
384
- width: canvas.width,
385
- height: canvas.height
386
- });
387
- }
388
- reBuildModel() {
389
- const {
390
- mask = false,
391
- maskInside = true
392
- } = this.layer.getLayerConfig();
393
- this.filterGlyphs();
394
- this.layer.buildLayerModel({
395
- moduleName: "pointText",
396
- vertexShader: import_text_vert.default,
397
- fragmentShader: import_text_frag.default,
398
- triangulation: TextTriangulation.bind(this),
399
- depth: { enable: false },
400
- blend: this.getBlend(),
401
- stencil: (0, import_l7_utils.getMask)(mask, maskInside)
402
- }).then((model) => {
403
- this.layer.models = [model];
404
- this.layer.renderLayers();
405
- }).catch((err) => {
406
- console.warn(err);
407
- this.layer.models = [];
408
- });
409
- }
410
- };
411
- // Annotate the CommonJS export names for ESM import in node:
412
- 0 && (module.exports = {
413
- TextTriangulation
414
- });
633
+ }]);
634
+ return TextModel;
635
+ }(_BaseModel2.default);
636
+
637
+ exports.default = TextModel;