@antv/l7-layers 2.21.0 → 2.21.2

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 (397) hide show
  1. package/es/canvas/index.js +60 -113
  2. package/es/canvas/models/canvas.js +95 -135
  3. package/es/canvas/models/constants.js +1 -1
  4. package/es/citybuliding/building.js +20 -58
  5. package/es/citybuliding/models/build.js +142 -199
  6. package/es/core/BaseLayer.d.ts +2 -1
  7. package/es/core/BaseLayer.js +1113 -1405
  8. package/es/core/BaseModel.js +262 -318
  9. package/es/core/CommonStyleAttribute.js +25 -18
  10. package/es/core/LayerPickService.js +92 -142
  11. package/es/core/TextureService.js +58 -69
  12. package/es/core/constant.js +2 -2
  13. package/es/core/interface.js +5 -5
  14. package/es/core/line_trangluation.js +38 -43
  15. package/es/core/shape/Path.js +21 -13
  16. package/es/core/shape/arrow.js +50 -62
  17. package/es/core/shape/extrude.js +54 -63
  18. package/es/core/triangulation.js +192 -171
  19. package/es/core/utils.js +5 -5
  20. package/es/earth/index.js +35 -73
  21. package/es/earth/models/atmosphere.js +98 -148
  22. package/es/earth/models/base.js +148 -202
  23. package/es/earth/models/bloomsphere.js +97 -147
  24. package/es/earth/utils.js +37 -38
  25. package/es/geometry/index.js +36 -75
  26. package/es/geometry/models/billboard.js +147 -204
  27. package/es/geometry/models/index.js +1 -1
  28. package/es/geometry/models/plane.js +277 -357
  29. package/es/geometry/models/sprite.js +182 -240
  30. package/es/heatmap/index.js +72 -122
  31. package/es/heatmap/models/grid.js +66 -118
  32. package/es/heatmap/models/grid3d.js +101 -151
  33. package/es/heatmap/models/heatmap.js +398 -455
  34. package/es/heatmap/models/hexagon.js +67 -119
  35. package/es/heatmap/models/index.js +1 -1
  36. package/es/heatmap/triangulation.js +20 -20
  37. package/es/image/index.js +23 -62
  38. package/es/image/models/image.js +99 -163
  39. package/es/image/models/index.js +1 -1
  40. package/es/line/index.js +65 -106
  41. package/es/line/models/arc.js +200 -248
  42. package/es/line/models/arc_3d.js +190 -242
  43. package/es/line/models/flow.js +101 -153
  44. package/es/line/models/great_circle.js +183 -234
  45. package/es/line/models/index.js +1 -1
  46. package/es/line/models/line.js +232 -288
  47. package/es/line/models/simple_line.js +142 -192
  48. package/es/line/models/wall.js +221 -273
  49. package/es/line/shaders/line/line_vert.glsl +0 -2
  50. package/es/line/shaders/wall/wall_vert.glsl +15 -0
  51. package/es/mask/index.js +16 -53
  52. package/es/mask/models/fill.js +51 -108
  53. package/es/mask/models/index.js +1 -1
  54. package/es/plugins/DataMappingPlugin.js +205 -251
  55. package/es/plugins/DataSourcePlugin.js +64 -92
  56. package/es/plugins/FeatureScalePlugin.js +258 -302
  57. package/es/plugins/LayerAnimateStylePlugin.js +12 -22
  58. package/es/plugins/LayerMaskPlugin.js +15 -24
  59. package/es/plugins/LayerModelPlugin.js +52 -136
  60. package/es/plugins/LayerStylePlugin.js +14 -23
  61. package/es/plugins/LightingPlugin.js +26 -37
  62. package/es/plugins/MultiPassRendererPlugin.js +34 -39
  63. package/es/plugins/PixelPickingPlugin.js +129 -151
  64. package/es/plugins/RegisterStyleAttributePlugin.js +80 -96
  65. package/es/plugins/ShaderUniformPlugin.js +159 -131
  66. package/es/plugins/UpdateModelPlugin.js +16 -26
  67. package/es/plugins/UpdateStyleAttributePlugin.js +47 -65
  68. package/es/point/index.js +118 -182
  69. package/es/point/models/billboard_point.js +72 -127
  70. package/es/point/models/earthExtrude.js +170 -220
  71. package/es/point/models/earthFill.js +136 -192
  72. package/es/point/models/extrude.js +167 -217
  73. package/es/point/models/fill.js +153 -210
  74. package/es/point/models/fillImage.js +156 -211
  75. package/es/point/models/image.js +127 -180
  76. package/es/point/models/index.js +1 -1
  77. package/es/point/models/normal.js +67 -122
  78. package/es/point/models/radar.js +93 -148
  79. package/es/point/models/text.js +447 -578
  80. package/es/point/shape/extrude.js +19 -25
  81. package/es/polygon/index.js +61 -99
  82. package/es/polygon/models/extrude.js +208 -281
  83. package/es/polygon/models/extrusion.js +95 -142
  84. package/es/polygon/models/fill.js +103 -155
  85. package/es/polygon/models/index.js +1 -2
  86. package/es/polygon/models/ocean.js +139 -198
  87. package/es/polygon/models/water.js +120 -179
  88. package/es/raster/buffers/triangulation.js +13 -11
  89. package/es/raster/index.js +47 -88
  90. package/es/raster/models/index.js +1 -1
  91. package/es/raster/models/raster.js +134 -202
  92. package/es/raster/models/rasterRgb.js +134 -208
  93. package/es/raster/models/rasterTerrainRgb.js +98 -153
  94. package/es/tile/core/BaseLayer.d.ts +1 -0
  95. package/es/tile/core/BaseLayer.js +206 -282
  96. package/es/tile/core/TileDebugLayer.js +12 -46
  97. package/es/tile/interaction/getRasterData.js +24 -31
  98. package/es/tile/interaction/utils.js +15 -33
  99. package/es/tile/service/TileLayerService.js +104 -177
  100. package/es/tile/service/TilePickService.js +99 -156
  101. package/es/tile/service/TileSourceService.js +17 -26
  102. package/es/tile/tile/DebugTile.js +41 -78
  103. package/es/tile/tile/ImageTile.js +33 -66
  104. package/es/tile/tile/MaskTile.js +47 -81
  105. package/es/tile/tile/RasterRGBTile.js +40 -71
  106. package/es/tile/tile/RasterTerrainRGBTile.js +33 -66
  107. package/es/tile/tile/RasterTile.js +69 -104
  108. package/es/tile/tile/Tile.d.ts +1 -1
  109. package/es/tile/tile/Tile.js +151 -232
  110. package/es/tile/tile/VectorTile.js +77 -124
  111. package/es/tile/tile/index.js +4 -2
  112. package/es/tile/utils/constants.js +1 -1
  113. package/es/tile/utils/utils.js +2 -2
  114. package/es/utils/blend.js +52 -47
  115. package/es/utils/collision-index.js +62 -70
  116. package/es/utils/extrude_polyline.js +441 -471
  117. package/es/utils/grid-index.js +97 -123
  118. package/es/utils/identityScale.js +5 -5
  119. package/es/utils/load-image.js +15 -39
  120. package/es/utils/multiPassRender.js +7 -9
  121. package/es/utils/polylineNormal.js +40 -43
  122. package/es/utils/rampcolor_legend.js +5 -4
  123. package/es/utils/simpleLine.js +53 -66
  124. package/es/utils/symbol-layout.js +95 -117
  125. package/es/wind/index.js +28 -71
  126. package/es/wind/models/index.js +1 -1
  127. package/es/wind/models/utils.js +36 -34
  128. package/es/wind/models/wind.js +203 -260
  129. package/es/wind/models/windRender.js +258 -269
  130. package/es/wind/models/windShader.js +145 -6
  131. package/lib/canvas/index.d.ts +18 -0
  132. package/lib/canvas/index.js +64 -113
  133. package/lib/canvas/models/canvas.d.ts +23 -0
  134. package/lib/canvas/models/canvas.js +97 -136
  135. package/lib/canvas/models/constants.d.ts +2 -0
  136. package/lib/canvas/models/constants.js +1 -1
  137. package/lib/canvas/models/index.d.ts +2 -0
  138. package/lib/canvas/models/index.js +2 -2
  139. package/lib/citybuliding/building.d.ts +7 -0
  140. package/lib/citybuliding/building.js +22 -58
  141. package/lib/citybuliding/models/build.d.ts +17 -0
  142. package/lib/citybuliding/models/build.js +144 -199
  143. package/lib/core/BaseLayer.d.ts +247 -0
  144. package/lib/core/BaseLayer.js +1115 -1405
  145. package/lib/core/BaseModel.d.ts +82 -0
  146. package/lib/core/BaseModel.js +262 -316
  147. package/lib/core/CommonStyleAttribute.d.ts +20 -0
  148. package/lib/core/CommonStyleAttribute.js +25 -18
  149. package/lib/core/LayerPickService.d.ts +12 -0
  150. package/lib/core/LayerPickService.js +93 -141
  151. package/lib/core/TextureService.d.ts +15 -0
  152. package/lib/core/TextureService.js +59 -68
  153. package/lib/core/constant.d.ts +6 -0
  154. package/lib/core/constant.js +2 -2
  155. package/lib/core/interface.d.ts +282 -0
  156. package/lib/core/interface.js +5 -5
  157. package/lib/core/line_trangluation.d.ts +19 -0
  158. package/lib/core/line_trangluation.js +38 -43
  159. package/lib/core/schema.d.ts +27 -0
  160. package/lib/core/shape/Path.d.ts +39 -0
  161. package/lib/core/shape/Path.js +21 -14
  162. package/lib/core/shape/arrow.d.ts +25 -0
  163. package/lib/core/shape/arrow.js +50 -62
  164. package/lib/core/shape/extrude.d.ts +17 -0
  165. package/lib/core/shape/extrude.js +54 -63
  166. package/lib/core/triangulation.d.ts +136 -0
  167. package/lib/core/triangulation.js +194 -174
  168. package/lib/core/utils.d.ts +4 -0
  169. package/lib/core/utils.js +5 -5
  170. package/lib/earth/index.d.ts +22 -0
  171. package/lib/earth/index.js +37 -73
  172. package/lib/earth/models/atmosphere.d.ts +15 -0
  173. package/lib/earth/models/atmosphere.js +100 -148
  174. package/lib/earth/models/base.d.ts +22 -0
  175. package/lib/earth/models/base.js +150 -202
  176. package/lib/earth/models/bloomsphere.d.ts +15 -0
  177. package/lib/earth/models/bloomsphere.js +99 -147
  178. package/lib/earth/utils.d.ts +26 -0
  179. package/lib/earth/utils.js +37 -39
  180. package/lib/geometry/index.d.ts +22 -0
  181. package/lib/geometry/index.js +38 -75
  182. package/lib/geometry/models/billboard.d.ts +24 -0
  183. package/lib/geometry/models/billboard.js +149 -204
  184. package/lib/geometry/models/index.d.ts +5 -0
  185. package/lib/geometry/models/index.js +1 -1
  186. package/lib/geometry/models/plane.d.ts +43 -0
  187. package/lib/geometry/models/plane.js +280 -357
  188. package/lib/geometry/models/sprite.d.ts +48 -0
  189. package/lib/geometry/models/sprite.js +184 -240
  190. package/lib/heatmap/index.d.ts +13 -0
  191. package/lib/heatmap/index.js +74 -122
  192. package/lib/heatmap/models/grid.d.ts +15 -0
  193. package/lib/heatmap/models/grid.js +68 -118
  194. package/lib/heatmap/models/grid3d.d.ts +15 -0
  195. package/lib/heatmap/models/grid3d.js +103 -151
  196. package/lib/heatmap/models/heatmap.d.ts +27 -0
  197. package/lib/heatmap/models/heatmap.js +400 -455
  198. package/lib/heatmap/models/hexagon.d.ts +15 -0
  199. package/lib/heatmap/models/hexagon.js +69 -119
  200. package/lib/heatmap/models/index.d.ts +5 -0
  201. package/lib/heatmap/models/index.js +1 -1
  202. package/lib/heatmap/triangulation.d.ts +5 -0
  203. package/lib/heatmap/triangulation.js +20 -20
  204. package/lib/image/index.d.ts +9 -0
  205. package/lib/image/index.js +25 -62
  206. package/lib/image/models/image.d.ts +17 -0
  207. package/lib/image/models/image.js +101 -163
  208. package/lib/image/models/index.d.ts +5 -0
  209. package/lib/image/models/index.js +1 -1
  210. package/lib/index.d.ts +18 -0
  211. package/lib/index.js +17 -17
  212. package/lib/line/index.d.ts +36 -0
  213. package/lib/line/index.js +67 -106
  214. package/lib/line/models/arc.d.ts +22 -0
  215. package/lib/line/models/arc.js +202 -248
  216. package/lib/line/models/arc_3d.d.ts +22 -0
  217. package/lib/line/models/arc_3d.js +193 -242
  218. package/lib/line/models/flow.d.ts +14 -0
  219. package/lib/line/models/flow.js +103 -153
  220. package/lib/line/models/great_circle.d.ts +17 -0
  221. package/lib/line/models/great_circle.js +185 -234
  222. package/lib/line/models/index.d.ts +5 -0
  223. package/lib/line/models/index.js +1 -1
  224. package/lib/line/models/line.d.ts +27 -0
  225. package/lib/line/models/line.js +233 -285
  226. package/lib/line/models/simple_line.d.ts +19 -0
  227. package/lib/line/models/simple_line.js +144 -192
  228. package/lib/line/models/wall.d.ts +17 -0
  229. package/lib/line/models/wall.js +223 -273
  230. package/lib/line/shaders/line/line_vert.glsl +0 -2
  231. package/lib/line/shaders/wall/wall_vert.glsl +15 -0
  232. package/lib/mask/index.d.ts +16 -0
  233. package/lib/mask/index.js +18 -53
  234. package/lib/mask/models/fill.d.ts +18 -0
  235. package/lib/mask/models/fill.js +53 -108
  236. package/lib/mask/models/index.d.ts +5 -0
  237. package/lib/mask/models/index.js +1 -1
  238. package/lib/plugins/DataMappingPlugin.d.ts +13 -0
  239. package/lib/plugins/DataMappingPlugin.js +206 -250
  240. package/lib/plugins/DataSourcePlugin.d.ts +6 -0
  241. package/lib/plugins/DataSourcePlugin.js +65 -91
  242. package/lib/plugins/FeatureScalePlugin.d.ts +20 -0
  243. package/lib/plugins/FeatureScalePlugin.js +261 -304
  244. package/lib/plugins/LayerAnimateStylePlugin.d.ts +4 -0
  245. package/lib/plugins/LayerAnimateStylePlugin.js +13 -21
  246. package/lib/plugins/LayerMaskPlugin.d.ts +7 -0
  247. package/lib/plugins/LayerMaskPlugin.js +16 -24
  248. package/lib/plugins/LayerModelPlugin.d.ts +10 -0
  249. package/lib/plugins/LayerModelPlugin.js +53 -135
  250. package/lib/plugins/LayerStylePlugin.d.ts +7 -0
  251. package/lib/plugins/LayerStylePlugin.js +15 -23
  252. package/lib/plugins/LightingPlugin.d.ts +35 -0
  253. package/lib/plugins/LightingPlugin.js +27 -36
  254. package/lib/plugins/MultiPassRendererPlugin.d.ts +22 -0
  255. package/lib/plugins/MultiPassRendererPlugin.js +35 -38
  256. package/lib/plugins/PixelPickingPlugin.d.ts +11 -0
  257. package/lib/plugins/PixelPickingPlugin.js +130 -150
  258. package/lib/plugins/RegisterStyleAttributePlugin.d.ts +11 -0
  259. package/lib/plugins/RegisterStyleAttributePlugin.js +81 -96
  260. package/lib/plugins/ShaderUniformPlugin.d.ts +22 -0
  261. package/lib/plugins/ShaderUniformPlugin.js +160 -130
  262. package/lib/plugins/UpdateModelPlugin.d.ts +7 -0
  263. package/lib/plugins/UpdateModelPlugin.js +17 -26
  264. package/lib/plugins/UpdateStyleAttributePlugin.d.ts +9 -0
  265. package/lib/plugins/UpdateStyleAttributePlugin.js +48 -65
  266. package/lib/plugins/index.d.ts +15 -0
  267. package/lib/point/index.d.ts +33 -0
  268. package/lib/point/index.js +120 -182
  269. package/lib/point/models/billboard_point.d.ts +21 -0
  270. package/lib/point/models/billboard_point.js +74 -127
  271. package/lib/point/models/earthExtrude.d.ts +16 -0
  272. package/lib/point/models/earthExtrude.js +172 -220
  273. package/lib/point/models/earthFill.d.ts +15 -0
  274. package/lib/point/models/earthFill.js +138 -192
  275. package/lib/point/models/extrude.d.ts +16 -0
  276. package/lib/point/models/extrude.js +169 -217
  277. package/lib/point/models/fill.d.ts +31 -0
  278. package/lib/point/models/fill.js +155 -210
  279. package/lib/point/models/fillImage.d.ts +26 -0
  280. package/lib/point/models/fillImage.js +159 -211
  281. package/lib/point/models/image.d.ts +18 -0
  282. package/lib/point/models/image.js +129 -180
  283. package/lib/point/models/index.d.ts +5 -0
  284. package/lib/point/models/index.js +1 -1
  285. package/lib/point/models/normal.d.ts +22 -0
  286. package/lib/point/models/normal.js +69 -122
  287. package/lib/point/models/radar.d.ts +22 -0
  288. package/lib/point/models/radar.js +95 -148
  289. package/lib/point/models/text.d.ts +69 -0
  290. package/lib/point/models/text.js +449 -578
  291. package/lib/point/shape/extrude.d.ts +15 -0
  292. package/lib/point/shape/extrude.js +19 -25
  293. package/lib/polygon/index.d.ts +18 -0
  294. package/lib/polygon/index.js +63 -99
  295. package/lib/polygon/models/extrude.d.ts +25 -0
  296. package/lib/polygon/models/extrude.js +210 -281
  297. package/lib/polygon/models/extrusion.d.ts +24 -0
  298. package/lib/polygon/models/extrusion.js +97 -142
  299. package/lib/polygon/models/fill.d.ts +18 -0
  300. package/lib/polygon/models/fill.js +104 -154
  301. package/lib/polygon/models/index.d.ts +5 -0
  302. package/lib/polygon/models/index.js +1 -1
  303. package/lib/polygon/models/ocean.d.ts +23 -0
  304. package/lib/polygon/models/ocean.js +141 -198
  305. package/lib/polygon/models/water.d.ts +21 -0
  306. package/lib/polygon/models/water.js +122 -179
  307. package/lib/raster/buffers/triangulation.d.ts +6 -0
  308. package/lib/raster/buffers/triangulation.js +13 -11
  309. package/lib/raster/index.d.ts +11 -0
  310. package/lib/raster/index.js +49 -88
  311. package/lib/raster/models/index.d.ts +5 -0
  312. package/lib/raster/models/index.js +1 -1
  313. package/lib/raster/models/raster.d.ts +21 -0
  314. package/lib/raster/models/raster.js +136 -202
  315. package/lib/raster/models/rasterRgb.d.ts +21 -0
  316. package/lib/raster/models/rasterRgb.js +136 -208
  317. package/lib/raster/models/rasterTerrainRgb.d.ts +16 -0
  318. package/lib/raster/models/rasterTerrainRgb.js +100 -153
  319. package/lib/tile/core/BaseLayer.d.ts +48 -0
  320. package/lib/tile/core/BaseLayer.js +207 -281
  321. package/lib/tile/core/TileDebugLayer.d.ts +15 -0
  322. package/lib/tile/core/TileDebugLayer.js +14 -46
  323. package/lib/tile/interaction/getFeatureData.d.ts +0 -0
  324. package/lib/tile/interaction/getRasterData.d.ts +4 -0
  325. package/lib/tile/interaction/getRasterData.js +24 -32
  326. package/lib/tile/interaction/utils.d.ts +11 -0
  327. package/lib/tile/interaction/utils.js +15 -34
  328. package/lib/tile/interface.d.ts +29 -0
  329. package/lib/tile/service/TileLayerService.d.ts +33 -0
  330. package/lib/tile/service/TileLayerService.js +105 -177
  331. package/lib/tile/service/TilePickService.d.ts +26 -0
  332. package/lib/tile/service/TilePickService.js +100 -156
  333. package/lib/tile/service/TileSourceService.d.ts +7 -0
  334. package/lib/tile/service/TileSourceService.js +20 -29
  335. package/lib/tile/tile/DebugTile.d.ts +16 -0
  336. package/lib/tile/tile/DebugTile.js +43 -78
  337. package/lib/tile/tile/ImageTile.d.ts +14 -0
  338. package/lib/tile/tile/ImageTile.js +35 -66
  339. package/lib/tile/tile/MaskTile.d.ts +18 -0
  340. package/lib/tile/tile/MaskTile.js +49 -81
  341. package/lib/tile/tile/RasterRGBTile.d.ts +11 -0
  342. package/lib/tile/tile/RasterRGBTile.js +42 -71
  343. package/lib/tile/tile/RasterTerrainRGBTile.d.ts +14 -0
  344. package/lib/tile/tile/RasterTerrainRGBTile.js +35 -66
  345. package/lib/tile/tile/RasterTile.d.ts +18 -0
  346. package/lib/tile/tile/RasterTile.js +71 -104
  347. package/lib/tile/tile/Tile.d.ts +114 -0
  348. package/lib/tile/tile/Tile.js +152 -231
  349. package/lib/tile/tile/VectorTile.d.ts +26 -0
  350. package/lib/tile/tile/VectorTile.js +79 -124
  351. package/lib/tile/tile/index.d.ts +12 -0
  352. package/lib/tile/tile/index.js +6 -4
  353. package/lib/tile/tile/util.d.ts +5 -0
  354. package/lib/tile/utils/constants.d.ts +1 -0
  355. package/lib/tile/utils/constants.js +1 -1
  356. package/lib/tile/utils/utils.d.ts +8 -0
  357. package/lib/tile/utils/utils.js +2 -2
  358. package/lib/utils/blend.d.ts +2 -0
  359. package/lib/utils/blend.js +52 -48
  360. package/lib/utils/collision-index.d.ts +47 -0
  361. package/lib/utils/collision-index.js +64 -69
  362. package/lib/utils/extrude_polyline.d.ts +68 -0
  363. package/lib/utils/extrude_polyline.js +442 -470
  364. package/lib/utils/grid-index.d.ts +28 -0
  365. package/lib/utils/grid-index.js +97 -123
  366. package/lib/utils/identityScale.d.ts +8 -0
  367. package/lib/utils/identityScale.js +5 -5
  368. package/lib/utils/load-image.d.ts +1 -0
  369. package/lib/utils/load-image.js +15 -39
  370. package/lib/utils/multiPassRender.d.ts +16 -0
  371. package/lib/utils/multiPassRender.js +7 -10
  372. package/lib/utils/polylineNormal.d.ts +9 -0
  373. package/lib/utils/polylineNormal.js +40 -44
  374. package/lib/utils/rampcolor_legend.d.ts +6 -0
  375. package/lib/utils/rampcolor_legend.js +5 -5
  376. package/lib/utils/simpleLine.d.ts +23 -0
  377. package/lib/utils/simpleLine.js +54 -65
  378. package/lib/utils/stencil.d.ts +7 -0
  379. package/lib/utils/symbol-layout.d.ts +43 -0
  380. package/lib/utils/symbol-layout.js +95 -117
  381. package/lib/wind/index.d.ts +11 -0
  382. package/lib/wind/index.js +30 -71
  383. package/lib/wind/models/index.d.ts +5 -0
  384. package/lib/wind/models/index.js +1 -1
  385. package/lib/wind/models/utils.d.ts +19 -0
  386. package/lib/wind/models/utils.js +36 -34
  387. package/lib/wind/models/wind.d.ts +24 -0
  388. package/lib/wind/models/wind.js +205 -260
  389. package/lib/wind/models/windRender.d.ts +104 -0
  390. package/lib/wind/models/windRender.js +261 -272
  391. package/lib/wind/models/windShader.d.ts +12 -0
  392. package/lib/wind/models/windShader.js +145 -6
  393. package/package.json +16 -19
  394. package/CHANGELOG.md +0 -492
  395. package/LICENSE.md +0 -21
  396. package/es/glsl.d.ts +0 -5
  397. package/lib/glsl.d.ts +0 -5
