@antv/l7-layers 2.15.5 → 2.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) 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 +486 -321
  10. package/es/core/BaseModel.js +126 -97
  11. package/es/core/LayerPickService.js +32 -21
  12. package/es/core/TextureService.js +13 -0
  13. package/es/core/interface.js +24 -17
  14. package/es/core/shape/Path.js +20 -13
  15. package/es/core/shape/extrude.js +31 -10
  16. package/es/core/triangulation.js +114 -54
  17. package/es/earth/index.js +33 -9
  18. package/es/earth/models/atmosphere.js +54 -30
  19. package/es/earth/models/base.js +85 -47
  20. package/es/earth/models/bloomsphere.js +54 -30
  21. package/es/earth/utils.js +13 -9
  22. package/es/heatmap/index.js +40 -10
  23. package/es/heatmap/models/grid.js +52 -28
  24. package/es/heatmap/models/grid3d.js +52 -28
  25. package/es/heatmap/models/heatmap.js +146 -91
  26. package/es/heatmap/models/hexagon.js +52 -28
  27. package/es/heatmap/triangulation.js +4 -0
  28. package/es/image/index.js +28 -9
  29. package/es/image/models/image.js +100 -66
  30. package/es/index.js +17 -9
  31. package/es/line/index.js +34 -9
  32. package/es/line/models/arc.js +118 -66
  33. package/es/line/models/arc_3d.js +108 -60
  34. package/es/line/models/earthArc_3d.js +111 -63
  35. package/es/line/models/great_circle.js +100 -56
  36. package/es/line/models/half.js +77 -46
  37. package/es/line/models/line.js +148 -94
  38. package/es/line/models/linearline.js +80 -45
  39. package/es/line/models/simpleLine.js +74 -41
  40. package/es/line/models/wall.js +92 -52
  41. package/es/mask/index.js +28 -9
  42. package/es/mask/models/fill.js +54 -29
  43. package/es/plugins/DataMappingPlugin.js +117 -80
  44. package/es/plugins/DataSourcePlugin.js +68 -45
  45. package/es/plugins/FeatureScalePlugin.js +122 -67
  46. package/es/plugins/LayerAnimateStylePlugin.js +5 -0
  47. package/es/plugins/LayerMaskPlugin.js +11 -3
  48. package/es/plugins/LayerModelPlugin.js +104 -67
  49. package/es/plugins/LayerStylePlugin.js +9 -3
  50. package/es/plugins/LightingPlugin.js +18 -12
  51. package/es/plugins/MultiPassRendererPlugin.js +16 -11
  52. package/es/plugins/PixelPickingPlugin.js +21 -12
  53. package/es/plugins/RegisterStyleAttributePlugin.js +12 -5
  54. package/es/plugins/ShaderUniformPlugin.js +27 -13
  55. package/es/plugins/UpdateModelPlugin.js +5 -0
  56. package/es/plugins/UpdateStyleAttributePlugin.js +11 -5
  57. package/es/point/index.js +77 -26
  58. package/es/point/models/earthExtrude.js +102 -61
  59. package/es/point/models/earthFill.js +87 -57
  60. package/es/point/models/extrude.js +101 -60
  61. package/es/point/models/fill.js +100 -70
  62. package/es/point/models/fillmage.js +107 -63
  63. package/es/point/models/image.js +88 -48
  64. package/es/point/models/index.js +2 -2
  65. package/es/point/models/normal.js +54 -30
  66. package/es/point/models/radar.js +64 -40
  67. package/es/point/models/simplePoint.js +69 -41
  68. package/es/point/models/text.d.ts +2 -1
  69. package/es/point/models/text.js +305 -201
  70. package/es/point/shape/extrude.js +13 -4
  71. package/es/polygon/index.js +40 -11
  72. package/es/polygon/models/extrude.js +92 -48
  73. package/es/polygon/models/fill.js +88 -54
  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/dataMappingStyle.js +18 -8
  104. package/es/utils/extrude_polyline.js +149 -101
  105. package/es/utils/grid-index.js +27 -2
  106. package/es/utils/identityScale.js +8 -0
  107. package/es/utils/layerData.js +44 -30
  108. package/es/utils/multiPassRender.js +13 -11
  109. package/es/utils/polylineNormal.js +37 -31
  110. package/es/utils/simpleLine.js +16 -2
  111. package/es/utils/stencil.js +3 -2
  112. package/es/utils/symbol-layout.js +53 -27
  113. package/es/wind/index.js +29 -9
  114. package/es/wind/models/utils.js +51 -26
  115. package/es/wind/models/wind.js +147 -101
  116. package/es/wind/models/windRender.js +66 -53
  117. package/lib/Geometry/index.js +38 -9
  118. package/lib/Geometry/models/billboard.js +97 -51
  119. package/lib/Geometry/models/index.js +5 -0
  120. package/lib/Geometry/models/plane.js +151 -79
  121. package/lib/Geometry/models/sprite.js +127 -60
  122. package/lib/canvas/index.js +40 -10
  123. package/lib/canvas/models/canvas.js +101 -41
  124. package/lib/canvas/models/index.js +3 -0
  125. package/lib/citybuliding/building.js +35 -8
  126. package/lib/citybuliding/models/build.js +92 -57
  127. package/lib/core/BaseLayer.js +480 -321
  128. package/lib/core/BaseModel.js +139 -97
  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 +54 -10
  135. package/lib/core/triangulation.js +153 -53
  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 +162 -91
  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 +128 -64
  154. package/lib/line/models/arc_3d.js +119 -58
  155. package/lib/line/models/earthArc_3d.js +122 -61
  156. package/lib/line/models/great_circle.js +111 -56
  157. package/lib/line/models/half.js +87 -46
  158. package/lib/line/models/index.js +11 -0
  159. package/lib/line/models/line.js +156 -92
  160. package/lib/line/models/linearline.js +92 -45
  161. package/lib/line/models/simpleLine.js +84 -41
  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 +128 -80
  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 +113 -68
  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 +113 -61
  182. package/lib/point/models/earthFill.js +117 -57
  183. package/lib/point/models/extrude.js +111 -60
  184. package/lib/point/models/fill.js +109 -68
  185. package/lib/point/models/fillmage.js +115 -61
  186. package/lib/point/models/image.js +98 -48
  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 +74 -40
  190. package/lib/point/models/simplePoint.js +79 -41
  191. package/lib/point/models/text.js +314 -202
  192. package/lib/point/shape/extrude.js +20 -4
  193. package/lib/polygon/index.js +48 -11
  194. package/lib/polygon/models/extrude.js +103 -48
  195. package/lib/polygon/models/fill.js +98 -54
  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/dataMappingStyle.js +19 -8
  228. package/lib/utils/extrude_polyline.js +181 -101
  229. package/lib/utils/grid-index.js +28 -2
  230. package/lib/utils/identityScale.js +9 -0
  231. package/lib/utils/layerData.js +49 -30
  232. package/lib/utils/multiPassRender.js +16 -11
  233. package/lib/utils/polylineNormal.js +66 -31
  234. package/lib/utils/simpleLine.js +21 -2
  235. package/lib/utils/stencil.js +4 -0
  236. package/lib/utils/symbol-layout.js +55 -27
  237. package/lib/wind/index.js +37 -9
  238. package/lib/wind/models/index.js +3 -0
  239. package/lib/wind/models/utils.js +62 -26
  240. package/lib/wind/models/wind.js +157 -101
  241. package/lib/wind/models/windRender.js +71 -53
  242. package/lib/wind/models/windShader.js +1 -0
  243. package/package.json +7 -7
