@antv/l7-layers 2.17.2 → 2.17.4

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 (242) hide show
  1. package/es/Geometry/index.js +31 -9
  2. package/es/Geometry/models/billboard.js +89 -51
  3. package/es/Geometry/models/plane.js +143 -81
  4. package/es/Geometry/models/sprite.js +118 -60
  5. package/es/canvas/index.js +33 -10
  6. package/es/canvas/models/canvas.js +97 -41
  7. package/es/citybuliding/building.js +27 -8
  8. package/es/citybuliding/models/build.js +82 -57
  9. package/es/core/BaseLayer.js +478 -313
  10. package/es/core/BaseModel.js +80 -51
  11. package/es/core/CommonStyleAttribute.js +5 -2
  12. package/es/core/LayerPickService.js +32 -21
  13. package/es/core/TextureService.js +13 -0
  14. package/es/core/interface.js +24 -17
  15. package/es/core/shape/Path.js +20 -13
  16. package/es/core/shape/extrude.js +39 -27
  17. package/es/core/triangulation.js +136 -99
  18. package/es/earth/index.js +33 -9
  19. package/es/earth/models/atmosphere.js +54 -30
  20. package/es/earth/models/base.js +85 -47
  21. package/es/earth/models/bloomsphere.js +54 -30
  22. package/es/earth/utils.js +13 -9
  23. package/es/heatmap/index.js +40 -10
  24. package/es/heatmap/models/grid.js +52 -28
  25. package/es/heatmap/models/grid3d.js +52 -28
  26. package/es/heatmap/models/heatmap.js +149 -92
  27. package/es/heatmap/models/hexagon.js +52 -28
  28. package/es/heatmap/triangulation.js +4 -0
  29. package/es/image/index.js +28 -9
  30. package/es/image/models/image.js +100 -66
  31. package/es/index.js +17 -9
  32. package/es/line/index.js +35 -9
  33. package/es/line/models/arc.js +114 -64
  34. package/es/line/models/arc_3d.js +102 -58
  35. package/es/line/models/earthArc_3d.js +105 -60
  36. package/es/line/models/flow.js +60 -36
  37. package/es/line/models/great_circle.js +94 -53
  38. package/es/line/models/line.js +138 -86
  39. package/es/line/models/linearline.js +76 -43
  40. package/es/line/models/simpleLine.js +69 -39
  41. package/es/line/models/wall.js +92 -52
  42. package/es/mask/index.js +28 -9
  43. package/es/mask/models/fill.js +54 -29
  44. package/es/plugins/DataMappingPlugin.js +114 -78
  45. package/es/plugins/DataSourcePlugin.js +68 -45
  46. package/es/plugins/FeatureScalePlugin.js +122 -67
  47. package/es/plugins/LayerAnimateStylePlugin.js +5 -0
  48. package/es/plugins/LayerMaskPlugin.js +11 -3
  49. package/es/plugins/LayerModelPlugin.js +108 -69
  50. package/es/plugins/LayerStylePlugin.js +9 -3
  51. package/es/plugins/LightingPlugin.js +18 -12
  52. package/es/plugins/MultiPassRendererPlugin.js +16 -11
  53. package/es/plugins/PixelPickingPlugin.js +21 -12
  54. package/es/plugins/RegisterStyleAttributePlugin.js +12 -5
  55. package/es/plugins/ShaderUniformPlugin.js +27 -13
  56. package/es/plugins/UpdateModelPlugin.js +5 -0
  57. package/es/plugins/UpdateStyleAttributePlugin.js +11 -5
  58. package/es/point/index.js +78 -26
  59. package/es/point/models/earthExtrude.js +95 -58
  60. package/es/point/models/earthFill.js +80 -52
  61. package/es/point/models/extrude.js +94 -57
  62. package/es/point/models/fill.js +81 -56
  63. package/es/point/models/fillmage.js +100 -60
  64. package/es/point/models/image.js +83 -47
  65. package/es/point/models/index.js +2 -2
  66. package/es/point/models/normal.js +54 -30
  67. package/es/point/models/radar.js +63 -38
  68. package/es/point/models/simplePoint.js +62 -38
  69. package/es/point/models/text.js +296 -199
  70. package/es/point/shape/extrude.js +13 -4
  71. package/es/polygon/index.js +41 -11
  72. package/es/polygon/models/extrude.js +135 -87
  73. package/es/polygon/models/fill.js +79 -50
  74. package/es/polygon/models/index.js +2 -3
  75. package/es/polygon/models/ocean.js +76 -42
  76. package/es/polygon/models/water.js +71 -37
  77. package/es/raster/buffers/triangulation.js +4 -2
  78. package/es/raster/index.js +32 -9
  79. package/es/raster/models/raster.js +116 -80
  80. package/es/raster/models/rasterRgb.js +127 -84
  81. package/es/raster/models/rasterTerrainRgb.js +84 -56
  82. package/es/tile/interaction/getRasterData.js +20 -14
  83. package/es/tile/interaction/utils.js +9 -7
  84. package/es/tile/manager/base.js +96 -63
  85. package/es/tile/service/TileLayerService.js +55 -33
  86. package/es/tile/service/TilePickService.js +40 -26
  87. package/es/tile/service/TileSourceService.js +7 -3
  88. package/es/tile/tileFactory/DebugTile.js +46 -29
  89. package/es/tile/tileFactory/ImageTile.js +38 -20
  90. package/es/tile/tileFactory/MaskTile.js +43 -22
  91. package/es/tile/tileFactory/RasterRGBTile.js +42 -22
  92. package/es/tile/tileFactory/RasterTerrainRGBTile.js +38 -20
  93. package/es/tile/tileFactory/RasterTile.js +53 -30
  94. package/es/tile/tileFactory/Tile.js +97 -63
  95. package/es/tile/tileFactory/VectorTile.js +68 -41
  96. package/es/tile/tileFactory/index.js +11 -0
  97. package/es/tile/tileFactory/layers/TileDebugLayer.js +27 -6
  98. package/es/tile/tileFactory/util.js +3 -0
  99. package/es/tile/tileLayer/BaseLayer.js +146 -105
  100. package/es/tile/utils.js +1 -1
  101. package/es/utils/blend.js +2 -0
  102. package/es/utils/collision-index.js +16 -9
  103. package/es/utils/extrude_polyline.js +149 -101
  104. package/es/utils/grid-index.js +27 -2
  105. package/es/utils/identityScale.js +8 -0
  106. package/es/utils/layerData.js +44 -30
  107. package/es/utils/multiPassRender.js +13 -11
  108. package/es/utils/polylineNormal.js +37 -31
  109. package/es/utils/simpleLine.js +16 -2
  110. package/es/utils/stencil.js +3 -2
  111. package/es/utils/symbol-layout.js +53 -27
  112. package/es/wind/index.js +29 -9
  113. package/es/wind/models/utils.js +51 -26
  114. package/es/wind/models/wind.js +147 -101
  115. package/es/wind/models/windRender.js +66 -53
  116. package/lib/Geometry/index.js +38 -9
  117. package/lib/Geometry/models/billboard.js +97 -51
  118. package/lib/Geometry/models/index.js +5 -0
  119. package/lib/Geometry/models/plane.js +151 -79
  120. package/lib/Geometry/models/sprite.js +127 -60
  121. package/lib/canvas/index.js +40 -10
  122. package/lib/canvas/models/canvas.js +101 -41
  123. package/lib/canvas/models/index.js +3 -0
  124. package/lib/citybuliding/building.js +35 -8
  125. package/lib/citybuliding/models/build.js +92 -57
  126. package/lib/core/BaseLayer.js +469 -313
  127. package/lib/core/BaseModel.js +90 -51
  128. package/lib/core/CommonStyleAttribute.js +7 -2
  129. package/lib/core/LayerPickService.js +37 -21
  130. package/lib/core/TextureService.js +16 -0
  131. package/lib/core/interface.js +31 -21
  132. package/lib/core/schema.js +1 -0
  133. package/lib/core/shape/Path.js +31 -14
  134. package/lib/core/shape/extrude.js +62 -27
  135. package/lib/core/triangulation.js +177 -98
  136. package/lib/earth/index.js +43 -9
  137. package/lib/earth/models/atmosphere.js +63 -30
  138. package/lib/earth/models/base.js +90 -47
  139. package/lib/earth/models/bloomsphere.js +63 -30
  140. package/lib/earth/utils.js +31 -7
  141. package/lib/heatmap/index.js +48 -10
  142. package/lib/heatmap/models/grid.js +60 -28
  143. package/lib/heatmap/models/grid3d.js +60 -28
  144. package/lib/heatmap/models/heatmap.js +166 -92
  145. package/lib/heatmap/models/hexagon.js +60 -28
  146. package/lib/heatmap/models/index.js +6 -0
  147. package/lib/heatmap/triangulation.js +5 -0
  148. package/lib/image/index.js +36 -9
  149. package/lib/image/models/image.js +109 -66
  150. package/lib/image/models/index.js +3 -0
  151. package/lib/index.js +61 -7
  152. package/lib/line/index.js +40 -9
  153. package/lib/line/models/arc.js +124 -62
  154. package/lib/line/models/arc_3d.js +113 -56
  155. package/lib/line/models/earthArc_3d.js +115 -58
  156. package/lib/line/models/flow.js +70 -36
  157. package/lib/line/models/great_circle.js +104 -53
  158. package/lib/line/models/index.js +11 -0
  159. package/lib/line/models/line.js +146 -84
  160. package/lib/line/models/linearline.js +88 -43
  161. package/lib/line/models/simpleLine.js +79 -39
  162. package/lib/line/models/wall.js +103 -52
  163. package/lib/mask/index.js +36 -9
  164. package/lib/mask/models/fill.js +63 -29
  165. package/lib/mask/models/index.js +3 -0
  166. package/lib/plugins/DataMappingPlugin.js +125 -78
  167. package/lib/plugins/DataSourcePlugin.js +76 -45
  168. package/lib/plugins/FeatureScalePlugin.js +138 -67
  169. package/lib/plugins/LayerAnimateStylePlugin.js +10 -0
  170. package/lib/plugins/LayerMaskPlugin.js +17 -4
  171. package/lib/plugins/LayerModelPlugin.js +117 -70
  172. package/lib/plugins/LayerStylePlugin.js +14 -4
  173. package/lib/plugins/LightingPlugin.js +25 -12
  174. package/lib/plugins/MultiPassRendererPlugin.js +22 -11
  175. package/lib/plugins/PixelPickingPlugin.js +27 -12
  176. package/lib/plugins/RegisterStyleAttributePlugin.js +19 -5
  177. package/lib/plugins/ShaderUniformPlugin.js +34 -13
  178. package/lib/plugins/UpdateModelPlugin.js +10 -1
  179. package/lib/plugins/UpdateStyleAttributePlugin.js +16 -5
  180. package/lib/point/index.js +83 -26
  181. package/lib/point/models/earthExtrude.js +106 -58
  182. package/lib/point/models/earthFill.js +110 -52
  183. package/lib/point/models/extrude.js +103 -57
  184. package/lib/point/models/fill.js +90 -54
  185. package/lib/point/models/fillmage.js +107 -58
  186. package/lib/point/models/image.js +92 -47
  187. package/lib/point/models/index.js +12 -1
  188. package/lib/point/models/normal.js +64 -30
  189. package/lib/point/models/radar.js +72 -38
  190. package/lib/point/models/simplePoint.js +72 -38
  191. package/lib/point/models/text.js +305 -199
  192. package/lib/point/shape/extrude.js +20 -4
  193. package/lib/polygon/index.js +48 -11
  194. package/lib/polygon/models/extrude.js +146 -87
  195. package/lib/polygon/models/fill.js +89 -50
  196. package/lib/polygon/models/index.js +14 -2
  197. package/lib/polygon/models/ocean.js +88 -42
  198. package/lib/polygon/models/water.js +82 -37
  199. package/lib/raster/buffers/triangulation.js +7 -3
  200. package/lib/raster/index.js +40 -9
  201. package/lib/raster/models/index.js +5 -0
  202. package/lib/raster/models/raster.js +125 -80
  203. package/lib/raster/models/rasterRgb.js +139 -84
  204. package/lib/raster/models/rasterTerrainRgb.js +93 -56
  205. package/lib/tile/interaction/getRasterData.js +25 -14
  206. package/lib/tile/interaction/utils.js +19 -7
  207. package/lib/tile/manager/base.js +104 -63
  208. package/lib/tile/service/TileLayerService.js +60 -33
  209. package/lib/tile/service/TilePickService.js +48 -26
  210. package/lib/tile/service/TileSourceService.js +16 -2
  211. package/lib/tile/style/utils.js +3 -0
  212. package/lib/tile/tileFactory/DebugTile.js +54 -29
  213. package/lib/tile/tileFactory/ImageTile.js +46 -20
  214. package/lib/tile/tileFactory/MaskTile.js +51 -22
  215. package/lib/tile/tileFactory/RasterRGBTile.js +50 -22
  216. package/lib/tile/tileFactory/RasterTerrainRGBTile.js +46 -20
  217. package/lib/tile/tileFactory/RasterTile.js +63 -30
  218. package/lib/tile/tileFactory/Tile.js +102 -63
  219. package/lib/tile/tileFactory/VectorTile.js +76 -41
  220. package/lib/tile/tileFactory/index.js +25 -0
  221. package/lib/tile/tileFactory/layers/TileDebugLayer.js +32 -6
  222. package/lib/tile/tileFactory/util.js +9 -0
  223. package/lib/tile/tileLayer/BaseLayer.js +153 -105
  224. package/lib/tile/utils.js +5 -1
  225. package/lib/utils/blend.js +5 -0
  226. package/lib/utils/collision-index.js +25 -9
  227. package/lib/utils/extrude_polyline.js +181 -101
  228. package/lib/utils/grid-index.js +28 -2
  229. package/lib/utils/identityScale.js +9 -0
  230. package/lib/utils/layerData.js +49 -30
  231. package/lib/utils/multiPassRender.js +16 -11
  232. package/lib/utils/polylineNormal.js +66 -31
  233. package/lib/utils/simpleLine.js +21 -2
  234. package/lib/utils/stencil.js +4 -0
  235. package/lib/utils/symbol-layout.js +55 -27
  236. package/lib/wind/index.js +37 -9
  237. package/lib/wind/models/index.js +3 -0
  238. package/lib/wind/models/utils.js +62 -26
  239. package/lib/wind/models/wind.js +157 -101
  240. package/lib/wind/models/windRender.js +71 -53
  241. package/lib/wind/models/windShader.js +1 -0
  242. package/package.json +7 -7