@@ -1,36 +1,25 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/esm/createClass";
5
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
- import _inherits from "@babel/runtime/helpers/esm/inherits";
7
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
8
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
9
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
10
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
11
- 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; } } }; }
12
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
14
- import _regeneratorRuntime from "@babel/runtime/regenerator";
15
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
16
- 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; } }
17
4
  import { AttributeType, gl } from '@antv/l7-core';
18
5
  import { boundsContains, calculateCentroid, lodashUtil, padBounds, rgb2arr } from '@antv/l7-utils';
19
6
  import BaseModel from "../../core/BaseModel";
20
7
  import CollisionIndex from "../../utils/collision-index";
21
8
  import { getGlyphQuads, shapeText } from "../../utils/symbol-layout";
22
9
  /* babel-plugin-inline-import '../shaders/text/text_frag.glsl' */
23
- var textFrag = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 48.0\n\nuniform sampler2D u_sdf_map;\nlayout(std140) uniform commonUniforms {\n vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];\n vec2 u_sdf_map_size;\n float u_raisingHeight: 0.0;\n float u_stroke_width : 2;\n float u_gamma_scale : 0.5;\n float u_halo_blur : 0.5;\n};\n\nin vec2 v_uv;\nin float v_gamma_scale;\nin vec4 v_color;\nin vec4 v_stroke_color;\nin float v_fontScale;\n\nout vec4 outputColor;\n\n#pragma include \"picking\"\nvoid main() {\n // get style data mapping\n\n // get sdf from atlas\n float dist = texture(SAMPLER_2D(u_sdf_map), v_uv).a;\n\n lowp float buff = (6.0 - u_stroke_width / v_fontScale) / SDF_PX;\n highp float gamma = (u_halo_blur * 1.19 / SDF_PX + EDGE_GAMMA) / (v_fontScale * u_gamma_scale) / 1.0;\n\n highp float gamma_scaled = gamma * v_gamma_scale;\n\n highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);\n\n outputColor = mix(v_color, v_stroke_color, smoothstep(0., 0.5, 1.- dist));\n\n outputColor.a *= alpha;\n // \u4F5C\u4E3A mask \u6A21\u677F\u65F6\u9700\u8981\u4E22\u5F03\u900F\u660E\u7684\u50CF\u7D20\n if (outputColor.a < 0.01) {\n discard;\n }\n outputColor = filterColor(outputColor);\n}\n";
10
+ const textFrag = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 48.0\n\nuniform sampler2D u_sdf_map;\nlayout(std140) uniform commonUniforms {\n vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];\n vec2 u_sdf_map_size;\n float u_raisingHeight: 0.0;\n float u_stroke_width : 2;\n float u_gamma_scale : 0.5;\n float u_halo_blur : 0.5;\n};\n\nin vec2 v_uv;\nin float v_gamma_scale;\nin vec4 v_color;\nin vec4 v_stroke_color;\nin float v_fontScale;\n\nout vec4 outputColor;\n\n#pragma include \"picking\"\nvoid main() {\n // get style data mapping\n\n // get sdf from atlas\n float dist = texture(SAMPLER_2D(u_sdf_map), v_uv).a;\n\n lowp float buff = (6.0 - u_stroke_width / v_fontScale) / SDF_PX;\n highp float gamma = (u_halo_blur * 1.19 / SDF_PX + EDGE_GAMMA) / (v_fontScale * u_gamma_scale) / 1.0;\n\n highp float gamma_scaled = gamma * v_gamma_scale;\n\n highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);\n\n outputColor = mix(v_color, v_stroke_color, smoothstep(0., 0.5, 1.- dist));\n\n outputColor.a *= alpha;\n // \u4F5C\u4E3A mask \u6A21\u677F\u65F6\u9700\u8981\u4E22\u5F03\u900F\u660E\u7684\u50CF\u7D20\n if (outputColor.a < 0.01) {\n discard;\n }\n outputColor = filterColor(outputColor);\n}\n";
24
11
  /* babel-plugin-inline-import '../shaders/text/text_vert.glsl' */