@@ -1,42 +1,68 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
- exports.TextTriangulation = TextTriangulation;
8
+ exports.TextTrianglation = TextTrianglation;
8
9
  exports.default = void 0;
10
+
9
11
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
12
+
10
13
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
+
11
15
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
16
+
12
17
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
18
+
13
19
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
20
+
14
21
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
22
+
15
23
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
24
+
16
25
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
26
+
17
27
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
28
+
18
29
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
30
+
19
31
  var _l7Core = require("@antv/l7-core");
32
+
20
33
  var _l7Utils = require("@antv/l7-utils");
34
+
21
35
  var _lodash = require("lodash");
36
+
22
37
  var _BaseModel2 = _interopRequireDefault(require("../../core/BaseModel"));
38
+
23
39
  var _collisionIndex = _interopRequireDefault(require("../../utils/collision-index"));
40
+
24
41
  var _symbolLayout = require("../../utils/symbol-layout");
42
+
25
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
+
26
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); }
27
- 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; }
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
+
28
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
+
29
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
+
30
53
  /* babel-plugin-inline-import '../shaders/text_frag.glsl' */
31
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 // \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";
55
+
32
56
  /* babel-plugin-inline-import '../shaders/text_vert.glsl' */
33
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";
34
- function TextTriangulation(feature) {
58
+
59
+ function TextTrianglation(feature) {
35
60
  // @ts-ignore
36
61
  var that = this;
37
62
  var id = feature.id;
38
63
  var vertices = [];
39
64
  var indices = [];
65
+
40
66
  if (!that.glyphInfoMap || !that.glyphInfoMap[id]) {
41
67
  return {
42
68
  vertices: [],
@@ -45,7 +71,9 @@ function TextTriangulation(feature) {
45
71
  size: 7
46
72
  };
47
73
  }
74
+
48
75
  var centroid = that.glyphInfoMap[id].centroid; // 计算中心点
76
+
49
77
  var coord = centroid.length === 2 ? [centroid[0], centroid[1], 0] : centroid;
50
78
  that.glyphInfoMap[id].glyphQuads.forEach(function (quad, index) {
51
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]));
@@ -58,15 +86,21 @@ function TextTriangulation(feature) {
58
86
  size: 7
59
87
  };
60
88
  }
89
+
61
90
  var TextModel = /*#__PURE__*/function (_BaseModel) {
62
91
  (0, _inherits2.default)(TextModel, _BaseModel);
92
+
63
93
  var _super = _createSuper(TextModel);
94
+
64
95
  function TextModel() {
65
96
  var _this;
97
+
66
98
  (0, _classCallCheck2.default)(this, TextModel);
99
+
67
100
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
68
101
  args[_key] = arguments[_key];
69
102
  }
103
+
70
104
  _this = _super.call.apply(_super, [this].concat(args));
71
105
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "glyphInfoMap", {});
72
106
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "currentZoom", -1);
@@ -75,43 +109,54 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
75
109
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "preTextStyle", {});
76
110
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "mapping", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
77
111
  return _regenerator.default.wrap(function _callee$(_context) {
78
- while (1) switch (_context.prev = _context.next) {
79
- case 0:
80
- _this.initGlyph(); //
81
- _this.updateTexture();
82
- _context.next = 4;
83
- return _this.reBuildModel();
84
- case 4:
85
- case "end":
86
- return _context.stop();
112
+ while (1) {
113
+ switch (_context.prev = _context.next) {
114
+ case 0:
115
+ _this.initGlyph(); //
116
+
117
+
118
+ _this.updateTexture();
119
+
120
+ _context.next = 4;
121
+ return _this.reBuildModel();
122
+
123
+ case 4:
124
+ case "end":
125
+ return _context.stop();
126
+ }
87
127
  }
88
128
  }, _callee);
89
129
  })));
