@antv/l7-layers 2.16.0 → 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 (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 +485 -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.js +301 -198
  69. package/es/point/shape/extrude.js +13 -4
  70. package/es/polygon/index.js +40 -11
  71. package/es/polygon/models/extrude.js +92 -48
  72. package/es/polygon/models/fill.js +88 -54
  73. package/es/polygon/models/index.js +2 -3
  74. package/es/polygon/models/ocean.js +76 -42
  75. package/es/polygon/models/water.js +71 -37
  76. package/es/raster/buffers/triangulation.js +4 -2
  77. package/es/raster/index.js +32 -9
  78. package/es/raster/models/raster.js +116 -80
  79. package/es/raster/models/rasterRgb.js +127 -84
  80. package/es/raster/models/rasterTerrainRgb.js +84 -56
  81. package/es/tile/interaction/getRasterData.js +20 -14
  82. package/es/tile/interaction/utils.js +9 -7
  83. package/es/tile/manager/base.js +96 -63
  84. package/es/tile/service/TileLayerService.js +55 -33
  85. package/es/tile/service/TilePickService.js +40 -26
  86. package/es/tile/service/TileSourceService.js +7 -3
  87. package/es/tile/tileFactory/DebugTile.js +46 -29
  88. package/es/tile/tileFactory/ImageTile.js +38 -20
  89. package/es/tile/tileFactory/MaskTile.js +43 -22
  90. package/es/tile/tileFactory/RasterRGBTile.js +42 -22
  91. package/es/tile/tileFactory/RasterTerrainRGBTile.js +38 -20
  92. package/es/tile/tileFactory/RasterTile.js +53 -30
  93. package/es/tile/tileFactory/Tile.js +97 -63
  94. package/es/tile/tileFactory/VectorTile.js +68 -41
  95. package/es/tile/tileFactory/index.js +11 -0
  96. package/es/tile/tileFactory/layers/TileDebugLayer.js +27 -6
  97. package/es/tile/tileFactory/util.js +3 -0
  98. package/es/tile/tileLayer/BaseLayer.js +146 -105
  99. package/es/tile/utils.js +1 -1
  100. package/es/utils/blend.js +2 -0
  101. package/es/utils/collision-index.js +16 -9
  102. package/es/utils/dataMappingStyle.js +18 -8
  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 +479 -321
  127. package/lib/core/BaseModel.js +139 -97
  128. package/lib/core/LayerPickService.js +37 -21
  129. package/lib/core/TextureService.js +16 -0
  130. package/lib/core/interface.js +31 -21
  131. package/lib/core/schema.js +1 -0
  132. package/lib/core/shape/Path.js +31 -14
  133. package/lib/core/shape/extrude.js +54 -10
  134. package/lib/core/triangulation.js +153 -53
  135. package/lib/earth/index.js +43 -9
  136. package/lib/earth/models/atmosphere.js +63 -30
  137. package/lib/earth/models/base.js +90 -47
  138. package/lib/earth/models/bloomsphere.js +63 -30
  139. package/lib/earth/utils.js +31 -7
  140. package/lib/heatmap/index.js +48 -10
  141. package/lib/heatmap/models/grid.js +60 -28
  142. package/lib/heatmap/models/grid3d.js +60 -28
  143. package/lib/heatmap/models/heatmap.js +162 -91
  144. package/lib/heatmap/models/hexagon.js +60 -28
  145. package/lib/heatmap/models/index.js +6 -0
  146. package/lib/heatmap/triangulation.js +5 -0
  147. package/lib/image/index.js +36 -9
  148. package/lib/image/models/image.js +109 -66
  149. package/lib/image/models/index.js +3 -0
  150. package/lib/index.js +61 -7
  151. package/lib/line/index.js +40 -9
  152. package/lib/line/models/arc.js +128 -64
  153. package/lib/line/models/arc_3d.js +119 -58
  154. package/lib/line/models/earthArc_3d.js +122 -61
  155. package/lib/line/models/great_circle.js +111 -56
  156. package/lib/line/models/half.js +87 -46
  157. package/lib/line/models/index.js +11 -0
  158. package/lib/line/models/line.js +156 -92
  159. package/lib/line/models/linearline.js +92 -45
  160. package/lib/line/models/simpleLine.js +84 -41
  161. package/lib/line/models/wall.js +103 -52
  162. package/lib/mask/index.js +36 -9
  163. package/lib/mask/models/fill.js +63 -29
  164. package/lib/mask/models/index.js +3 -0
  165. package/lib/plugins/DataMappingPlugin.js +128 -80
  166. package/lib/plugins/DataSourcePlugin.js +76 -45
  167. package/lib/plugins/FeatureScalePlugin.js +138 -67
  168. package/lib/plugins/LayerAnimateStylePlugin.js +10 -0
  169. package/lib/plugins/LayerMaskPlugin.js +17 -4
  170. package/lib/plugins/LayerModelPlugin.js +113 -68
  171. package/lib/plugins/LayerStylePlugin.js +14 -4
  172. package/lib/plugins/LightingPlugin.js +25 -12
  173. package/lib/plugins/MultiPassRendererPlugin.js +22 -11
  174. package/lib/plugins/PixelPickingPlugin.js +27 -12
  175. package/lib/plugins/RegisterStyleAttributePlugin.js +19 -5
  176. package/lib/plugins/ShaderUniformPlugin.js +34 -13
  177. package/lib/plugins/UpdateModelPlugin.js +10 -1
  178. package/lib/plugins/UpdateStyleAttributePlugin.js +16 -5
  179. package/lib/point/index.js +83 -26
  180. package/lib/point/models/earthExtrude.js +113 -61
  181. package/lib/point/models/earthFill.js +117 -57
  182. package/lib/point/models/extrude.js +111 -60
  183. package/lib/point/models/fill.js +109 -68
  184. package/lib/point/models/fillmage.js +115 -61
  185. package/lib/point/models/image.js +98 -48
  186. package/lib/point/models/index.js +12 -1
  187. package/lib/point/models/normal.js +64 -30
  188. package/lib/point/models/radar.js +74 -40
  189. package/lib/point/models/simplePoint.js +79 -41
  190. package/lib/point/models/text.js +309 -198
  191. package/lib/point/shape/extrude.js +20 -4
  192. package/lib/polygon/index.js +48 -11
  193. package/lib/polygon/models/extrude.js +103 -48
  194. package/lib/polygon/models/fill.js +98 -54
  195. package/lib/polygon/models/index.js +14 -2
  196. package/lib/polygon/models/ocean.js +88 -42
  197. package/lib/polygon/models/water.js +82 -37
  198. package/lib/raster/buffers/triangulation.js +7 -3
  199. package/lib/raster/index.js +40 -9
  200. package/lib/raster/models/index.js +5 -0
  201. package/lib/raster/models/raster.js +125 -80
  202. package/lib/raster/models/rasterRgb.js +139 -84
  203. package/lib/raster/models/rasterTerrainRgb.js +93 -56
  204. package/lib/tile/interaction/getRasterData.js +25 -14
  205. package/lib/tile/interaction/utils.js +19 -7
  206. package/lib/tile/manager/base.js +104 -63
  207. package/lib/tile/service/TileLayerService.js +60 -33
  208. package/lib/tile/service/TilePickService.js +48 -26
  209. package/lib/tile/service/TileSourceService.js +16 -2
  210. package/lib/tile/style/utils.js +3 -0
  211. package/lib/tile/tileFactory/DebugTile.js +54 -29
  212. package/lib/tile/tileFactory/ImageTile.js +46 -20
  213. package/lib/tile/tileFactory/MaskTile.js +51 -22
  214. package/lib/tile/tileFactory/RasterRGBTile.js +50 -22
  215. package/lib/tile/tileFactory/RasterTerrainRGBTile.js +46 -20
  216. package/lib/tile/tileFactory/RasterTile.js +63 -30
  217. package/lib/tile/tileFactory/Tile.js +102 -63
  218. package/lib/tile/tileFactory/VectorTile.js +76 -41
  219. package/lib/tile/tileFactory/index.js +25 -0
  220. package/lib/tile/tileFactory/layers/TileDebugLayer.js +32 -6
  221. package/lib/tile/tileFactory/util.js +9 -0
  222. package/lib/tile/tileLayer/BaseLayer.js +153 -105
  223. package/lib/tile/utils.js +5 -1
  224. package/lib/utils/blend.js +5 -0
  225. package/lib/utils/collision-index.js +25 -9
  226. package/lib/utils/dataMappingStyle.js +19 -8
  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
@@ -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
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";
58
+
34
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 TextTrianglation(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 TextTrianglation(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,23 +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.rawEncodeData = this.layer.getEncodedData();
172
- this.preTextStyle = this.getTextStyle();
173
- return _context2.abrupt("return", this.buildModels());
174
- case 5:
175
- case "end":
176
- 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
+ }
177
229
  }
178
230
  }, _callee2, this);