@@ -8,20 +8,29 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConst
8
8
  import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
9
9
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
10
10
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
11
+
11
12
  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; } } }; }
13
+
12
14
  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); }
13
- 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; }
15
+
16
+ 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; }
17
+
14
18
  import _regeneratorRuntime from "@babel/runtime/regenerator";
19
+
15
20
  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); }; }
21
+
16
22
  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; } }
23
+
17
24
  import { AttributeType, gl } from '@antv/l7-core';
18
25
  import { boundsContains, calculateCentroid, padBounds, rgb2arr } from '@antv/l7-utils';
19
26
  import { isEqual } from 'lodash';
20
27
  import BaseModel from "../../core/BaseModel";
21
28
  import CollisionIndex from "../../utils/collision-index";
22
29
  import { getGlyphQuads, shapeText } from "../../utils/symbol-layout";
30
+
23
31
  /* babel-plugin-inline-import '../shaders/text_frag.glsl' */
24
32
  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;\nuniform float u_stroke_width : 2.0;\nuniform float u_halo_blur : 0.5;\nuniform float u_DevicePixelRatio;\n\nvarying vec4 v_color;\nvarying vec4 v_stroke_color;\nvarying vec2 v_uv;\nvarying float v_gamma_scale;\nvarying float v_fontScale;\n\n\n#pragma include \"picking\"\nvoid main() {\n // get style data mapping\n\n // get sdf from atlas\n float dist = texture2D(u_sdf_map, v_uv).a;\n\n lowp float buff = (6.0 - u_stroke_width / 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\n gl_FragColor = mix(v_color, v_stroke_color, smoothstep(0., 0.5, 1.- dist));\n\n gl_FragColor.a *= alpha;\n // \u4F5C\u4E3A mask \u6A21\u677F\u65F6\u9700\u8981\u4E22\u5F03\u900F\u660E\u7684\u50CF\u7D20\n if (gl_FragColor.a < 0.01) {\n discard;\n }\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