90
130
  return _this;
91
131
  }
132
+
92
133
  (0, _createClass2.default)(TextModel, [{
93
134
  key: "getUninforms",
94
135
  value: function getUninforms() {
95
136
  var _ref2 = this.layer.getLayerConfig(),
96
- _ref2$opacity = _ref2.opacity,
97
- opacity = _ref2$opacity === void 0 ? 1.0 : _ref2$opacity,
98
- _ref2$stroke = _ref2.stroke,
99
- stroke = _ref2$stroke === void 0 ? '#fff' : _ref2$stroke,
100
- _ref2$strokeWidth = _ref2.strokeWidth,
101
- strokeWidth = _ref2$strokeWidth === void 0 ? 0 : _ref2$strokeWidth,
102
- _ref2$halo = _ref2.halo,
103
- halo = _ref2$halo === void 0 ? 0.5 : _ref2$halo,
104
- _ref2$gamma = _ref2.gamma,
105
- gamma = _ref2$gamma === void 0 ? 2.0 : _ref2$gamma,
106
- _ref2$raisingHeight = _ref2.raisingHeight,
107
- raisingHeight = _ref2$raisingHeight === void 0 ? 0 : _ref2$raisingHeight;
137
+ _ref2$opacity = _ref2.opacity,
138
+ opacity = _ref2$opacity === void 0 ? 1.0 : _ref2$opacity,
139
+ _ref2$stroke = _ref2.stroke,
140
+ stroke = _ref2$stroke === void 0 ? '#fff' : _ref2$stroke,
141
+ _ref2$strokeWidth = _ref2.strokeWidth,
142
+ strokeWidth = _ref2$strokeWidth === void 0 ? 0 : _ref2$strokeWidth,
143
+ _ref2$halo = _ref2.halo,
144
+ halo = _ref2$halo === void 0 ? 0.5 : _ref2$halo,
145
+ _ref2$gamma = _ref2.gamma,
146
+ gamma = _ref2$gamma === void 0 ? 2.0 : _ref2$gamma,
147
+ _ref2$raisingHeight = _ref2.raisingHeight,
148
+ raisingHeight = _ref2$raisingHeight === void 0 ? 0 : _ref2$raisingHeight;
149
+
108
150
  var mapping = this.getFontServiceMapping();
109
151
  var canvas = this.getFontServiceCanvas();
152
+
110
153
  if (mapping && Object.keys(mapping).length !== this.textCount && canvas) {
111
154
  this.updateTexture();
112
155
  this.textCount = Object.keys(mapping).length;
113
156
  }
157
+
114
158
  this.preTextStyle = this.getTextStyle();
159
+
115
160
  if (this.dataTextureTest && this.dataTextureNeedUpdate({
116
161
  opacity: opacity,
117
162
  strokeWidth: strokeWidth,
@@ -123,11 +168,14 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
123
168
  stroke: stroke
124
169
  });
125
170
  var encodeData = this.layer.getEncodedData();
171
+
126
172
  var _this$calDataFrame = this.calDataFrame(this.cellLength, encodeData, this.cellProperties),
127
- data = _this$calDataFrame.data,
128
- width = _this$calDataFrame.width,
129
- height = _this$calDataFrame.height;
173
+ data = _this$calDataFrame.data,
174
+ width = _this$calDataFrame.width,
175
+ height = _this$calDataFrame.height;
176
+
130
177
  this.rowCount = height; // 当前数据纹理有多少行
178
+
131
179
  this.dataTexture = this.cellLength > 0 && data.length > 0 ? this.createTexture2D({
132
180
  flipY: true,
133
181
  data: data,
@@ -144,6 +192,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
144
192
  height: 1
145
193
  });
146
194
  }
195
+
147
196
  return {
148
197
  u_dataTexture: this.dataTexture,
149
198
  // 数据纹理 - 有数据映射的时候纹理中带数据,若没有任何数据映射时纹理是 [1]
@@ -163,22 +212,28 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
163
212
  value: function () {
164
213
  var _initModels = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
165
214
  return _regenerator.default.wrap(function _callee2$(_context2) {
166
- while (1) switch (_context2.prev = _context2.next) {
167
- case 0:
168
- // 绑定事件
169
- this.bindEvent();
170
- this.extent = this.textExtent();
171
- this.preTextStyle = this.getTextStyle();
172
- return _context2.abrupt("return", this.buildModels());
173
- case 4:
174
- case "end":
175
- return _context2.stop();
215
+ while (1) {
216
+ switch (_context2.prev = _context2.next) {
217
+ case 0:
218
+ // 绑定事件
219
+ this.bindEvent();
220
+ this.extent = this.textExtent();
221
+ this.rawEncodeData = this.layer.getEncodedData();
222
+ this.preTextStyle = this.getTextStyle();
223
+ return _context2.abrupt("return", this.buildModels());
224
+
225
+ case 5:
226
+ case "end":
227
+ return _context2.stop();
228
+ }
176
229
  }
177
230
  }, _callee2, this);
178
231
  }));
232
+
179
233
  function initModels() {
180
234
  return _initModels.apply(this, arguments);
181
235
  }
236
+
182
237
  return initModels;
183
238
  }()
184
239
  }, {
@@ -186,37 +241,48 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
186
241
  value: function () {
187
242
  var _buildModels = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
188
243
  var _ref3, _ref3$textAllowOverla, textAllowOverlap, model;
244
+
189
245
  return _regenerator.default.wrap(function _callee3$(_context3) {
190
- while (1) switch (_context3.prev = _context3.next) {
191
- case 0:
192
- _ref3 = this.layer.getLayerConfig(), _ref3$textAllowOverla = _ref3.textAllowOverlap, textAllowOverlap = _ref3$textAllowOverla === void 0 ? false : _ref3$textAllowOverla; // this.mapping(); 重复调用
193
- this.initGlyph(); //
194
- this.updateTexture();
195
- if (!textAllowOverlap) {
196
- this.filterGlyphs();
197
- }
198
- _context3.next = 6;
199
- return this.layer.buildLayerModel({
200
- moduleName: 'pointText',
201
- vertexShader: textVert,
202
- fragmentShader: textFrag,
203
- triangulation: TextTriangulation.bind(this),
204
- depth: {
205
- enable: false
246
+ while (1) {
247
+ switch (_context3.prev = _context3.next) {
248
+ case 0:
249
+ _ref3 = this.layer.getLayerConfig(), _ref3$textAllowOverla = _ref3.textAllowOverlap, textAllowOverlap = _ref3$textAllowOverla === void 0 ? false : _ref3$textAllowOverla; // this.mapping(); 重复调用
250
+
251
+ this.initGlyph(); //
252
+
253
+ this.updateTexture();
254
+
255
+ if (!textAllowOverlap) {
256
+ this.filterGlyphs();
206
257
  }
207
- });
208
- case 6:
209
- model = _context3.sent;
210
- return _context3.abrupt("return", [model]);
211
- case 8:
212
- case "end":
213
- return _context3.stop();
258
+
259
+ _context3.next = 6;
260
+ return this.layer.buildLayerModel({
261
+ moduleName: 'pointText',
262
+ vertexShader: textVert,
263
+ fragmentShader: textFrag,
264
+ triangulation: TextTrianglation.bind(this),
265
+ depth: {
266
+ enable: false
267
+ }
268
+ });
269
+
270
+ case 6:
271
+ model = _context3.sent;
272
+ return _context3.abrupt("return", [model]);
273
+
274
+ case 8:
275
+ case "end":
276
+ return _context3.stop();
277
+ }
214
278
  }
215
279
  }, _callee3, this);
216
280
  }));
281
+
217
282
  function buildModels() {
218
283
  return _buildModels.apply(this, arguments);
219
284
  }
285
+
220
286
  return buildModels;
221
287
  }() // 需要更新的场景
222
288
  // 1. 文本偏移量发生改变
@@ -224,62 +290,80 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
224
290
  // 3. 文本允许重叠发生改变
225
291
  // 4. 文本字体发生改变
226
292
  // 5. 文本字体粗细发生改变
293
+
227
294
  }, {
228
295
  key: "needUpdate",
229
296
  value: function () {
230
297
  var _needUpdate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
231
298
  var _ref4, _ref4$textAllowOverla, textAllowOverlap, _ref4$textAnchor, textAnchor, textOffset, padding, fontFamily, fontWeight, zoom, extent, flag;
299
+
232
300
  return _regenerator.default.wrap(function _callee4$(_context4) {
233
- while (1) switch (_context4.prev = _context4.next) {
234
- case 0:
235
- _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;
236
- if (!(!(0, _lodash.isEqual)(padding, this.preTextStyle.padding) || !(0, _lodash.isEqual)(textOffset, this.preTextStyle.textOffset) || !(0, _lodash.isEqual)(textAnchor, this.preTextStyle.textAnchor) || !(0, _lodash.isEqual)(fontFamily, this.preTextStyle.fontFamily) || !(0, _lodash.isEqual)(fontWeight, this.preTextStyle.fontWeight))) {
237
- _context4.next = 5;
238
- break;
239
- }
240
- _context4.next = 4;
241
- return this.mapping();
242
- case 4:
243
- return _context4.abrupt("return", true);
244
- case 5:
245
- if (!textAllowOverlap) {
246
- _context4.next = 7;
247
- break;
248
- }
249
- return _context4.abrupt("return", false);
250
- case 7:
251
- // textAllowOverlap 发生改变
252
- zoom = this.mapService.getZoom();
253
- extent = this.mapService.getBounds();
254
- flag = (0, _l7Utils.boundsContains)(this.extent, extent); // 文本不能压盖则进行过滤
255
- if (!(Math.abs(this.currentZoom - zoom) > 0.5 || !flag || textAllowOverlap !== this.preTextStyle.textAllowOverlap)) {
256
- _context4.next = 14;
257
- break;
258
- }
259
- _context4.next = 13;
260
- return this.reBuildModel();
261
- case 13:
262
- return _context4.abrupt("return", true);
263
- case 14:
264
- return _context4.abrupt("return", false);
265
- case 15:
266
- case "end":
267
- return _context4.stop();
301
+ while (1) {
302
+ switch (_context4.prev = _context4.next) {
303
+ case 0:
304
+ _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;
305
+
306
+ if (!(!(0, _lodash.isEqual)(padding, this.preTextStyle.padding) || !(0, _lodash.isEqual)(textOffset, this.preTextStyle.textOffset) || !(0, _lodash.isEqual)(textAnchor, this.preTextStyle.textAnchor) || !(0, _lodash.isEqual)(fontFamily, this.preTextStyle.fontFamily) || !(0, _lodash.isEqual)(fontWeight, this.preTextStyle.fontWeight))) {
307
+ _context4.next = 5;
308
+ break;
309
+ }
310
+
311
+ _context4.next = 4;
312
+ return this.mapping();
313
+
314
+ case 4:
315
+ return _context4.abrupt("return", true);
316
+
317
+ case 5:
318
+ if (!textAllowOverlap) {
319
+ _context4.next = 7;
320
+ break;
321
+ }
322
+
323
+ return _context4.abrupt("return", false);
324
+
325
+ case 7:
326
+ // textAllowOverlap 发生改变
327
+ zoom = this.mapService.getZoom();
328
+ extent = this.mapService.getBounds();
329
+ flag = (0, _l7Utils.boundsContains)(this.extent, extent); // 文本不能压盖则进行过滤
330
+
331
+ if (!(Math.abs(this.currentZoom - zoom) > 0.5 || !flag || textAllowOverlap !== this.preTextStyle.textAllowOverlap)) {
332
+ _context4.next = 14;
333
+ break;
334
+ }
335
+
336
+ _context4.next = 13;
337
+ return this.reBuildModel();
338
+
339
+ case 13:
340
+ return _context4.abrupt("return", true);
341
+
342
+ case 14:
343
+ return _context4.abrupt("return", false);
344
+
345
+ case 15:
346
+ case "end":
347
+ return _context4.stop();
348
+ }
268
349
  }
269
350
  }, _callee4, this);
270
351
  }));
352
+
271
353
  function needUpdate() {
272
354
  return _needUpdate.apply(this, arguments);
273
355
  }
356
+
274
357
  return needUpdate;
275
358
  }()