25
- var textVert = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 24.0\n\nlayout(location = 0) in vec3 a_Position;\nlayout(location = 1) in vec4 a_Color;\nlayout(location = 9) in float a_Size;\nlayout(location = 10) in vec2 a_textOffsets;\nlayout(location = 14) in vec2 a_tex;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];\n vec2 u_sdf_map_size;\n float u_raisingHeight: 0.0;\n float u_stroke_width : 2;\n float u_gamma_scale : 0.5;\n float u_halo_blur : 0.5;\n};\n\nout vec2 v_uv;\nout float v_gamma_scale;\nout vec4 v_color;\nout vec4 v_stroke_color;\nout float v_fontScale;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n#pragma include \"rotation_2d\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n \n v_uv = a_tex / u_sdf_map_size;\n\n\n\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n v_stroke_color = vec4(u_stroke_color.xyz, u_stroke_color.w * opacity);\n\n // \u6587\u672C\u7F29\u653E\u6BD4\u4F8B\n float fontScale = a_Size / FONT_SIZE;\n v_fontScale = fontScale;\n\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n // vec4 projected_position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n vec2 offset = rotate_matrix(a_textOffsets,rotation);\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 = project_common_position_to_clipspace_v2(vec4(project_pos.xyz + vec3(0.0, 0.0, raiseHeight), 1.0));\n\n gl_Position = vec4(\n projected_position.xy / projected_position.w + offset * 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";
12
+ const textVert = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 24.0\n\nlayout(location = 0) in vec3 a_Position;\nlayout(location = 1) in vec4 a_Color;\nlayout(location = 9) in float a_Size;\nlayout(location = 10) in vec2 a_textOffsets;\nlayout(location = 14) in vec2 a_tex;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];\n vec2 u_sdf_map_size;\n float u_raisingHeight: 0.0;\n float u_stroke_width : 2;\n float u_gamma_scale : 0.5;\n float u_halo_blur : 0.5;\n};\n\nout vec2 v_uv;\nout float v_gamma_scale;\nout vec4 v_color;\nout vec4 v_stroke_color;\nout float v_fontScale;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n#pragma include \"rotation_2d\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n \n v_uv = a_tex / u_sdf_map_size;\n\n\n\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n v_stroke_color = vec4(u_stroke_color.xyz, u_stroke_color.w * opacity);\n\n // \u6587\u672C\u7F29\u653E\u6BD4\u4F8B\n float fontScale = a_Size / FONT_SIZE;\n v_fontScale = fontScale;\n\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n // vec4 projected_position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n vec2 offset = rotate_matrix(a_textOffsets,rotation);\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 = project_common_position_to_clipspace_v2(vec4(project_pos.xyz + vec3(0.0, 0.0, raiseHeight), 1.0));\n\n gl_Position = vec4(\n projected_position.xy / projected_position.w + offset * 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";
26
13
  import { ShaderLocation } from "../../core/CommonStyleAttribute";