179
231
  }));
232
+
180
233
  function initModels() {
181
234
  return _initModels.apply(this, arguments);
182
235
  }
236
+
183
237
  return initModels;
184
238
  }()
185
239
  }, {
@@ -187,37 +241,48 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
187
241
  value: function () {
188
242
  var _buildModels = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
189
243
  var _ref3, _ref3$textAllowOverla, textAllowOverlap, model;
244
+
190
245
  return _regenerator.default.wrap(function _callee3$(_context3) {
191
- while (1) 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
- this.initGlyph(); //
195
- this.updateTexture();
196
- if (!textAllowOverlap) {
197
- this.filterGlyphs();
198
- }
199
- _context3.next = 6;
200
- return this.layer.buildLayerModel({
201
- moduleName: 'pointText',
202
- vertexShader: textVert,
203
- fragmentShader: textFrag,
204
- triangulation: TextTrianglation.bind(this),
205
- depth: {
206
- 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();
207
257
  }
208
- });
209
- case 6:
210
- model = _context3.sent;
211
- return _context3.abrupt("return", [model]);
212
- case 8:
213
- case "end":
214
- 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
+ }
215
278
  }
216
279
  }, _callee3, this);
217
280
  }));
281
+
218
282
  function buildModels() {
219
283
  return _buildModels.apply(this, arguments);
220
284
  }