276
359
  }, {
277
360
  key: "clearModels",
278
361
  value: function clearModels() {
279
362
  var _this$texture, _this$dataTexture;
363
+
280
364
  (_this$texture = this.texture) === null || _this$texture === void 0 ? void 0 : _this$texture.destroy();
281
- (_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy();
282
- // TODO this.mapping
365
+ (_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy(); // TODO this.mapping
366
+
283
367
  this.layer.off('remapping', this.mapping);
284
368
  }
285
369
  }, {
@@ -298,7 +382,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
298
382
  size: 1,
299
383
  update: function update(feature) {
300
384
  var _feature$rotate = feature.rotate,
301
- rotate = _feature$rotate === void 0 ? 0 : _feature$rotate;
385
+ rotate = _feature$rotate === void 0 ? 0 : _feature$rotate;
302
386
  return Array.isArray(rotate) ? [rotate[0]] : [rotate];
303
387
  }
304
388
  }
@@ -319,9 +403,8 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
319
403
  return [vertex[5], vertex[6]];
320
404
  }
321
405
  }
322
- });
406
+ }); // point layer size;
323
407
 
324
- // point layer size;
325
408
  this.styleAttributeService.registerStyleAttribute({
326
409
  name: 'size',
327
410
  type: _l7Core.AttributeType.Attribute,
@@ -336,7 +419,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
336
419
  size: 1,
337
420
  update: function update(feature) {
338
421
  var _feature$size = feature.size,
339
- size = _feature$size === void 0 ? 12 : _feature$size;
422
+ size = _feature$size === void 0 ? 12 : _feature$size;
340
423
  return Array.isArray(size) ? [size[0]] : [size];
341
424
  }
342
425
  }
@@ -375,23 +458,28 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
375
458
  /**
376
459
  * 生成文字纹理(生成文字纹理字典)
377
460
  */
461
+
378
462
  }, {
379
463
  key: "initTextFont",
380
464
  value: function initTextFont() {
381
465
  var _this$getTextStyle = this.getTextStyle(),
382
- fontWeight = _this$getTextStyle.fontWeight,
383
- fontFamily = _this$getTextStyle.fontFamily;
384
- var data = this.layer.getEncodedData();
466
+ fontWeight = _this$getTextStyle.fontWeight,
467
+ fontFamily = _this$getTextStyle.fontFamily;
468
+
469
+ var data = this.rawEncodeData;
385
470
  var characterSet = [];
386
471
  data.forEach(function (item) {
387
472
  var _item$shape = item.shape,
388
- shape = _item$shape === void 0 ? '' : _item$shape;
473
+ shape = _item$shape === void 0 ? '' : _item$shape;
389
474
  shape = shape.toString();
475
+
390
476
  var _iterator = _createForOfIteratorHelper(shape),
391
- _step;
477
+ _step;
478
+
392
479
  try {
393
480
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
394
481
  var char = _step.value;
482
+
395
483
  // 去重
396
484
  if (characterSet.indexOf(char) === -1) {
397
485
  characterSet.push(char);
@@ -410,22 +498,24 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
410
498
  iconfont: false
411
499
  });
412
500
  }
413
-
414
501
  /**
415
502
  * 生成 iconfont 纹理字典
416
503
  */
504
+
417
505
  }, {
418
506
  key: "initIconFontTex",
419
507
  value: function initIconFontTex() {
420
508
  var _this$getTextStyle2 = this.getTextStyle(),
421
- fontWeight = _this$getTextStyle2.fontWeight,
422
- fontFamily = _this$getTextStyle2.fontFamily;
423
- var data = this.layer.getEncodedData();
509
+ fontWeight = _this$getTextStyle2.fontWeight,
510
+ fontFamily = _this$getTextStyle2.fontFamily;
511
+
512
+ var data = this.rawEncodeData;
424
513
  var characterSet = [];
425
514
  data.forEach(function (item) {
426
515
  var _item$shape2 = item.shape,
427
- shape = _item$shape2 === void 0 ? '' : _item$shape2;
516
+ shape = _item$shape2 === void 0 ? '' : _item$shape2;
428
517
  shape = "".concat(shape);
518
+
429
519
  if (characterSet.indexOf(shape) === -1) {
430
520
  characterSet.push(shape);
431
521
  }
@@ -441,26 +531,27 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
441
531
  key: "getTextStyle",
442
532
  value: function getTextStyle() {
443
533
  var _ref5 = this.layer.getLayerConfig(),
444
- _ref5$fontWeight = _ref5.fontWeight,
445
- fontWeight = _ref5$fontWeight === void 0 ? '400' : _ref5$fontWeight,
446
- _ref5$fontFamily = _ref5.fontFamily,
447
- fontFamily = _ref5$fontFamily === void 0 ? 'sans-serif' : _ref5$fontFamily,
448
- _ref5$textAllowOverla = _ref5.textAllowOverlap,
449
- textAllowOverlap = _ref5$textAllowOverla === void 0 ? false : _ref5$textAllowOverla,
450
- _ref5$padding = _ref5.padding,
451
- padding = _ref5$padding === void 0 ? [0, 0] : _ref5$padding,
452
- _ref5$textAnchor = _ref5.textAnchor,
453
- textAnchor = _ref5$textAnchor === void 0 ? 'center' : _ref5$textAnchor,
454
- _ref5$textOffset = _ref5.textOffset,
455
- textOffset = _ref5$textOffset === void 0 ? [0, 0] : _ref5$textOffset,
456
- _ref5$opacity = _ref5.opacity,
457
- opacity = _ref5$opacity === void 0 ? 1 : _ref5$opacity,
458
- _ref5$strokeOpacity = _ref5.strokeOpacity,
459
- strokeOpacity = _ref5$strokeOpacity === void 0 ? 1 : _ref5$strokeOpacity,
460
- _ref5$strokeWidth = _ref5.strokeWidth,
461
- strokeWidth = _ref5$strokeWidth === void 0 ? 0 : _ref5$strokeWidth,
462
- _ref5$stroke = _ref5.stroke,
463
- stroke = _ref5$stroke === void 0 ? '#000' : _ref5$stroke;
534
+ _ref5$fontWeight = _ref5.fontWeight,
535
+ fontWeight = _ref5$fontWeight === void 0 ? '400' : _ref5$fontWeight,
536
+ _ref5$fontFamily = _ref5.fontFamily,
537
+ fontFamily = _ref5$fontFamily === void 0 ? 'sans-serif' : _ref5$fontFamily,
538
+ _ref5$textAllowOverla = _ref5.textAllowOverlap,
539
+ textAllowOverlap = _ref5$textAllowOverla === void 0 ? false : _ref5$textAllowOverla,
540
+ _ref5$padding = _ref5.padding,
541
+ padding = _ref5$padding === void 0 ? [0, 0] : _ref5$padding,
542
+ _ref5$textAnchor = _ref5.textAnchor,
543
+ textAnchor = _ref5$textAnchor === void 0 ? 'center' : _ref5$textAnchor,
544
+ _ref5$textOffset = _ref5.textOffset,
545
+ textOffset = _ref5$textOffset === void 0 ? [0, 0] : _ref5$textOffset,
546
+ _ref5$opacity = _ref5.opacity,
547
+ opacity = _ref5$opacity === void 0 ? 1 : _ref5$opacity,
548
+ _ref5$strokeOpacity = _ref5.strokeOpacity,
549
+ strokeOpacity = _ref5$strokeOpacity === void 0 ? 1 : _ref5$strokeOpacity,
550
+ _ref5$strokeWidth = _ref5.strokeWidth,
551
+ strokeWidth = _ref5$strokeWidth === void 0 ? 0 : _ref5$strokeWidth,
552
+ _ref5$stroke = _ref5.stroke,
553
+ stroke = _ref5$stroke === void 0 ? '#000' : _ref5$stroke;
554
+
464
555
  return {
465
556
  fontWeight: fontWeight,
466
557
  fontFamily: fontFamily,
@@ -474,39 +565,39 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
474
565
  stroke: stroke
475
566
  };
476
567
  }
477
-
478
568
  /**
479
569
  * 生成文字布局(对照文字纹理字典提取对应文字的位置很好信息)
480
570
  */
571
+
481
572
  }, {
482
573
  key: "generateGlyphLayout",
483
574
  value: function generateGlyphLayout(iconfont) {
484
575
  var _this2 = this;
576
+
485
577
  var mapping = this.getFontServiceMapping();
578
+
486
579
  var _ref6 = this.layer.getLayerConfig(),
487
- _ref6$spacing = _ref6.spacing,
488
- spacing = _ref6$spacing === void 0 ? 2 : _ref6$spacing,
489
- _ref6$textAnchor = _ref6.textAnchor,
490
- textAnchor = _ref6$textAnchor === void 0 ? 'center' : _ref6$textAnchor,
491
- textOffset = _ref6.textOffset;
492
- var data = this.layer.getEncodedData();
580
+ _ref6$spacing = _ref6.spacing,
581
+ spacing = _ref6$spacing === void 0 ? 2 : _ref6$spacing,
582
+ _ref6$textAnchor = _ref6.textAnchor,
583
+ textAnchor = _ref6$textAnchor === void 0 ? 'center' : _ref6$textAnchor,
584
+ textOffset = _ref6.textOffset;
585
+
586
+ var data = this.rawEncodeData;
493
587
  this.glyphInfo = data.map(function (feature) {
494
588
  var _feature$shape = feature.shape,
495
- shape = _feature$shape === void 0 ? '' : _feature$shape,
496
- id = feature.id,
497
- _feature$size2 = feature.size,
498
- size = _feature$size2 === void 0 ? 1 : _feature$size2;
499
- var shaping = (0, _symbolLayout.shapeText)(shape.toString(), mapping,
500
- // @ts-ignore
589
+ shape = _feature$shape === void 0 ? '' : _feature$shape,
590
+ id = feature.id,
591
+ _feature$size2 = feature.size,
592
+ size = _feature$size2 === void 0 ? 1 : _feature$size2;
593
+ var shaping = (0, _symbolLayout.shapeText)(shape.toString(), mapping, // @ts-ignore
501
594
  size, textAnchor, 'left', spacing, textOffset || feature.textOffset || [0, 0], iconfont);
502
595
  var glyphQuads = (0, _symbolLayout.getGlyphQuads)(shaping, textOffset, false);
503
596
  feature.shaping = shaping;
504
- feature.glyphQuads = glyphQuads;
505
- // feature.centroid = calculteCentroid(coordinates);
597
+ feature.glyphQuads = glyphQuads; // feature.centroid = calculteCentroid(coordinates);
506
598
 
507
- feature.centroid = (0, _l7Utils.calculateCentroid)(feature.coordinates);
599
+ feature.centroid = (0, _l7Utils.calculateCentroid)(feature.coordinates); // 此时地图高德2.0 originCentroid == centroid
508
600
 
509
- // 此时地图高德2.0 originCentroid == centroid
510
601
  feature.originCentroid = feature.version === 'GAODE2.x' ? (0, _l7Utils.calculateCentroid)(feature.originCoordinates) : feature.originCentroid = feature.centroid;
511
602
  _this2.glyphInfoMap[id] = {
512
603
  shaping: shaping,
@@ -520,66 +611,76 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
520
611
  key: "getFontServiceMapping",
521
612
  value: function getFontServiceMapping() {
522
613
  var _ref7 = this.layer.getLayerConfig(),
523
- _ref7$fontWeight = _ref7.fontWeight,
524
- fontWeight = _ref7$fontWeight === void 0 ? '400' : _ref7$fontWeight,
525
- _ref7$fontFamily = _ref7.fontFamily,
526
- fontFamily = _ref7$fontFamily === void 0 ? 'sans-serif' : _ref7$fontFamily;
614
+ _ref7$fontWeight = _ref7.fontWeight,
615
+ fontWeight = _ref7$fontWeight === void 0 ? '400' : _ref7$fontWeight,
616
+ _ref7$fontFamily = _ref7.fontFamily,
617
+ fontFamily = _ref7$fontFamily === void 0 ? 'sans-serif' : _ref7$fontFamily;
618
+
527
619
  return this.fontService.getMappingByKey("".concat(fontFamily, "_").concat(fontWeight));
528
620
  }
529
621
  }, {
530
622
  key: "getFontServiceCanvas",
531
623
  value: function getFontServiceCanvas() {
532
624
  var _ref8 = this.layer.getLayerConfig(),
533
- _ref8$fontWeight = _ref8.fontWeight,
534
- fontWeight = _ref8$fontWeight === void 0 ? '400' : _ref8$fontWeight,
535
- _ref8$fontFamily = _ref8.fontFamily,
536
- fontFamily = _ref8$fontFamily === void 0 ? 'sans-serif' : _ref8$fontFamily;
537
- // 更新文字布局
625
+ _ref8$fontWeight = _ref8.fontWeight,
626
+ fontWeight = _ref8$fontWeight === void 0 ? '400' : _ref8$fontWeight,
627
+ _ref8$fontFamily = _ref8.fontFamily,
628
+ fontFamily = _ref8$fontFamily === void 0 ? 'sans-serif' : _ref8$fontFamily; // 更新文字布局
629
+
630
+
538
631
  return this.fontService.getCanvasByKey("".concat(fontFamily, "_").concat(fontWeight));
539
632
  }
540
-
541
633
  /**
542
634
  * 文字避让 depend on originCentorid
543
635
  */
636
+
544
637
  }, {
545
638
  key: "filterGlyphs",
546
639
  value: function filterGlyphs() {
547
640
  var _this3 = this;
641
+
548
642
  var _ref9 = this.layer.getLayerConfig(),
549
- _ref9$padding = _ref9.padding,
550
- padding = _ref9$padding === void 0 ? [0, 0] : _ref9$padding,
551
- _ref9$textAllowOverla = _ref9.textAllowOverlap,
552
- textAllowOverlap = _ref9$textAllowOverla === void 0 ? false : _ref9$textAllowOverla;
643
+ _ref9$padding = _ref9.padding,
644
+ padding = _ref9$padding === void 0 ? [0, 0] : _ref9$padding,
645
+ _ref9$textAllowOverla = _ref9.textAllowOverlap,
646
+ textAllowOverlap = _ref9$textAllowOverla === void 0 ? false : _ref9$textAllowOverla;
647
+
553
648
  if (textAllowOverlap) {
554
649
  // 如果允许文本覆盖
555
650
  return;
556
651
  }
652
+
557
653
  this.glyphInfoMap = {};
558
654
  this.currentZoom = this.mapService.getZoom();
559
655
  this.extent = this.textExtent();
656
+
560
657
  var _this$rendererService = this.rendererService.getViewportSize(),
561
- width = _this$rendererService.width,
562
- height = _this$rendererService.height;
658
+ width = _this$rendererService.width,
659
+ height = _this$rendererService.height;
660
+
563
661
  var collisionIndex = new _collisionIndex.default(width, height);
564
662
  var filterData = this.glyphInfo.filter(function (feature) {
565
663
  var shaping = feature.shaping,
566
- _feature$id = feature.id,
567
- id = _feature$id === void 0 ? 0 : _feature$id;
568
- // const centroid = feature.centroid as [number, number];
664
+ _feature$id = feature.id,
665
+ id = _feature$id === void 0 ? 0 : _feature$id; // const centroid = feature.centroid as [number, number];
569
666
  // const centroid = feature.originCentroid as [number, number];
667
+
570
668
  var centroid = feature.version === 'GAODE2.x' ? feature.originCentroid : feature.centroid;
571
669
  var size = feature.size;
572
670
  var fontScale = size / 16;
671
+
573
672
  var pixels = _this3.mapService.lngLatToContainer(centroid);
673
+
574
674
  var _collisionIndex$place = collisionIndex.placeCollisionBox({
575
- x1: shaping.left * fontScale - padding[0],
576
- x2: shaping.right * fontScale + padding[0],
577
- y1: shaping.top * fontScale - padding[1],
578
- y2: shaping.bottom * fontScale + padding[1],
579
- anchorPointX: pixels.x,
580
- anchorPointY: pixels.y
581
- }),
582
- box = _collisionIndex$place.box;
675
+ x1: shaping.left * fontScale - padding[0],
676
+ x2: shaping.right * fontScale + padding[0],
677
+ y1: shaping.top * fontScale - padding[1],
678
+ y2: shaping.bottom * fontScale + padding[1],
679
+ anchorPointX: pixels.x,
680
+ anchorPointY: pixels.y
681
+ }),
682
+ box = _collisionIndex$place.box;
683
+
583
684
  if (box && box.length) {
584
685
  collisionIndex.insertCollisionBox(box, id);
585
686
  return true;
@@ -590,35 +691,39 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
590
691
  filterData.forEach(function (item) {
591
692
  // @ts-ignore
592
693
  _this3.glyphInfoMap[item.id] = item;
593
- });
594
- // this.layer.setEncodedData(filterData);
694
+ }); // this.layer.setEncodedData(filterData);
595
695
  }
596
696
  /**
597
697
  * 初始化文字布局
598
698
  */
699
+
599
700
  }, {
600
701
  key: "initGlyph",
601
702
  value: function initGlyph() {
602
703
  var _this$layer$getLayerC = this.layer.getLayerConfig(),
603
- _this$layer$getLayerC2 = _this$layer$getLayerC.iconfont,
604
- iconfont = _this$layer$getLayerC2 === void 0 ? false : _this$layer$getLayerC2;
605
- // 1.生成文字纹理(或是生成 iconfont)
606
- iconfont ? this.initIconFontTex() : this.initTextFont();
607
- // 2.生成文字布局
704
+ _this$layer$getLayerC2 = _this$layer$getLayerC.iconfont,
705
+ iconfont = _this$layer$getLayerC2 === void 0 ? false : _this$layer$getLayerC2; // 1.生成文字纹理(或是生成 iconfont)
706
+
707
+
708
+ iconfont ? this.initIconFontTex() : this.initTextFont(); // 2.生成文字布局
709
+
608
710
  this.generateGlyphLayout(iconfont);
609
711
  }
610
712
  /**
611
713
  * 更新文字纹理
612
714
  */
715
+
613
716
  }, {
614
717
  key: "updateTexture",
615
718
  value: function updateTexture() {
616
719
  var createTexture2D = this.rendererService.createTexture2D;
617
720
  var canvas = this.getFontServiceCanvas();
618
721
  this.textureHeight = canvas.height;
722
+
619
723
  if (this.texture) {
620
724
  this.texture.destroy();
621
725
  }
726
+
622
727
  this.texture = createTexture2D({
623
728
  data: canvas,
624
729
  mag: _l7Core.gl.LINEAR,
@@ -633,35 +738,42 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
633
738
  var _reBuildModel = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
634
739
  var model;
635
740
  return _regenerator.default.wrap(function _callee5$(_context5) {
636
- while (1) switch (_context5.prev = _context5.next) {
637
- case 0:
638
- this.filterGlyphs();
639
- _context5.next = 3;
640
- return this.layer.buildLayerModel({
641
- moduleName: 'pointText',
642
- vertexShader: textVert,
643
- fragmentShader: textFrag,
644
- triangulation: TextTriangulation.bind(this),
645
- depth: {
646
- enable: false
647
- }
648
- });
649
- case 3:
650
- model = _context5.sent;
651
- // TODO 渲染流程待修改
652
- this.layer.models = [model];
653
- case 5:
654
- case "end":
655
- return _context5.stop();
741
+ while (1) {
742
+ switch (_context5.prev = _context5.next) {
743
+ case 0:
744
+ this.filterGlyphs();
745
+ _context5.next = 3;
746
+ return this.layer.buildLayerModel({
747
+ moduleName: 'pointText',
748
+ vertexShader: textVert,
749
+ fragmentShader: textFrag,
750
+ triangulation: TextTrianglation.bind(this),
751
+ depth: {
752
+ enable: false
753
+ }
754
+ });
755
+
756
+ case 3:
757
+ model = _context5.sent;
758
+ // TODO 渲染流程待修改
759
+ this.layer.models = [model];
760
+
761
+ case 5:
762
+ case "end":
763
+ return _context5.stop();
764
+ }
656
765
  }
657
766
  }, _callee5, this);
658
767
  }));
768
+
659
769
  function reBuildModel() {
660
770
  return _reBuildModel.apply(this, arguments);
661
771
  }
772
+
662
773
  return reBuildModel;
663
774
  }()
664
775
  }]);
665
776
  return TextModel;
666
777
  }(_BaseModel2.default);
778
+
667
779
  exports.default = TextModel;