27
- var isEqual = lodashUtil.isEqual;
14
+ const {
15
+ isEqual
16
+ } = lodashUtil;
28
17
  export function TextTrianglation(feature) {
29
18
  // @ts-ignore
30
- var that = this;
31
- var id = feature.id;
32
- var vertices = [];
33
- var indices = [];
19
+ const that = this;
20
+ const id = feature.id;
21
+ const vertices = [];
22
+ const indices = [];
34
23
  if (!that.glyphInfoMap || !that.glyphInfoMap[id]) {
35
24
  return {
36
25
  vertices: [],
@@ -39,589 +28,469 @@ export function TextTrianglation(feature) {
39
28
  size: 7
40
29
  };
41
30
  }
42
- var centroid = that.glyphInfoMap[id].centroid; // 计算中心点
43
- var coord = centroid.length === 2 ? [centroid[0], centroid[1], 0] : centroid;
44
- that.glyphInfoMap[id].glyphQuads.forEach(function (quad, index) {
45
- vertices.push.apply(vertices, _toConsumableArray(coord).concat([quad.tex.x, quad.tex.y + quad.tex.height, quad.tl.x, quad.tl.y], _toConsumableArray(coord), [quad.tex.x + quad.tex.width, quad.tex.y + quad.tex.height, quad.tr.x, quad.tr.y], _toConsumableArray(coord), [quad.tex.x + quad.tex.width, quad.tex.y, quad.br.x, quad.br.y], _toConsumableArray(coord), [quad.tex.x, quad.tex.y, quad.bl.x, quad.bl.y]));
31
+ const centroid = that.glyphInfoMap[id].centroid; // 计算中心点
32
+ const coord = centroid.length === 2 ? [centroid[0], centroid[1], 0] : centroid;
33
+ that.glyphInfoMap[id].glyphQuads.forEach((quad, index) => {
34
+ vertices.push(...coord, quad.tex.x, quad.tex.y + quad.tex.height, quad.tl.x, quad.tl.y, ...coord, quad.tex.x + quad.tex.width, quad.tex.y + quad.tex.height, quad.tr.x, quad.tr.y, ...coord, quad.tex.x + quad.tex.width, quad.tex.y, quad.br.x, quad.br.y, ...coord, quad.tex.x, quad.tex.y, quad.bl.x, quad.bl.y);
46
35
  indices.push(0 + index * 4, 1 + index * 4, 2 + index * 4, 2 + index * 4, 3 + index * 4, 0 + index * 4);
47
36
  });
48
37
  return {
49
- vertices: vertices,
38
+ vertices,
50
39
  // [ x, y, z, tex.x,tex.y, offset.x. offset.y]
51
- indices: indices,
40
+ indices,
52
41
  size: 7
53
42
  };
54
43
  }
55
- var TextModel = /*#__PURE__*/function (_BaseModel) {
56
- _inherits(TextModel, _BaseModel);
57
- var _super = _createSuper(TextModel);
58
- function TextModel() {
44
+ export default class TextModel extends BaseModel {
45
+ constructor(...args) {
59
46
  var _this;
60
- _classCallCheck(this, TextModel);
61
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
62
- args[_key] = arguments[_key];
63
- }
64
- _this = _super.call.apply(_super, [this].concat(args));
65
- _defineProperty(_assertThisInitialized(_this), "glyphInfoMap", {});
66
- _defineProperty(_assertThisInitialized(_this), "currentZoom", -1);
67
- _defineProperty(_assertThisInitialized(_this), "textureHeight", 0);
68
- _defineProperty(_assertThisInitialized(_this), "textCount", 0);
69
- _defineProperty(_assertThisInitialized(_this), "preTextStyle", {});
70
- _defineProperty(_assertThisInitialized(_this), "mapping", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
71
- return _regeneratorRuntime.wrap(function _callee$(_context) {
72
- while (1) switch (_context.prev = _context.next) {
73
- case 0:
74
- _this.initGlyph(); //
75
- _this.updateTexture();
76
- _context.next = 4;
77
- return _this.reBuildModel();
78
- case 4:
79
- case "end":
80
- return _context.stop();
81
- }
82
- }, _callee);
83
- })));
84
- return _this;
47
+ super(...args);
48
+ _this = this;
49
+ _defineProperty(this, "glyphInfo", void 0);
50
+ _defineProperty(this, "glyphInfoMap", {});
51
+ _defineProperty(this, "rawEncodeData", void 0);
52
+ _defineProperty(this, "texture", void 0);
53
+ _defineProperty(this, "currentZoom", -1);
54
+ _defineProperty(this, "extent", void 0);
55
+ _defineProperty(this, "textureHeight", 0);
56
+ _defineProperty(this, "textCount", 0);
57
+ _defineProperty(this, "preTextStyle", {});
58
+ _defineProperty(this, "mapping", /*#__PURE__*/_asyncToGenerator(function* () {
59
+ _this.initGlyph(); //
60
+ _this.updateTexture();
61
+ yield _this.reBuildModel();
62
+ }));
85
63
  }
86
- _createClass(TextModel, [{
87
- key: "getUninforms",
88
- value: function getUninforms() {
89
- var commoninfo = this.getCommonUniformsInfo();
90
- var attributeInfo = this.getUniformsBufferInfo(this.getStyleAttribute());
91
- this.updateStyleUnifoms();
92
- return _objectSpread(_objectSpread(_objectSpread({}, commoninfo.uniformsOption), attributeInfo.uniformsOption), {
93
- u_sdf_map: this.textures[0]
94
- });
64
+ getUninforms() {
65
+ const commoninfo = this.getCommonUniformsInfo();
66
+ const attributeInfo = this.getUniformsBufferInfo(this.getStyleAttribute());
67
+ this.updateStyleUnifoms();
68
+ return _objectSpread(_objectSpread(_objectSpread({}, commoninfo.uniformsOption), attributeInfo.uniformsOption), {
69
+ u_sdf_map: this.textures[0]
70
+ });
71
+ }
72
+ getCommonUniformsInfo() {
73
+ const {
74
+ stroke = '#fff',
75
+ strokeWidth = 0,
76
+ halo = 0.5,
77
+ gamma = 2.0,
78
+ raisingHeight = 0
79
+ } = this.layer.getLayerConfig();
80
+ const mapping = this.getFontServiceMapping();
81
+ const canvas = this.getFontServiceCanvas();
82
+ if (mapping && Object.keys(mapping).length !== this.textCount && canvas) {
83
+ this.updateTexture();
84
+ this.textCount = Object.keys(mapping).length;
95
85
  }
96
- }, {
97
- key: "getCommonUniformsInfo",
98
- value: function getCommonUniformsInfo() {
99
- var _ref2 = this.layer.getLayerConfig(),
100
- _ref2$stroke = _ref2.stroke,
101
- stroke = _ref2$stroke === void 0 ? '#fff' : _ref2$stroke,
102
- _ref2$strokeWidth = _ref2.strokeWidth,
103
- strokeWidth = _ref2$strokeWidth === void 0 ? 0 : _ref2$strokeWidth,
104
- _ref2$halo = _ref2.halo,
105
- halo = _ref2$halo === void 0 ? 0.5 : _ref2$halo,
106
- _ref2$gamma = _ref2.gamma,
107
- gamma = _ref2$gamma === void 0 ? 2.0 : _ref2$gamma,
108
- _ref2$raisingHeight = _ref2.raisingHeight,
109
- raisingHeight = _ref2$raisingHeight === void 0 ? 0 : _ref2$raisingHeight;
110
- var mapping = this.getFontServiceMapping();
111
- var canvas = this.getFontServiceCanvas();
112
- if (mapping && Object.keys(mapping).length !== this.textCount && canvas) {
113
- this.updateTexture();
114
- this.textCount = Object.keys(mapping).length;
86
+ this.preTextStyle = this.getTextStyle();
87
+ const commonOptions = {
88
+ u_stroke_color: rgb2arr(stroke),
89
+ u_sdf_map_size: [(canvas === null || canvas === void 0 ? void 0 : canvas.width) || 1, (canvas === null || canvas === void 0 ? void 0 : canvas.height) || 1],
90
+ u_raisingHeight: Number(raisingHeight),
91
+ u_stroke_width: strokeWidth,
92
+ u_gamma_scale: gamma,
93
+ u_halo_blur: halo
94
+ };
95
+ const commonBufferInfo = this.getUniformsBufferInfo(commonOptions);
96
+ return commonBufferInfo;
97
+ }
98
+ initModels() {
99
+ var _this2 = this;
100
+ return _asyncToGenerator(function* () {
101
+ // 绑定事件
102
+ _this2.bindEvent();
103
+ _this2.extent = _this2.textExtent();
104
+ _this2.rawEncodeData = _this2.layer.getEncodedData();
105
+ _this2.preTextStyle = _this2.getTextStyle();
106
+ _this2.initUniformsBuffer();
107
+ return _this2.buildModels();
108
+ })();
109
+ }
110
+ buildModels() {
111
+ var _this3 = this;
112
+ return _asyncToGenerator(function* () {
113
+ const {
114
+ textAllowOverlap = false
115
+ } = _this3.layer.getLayerConfig();
116
+
117
+ // this.mapping(); 重复调用
118
+ _this3.initGlyph(); //
119
+ _this3.updateTexture();
120
+ if (!textAllowOverlap) {
121
+ _this3.filterGlyphs();
115
122
  }
116
- this.preTextStyle = this.getTextStyle();
117
- var commonOptions = {
118
- u_stroke_color: rgb2arr(stroke),
119
- u_sdf_map_size: [(canvas === null || canvas === void 0 ? void 0 : canvas.width) || 1, (canvas === null || canvas === void 0 ? void 0 : canvas.height) || 1],
120
- u_raisingHeight: Number(raisingHeight),
121
- u_stroke_width: strokeWidth,
122
- u_gamma_scale: gamma,
123
- u_halo_blur: halo
124
- };
125
- var commonBufferInfo = this.getUniformsBufferInfo(commonOptions);
126
- return commonBufferInfo;
127
- }
128
- }, {
129
- key: "initModels",
130
- value: function () {
131
- var _initModels = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
132
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
133
- while (1) switch (_context2.prev = _context2.next) {
134
- case 0:
135
- // 绑定事件
136
- this.bindEvent();
137
- this.extent = this.textExtent();
138
- this.rawEncodeData = this.layer.getEncodedData();
139
- this.preTextStyle = this.getTextStyle();
140
- this.initUniformsBuffer();
141
- return _context2.abrupt("return", this.buildModels());
142
- case 6:
143
- case "end":
144
- return _context2.stop();
145
- }
146
- }, _callee2, this);
147
- }));
148
- function initModels() {
149
- return _initModels.apply(this, arguments);
123
+ const model = yield _this3.layer.buildLayerModel({
124
+ moduleName: 'pointText',
125
+ vertexShader: textVert,
126
+ fragmentShader: textFrag,
127
+ inject: _this3.getInject(),
128
+ triangulation: TextTrianglation.bind(_this3),
129
+ depth: {
130
+ enable: false
131
+ }
132
+ });
133
+ return [model];
134
+ })();
135
+ }
136
+ // 需要更新的场景
137
+ // 1. 文本偏移量发生改变
138
+ // 2. 文本锚点发生改变
139
+ // 3. 文本允许重叠发生改变
140
+ // 4. 文本字体发生改变
141
+ // 5. 文本字体粗细发生改变
142
+ needUpdate() {
143
+ var _this4 = this;
144
+ return _asyncToGenerator(function* () {
145
+ const {
146
+ textAllowOverlap = false,
147
+ textAnchor = 'center',
148
+ textOffset,
149
+ padding,
150
+ fontFamily,
151
+ fontWeight
152
+ } = _this4.getTextStyle();
153
+ if (!isEqual(padding, _this4.preTextStyle.padding) || !isEqual(textOffset, _this4.preTextStyle.textOffset) || !isEqual(textAnchor, _this4.preTextStyle.textAnchor) || !isEqual(fontFamily, _this4.preTextStyle.fontFamily) || !isEqual(fontWeight, _this4.preTextStyle.fontWeight)) {
154
+ yield _this4.mapping();
155
+ return true;
150
156
  }
151
- return initModels;
152
- }()
153
- }, {
154
- key: "buildModels",
155
- value: function () {
156
- var _buildModels = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
157
- var _ref3, _ref3$textAllowOverla, textAllowOverlap, model;
158
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
159
- while (1) switch (_context3.prev = _context3.next) {
160
- case 0:
161
- _ref3 = this.layer.getLayerConfig(), _ref3$textAllowOverla = _ref3.textAllowOverlap, textAllowOverlap = _ref3$textAllowOverla === void 0 ? false : _ref3$textAllowOverla; // this.mapping(); 重复调用
162
- this.initGlyph(); //
163
- this.updateTexture();
164
- if (!textAllowOverlap) {
165
- this.filterGlyphs();
166
- }
167
- _context3.next = 6;
168
- return this.layer.buildLayerModel({
169
- moduleName: 'pointText',
170
- vertexShader: textVert,
171
- fragmentShader: textFrag,
172
- inject: this.getInject(),
173
- triangulation: TextTrianglation.bind(this),
174
- depth: {
175
- enable: false
176
- }
177
- });
178
- case 6:
179
- model = _context3.sent;
180
- return _context3.abrupt("return", [model]);
181
- case 8:
182
- case "end":
183
- return _context3.stop();
184
- }
185
- }, _callee3, this);
186
- }));
187
- function buildModels() {
188
- return _buildModels.apply(this, arguments);
157
+ if (textAllowOverlap) {
158
+ // 小于不做避让
159
+ return false;
189
160
  }
190
- return buildModels;
191
- }() // 需要更新的场景
192
- // 1. 文本偏移量发生改变
193
- // 2. 文本锚点发生改变
194
- // 3. 文本允许重叠发生改变
195
- // 4. 文本字体发生改变
196
- // 5. 文本字体粗细发生改变
197
- }, {
198
- key: "needUpdate",
199
- value: function () {
200
- var _needUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
201
- var _ref4, _ref4$textAllowOverla, textAllowOverlap, _ref4$textAnchor, textAnchor, textOffset, padding, fontFamily, fontWeight, zoom, extent, flag;
202
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
203
- while (1) switch (_context4.prev = _context4.next) {
204
- case 0:
205
- _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;
206
- if (!(!isEqual(padding, this.preTextStyle.padding) || !isEqual(textOffset, this.preTextStyle.textOffset) || !isEqual(textAnchor, this.preTextStyle.textAnchor) || !isEqual(fontFamily, this.preTextStyle.fontFamily) || !isEqual(fontWeight, this.preTextStyle.fontWeight))) {
207
- _context4.next = 5;
208
- break;
209
- }
210
- _context4.next = 4;
211
- return this.mapping();
212
- case 4:
213
- return _context4.abrupt("return", true);
214
- case 5:
215
- if (!textAllowOverlap) {
216
- _context4.next = 7;
217
- break;
218
- }
219
- return _context4.abrupt("return", false);
220
- case 7:
221
- // textAllowOverlap 发生改变
222
- zoom = this.mapService.getZoom();
223
- extent = this.mapService.getBounds();
224
- flag = boundsContains(this.extent, extent); // 文本不能压盖则进行过滤
225
- if (!(Math.abs(this.currentZoom - zoom) > 0.5 || !flag || textAllowOverlap !== this.preTextStyle.textAllowOverlap)) {
226
- _context4.next = 14;
227
- break;
228
- }
229
- _context4.next = 13;
230
- return this.reBuildModel();
231
- case 13:
232
- return _context4.abrupt("return", true);
233
- case 14:
234
- return _context4.abrupt("return", false);
235
- case 15:
236
- case "end":
237
- return _context4.stop();
238
- }
239
- }, _callee4, this);
240
- }));
241
- function needUpdate() {
242
- return _needUpdate.apply(this, arguments);
161
+
162
+ // textAllowOverlap 发生改变
163
+ const zoom = _this4.mapService.getZoom();
164
+ const extent = _this4.mapService.getBounds();
165
+ const flag = boundsContains(_this4.extent, extent);
166
+ // 文本不能压盖则进行过滤
167
+ if (Math.abs(_this4.currentZoom - zoom) > 0.5 || !flag || textAllowOverlap !== _this4.preTextStyle.textAllowOverlap) {
168
+ // TODO this.mapping 数据未变化,避让
169
+ yield _this4.reBuildModel();
170
+ return true;
243
171
  }
244
- return needUpdate;
245
- }()
246
- }, {
247
- key: "clearModels",
248
- value: function clearModels() {
249
- var _this$texture;
250
- (_this$texture = this.texture) === null || _this$texture === void 0 || _this$texture.destroy();
251
- // TODO this.mapping
252
- this.layer.off('remapping', this.mapping);
253
- }
254
- }, {
255
- key: "registerBuiltinAttributes",
256
- value: function registerBuiltinAttributes() {
257
- this.styleAttributeService.registerStyleAttribute({
258
- name: 'textOffsets',
259
- type: AttributeType.Attribute,
260
- descriptor: {
261
- shaderLocation: 10,
262
- name: 'a_textOffsets',
263
- // 文字偏移量
264
- buffer: {
265
- // give the WebGL driver a hint that this buffer may change
266
- usage: gl.STATIC_DRAW,
267
- data: [],
268
- type: gl.FLOAT
269
- },
270
- size: 2,
271
- update: function update(feature, featureIdx, vertex) {
272
- return [vertex[5], vertex[6]];
273
- }
172
+ return false;
173
+ })();
174
+ }
175
+ clearModels() {
176
+ var _this$texture;
177
+ (_this$texture = this.texture) === null || _this$texture === void 0 || _this$texture.destroy();
178
+ // TODO this.mapping
179
+ this.layer.off('remapping', this.mapping);
180
+ }
181
+ registerBuiltinAttributes() {
182
+ this.styleAttributeService.registerStyleAttribute({
183
+ name: 'textOffsets',
184
+ type: AttributeType.Attribute,
185
+ descriptor: {
186
+ shaderLocation: 10,
187
+ name: 'a_textOffsets',
188
+ // 文字偏移量
189
+ buffer: {
190
+ // give the WebGL driver a hint that this buffer may change
191
+ usage: gl.STATIC_DRAW,
192
+ data: [],
193
+ type: gl.FLOAT
194
+ },
195
+ size: 2,
196
+ update: (feature, featureIdx, vertex) => {
197
+ return [vertex[5], vertex[6]];
274
198
  }
275
- });
276
- this.styleAttributeService.registerStyleAttribute({
277
- name: 'textUv',
278
- type: AttributeType.Attribute,
279
- descriptor: {
280
- name: 'a_tex',
281
- shaderLocation: ShaderLocation.UV,
282
- buffer: {
283
- usage: gl.DYNAMIC_DRAW,
284
- data: [],
285
- type: gl.FLOAT
286
- },
287
- size: 2,
288
- update: function update(feature, featureIdx, vertex) {
289
- return [vertex[3], vertex[4]];
290
- }
199
+ }
200
+ });
201
+ this.styleAttributeService.registerStyleAttribute({
202
+ name: 'textUv',
203
+ type: AttributeType.Attribute,
204
+ descriptor: {
205
+ name: 'a_tex',
206
+ shaderLocation: ShaderLocation.UV,
207
+ buffer: {
208
+ usage: gl.DYNAMIC_DRAW,
209
+ data: [],
210
+ type: gl.FLOAT
211
+ },
212
+ size: 2,
213
+ update: (feature, featureIdx, vertex) => {
214
+ return [vertex[3], vertex[4]];
291
215
  }
292
- });
293
- // point layer size;
294
- this.styleAttributeService.registerStyleAttribute({
295
- name: 'size',
296
- type: AttributeType.Attribute,
297
- descriptor: {
298
- name: 'a_Size',
299
- shaderLocation: ShaderLocation.SIZE,
300
- buffer: {
301
- // give the WebGL driver a hint that this buffer may change
302
- usage: gl.DYNAMIC_DRAW,
303
- data: [],
304
- type: gl.FLOAT
305
- },
306
- size: 1,
307
- update: function update(feature) {
308
- var _feature$size = feature.size,
309
- size = _feature$size === void 0 ? 12 : _feature$size;
310
- return Array.isArray(size) ? [size[0]] : [size];
311
- }
216
+ }
217
+ });
218
+ // point layer size;
219
+ this.styleAttributeService.registerStyleAttribute({
220
+ name: 'size',
221
+ type: AttributeType.Attribute,
222
+ descriptor: {
223
+ name: 'a_Size',
224
+ shaderLocation: ShaderLocation.SIZE,
225
+ buffer: {
226
+ // give the WebGL driver a hint that this buffer may change
227
+ usage: gl.DYNAMIC_DRAW,
228
+ data: [],
229
+ type: gl.FLOAT
230
+ },
231
+ size: 1,
232
+ update: feature => {
233
+ const {
234
+ size = 12
235
+ } = feature;
236
+ return Array.isArray(size) ? [size[0]] : [size];
312
237
  }
313
- });
314
- }
315
- }, {
316
- key: "bindEvent",
317
- value: function bindEvent() {
318
- if (!this.layer.isTileLayer) {
319
- // 重新绑定
320
- this.layer.on('remapping', this.mapping);
321
238
  }
239
+ });
240
+ }
241
+ bindEvent() {
242
+ if (!this.layer.isTileLayer) {
243
+ // 重新绑定
244
+ this.layer.on('remapping', this.mapping);
322
245
  }
323
- }, {
324
- key: "textExtent",
325
- value: function textExtent() {
326
- var bounds = this.mapService.getBounds();
327
- return padBounds(bounds, 0.5);
328
- }
329
- /**
330
- * 生成文字纹理(生成文字纹理字典)
331
- */
332
- }, {
333
- key: "initTextFont",
334
- value: function initTextFont() {
335
- var _this$getTextStyle = this.getTextStyle(),
336
- fontWeight = _this$getTextStyle.fontWeight,
337
- fontFamily = _this$getTextStyle.fontFamily;
338
- var data = this.rawEncodeData;
339
- var characterSet = [];
340
- data.forEach(function (item) {
341
- var _item$shape = item.shape,
342
- shape = _item$shape === void 0 ? '' : _item$shape;
343
- shape = shape.toString();
344
- var _iterator = _createForOfIteratorHelper(shape),
345
- _step;
346
- try {
347
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
348
- var char = _step.value;
349
- // 去重
350
- if (characterSet.indexOf(char) === -1) {
351
- characterSet.push(char);
352
- }
353
- }
354
- } catch (err) {
355
- _iterator.e(err);
356
- } finally {
357
- _iterator.f();
246
+ }
247
+ textExtent() {
248
+ const bounds = this.mapService.getBounds();
249
+ return padBounds(bounds, 0.5);
250
+ }
251
+ /**
252
+ * 生成文字纹理(生成文字纹理字典)
253
+ */
254
+ initTextFont() {
255
+ const {
256
+ fontWeight,
257
+ fontFamily
258
+ } = this.getTextStyle();
259
+ const data = this.rawEncodeData;
260
+ const characterSet = [];
261
+ data.forEach(item => {
262
+ let {
263
+ shape = ''
264
+ } = item;
265
+ shape = shape.toString();
266
+ for (const char of shape) {
267
+ // 去重
268
+ if (characterSet.indexOf(char) === -1) {
269
+ characterSet.push(char);
358
270
  }
359
- });
360
- this.fontService.setFontOptions({
361
- characterSet: characterSet,
362
- fontWeight: fontWeight,
363
- fontFamily: fontFamily,
364
- iconfont: false
365
- });
366
- }
271
+ }
272
+ });
273
+ this.fontService.setFontOptions({
274
+ characterSet,
275
+ fontWeight,
276
+ fontFamily,
277
+ iconfont: false
278
+ });
279
+ }
367
280
 
368
- /**
369
- * 生成 iconfont 纹理字典
370
- */
371
- }, {
372
- key: "initIconFontTex",
373
- value: function initIconFontTex() {
374
- var _this$getTextStyle2 = this.getTextStyle(),
375
- fontWeight = _this$getTextStyle2.fontWeight,
376
- fontFamily = _this$getTextStyle2.fontFamily;
377
- var data = this.rawEncodeData;
378
- var characterSet = [];
379
- data.forEach(function (item) {
380
- var _item$shape2 = item.shape,
381
- shape = _item$shape2 === void 0 ? '' : _item$shape2;
382
- shape = "".concat(shape);
383
- if (characterSet.indexOf(shape) === -1) {
384
- characterSet.push(shape);
385
- }
386
- });
387
- this.fontService.setFontOptions({
388
- characterSet: characterSet,
389
- fontWeight: fontWeight,
390
- fontFamily: fontFamily,
391
- iconfont: true
392
- });
393
- }
394
- }, {
395
- key: "getTextStyle",
396
- value: function getTextStyle() {
397
- var _ref5 = this.layer.getLayerConfig(),
398
- _ref5$fontWeight = _ref5.fontWeight,
399
- fontWeight = _ref5$fontWeight === void 0 ? '400' : _ref5$fontWeight,
400
- _ref5$fontFamily = _ref5.fontFamily,
401
- fontFamily = _ref5$fontFamily === void 0 ? 'sans-serif' : _ref5$fontFamily,
402
- _ref5$textAllowOverla = _ref5.textAllowOverlap,
403
- textAllowOverlap = _ref5$textAllowOverla === void 0 ? false : _ref5$textAllowOverla,
404
- _ref5$padding = _ref5.padding,
405
- padding = _ref5$padding === void 0 ? [0, 0] : _ref5$padding,
406
- _ref5$textAnchor = _ref5.textAnchor,
407
- textAnchor = _ref5$textAnchor === void 0 ? 'center' : _ref5$textAnchor,
408
- _ref5$textOffset = _ref5.textOffset,
409
- textOffset = _ref5$textOffset === void 0 ? [0, 0] : _ref5$textOffset,
410
- _ref5$opacity = _ref5.opacity,
411
- opacity = _ref5$opacity === void 0 ? 1 : _ref5$opacity,
412
- _ref5$strokeOpacity = _ref5.strokeOpacity,
413
- strokeOpacity = _ref5$strokeOpacity === void 0 ? 1 : _ref5$strokeOpacity,
414
- _ref5$strokeWidth = _ref5.strokeWidth,
415
- strokeWidth = _ref5$strokeWidth === void 0 ? 0 : _ref5$strokeWidth,
416
- _ref5$stroke = _ref5.stroke,
417
- stroke = _ref5$stroke === void 0 ? '#000' : _ref5$stroke;
418
- return {
419
- fontWeight: fontWeight,
420
- fontFamily: fontFamily,
421
- textAllowOverlap: textAllowOverlap,
422
- padding: padding,
423
- textAnchor: textAnchor,
424
- textOffset: textOffset,
425
- opacity: opacity,
426
- strokeOpacity: strokeOpacity,
427
- strokeWidth: strokeWidth,
428
- stroke: stroke
429
- };
430
- }
281
+ /**
282
+ * 生成 iconfont 纹理字典
283
+ */
284
+ initIconFontTex() {
285
+ const {
286
+ fontWeight,
287
+ fontFamily
288
+ } = this.getTextStyle();
289
+ const data = this.rawEncodeData;
290
+ const characterSet = [];
291
+ data.forEach(item => {
292
+ let {
293
+ shape = ''
294
+ } = item;
295
+ shape = `${shape}`;
296
+ if (characterSet.indexOf(shape) === -1) {
297
+ characterSet.push(shape);
298
+ }
299
+ });
300
+ this.fontService.setFontOptions({
301
+ characterSet,
302
+ fontWeight,
303
+ fontFamily,
304
+ iconfont: true
305
+ });
306
+ }
307
+ getTextStyle() {
308
+ const {
309
+ fontWeight = '400',
310
+ fontFamily = 'sans-serif',
311
+ textAllowOverlap = false,
312
+ padding = [0, 0],
313
+ textAnchor = 'center',
314
+ textOffset = [0, 0],
315
+ opacity = 1,
316
+ strokeOpacity = 1,
317
+ strokeWidth = 0,
318
+ stroke = '#000'
319
+ } = this.layer.getLayerConfig();
320
+ return {
321
+ fontWeight,
322
+ fontFamily,
323
+ textAllowOverlap,
324
+ padding,
325
+ textAnchor,
326
+ textOffset,
327
+ opacity,
328
+ strokeOpacity,
329
+ strokeWidth,
330
+ stroke
331
+ };
332
+ }
431
333
 
432
- /**
433
- * 生成文字布局(对照文字纹理字典提取对应文字的位置很好信息)
434
- */
435
- }, {
436
- key: "generateGlyphLayout",
437
- value: function generateGlyphLayout(iconfont) {
438
- var _this2 = this;
439
- var mapping = this.getFontServiceMapping();
440
- var _ref6 = this.layer.getLayerConfig(),
441
- _ref6$spacing = _ref6.spacing,
442
- spacing = _ref6$spacing === void 0 ? 2 : _ref6$spacing,
443
- _ref6$textAnchor = _ref6.textAnchor,
444
- textAnchor = _ref6$textAnchor === void 0 ? 'center' : _ref6$textAnchor,
445
- textOffset = _ref6.textOffset;
446
- var data = this.rawEncodeData;
447
- this.glyphInfo = data.map(function (feature) {
448
- var _feature$shape = feature.shape,
449
- shape = _feature$shape === void 0 ? '' : _feature$shape,
450
- id = feature.id,
451
- _feature$size2 = feature.size,
452
- size = _feature$size2 === void 0 ? 1 : _feature$size2;
453
- var offset = feature.textOffset ? feature.textOffset : textOffset || [0, 0];
454
- var anchor = feature.textAnchor ? feature.textAnchor : textAnchor || 'center';
455
- var shaping = shapeText(shape.toString(), mapping,
456
- // @ts-ignore
457
- size, anchor, 'left', spacing, offset,
458
- //
459
- iconfont);
460
- var glyphQuads = getGlyphQuads(shaping, offset, false);
461
- feature.shaping = shaping;
462
- feature.glyphQuads = glyphQuads;
463
- // feature.centroid = calculteCentroid(coordinates);
334
+ /**
335
+ * 生成文字布局(对照文字纹理字典提取对应文字的位置很好信息)
336
+ */
337
+ generateGlyphLayout(iconfont) {
338
+ const mapping = this.getFontServiceMapping();
339
+ const {
340
+ spacing = 2,
341
+ textAnchor = 'center',
342
+ textOffset
343
+ } = this.layer.getLayerConfig();
344
+ const data = this.rawEncodeData;
345
+ this.glyphInfo = data.map(feature => {
346
+ const {
347
+ shape = '',
348
+ id,
349
+ size = 1
350
+ } = feature;
351
+ const offset = feature.textOffset ? feature.textOffset : textOffset || [0, 0];
352
+ const anchor = feature.textAnchor ? feature.textAnchor : textAnchor || 'center';
353
+ const shaping = shapeText(shape.toString(), mapping,
354
+ // @ts-ignore
355
+ size, anchor, 'left', spacing, offset,
356
+ //
357
+ iconfont);
358
+ const glyphQuads = getGlyphQuads(shaping, offset, false);
359
+ feature.shaping = shaping;
360
+ feature.glyphQuads = glyphQuads;
361
+ // feature.centroid = calculteCentroid(coordinates);
464
362
 
465
- feature.centroid = calculateCentroid(feature.coordinates);
363
+ feature.centroid = calculateCentroid(feature.coordinates);
466
364
 
467
- // 此时地图高德2.0 originCentroid == centroid
468
- feature.originCentroid = feature.version === 'GAODE2.x' ? calculateCentroid(feature.originCoordinates) : feature.originCentroid = feature.centroid;
469
- _this2.glyphInfoMap[id] = {
470
- shaping: shaping,
471
- glyphQuads: glyphQuads,
472
- centroid: calculateCentroid(feature.coordinates)
473
- };
474
- return feature;
475
- });
476
- }
477
- }, {
478
- key: "getFontServiceMapping",
479
- value: function getFontServiceMapping() {
480
- var _ref7 = this.layer.getLayerConfig(),
481
- _ref7$fontWeight = _ref7.fontWeight,
482
- fontWeight = _ref7$fontWeight === void 0 ? '400' : _ref7$fontWeight,
483
- _ref7$fontFamily = _ref7.fontFamily,
484
- fontFamily = _ref7$fontFamily === void 0 ? 'sans-serif' : _ref7$fontFamily;
485
- return this.fontService.getMappingByKey("".concat(fontFamily, "_").concat(fontWeight));
486
- }
487
- }, {
488
- key: "getFontServiceCanvas",
489
- value: function getFontServiceCanvas() {
490
- var _ref8 = this.layer.getLayerConfig(),
491
- _ref8$fontWeight = _ref8.fontWeight,
492
- fontWeight = _ref8$fontWeight === void 0 ? '400' : _ref8$fontWeight,
493
- _ref8$fontFamily = _ref8.fontFamily,
494
- fontFamily = _ref8$fontFamily === void 0 ? 'sans-serif' : _ref8$fontFamily;
495
- // 更新文字布局
496
- return this.fontService.getCanvasByKey("".concat(fontFamily, "_").concat(fontWeight));
497
- }
365
+ // 此时地图高德2.0 originCentroid == centroid
366
+ feature.originCentroid = feature.version === 'GAODE2.x' ? calculateCentroid(feature.originCoordinates) : feature.originCentroid = feature.centroid;
367
+ this.glyphInfoMap[id] = {
368
+ shaping,
369
+ glyphQuads,
370
+ centroid: calculateCentroid(feature.coordinates)
371
+ };
372
+ return feature;
373
+ });
374
+ }
375
+ getFontServiceMapping() {
376
+ const {
377
+ fontWeight = '400',
378
+ fontFamily = 'sans-serif'
379
+ } = this.layer.getLayerConfig();
380
+ return this.fontService.getMappingByKey(`${fontFamily}_${fontWeight}`);
381
+ }
382
+ getFontServiceCanvas() {
383
+ const {
384
+ fontWeight = '400',
385
+ fontFamily = 'sans-serif'
386
+ } = this.layer.getLayerConfig();
387
+ // 更新文字布局
388
+ return this.fontService.getCanvasByKey(`${fontFamily}_${fontWeight}`);
389
+ }
498
390
 
499
- /**
500
- * 文字避让 depend on originCentorid
501
- */
502
- }, {
503
- key: "filterGlyphs",
504
- value: function filterGlyphs() {
505
- var _this3 = this;
506
- var _ref9 = this.layer.getLayerConfig(),
507
- _ref9$padding = _ref9.padding,
508
- padding = _ref9$padding === void 0 ? [0, 0] : _ref9$padding,
509
- _ref9$textAllowOverla = _ref9.textAllowOverlap,
510
- textAllowOverlap = _ref9$textAllowOverla === void 0 ? false : _ref9$textAllowOverla;
511
- if (textAllowOverlap) {
512
- // 如果允许文本覆盖
513
- return;
514
- }
515
- this.glyphInfoMap = {};
516
- this.currentZoom = this.mapService.getZoom();
517
- this.extent = this.textExtent();
518
- var _this$rendererService = this.rendererService.getViewportSize(),
519
- width = _this$rendererService.width,
520
- height = _this$rendererService.height;
521
- var collisionIndex = new CollisionIndex(width, height);
522
- var filterData = this.glyphInfo.filter(function (feature) {
523
- var shaping = feature.shaping,
524
- _feature$id = feature.id,
525
- id = _feature$id === void 0 ? 0 : _feature$id;
526
- // const centroid = feature.centroid as [number, number];
527
- // const centroid = feature.originCentroid as [number, number];
528
- var centroid = feature.version === 'GAODE2.x' ? feature.originCentroid : feature.centroid;
529
- var size = feature.size;
530
- var fontScale = size / 16;
531
- var pixels = _this3.mapService.lngLatToContainer(centroid);
532
- var _collisionIndex$place = collisionIndex.placeCollisionBox({
533
- x1: shaping.left * fontScale - padding[0],
534
- x2: shaping.right * fontScale + padding[0],
535
- y1: shaping.top * fontScale - padding[1],
536
- y2: shaping.bottom * fontScale + padding[1],
537
- anchorPointX: pixels.x,
538
- anchorPointY: pixels.y
539
- }),
540
- box = _collisionIndex$place.box;
541
- if (box && box.length) {
542
- collisionIndex.insertCollisionBox(box, id);
543
- return true;
544
- } else {
545
- return false;
546
- }
547
- });
548
- filterData.forEach(function (item) {
549
- // @ts-ignore
550
- _this3.glyphInfoMap[item.id] = item;
551
- });
552
- // this.layer.setEncodedData(filterData);
391
+ /**
392
+ * 文字避让 depend on originCentorid
393
+ */
394
+ filterGlyphs() {
395
+ const {
396
+ padding = [0, 0],
397
+ textAllowOverlap = false
398
+ } = this.layer.getLayerConfig();
399
+ if (textAllowOverlap) {
400
+ // 如果允许文本覆盖
401
+ return;
553
402
  }
554
- /**
555
- * 初始化文字布局
556
- */
557
- }, {
558
- key: "initGlyph",
559
- value: function initGlyph() {
560
- var _this$layer$getLayerC = this.layer.getLayerConfig(),
561
- _this$layer$getLayerC2 = _this$layer$getLayerC.iconfont,
562
- iconfont = _this$layer$getLayerC2 === void 0 ? false : _this$layer$getLayerC2;
563
- // 1.生成文字纹理(或是生成 iconfont)
564
- iconfont ? this.initIconFontTex() : this.initTextFont();
565
- // 2.生成文字布局
566
- this.generateGlyphLayout(iconfont);
567
- }
568
- /**
569
- * 更新文字纹理
570
- */
571
- }, {
572
- key: "updateTexture",
573
- value: function updateTexture() {
574
- var createTexture2D = this.rendererService.createTexture2D;
575
- var canvas = this.getFontServiceCanvas();
576
- this.textureHeight = canvas.height;
577
- if (this.texture) {
578
- this.texture.destroy();
579
- }
580
- this.texture = createTexture2D({
581
- data: canvas,
582
- mag: gl.LINEAR,
583
- min: gl.LINEAR,
584
- width: canvas.width,
585
- height: canvas.height
403
+ this.glyphInfoMap = {};
404
+ this.currentZoom = this.mapService.getZoom();
405
+ this.extent = this.textExtent();
406
+ const {
407
+ width,
408
+ height
409
+ } = this.rendererService.getViewportSize();
410
+ const collisionIndex = new CollisionIndex(width, height);
411
+ const filterData = this.glyphInfo.filter(feature => {
412
+ const {
413
+ shaping,
414
+ id = 0
415
+ } = feature;
416
+ // const centroid = feature.centroid as [number, number];
417
+ // const centroid = feature.originCentroid as [number, number];
418
+ const centroid = feature.version === 'GAODE2.x' ? feature.originCentroid : feature.centroid;
419
+ const size = feature.size;
420
+ const fontScale = size / 16;
421
+ const pixels = this.mapService.lngLatToContainer(centroid);
422
+ const {
423
+ box
424
+ } = collisionIndex.placeCollisionBox({
425
+ x1: shaping.left * fontScale - padding[0],
426
+ x2: shaping.right * fontScale + padding[0],
427
+ y1: shaping.top * fontScale - padding[1],
428
+ y2: shaping.bottom * fontScale + padding[1],
429
+ anchorPointX: pixels.x,
430
+ anchorPointY: pixels.y
586
431
  });
587
- this.textures = [this.texture];
588
- }
589
- }, {
590
- key: "reBuildModel",
591
- value: function () {
592
- var _reBuildModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
593
- var model;
594
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
595
- while (1) switch (_context5.prev = _context5.next) {
596
- case 0:
597
- this.filterGlyphs();
598
- _context5.next = 3;
599
- return this.layer.buildLayerModel({
600
- moduleName: 'pointText',
601
- vertexShader: textVert,
602
- fragmentShader: textFrag,
603
- triangulation: TextTrianglation.bind(this),
604
- inject: this.getInject(),
605
- depth: {
606
- enable: false
607
- }
608
- });
609
- case 3:
610
- model = _context5.sent;
611
- // TODO 渲染流程待修改
612
- this.layer.models = [model];
613
- case 5:
614
- case "end":
615
- return _context5.stop();
616
- }
617
- }, _callee5, this);
618
- }));
619
- function reBuildModel() {
620
- return _reBuildModel.apply(this, arguments);
432
+ if (box && box.length) {
433
+ collisionIndex.insertCollisionBox(box, id);
434
+ return true;
435
+ } else {
436
+ return false;
621
437
  }
622
- return reBuildModel;
623
- }()
624
- }]);
625
- return TextModel;
626
- }(BaseModel);
627
- export { TextModel as default };
438
+ });
439
+ filterData.forEach(item => {
440
+ // @ts-ignore
441
+ this.glyphInfoMap[item.id] = item;
442
+ });
443
+ // this.layer.setEncodedData(filterData);
444
+ }
445
+ /**
446
+ * 初始化文字布局
447
+ */
448
+ initGlyph() {
449
+ const {
450
+ iconfont = false
451
+ } = this.layer.getLayerConfig();
452
+ // 1.生成文字纹理(或是生成 iconfont)
453
+ iconfont ? this.initIconFontTex() : this.initTextFont();
454
+ // 2.生成文字布局
455
+ this.generateGlyphLayout(iconfont);
456
+ }
457
+ /**
458
+ * 更新文字纹理
459
+ */
460
+ updateTexture() {
461
+ const {
462
+ createTexture2D
463
+ } = this.rendererService;
464
+ const canvas = this.getFontServiceCanvas();
465
+ this.textureHeight = canvas.height;
466
+ if (this.texture) {
467
+ this.texture.destroy();
468
+ }
469
+ this.texture = createTexture2D({
470
+ data: canvas,
471
+ mag: gl.LINEAR,
472
+ min: gl.LINEAR,
473
+ width: canvas.width,
474
+ height: canvas.height
475
+ });
476
+ this.textures = [this.texture];
477
+ }
478
+ reBuildModel() {
479
+ var _this5 = this;
480
+ return _asyncToGenerator(function* () {
481
+ _this5.filterGlyphs();
482
+ const model = yield _this5.layer.buildLayerModel({
483
+ moduleName: 'pointText',
484
+ vertexShader: textVert,
485
+ fragmentShader: textFrag,
486
+ triangulation: TextTrianglation.bind(_this5),
487
+ inject: _this5.getInject(),
488
+ depth: {
489
+ enable: false
490
+ }
491
+ });
492
+ // TODO 渲染流程待修改
493
+ _this5.layer.models = [model];
494
+ })();
495
+ }
496
+ }