285
+
221
286
  return buildModels;
222
287
  }() // 需要更新的场景
223
288
  // 1. 文本偏移量发生改变
@@ -225,62 +290,80 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
225
290
  // 3. 文本允许重叠发生改变
226
291
  // 4. 文本字体发生改变
227
292
  // 5. 文本字体粗细发生改变
293
+
228
294
  }, {
229
295
  key: "needUpdate",
230
296
  value: function () {
231
297
  var _needUpdate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
232
298
  var _ref4, _ref4$textAllowOverla, textAllowOverlap, _ref4$textAnchor, textAnchor, textOffset, padding, fontFamily, fontWeight, zoom, extent, flag;
299
+
233
300
  return _regenerator.default.wrap(function _callee4$(_context4) {
234
- while (1) switch (_context4.prev = _context4.next) {
235
- case 0:
236
- _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;
237
- 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))) {
238
- _context4.next = 5;
239
- break;
240
- }
241
- _context4.next = 4;
242
- return this.mapping();
243
- case 4:
244
- return _context4.abrupt("return", true);
245
- case 5:
246
- if (!textAllowOverlap) {
247
- _context4.next = 7;
248
- break;
249
- }
250
- return _context4.abrupt("return", false);
251
- case 7:
252
- // textAllowOverlap 发生改变
253
- zoom = this.mapService.getZoom();
254
- extent = this.mapService.getBounds();
255
- flag = (0, _l7Utils.boundsContains)(this.extent, extent); // 文本不能压盖则进行过滤
256
- if (!(Math.abs(this.currentZoom - zoom) > 0.5 || !flag || textAllowOverlap !== this.preTextStyle.textAllowOverlap)) {
257
- _context4.next = 14;
258
- break;
259
- }
260
- _context4.next = 13;
261
- return this.reBuildModel();
262
- case 13:
263
- return _context4.abrupt("return", true);
264
- case 14:
265
- return _context4.abrupt("return", false);
266
- case 15:
267
- case "end":
268
- 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
+ }
269
349
  }
