@antv/l7-layers 2.15.2 → 2.15.3

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