33
+
25
34
  /* babel-plugin-inline-import '../shaders/text_vert.glsl' */
26
35
  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 vec4 v_stroke_color;\nvarying float v_fontScale;\n// uniform 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\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 \n v_uv = a_tex / u_sdf_map_size;\n\n\n\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n v_stroke_color = vec4(u_stroke_color.xyz, u_stroke_color.w * opacity);\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";
27
36
  export function TextTrianglation(feature) {
@@ -30,6 +39,7 @@ export function TextTrianglation(feature) {
30
39
  var id = feature.id;
31
40
  var vertices = [];
32
41
  var indices = [];
42
+
33
43
  if (!that.glyphInfoMap || !that.glyphInfoMap[id]) {
34
44
  return {
35
45
  vertices: [],
@@ -38,7 +48,9 @@ export function TextTrianglation(feature) {
38
48
  size: 7
39
49
  };
40
50
  }
51
+
41
52
  var centroid = that.glyphInfoMap[id].centroid; // 计算中心点
53
+
42
54
  var coord = centroid.length === 2 ? [centroid[0], centroid[1], 0] : centroid;
43
55
  that.glyphInfoMap[id].glyphQuads.forEach(function (quad, index) {
44
56
  vertices.push.apply(vertices, _toConsumableArray(coord).concat([quad.tex.x, quad.tex.y + quad.tex.height, quad.tl.x, quad.tl.y], _toConsumableArray(coord), [quad.tex.x + quad.tex.width, quad.tex.y + quad.tex.height, quad.tr.x, quad.tr.y], _toConsumableArray(coord), [quad.tex.x + quad.tex.width, quad.tex.y, quad.br.x, quad.br.y], _toConsumableArray(coord), [quad.tex.x, quad.tex.y, quad.bl.x, quad.bl.y]));
@@ -51,59 +63,82 @@ export function TextTrianglation(feature) {
51
63
  size: 7
52
64
  };
53
65
  }
66
+
54
67
  var TextModel = /*#__PURE__*/function (_BaseModel) {
55
68
  _inherits(TextModel, _BaseModel);
69
+
56
70
  var _super = _createSuper(TextModel);
71
+
57
72
  function TextModel() {
58
73
  var _this;
74
+
59
75
  _classCallCheck(this, TextModel);
76
+
60
77
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
61
78
  args[_key] = arguments[_key];
62
79
  }
80
+
63
81
  _this = _super.call.apply(_super, [this].concat(args));
82
+
64
83
  _defineProperty(_assertThisInitialized(_this), "glyphInfoMap", {});
84
+
65
85
  _defineProperty(_assertThisInitialized(_this), "currentZoom", -1);
86
+
66
87
  _defineProperty(_assertThisInitialized(_this), "textureHeight", 0);
88
+
67
89
  _defineProperty(_assertThisInitialized(_this), "textCount", 0);
90
+
68
91
  _defineProperty(_assertThisInitialized(_this), "preTextStyle", {});
92
+
69
93
  _defineProperty(_assertThisInitialized(_this), "mapping", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
70
94
  return _regeneratorRuntime.wrap(function _callee$(_context) {
71
- while (1) switch (_context.prev = _context.next) {
72
- case 0:
73
- _this.initGlyph(); //
74
- _this.updateTexture();
75
- _context.next = 4;
76
- return _this.reBuildModel();
77
- case 4:
78
- case "end":
79
- return _context.stop();
95
+ while (1) {
96
+ switch (_context.prev = _context.next) {
97
+ case 0:
98
+ _this.initGlyph(); //
99
+
100
+
101
+ _this.updateTexture();
102
+
103
+ _context.next = 4;
104
+ return _this.reBuildModel();
105
+
106
+ case 4:
107
+ case "end":
108
+ return _context.stop();
109
+ }
80
110
  }
81
111
  }, _callee);
82
112
  })));
113
+
83
114
  return _this;
84
115
  }
116
+
85
117
  _createClass(TextModel, [{
86
118
  key: "getUninforms",
87
119
  value: function getUninforms() {
88
120
  var _ref2 = this.layer.getLayerConfig(),
89
- _ref2$opacity = _ref2.opacity,
90
- opacity = _ref2$opacity === void 0 ? 1.0 : _ref2$opacity,
91
- _ref2$stroke = _ref2.stroke,
92
- stroke = _ref2$stroke === void 0 ? '#fff' : _ref2$stroke,
93
- _ref2$strokeWidth = _ref2.strokeWidth,
94
- strokeWidth = _ref2$strokeWidth === void 0 ? 0 : _ref2$strokeWidth,
95
- _ref2$halo = _ref2.halo,
96
- halo = _ref2$halo === void 0 ? 0.5 : _ref2$halo,
97
- _ref2$gamma = _ref2.gamma,
98
- gamma = _ref2$gamma === void 0 ? 2.0 : _ref2$gamma,
99
- _ref2$raisingHeight = _ref2.raisingHeight,
100
- raisingHeight = _ref2$raisingHeight === void 0 ? 0 : _ref2$raisingHeight;
121
+ _ref2$opacity = _ref2.opacity,
122
+ opacity = _ref2$opacity === void 0 ? 1.0 : _ref2$opacity,
123
+ _ref2$stroke = _ref2.stroke,
124
+ stroke = _ref2$stroke === void 0 ? '#fff' : _ref2$stroke,
125
+ _ref2$strokeWidth = _ref2.strokeWidth,
126
+ strokeWidth = _ref2$strokeWidth === void 0 ? 0 : _ref2$strokeWidth,
127
+ _ref2$halo = _ref2.halo,
128
+ halo = _ref2$halo === void 0 ? 0.5 : _ref2$halo,
129
+ _ref2$gamma = _ref2.gamma,
130
+ gamma = _ref2$gamma === void 0 ? 2.0 : _ref2$gamma,
131
+ _ref2$raisingHeight = _ref2.raisingHeight,
132
+ raisingHeight = _ref2$raisingHeight === void 0 ? 0 : _ref2$raisingHeight;
133
+
101
134
  var mapping = this.getFontServiceMapping();
102
135
  var canvas = this.getFontServiceCanvas();
136
+
103
137
  if (mapping && Object.keys(mapping).length !== this.textCount && canvas) {
104
138
  this.updateTexture();
105
139
  this.textCount = Object.keys(mapping).length;
106
140
  }
141
+
107
142
  this.preTextStyle = this.getTextStyle();
108
143
  return _objectSpread({
109
144
  u_raisingHeight: Number(raisingHeight),
@@ -121,23 +156,28 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
121
156
  value: function () {
122
157
  var _initModels = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
123
158
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
124
- while (1) switch (_context2.prev = _context2.next) {
125
- case 0:
126
- // 绑定事件
127
- this.bindEvent();
128
- this.extent = this.textExtent();
129
- this.rawEncodeData = this.layer.getEncodedData();
130
- this.preTextStyle = this.getTextStyle();
131
- return _context2.abrupt("return", this.buildModels());
132
- case 5:
133
- case "end":
134
- return _context2.stop();
159
+ while (1) {
160
+ switch (_context2.prev = _context2.next) {
161
+ case 0:
162
+ // 绑定事件
163
+ this.bindEvent();
164
+ this.extent = this.textExtent();
165
+ this.rawEncodeData = this.layer.getEncodedData();
166
+ this.preTextStyle = this.getTextStyle();
167
+ return _context2.abrupt("return", this.buildModels());
168
+
169
+ case 5:
170
+ case "end":
171
+ return _context2.stop();
172
+ }
135
173
  }
136
174
  }, _callee2, this);
137
175
  }));
176
+
138
177
  function initModels() {
139
178
  return _initModels.apply(this, arguments);
140
179
  }
180
+
141
181
  return initModels;
142
182
  }()
143
183
  }, {
@@ -145,38 +185,49 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
145
185
  value: function () {
146
186
  var _buildModels = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
147
187
  var _ref3, _ref3$textAllowOverla, textAllowOverlap, model;
188
+
148
189
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
149
- while (1) switch (_context3.prev = _context3.next) {
150
- case 0:
151
- _ref3 = this.layer.getLayerConfig(), _ref3$textAllowOverla = _ref3.textAllowOverlap, textAllowOverlap = _ref3$textAllowOverla === void 0 ? false : _ref3$textAllowOverla; // this.mapping(); 重复调用
152
- this.initGlyph(); //
153
- this.updateTexture();
154
- if (!textAllowOverlap) {
155
- this.filterGlyphs();
156
- }
157
- _context3.next = 6;
158
- return this.layer.buildLayerModel({
159
- moduleName: 'pointText',
160
- vertexShader: textVert,
161
- fragmentShader: textFrag,
162
- inject: this.getInject(),
163
- triangulation: TextTrianglation.bind(this),
164
- depth: {
165
- enable: false
190
+ while (1) {
191
+ switch (_context3.prev = _context3.next) {
192
+ case 0:
193
+ _ref3 = this.layer.getLayerConfig(), _ref3$textAllowOverla = _ref3.textAllowOverlap, textAllowOverlap = _ref3$textAllowOverla === void 0 ? false : _ref3$textAllowOverla; // this.mapping(); 重复调用
194
+
195
+ this.initGlyph(); //
196
+
197
+ this.updateTexture();
198
+
199
+ if (!textAllowOverlap) {
200
+ this.filterGlyphs();
166
201
  }
167
- });
168
- case 6:
169
- model = _context3.sent;
170
- return _context3.abrupt("return", [model]);
171
- case 8:
172
- case "end":
173
- return _context3.stop();
202
+
203
+ _context3.next = 6;
204
+ return this.layer.buildLayerModel({
205
+ moduleName: 'pointText',
206
+ vertexShader: textVert,
207
+ fragmentShader: textFrag,
208
+ inject: this.getInject(),
209
+ triangulation: TextTrianglation.bind(this),
210
+ depth: {
211
+ enable: false
212
+ }
213
+ });
214
+
215
+ case 6:
216
+ model = _context3.sent;
217
+ return _context3.abrupt("return", [model]);
218
+
219
+ case 8:
220
+ case "end":
221
+ return _context3.stop();
222
+ }
174
223
  }
175
224
  }, _callee3, this);
176
225
  }));
226
+
177
227
  function buildModels() {
178
228
  return _buildModels.apply(this, arguments);
179
229
  }
230
+
180
231
  return buildModels;
181
232
  }() // 需要更新的场景
182
233
  // 1. 文本偏移量发生改变
@@ -184,61 +235,79 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
184
235
  // 3. 文本允许重叠发生改变
185
236
  // 4. 文本字体发生改变
186
237
  // 5. 文本字体粗细发生改变
238
+
187
239
  }, {
188
240
  key: "needUpdate",
189
241
  value: function () {
190
242
  var _needUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
191
243
  var _ref4, _ref4$textAllowOverla, textAllowOverlap, _ref4$textAnchor, textAnchor, textOffset, padding, fontFamily, fontWeight, zoom, extent, flag;
244
+
192
245
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
193
- while (1) switch (_context4.prev = _context4.next) {
194
- case 0:
195
- _ref4 = this.getTextStyle(), _ref4$textAllowOverla = _ref4.textAllowOverlap, textAllowOverlap = _ref4$textAllowOverla === void 0 ? false : _ref4$textAllowOverla, _ref4$textAnchor = _ref4.textAnchor, textAnchor = _ref4$textAnchor === void 0 ? 'center' : _ref4$textAnchor, textOffset = _ref4.textOffset, padding = _ref4.padding, fontFamily = _ref4.fontFamily, fontWeight = _ref4.fontWeight;
196
- if (!(!isEqual(padding, this.preTextStyle.padding) || !isEqual(textOffset, this.preTextStyle.textOffset) || !isEqual(textAnchor, this.preTextStyle.textAnchor) || !isEqual(fontFamily, this.preTextStyle.fontFamily) || !isEqual(fontWeight, this.preTextStyle.fontWeight))) {
197
- _context4.next = 5;
198
- break;
199
- }
200
- _context4.next = 4;
201
- return this.mapping();
202
- case 4:
203
- return _context4.abrupt("return", true);
204
- case 5:
205
- if (!textAllowOverlap) {
206
- _context4.next = 7;
207
- break;
208
- }
209
- return _context4.abrupt("return", false);
210
- case 7:
211
- // textAllowOverlap 发生改变
212
- zoom = this.mapService.getZoom();
213
- extent = this.mapService.getBounds();
214
- flag = boundsContains(this.extent, extent); // 文本不能压盖则进行过滤
215
- if (!(Math.abs(this.currentZoom - zoom) > 0.5 || !flag || textAllowOverlap !== this.preTextStyle.textAllowOverlap)) {
216
- _context4.next = 14;
217
- break;
218
- }
219
- _context4.next = 13;
220
- return this.reBuildModel();
221
- case 13:
222
- return _context4.abrupt("return", true);
223
- case 14:
224
- return _context4.abrupt("return", false);
225
- case 15:
226
- case "end":
227
- return _context4.stop();
246
+ while (1) {
247
+ switch (_context4.prev = _context4.next) {
248
+ case 0:
249
+ _ref4 = this.getTextStyle(), _ref4$textAllowOverla = _ref4.textAllowOverlap, textAllowOverlap = _ref4$textAllowOverla === void 0 ? false : _ref4$textAllowOverla, _ref4$textAnchor = _ref4.textAnchor, textAnchor = _ref4$textAnchor === void 0 ? 'center' : _ref4$textAnchor, textOffset = _ref4.textOffset, padding = _ref4.padding, fontFamily = _ref4.fontFamily, fontWeight = _ref4.fontWeight;
250
+
251
+ if (!(!isEqual(padding, this.preTextStyle.padding) || !isEqual(textOffset, this.preTextStyle.textOffset) || !isEqual(textAnchor, this.preTextStyle.textAnchor) || !isEqual(fontFamily, this.preTextStyle.fontFamily) || !isEqual(fontWeight, this.preTextStyle.fontWeight))) {
252
+ _context4.next = 5;
253
+ break;
254
+ }
255
+
256
+ _context4.next = 4;
257
+ return this.mapping();
258
+
259
+ case 4:
260
+ return _context4.abrupt("return", true);
261
+
262
+ case 5:
263
+ if (!textAllowOverlap) {
264
+ _context4.next = 7;
265
+ break;
266
+ }
267
+
268
+ return _context4.abrupt("return", false);
269
+
270
+ case 7:
271
+ // textAllowOverlap 发生改变
272
+ zoom = this.mapService.getZoom();
273
+ extent = this.mapService.getBounds();
274
+ flag = boundsContains(this.extent, extent); // 文本不能压盖则进行过滤
275
+
276
+ if (!(Math.abs(this.currentZoom - zoom) > 0.5 || !flag || textAllowOverlap !== this.preTextStyle.textAllowOverlap)) {
277
+ _context4.next = 14;
278
+ break;
279
+ }
280
+
281
+ _context4.next = 13;
282
+ return this.reBuildModel();
283
+
284
+ case 13:
285
+ return _context4.abrupt("return", true);
286
+
287
+ case 14:
288
+ return _context4.abrupt("return", false);
289
+
290
+ case 15:
291
+ case "end":
292
+ return _context4.stop();
293
+ }
228
294
  }
229
295
  }, _callee4, this);
230
296
  }));