270
350
  }, _callee4, this);
271
351
  }));
352
+
272
353
  function needUpdate() {
273
354
  return _needUpdate.apply(this, arguments);
274
355
  }
356
+
275
357
  return needUpdate;
276
358
  }()
277
359
  }, {
278
360
  key: "clearModels",
279
361
  value: function clearModels() {
280
362
  var _this$texture, _this$dataTexture;
363
+
281
364
  (_this$texture = this.texture) === null || _this$texture === void 0 ? void 0 : _this$texture.destroy();
282
- (_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy();
283
- // TODO this.mapping
365
+ (_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy(); // TODO this.mapping
366
+
284
367
  this.layer.off('remapping', this.mapping);
285
368
  }
286
369
  }, {
@@ -299,7 +382,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
299
382
  size: 1,
300
383
  update: function update(feature) {
301
384
  var _feature$rotate = feature.rotate,
302
- rotate = _feature$rotate === void 0 ? 0 : _feature$rotate;
385
+ rotate = _feature$rotate === void 0 ? 0 : _feature$rotate;
303
386
  return Array.isArray(rotate) ? [rotate[0]] : [rotate];
304
387
  }
305
388
  }
@@ -320,9 +403,8 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
320
403
  return [vertex[5], vertex[6]];
321
404
  }
322
405
  }
323
- });
406
+ }); // point layer size;
324
407
 
325
- // point layer size;
326
408
  this.styleAttributeService.registerStyleAttribute({
327
409
  name: 'size',
328
410
  type: _l7Core.AttributeType.Attribute,
@@ -337,7 +419,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
337
419
  size: 1,
338
420
  update: function update(feature) {
339
421
  var _feature$size = feature.size,
340
- size = _feature$size === void 0 ? 12 : _feature$size;
422
+ size = _feature$size === void 0 ? 12 : _feature$size;
341
423
  return Array.isArray(size) ? [size[0]] : [size];
342
424
  }
343
425
  }
@@ -376,23 +458,28 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
376
458
  /**
377
459
  * 生成文字纹理(生成文字纹理字典)
378
460
  */
461
+
379
462
  }, {
380
463
  key: "initTextFont",
381
464
  value: function initTextFont() {
382
465
  var _this$getTextStyle = this.getTextStyle(),
383
- fontWeight = _this$getTextStyle.fontWeight,
384
- fontFamily = _this$getTextStyle.fontFamily;
466
+ fontWeight = _this$getTextStyle.fontWeight,
467
+ fontFamily = _this$getTextStyle.fontFamily;
468
+
385
469
  var data = this.rawEncodeData;
386
470
  var characterSet = [];
387
471
  data.forEach(function (item) {
388
472
  var _item$shape = item.shape,
389
- shape = _item$shape === void 0 ? '' : _item$shape;
473
+ shape = _item$shape === void 0 ? '' : _item$shape;
390
474
  shape = shape.toString();
475
+
391
476
  var _iterator = _createForOfIteratorHelper(shape),
392
- _step;
477
+ _step;
478
+
393
479
  try {
394
480
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
395
481
  var char = _step.value;
482
+
396
483
  // 去重
397
484
  if (characterSet.indexOf(char) === -1) {
398
485
  characterSet.push(char);
@@ -411,22 +498,24 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
411
498
  iconfont: false
412
499
  });
413
500
  }
414
-
415
501
  /**
416
502
  * 生成 iconfont 纹理字典
417
503
  */
504
+
418
505
  }, {
419
506
  key: "initIconFontTex",
420
507
  value: function initIconFontTex() {
421
508
  var _this$getTextStyle2 = this.getTextStyle(),
422
- fontWeight = _this$getTextStyle2.fontWeight,
423
- fontFamily = _this$getTextStyle2.fontFamily;
509
+ fontWeight = _this$getTextStyle2.fontWeight,
510
+ fontFamily = _this$getTextStyle2.fontFamily;
511
+
424
512
  var data = this.rawEncodeData;
425
513
  var characterSet = [];
426
514
  data.forEach(function (item) {
427
515
  var _item$shape2 = item.shape,
428
- shape = _item$shape2 === void 0 ? '' : _item$shape2;
516
+ shape = _item$shape2 === void 0 ? '' : _item$shape2;
429
517
  shape = "".concat(shape);
518
+
430
519
  if (characterSet.indexOf(shape) === -1) {
431
520
  characterSet.push(shape);
432
521
  }
@@ -442,26 +531,27 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
442
531
  key: "getTextStyle",
443
532
  value: function getTextStyle() {
444
533
  var _ref5 = this.layer.getLayerConfig(),
445
- _ref5$fontWeight = _ref5.fontWeight,
446
- fontWeight = _ref5$fontWeight === void 0 ? '400' : _ref5$fontWeight,
447
- _ref5$fontFamily = _ref5.fontFamily,
448
- fontFamily = _ref5$fontFamily === void 0 ? 'sans-serif' : _ref5$fontFamily,
449
- _ref5$textAllowOverla = _ref5.textAllowOverlap,
450
- textAllowOverlap = _ref5$textAllowOverla === void 0 ? false : _ref5$textAllowOverla,
451
- _ref5$padding = _ref5.padding,
452
- padding = _ref5$padding === void 0 ? [0, 0] : _ref5$padding,
453
- _ref5$textAnchor = _ref5.textAnchor,
454
- textAnchor = _ref5$textAnchor === void 0 ? 'center' : _ref5$textAnchor,
455
- _ref5$textOffset = _ref5.textOffset,
456
- textOffset = _ref5$textOffset === void 0 ? [0, 0] : _ref5$textOffset,
457
- _ref5$opacity = _ref5.opacity,
458
- opacity = _ref5$opacity === void 0 ? 1 : _ref5$opacity,
459
- _ref5$strokeOpacity = _ref5.strokeOpacity,
460
- strokeOpacity = _ref5$strokeOpacity === void 0 ? 1 : _ref5$strokeOpacity,
461
- _ref5$strokeWidth = _ref5.strokeWidth,
462
- strokeWidth = _ref5$strokeWidth === void 0 ? 0 : _ref5$strokeWidth,
463
- _ref5$stroke = _ref5.stroke,
464
- 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
+
465
555
  return {
466
556
  fontWeight: fontWeight,
467
557
  fontFamily: fontFamily,
@@ -475,39 +565,39 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
475
565
  stroke: stroke
476
566
  };
477
567
  }
478
-
479
568
  /**
480
569
  * 生成文字布局(对照文字纹理字典提取对应文字的位置很好信息)
481
570
  */
571
+
482
572
  }, {
483
573
  key: "generateGlyphLayout",
484
574
  value: function generateGlyphLayout(iconfont) {
485
575
  var _this2 = this;
576
+
486
577
  var mapping = this.getFontServiceMapping();
578
+
487
579
  var _ref6 = this.layer.getLayerConfig(),
488
- _ref6$spacing = _ref6.spacing,
489
- spacing = _ref6$spacing === void 0 ? 2 : _ref6$spacing,
490
- _ref6$textAnchor = _ref6.textAnchor,
491
- textAnchor = _ref6$textAnchor === void 0 ? 'center' : _ref6$textAnchor,
492
- textOffset = _ref6.textOffset;
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
+
493
586
  var data = this.rawEncodeData;
494
587
  this.glyphInfo = data.map(function (feature) {
495
588
  var _feature$shape = feature.shape,
496
- shape = _feature$shape === void 0 ? '' : _feature$shape,
497
- id = feature.id,
498
- _feature$size2 = feature.size,
499
- size = _feature$size2 === void 0 ? 1 : _feature$size2;
500
- var shaping = (0, _symbolLayout.shapeText)(shape.toString(), mapping,
501
- // @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
502
594
  size, textAnchor, 'left', spacing, textOffset || feature.textOffset || [0, 0], iconfont);
503
595
  var glyphQuads = (0, _symbolLayout.getGlyphQuads)(shaping, textOffset, false);
504
596
  feature.shaping = shaping;
505
- feature.glyphQuads = glyphQuads;
506
- // feature.centroid = calculteCentroid(coordinates);
597
+ feature.glyphQuads = glyphQuads; // feature.centroid = calculteCentroid(coordinates);
507
598
 
508
- feature.centroid = (0, _l7Utils.calculateCentroid)(feature.coordinates);
599
+ feature.centroid = (0, _l7Utils.calculateCentroid)(feature.coordinates); // 此时地图高德2.0 originCentroid == centroid
509
600
 
510
- // 此时地图高德2.0 originCentroid == centroid
511
601
  feature.originCentroid = feature.version === 'GAODE2.x' ? (0, _l7Utils.calculateCentroid)(feature.originCoordinates) : feature.originCentroid = feature.centroid;
512
602
  _this2.glyphInfoMap[id] = {
513
603
  shaping: shaping,
@@ -521,66 +611,76 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
521
611
  key: "getFontServiceMapping",
522
612
  value: function getFontServiceMapping() {
523
613
  var _ref7 = this.layer.getLayerConfig(),
524
- _ref7$fontWeight = _ref7.fontWeight,
525
- fontWeight = _ref7$fontWeight === void 0 ? '400' : _ref7$fontWeight,
526
- _ref7$fontFamily = _ref7.fontFamily,
527
- 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
+
528
619
  return this.fontService.getMappingByKey("".concat(fontFamily, "_").concat(fontWeight));
529
620
  }
530
621
  }, {
531
622
  key: "getFontServiceCanvas",
532
623
  value: function getFontServiceCanvas() {
533
624
  var _ref8 = this.layer.getLayerConfig(),
534
- _ref8$fontWeight = _ref8.fontWeight,
535
- fontWeight = _ref8$fontWeight === void 0 ? '400' : _ref8$fontWeight,
536
- _ref8$fontFamily = _ref8.fontFamily,
537
- fontFamily = _ref8$fontFamily === void 0 ? 'sans-serif' : _ref8$fontFamily;
538
- // 更新文字布局
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
+
539
631
  return this.fontService.getCanvasByKey("".concat(fontFamily, "_").concat(fontWeight));
540
632
  }
541
-
542
633
  /**
543
634
  * 文字避让 depend on originCentorid
544
635
  */
636
+
545
637
  }, {
546
638
  key: "filterGlyphs",
547
639
  value: function filterGlyphs() {
548
640
  var _this3 = this;
641
+
549
642
  var _ref9 = this.layer.getLayerConfig(),
550
- _ref9$padding = _ref9.padding,
551
- padding = _ref9$padding === void 0 ? [0, 0] : _ref9$padding,
552
- _ref9$textAllowOverla = _ref9.textAllowOverlap,
553
- 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
+
554
648
  if (textAllowOverlap) {
555
649
  // 如果允许文本覆盖
556
650
  return;
557
651
  }
652
+
558
653
  this.glyphInfoMap = {};
559
654
  this.currentZoom = this.mapService.getZoom();
560
655
  this.extent = this.textExtent();
656
+
561
657
  var _this$rendererService = this.rendererService.getViewportSize(),
562
- width = _this$rendererService.width,
563
- height = _this$rendererService.height;
658
+ width = _this$rendererService.width,
659
+ height = _this$rendererService.height;
660
+
564
661
  var collisionIndex = new _collisionIndex.default(width, height);
565
662
  var filterData = this.glyphInfo.filter(function (feature) {
566
663
  var shaping = feature.shaping,
567
- _feature$id = feature.id,
568
- id = _feature$id === void 0 ? 0 : _feature$id;
569
- // 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];
570
666
  // const centroid = feature.originCentroid as [number, number];
667
+
571
668
  var centroid = feature.version === 'GAODE2.x' ? feature.originCentroid : feature.centroid;
572
669
  var size = feature.size;
573
670
  var fontScale = size / 16;
671
+
574
672
  var pixels = _this3.mapService.lngLatToContainer(centroid);
673
+
575
674
  var _collisionIndex$place = collisionIndex.placeCollisionBox({
576
- x1: shaping.left * fontScale - padding[0],
577
- x2: shaping.right * fontScale + padding[0],
578
- y1: shaping.top * fontScale - padding[1],
579
- y2: shaping.bottom * fontScale + padding[1],
580
- anchorPointX: pixels.x,
581
- anchorPointY: pixels.y
582
- }),
583
- 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
+
584
684
  if (box && box.length) {
585
685
  collisionIndex.insertCollisionBox(box, id);
586
686
  return true;
@@ -591,35 +691,39 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
591
691
  filterData.forEach(function (item) {
592
692
  // @ts-ignore
593
693
  _this3.glyphInfoMap[item.id] = item;
594
- });
595
- // this.layer.setEncodedData(filterData);
694
+ }); // this.layer.setEncodedData(filterData);
596
695
  }
597
696
  /**
598
697
  * 初始化文字布局
599
698
  */
699
+
600
700
  }, {
601
701
  key: "initGlyph",
602
702
  value: function initGlyph() {
603
703
  var _this$layer$getLayerC = this.layer.getLayerConfig(),
604
- _this$layer$getLayerC2 = _this$layer$getLayerC.iconfont,
605
- iconfont = _this$layer$getLayerC2 === void 0 ? false : _this$layer$getLayerC2;
606
- // 1.生成文字纹理(或是生成 iconfont)
607
- iconfont ? this.initIconFontTex() : this.initTextFont();
608
- // 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
+
609
710
  this.generateGlyphLayout(iconfont);
610
711
  }
611
712
  /**
612
713
  * 更新文字纹理
613
714
  */
715
+
614
716
  }, {
615
717
  key: "updateTexture",
616
718
  value: function updateTexture() {
617
719
  var createTexture2D = this.rendererService.createTexture2D;
618
720
  var canvas = this.getFontServiceCanvas();
619
721
  this.textureHeight = canvas.height;
722
+
620
723
  if (this.texture) {
621
724
  this.texture.destroy();
622
725
  }
726
+
623
727
  this.texture = createTexture2D({
624
728
  data: canvas,
625
729
  mag: _l7Core.gl.LINEAR,
@@ -634,35 +738,42 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
634
738
  var _reBuildModel = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
635
739
  var model;
636
740
  return _regenerator.default.wrap(function _callee5$(_context5) {
637
- while (1) switch (_context5.prev = _context5.next) {
638
- case 0:
639
- this.filterGlyphs();
640
- _context5.next = 3;
641
- return this.layer.buildLayerModel({
642
- moduleName: 'pointText',
643
- vertexShader: textVert,
644
- fragmentShader: textFrag,
645
- triangulation: TextTrianglation.bind(this),
646
- depth: {
647
- enable: false
648
- }
649
- });
650
- case 3:
651
- model = _context5.sent;
652
- // TODO 渲染流程待修改
653
- this.layer.models = [model];
654
- case 5:
655
- case "end":
656
- 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
+ }
657
765
  }
658
766
  }, _callee5, this);
659
767
  }));
768
+
660
769
  function reBuildModel() {
661
770
  return _reBuildModel.apply(this, arguments);
662
771
  }
772
+
663
773
  return reBuildModel;
664
774
  }()
665
775
  }]);
666
776
  return TextModel;
667
777
  }(_BaseModel2.default);
778
+
668
779
  exports.default = TextModel;