297
+
231
298
  function needUpdate() {
232
299
  return _needUpdate.apply(this, arguments);
233
300
  }
301
+
234
302
  return needUpdate;
235
303
  }()
236
304
  }, {
237
305
  key: "clearModels",
238
306
  value: function clearModels() {
239
307
  var _this$texture;
240
- (_this$texture = this.texture) === null || _this$texture === void 0 ? void 0 : _this$texture.destroy();
241
- // TODO this.mapping
308
+
309
+ (_this$texture = this.texture) === null || _this$texture === void 0 ? void 0 : _this$texture.destroy(); // TODO this.mapping
310
+
242
311
  this.layer.off('remapping', this.mapping);
243
312
  }
244
313
  }, {
@@ -257,7 +326,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
257
326
  size: 1,
258
327
  update: function update(feature) {
259
328
  var _feature$rotate = feature.rotate,
260
- rotate = _feature$rotate === void 0 ? 0 : _feature$rotate;
329
+ rotate = _feature$rotate === void 0 ? 0 : _feature$rotate;
261
330
  return Array.isArray(rotate) ? [rotate[0]] : [rotate];
262
331
  }
263
332
  }
@@ -279,9 +348,8 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
279
348
  return [vertex[5], vertex[6]];
280
349
  }
281
350
  }
282
- });
351
+ }); // point layer size;
283
352
 
284
- // point layer size;
285
353
  this.styleAttributeService.registerStyleAttribute({
286
354
  name: 'size',
287
355
  type: AttributeType.Attribute,
@@ -296,7 +364,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
296
364
  size: 1,
297
365
  update: function update(feature) {
298
366
  var _feature$size = feature.size,
299
- size = _feature$size === void 0 ? 12 : _feature$size;
367
+ size = _feature$size === void 0 ? 12 : _feature$size;
300
368
  return Array.isArray(size) ? [size[0]] : [size];
301
369
  }
302
370
  }
@@ -335,23 +403,28 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
335
403
  /**
336
404
  * 生成文字纹理(生成文字纹理字典)
337
405
  */
406
+
338
407
  }, {
339
408
  key: "initTextFont",
340
409
  value: function initTextFont() {
341
410
  var _this$getTextStyle = this.getTextStyle(),
342
- fontWeight = _this$getTextStyle.fontWeight,
343
- fontFamily = _this$getTextStyle.fontFamily;
411
+ fontWeight = _this$getTextStyle.fontWeight,
412
+ fontFamily = _this$getTextStyle.fontFamily;
413
+
344
414
  var data = this.rawEncodeData;
345
415
  var characterSet = [];
346
416
  data.forEach(function (item) {
347
417
  var _item$shape = item.shape,
348
- shape = _item$shape === void 0 ? '' : _item$shape;
418
+ shape = _item$shape === void 0 ? '' : _item$shape;
349
419
  shape = shape.toString();
420
+
350
421
  var _iterator = _createForOfIteratorHelper(shape),
351
- _step;
422
+ _step;
423
+
352
424
  try {
353
425
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
354
426
  var char = _step.value;
427
+
355
428
  // 去重
356
429
  if (characterSet.indexOf(char) === -1) {
357
430
  characterSet.push(char);
@@ -370,22 +443,24 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
370
443
  iconfont: false
371
444
  });
372
445
  }
373
-
374
446
  /**
375
447
  * 生成 iconfont 纹理字典
376
448
  */
449
+
377
450
  }, {
378
451
  key: "initIconFontTex",
379
452
  value: function initIconFontTex() {
380
453
  var _this$getTextStyle2 = this.getTextStyle(),
381
- fontWeight = _this$getTextStyle2.fontWeight,
382
- fontFamily = _this$getTextStyle2.fontFamily;
454
+ fontWeight = _this$getTextStyle2.fontWeight,
455
+ fontFamily = _this$getTextStyle2.fontFamily;
456
+
383
457
  var data = this.rawEncodeData;
384
458
  var characterSet = [];
385
459
  data.forEach(function (item) {
386
460
  var _item$shape2 = item.shape,
387
- shape = _item$shape2 === void 0 ? '' : _item$shape2;
461
+ shape = _item$shape2 === void 0 ? '' : _item$shape2;
388
462
  shape = "".concat(shape);
463
+
389
464
  if (characterSet.indexOf(shape) === -1) {
390
465
  characterSet.push(shape);
391
466
  }
@@ -401,26 +476,27 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
401
476
  key: "getTextStyle",
402
477
  value: function getTextStyle() {
403
478
  var _ref5 = this.layer.getLayerConfig(),
404
- _ref5$fontWeight = _ref5.fontWeight,
405
- fontWeight = _ref5$fontWeight === void 0 ? '400' : _ref5$fontWeight,
406
- _ref5$fontFamily = _ref5.fontFamily,
407
- fontFamily = _ref5$fontFamily === void 0 ? 'sans-serif' : _ref5$fontFamily,
408
- _ref5$textAllowOverla = _ref5.textAllowOverlap,
409
- textAllowOverlap = _ref5$textAllowOverla === void 0 ? false : _ref5$textAllowOverla,
410
- _ref5$padding = _ref5.padding,
411
- padding = _ref5$padding === void 0 ? [0, 0] : _ref5$padding,
412
- _ref5$textAnchor = _ref5.textAnchor,
413
- textAnchor = _ref5$textAnchor === void 0 ? 'center' : _ref5$textAnchor,
414
- _ref5$textOffset = _ref5.textOffset,
415
- textOffset = _ref5$textOffset === void 0 ? [0, 0] : _ref5$textOffset,
416
- _ref5$opacity = _ref5.opacity,
417
- opacity = _ref5$opacity === void 0 ? 1 : _ref5$opacity,
418
- _ref5$strokeOpacity = _ref5.strokeOpacity,
419
- strokeOpacity = _ref5$strokeOpacity === void 0 ? 1 : _ref5$strokeOpacity,
420
- _ref5$strokeWidth = _ref5.strokeWidth,
421
- strokeWidth = _ref5$strokeWidth === void 0 ? 0 : _ref5$strokeWidth,
422
- _ref5$stroke = _ref5.stroke,
423
- stroke = _ref5$stroke === void 0 ? '#000' : _ref5$stroke;
479
+ _ref5$fontWeight = _ref5.fontWeight,
480
+ fontWeight = _ref5$fontWeight === void 0 ? '400' : _ref5$fontWeight,
481
+ _ref5$fontFamily = _ref5.fontFamily,
482
+ fontFamily = _ref5$fontFamily === void 0 ? 'sans-serif' : _ref5$fontFamily,
483
+ _ref5$textAllowOverla = _ref5.textAllowOverlap,
484
+ textAllowOverlap = _ref5$textAllowOverla === void 0 ? false : _ref5$textAllowOverla,
485
+ _ref5$padding = _ref5.padding,
486
+ padding = _ref5$padding === void 0 ? [0, 0] : _ref5$padding,
487
+ _ref5$textAnchor = _ref5.textAnchor,
488
+ textAnchor = _ref5$textAnchor === void 0 ? 'center' : _ref5$textAnchor,
489
+ _ref5$textOffset = _ref5.textOffset,
490
+ textOffset = _ref5$textOffset === void 0 ? [0, 0] : _ref5$textOffset,
491
+ _ref5$opacity = _ref5.opacity,
492
+ opacity = _ref5$opacity === void 0 ? 1 : _ref5$opacity,
493
+ _ref5$strokeOpacity = _ref5.strokeOpacity,
494
+ strokeOpacity = _ref5$strokeOpacity === void 0 ? 1 : _ref5$strokeOpacity,
495
+ _ref5$strokeWidth = _ref5.strokeWidth,
496
+ strokeWidth = _ref5$strokeWidth === void 0 ? 0 : _ref5$strokeWidth,
497
+ _ref5$stroke = _ref5.stroke,
498
+ stroke = _ref5$stroke === void 0 ? '#000' : _ref5$stroke;
499
+
424
500
  return {
425
501
  fontWeight: fontWeight,
426
502
  fontFamily: fontFamily,
@@ -434,41 +510,40 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
434
510
  stroke: stroke
435
511
  };
436
512
  }
437
-
438
513
  /**
439
514
  * 生成文字布局(对照文字纹理字典提取对应文字的位置很好信息)
440
515
  */
516
+
441
517
  }, {
442
518
  key: "generateGlyphLayout",
443
519
  value: function generateGlyphLayout(iconfont) {
444
520
  var _this2 = this;
521
+
445
522
  var mapping = this.getFontServiceMapping();
523
+
446
524
  var _ref6 = this.layer.getLayerConfig(),
447
- _ref6$spacing = _ref6.spacing,
448
- spacing = _ref6$spacing === void 0 ? 2 : _ref6$spacing,
449
- _ref6$textAnchor = _ref6.textAnchor,
450
- textAnchor = _ref6$textAnchor === void 0 ? 'center' : _ref6$textAnchor,
451
- textOffset = _ref6.textOffset;
525
+ _ref6$spacing = _ref6.spacing,
526
+ spacing = _ref6$spacing === void 0 ? 2 : _ref6$spacing,
527
+ _ref6$textAnchor = _ref6.textAnchor,
528
+ textAnchor = _ref6$textAnchor === void 0 ? 'center' : _ref6$textAnchor,
529
+ textOffset = _ref6.textOffset;
530
+
452
531
  var data = this.rawEncodeData;
453
532
  this.glyphInfo = data.map(function (feature) {
454
533
  var _feature$shape = feature.shape,
455
- shape = _feature$shape === void 0 ? '' : _feature$shape,
456
- id = feature.id,
457
- _feature$size2 = feature.size,
458
- size = _feature$size2 === void 0 ? 1 : _feature$size2;
459
- var shaping = shapeText(shape.toString(), mapping,
460
- // @ts-ignore
461
- size, textAnchor, 'left', spacing, textOffset,
462
- // || feature['textOffset'] || [0, 0],// TODO: 文字偏移量 CPU 计算
534
+ shape = _feature$shape === void 0 ? '' : _feature$shape,
535
+ id = feature.id,
536
+ _feature$size2 = feature.size,
537
+ size = _feature$size2 === void 0 ? 1 : _feature$size2;
538
+ var shaping = shapeText(shape.toString(), mapping, // @ts-ignore
539
+ size, textAnchor, 'left', spacing, textOffset, // || feature['textOffset'] || [0, 0],// TODO: 文字偏移量 CPU 计算
463
540
  iconfont);
464
541
  var glyphQuads = getGlyphQuads(shaping, textOffset, false);
465
542
  feature.shaping = shaping;
466
- feature.glyphQuads = glyphQuads;
467
- // feature.centroid = calculteCentroid(coordinates);
543
+ feature.glyphQuads = glyphQuads; // feature.centroid = calculteCentroid(coordinates);
468
544
 
469
- feature.centroid = calculateCentroid(feature.coordinates);
545
+ feature.centroid = calculateCentroid(feature.coordinates); // 此时地图高德2.0 originCentroid == centroid
470
546
 
471
- // 此时地图高德2.0 originCentroid == centroid
472
547
  feature.originCentroid = feature.version === 'GAODE2.x' ? calculateCentroid(feature.originCoordinates) : feature.originCentroid = feature.centroid;
473
548
  _this2.glyphInfoMap[id] = {
474
549
  shaping: shaping,
@@ -482,66 +557,76 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
482
557
  key: "getFontServiceMapping",
483
558
  value: function getFontServiceMapping() {
484
559
  var _ref7 = this.layer.getLayerConfig(),
485
- _ref7$fontWeight = _ref7.fontWeight,
486
- fontWeight = _ref7$fontWeight === void 0 ? '400' : _ref7$fontWeight,
487
- _ref7$fontFamily = _ref7.fontFamily,
488
- fontFamily = _ref7$fontFamily === void 0 ? 'sans-serif' : _ref7$fontFamily;
560
+ _ref7$fontWeight = _ref7.fontWeight,
561
+ fontWeight = _ref7$fontWeight === void 0 ? '400' : _ref7$fontWeight,
562
+ _ref7$fontFamily = _ref7.fontFamily,
563
+ fontFamily = _ref7$fontFamily === void 0 ? 'sans-serif' : _ref7$fontFamily;
564
+
489
565
  return this.fontService.getMappingByKey("".concat(fontFamily, "_").concat(fontWeight));
490
566
  }
491
567
  }, {
492
568
  key: "getFontServiceCanvas",
493
569
  value: function getFontServiceCanvas() {
494
570
  var _ref8 = this.layer.getLayerConfig(),
495
- _ref8$fontWeight = _ref8.fontWeight,
496
- fontWeight = _ref8$fontWeight === void 0 ? '400' : _ref8$fontWeight,
497
- _ref8$fontFamily = _ref8.fontFamily,
498
- fontFamily = _ref8$fontFamily === void 0 ? 'sans-serif' : _ref8$fontFamily;
499
- // 更新文字布局
571
+ _ref8$fontWeight = _ref8.fontWeight,
572
+ fontWeight = _ref8$fontWeight === void 0 ? '400' : _ref8$fontWeight,
573
+ _ref8$fontFamily = _ref8.fontFamily,
574
+ fontFamily = _ref8$fontFamily === void 0 ? 'sans-serif' : _ref8$fontFamily; // 更新文字布局
575
+
576
+
500
577
  return this.fontService.getCanvasByKey("".concat(fontFamily, "_").concat(fontWeight));
501
578
  }
502
-
503
579
  /**
504
580
  * 文字避让 depend on originCentorid
505
581
  */
582
+
506
583
  }, {
507
584
  key: "filterGlyphs",
508
585
  value: function filterGlyphs() {
509
586
  var _this3 = this;
587
+
510
588
  var _ref9 = this.layer.getLayerConfig(),
511
- _ref9$padding = _ref9.padding,
512
- padding = _ref9$padding === void 0 ? [0, 0] : _ref9$padding,
513
- _ref9$textAllowOverla = _ref9.textAllowOverlap,
514
- textAllowOverlap = _ref9$textAllowOverla === void 0 ? false : _ref9$textAllowOverla;
589
+ _ref9$padding = _ref9.padding,
590
+ padding = _ref9$padding === void 0 ? [0, 0] : _ref9$padding,
591
+ _ref9$textAllowOverla = _ref9.textAllowOverlap,
592
+ textAllowOverlap = _ref9$textAllowOverla === void 0 ? false : _ref9$textAllowOverla;
593
+
515
594
  if (textAllowOverlap) {
516
595
  // 如果允许文本覆盖
517
596
  return;
518
597
  }
598
+
519
599
  this.glyphInfoMap = {};
520
600
  this.currentZoom = this.mapService.getZoom();
521
601
  this.extent = this.textExtent();
602
+
522
603
  var _this$rendererService = this.rendererService.getViewportSize(),
523
- width = _this$rendererService.width,
524
- height = _this$rendererService.height;
604
+ width = _this$rendererService.width,
605
+ height = _this$rendererService.height;
606
+
525
607
  var collisionIndex = new CollisionIndex(width, height);
526
608
  var filterData = this.glyphInfo.filter(function (feature) {
527
609
  var shaping = feature.shaping,
528
- _feature$id = feature.id,
529
- id = _feature$id === void 0 ? 0 : _feature$id;
530
- // const centroid = feature.centroid as [number, number];
610
+ _feature$id = feature.id,
611
+ id = _feature$id === void 0 ? 0 : _feature$id; // const centroid = feature.centroid as [number, number];
531
612
  // const centroid = feature.originCentroid as [number, number];
613
+
532
614
  var centroid = feature.version === 'GAODE2.x' ? feature.originCentroid : feature.centroid;
533
615
  var size = feature.size;
534
616
  var fontScale = size / 16;
617
+
535
618
  var pixels = _this3.mapService.lngLatToContainer(centroid);
619
+
536
620
  var _collisionIndex$place = collisionIndex.placeCollisionBox({
537
- x1: shaping.left * fontScale - padding[0],
538
- x2: shaping.right * fontScale + padding[0],
539
- y1: shaping.top * fontScale - padding[1],
540
- y2: shaping.bottom * fontScale + padding[1],
541
- anchorPointX: pixels.x,
542
- anchorPointY: pixels.y
543
- }),
544
- box = _collisionIndex$place.box;
621
+ x1: shaping.left * fontScale - padding[0],
622
+ x2: shaping.right * fontScale + padding[0],
623
+ y1: shaping.top * fontScale - padding[1],
624
+ y2: shaping.bottom * fontScale + padding[1],
625
+ anchorPointX: pixels.x,
626
+ anchorPointY: pixels.y
627
+ }),
628
+ box = _collisionIndex$place.box;
629
+
545
630
  if (box && box.length) {
546
631
  collisionIndex.insertCollisionBox(box, id);
547
632
  return true;
@@ -552,35 +637,39 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
552
637
  filterData.forEach(function (item) {
553
638
  // @ts-ignore
554
639
  _this3.glyphInfoMap[item.id] = item;
555
- });
556
- // this.layer.setEncodedData(filterData);
640
+ }); // this.layer.setEncodedData(filterData);
557
641
  }
558
642
  /**
559
643
  * 初始化文字布局
560
644
  */
645
+
561
646
  }, {
562
647
  key: "initGlyph",
563
648
  value: function initGlyph() {
564
649
  var _this$layer$getLayerC = this.layer.getLayerConfig(),
565
- _this$layer$getLayerC2 = _this$layer$getLayerC.iconfont,
566
- iconfont = _this$layer$getLayerC2 === void 0 ? false : _this$layer$getLayerC2;
567
- // 1.生成文字纹理(或是生成 iconfont)
568
- iconfont ? this.initIconFontTex() : this.initTextFont();
569
- // 2.生成文字布局
650
+ _this$layer$getLayerC2 = _this$layer$getLayerC.iconfont,
651
+ iconfont = _this$layer$getLayerC2 === void 0 ? false : _this$layer$getLayerC2; // 1.生成文字纹理(或是生成 iconfont)
652
+
653
+
654
+ iconfont ? this.initIconFontTex() : this.initTextFont(); // 2.生成文字布局
655
+
570
656
  this.generateGlyphLayout(iconfont);
571
657
  }
572
658
  /**
573
659
  * 更新文字纹理
574
660
  */
661
+
575
662
  }, {
576
663
  key: "updateTexture",
577
664
  value: function updateTexture() {
578
665
  var createTexture2D = this.rendererService.createTexture2D;
579
666
  var canvas = this.getFontServiceCanvas();
580
667
  this.textureHeight = canvas.height;
668
+
581
669
  if (this.texture) {
582
670
  this.texture.destroy();
583
671
  }
672
+
584
673
  this.texture = createTexture2D({
585
674
  data: canvas,
586
675
  mag: gl.LINEAR,
@@ -595,36 +684,44 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
595
684
  var _reBuildModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
596
685
  var model;
597
686
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
598
- while (1) switch (_context5.prev = _context5.next) {
599
- case 0:
600
- this.filterGlyphs();
601
- _context5.next = 3;
602
- return this.layer.buildLayerModel({
603
- moduleName: 'pointText',
604
- vertexShader: textVert,
605
- fragmentShader: textFrag,
606
- triangulation: TextTrianglation.bind(this),
607
- inject: this.getInject(),
608
- depth: {
609
- enable: false
610
- }
611
- });
612
- case 3:
613
- model = _context5.sent;
614
- // TODO 渲染流程待修改
615
- this.layer.models = [model];
616
- case 5:
617
- case "end":
618
- return _context5.stop();
687
+ while (1) {
688
+ switch (_context5.prev = _context5.next) {
689
+ case 0:
690
+ this.filterGlyphs();
691
+ _context5.next = 3;
692
+ return this.layer.buildLayerModel({
693
+ moduleName: 'pointText',
694
+ vertexShader: textVert,
695
+ fragmentShader: textFrag,
696
+ triangulation: TextTrianglation.bind(this),
697
+ inject: this.getInject(),
698
+ depth: {
699
+ enable: false
700
+ }
701
+ });
702
+
703
+ case 3:
704
+ model = _context5.sent;
705
+ // TODO 渲染流程待修改
706
+ this.layer.models = [model];
707
+
708
+ case 5:
709
+ case "end":
710
+ return _context5.stop();
711
+ }
619
712
  }
620
713
  }, _callee5, this);
621
714
  }));
715
+
622
716
  function reBuildModel() {
623
717
  return _reBuildModel.apply(this, arguments);
624
718
  }
719
+
625
720
  return reBuildModel;
626
721
  }()
627
722
  }]);
723
+
628
724
  return TextModel;
629
725
  }(BaseModel);
726
+
630
727
  export { TextModel as default };