@scoova/mgl 1.0.0

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 (565) hide show
  1. package/LICENSE.txt +116 -0
  2. package/README.md +174 -0
  3. package/build/banner.ts +12 -0
  4. package/build/bump-version-changelog.js +26 -0
  5. package/build/check-bundle-size.js +77 -0
  6. package/build/generate-dist-package.js +26 -0
  7. package/build/generate-doc-images.ts +78 -0
  8. package/build/generate-docs.ts +190 -0
  9. package/build/generate-shaders.ts +68 -0
  10. package/build/generate-struct-arrays.ts +438 -0
  11. package/build/generate-style-code.ts +283 -0
  12. package/build/readme.md +56 -0
  13. package/build/release-notes.js +45 -0
  14. package/build/rollup/bundle_prelude.js +29 -0
  15. package/build/rollup/maplibregl.js +22 -0
  16. package/build/rollup_plugins.ts +58 -0
  17. package/dist/LICENSE.txt +116 -0
  18. package/dist/maplibre-gl.css +1 -0
  19. package/dist/maplibre-gl.d.ts +13304 -0
  20. package/dist/maplibre-gl.js +59 -0
  21. package/dist/maplibre-gl.js.map +1 -0
  22. package/dist/package.json +1 -0
  23. package/package.json +192 -0
  24. package/src/css/maplibre-gl.css +854 -0
  25. package/src/css/svg/maplibregl-ctrl-attrib.svg +3 -0
  26. package/src/css/svg/maplibregl-ctrl-compass.svg +4 -0
  27. package/src/css/svg/maplibregl-ctrl-fullscreen.svg +3 -0
  28. package/src/css/svg/maplibregl-ctrl-geolocate.svg +5 -0
  29. package/src/css/svg/maplibregl-ctrl-logo.svg +11 -0
  30. package/src/css/svg/maplibregl-ctrl-shrink.svg +3 -0
  31. package/src/css/svg/maplibregl-ctrl-terrain.svg +3 -0
  32. package/src/css/svg/maplibregl-ctrl-zoom-in.svg +3 -0
  33. package/src/css/svg/maplibregl-ctrl-zoom-out.svg +3 -0
  34. package/src/data/array_types.g.ts +1130 -0
  35. package/src/data/bucket/circle_attributes.ts +8 -0
  36. package/src/data/bucket/circle_bucket.ts +197 -0
  37. package/src/data/bucket/fill_attributes.ts +8 -0
  38. package/src/data/bucket/fill_bucket.test.ts +95 -0
  39. package/src/data/bucket/fill_bucket.ts +228 -0
  40. package/src/data/bucket/fill_extrusion_attributes.ts +13 -0
  41. package/src/data/bucket/fill_extrusion_bucket.ts +305 -0
  42. package/src/data/bucket/heatmap_bucket.ts +12 -0
  43. package/src/data/bucket/line_attributes.ts +8 -0
  44. package/src/data/bucket/line_attributes_ext.ts +8 -0
  45. package/src/data/bucket/line_bucket.test.ts +142 -0
  46. package/src/data/bucket/line_bucket.ts +592 -0
  47. package/src/data/bucket/pattern_attributes.ts +9 -0
  48. package/src/data/bucket/pattern_bucket_features.ts +57 -0
  49. package/src/data/bucket/symbol_attributes.ts +122 -0
  50. package/src/data/bucket/symbol_bucket.test.ts +243 -0
  51. package/src/data/bucket/symbol_bucket.ts +975 -0
  52. package/src/data/bucket.ts +123 -0
  53. package/src/data/dem_data.test.ts +237 -0
  54. package/src/data/dem_data.ts +171 -0
  55. package/src/data/evaluation_feature.ts +18 -0
  56. package/src/data/extent.ts +13 -0
  57. package/src/data/feature_index.ts +337 -0
  58. package/src/data/feature_position_map.test.ts +33 -0
  59. package/src/data/feature_position_map.ts +126 -0
  60. package/src/data/index_array_type.ts +9 -0
  61. package/src/data/load_geometry.test.ts +49 -0
  62. package/src/data/load_geometry.ts +44 -0
  63. package/src/data/pos3d_attributes.ts +5 -0
  64. package/src/data/pos_attributes.ts +5 -0
  65. package/src/data/program_configuration.ts +735 -0
  66. package/src/data/raster_bounds_attributes.ts +6 -0
  67. package/src/data/segment.ts +89 -0
  68. package/src/geo/edge_insets.test.ts +83 -0
  69. package/src/geo/edge_insets.ts +146 -0
  70. package/src/geo/lng_lat.test.ts +65 -0
  71. package/src/geo/lng_lat.ts +169 -0
  72. package/src/geo/lng_lat_bounds.test.ts +357 -0
  73. package/src/geo/lng_lat_bounds.ts +356 -0
  74. package/src/geo/mercator_coordinate.test.ts +34 -0
  75. package/src/geo/mercator_coordinate.ts +157 -0
  76. package/src/geo/projection/projection.ts +72 -0
  77. package/src/geo/transform.test.ts +509 -0
  78. package/src/geo/transform.ts +1072 -0
  79. package/src/gl/color_mode.ts +31 -0
  80. package/src/gl/context.ts +321 -0
  81. package/src/gl/cull_face_mode.ts +22 -0
  82. package/src/gl/depth_mode.ts +26 -0
  83. package/src/gl/framebuffer.ts +48 -0
  84. package/src/gl/index_buffer.ts +55 -0
  85. package/src/gl/render_pool.test.ts +69 -0
  86. package/src/gl/render_pool.ts +93 -0
  87. package/src/gl/state.test.ts +125 -0
  88. package/src/gl/stencil_mode.ts +27 -0
  89. package/src/gl/types.ts +59 -0
  90. package/src/gl/value.ts +534 -0
  91. package/src/gl/vertex_buffer.test.ts +57 -0
  92. package/src/gl/vertex_buffer.ts +111 -0
  93. package/src/gl/webgl2.ts +12 -0
  94. package/src/index.test.ts +121 -0
  95. package/src/index.ts +250 -0
  96. package/src/render/draw_background.ts +53 -0
  97. package/src/render/draw_circle.ts +113 -0
  98. package/src/render/draw_collision_debug.ts +168 -0
  99. package/src/render/draw_custom.test.ts +73 -0
  100. package/src/render/draw_custom.ts +45 -0
  101. package/src/render/draw_debug.test.ts +122 -0
  102. package/src/render/draw_debug.ts +148 -0
  103. package/src/render/draw_fill.test.ts +137 -0
  104. package/src/render/draw_fill.ts +128 -0
  105. package/src/render/draw_fill_extrusion.ts +97 -0
  106. package/src/render/draw_heatmap.ts +228 -0
  107. package/src/render/draw_hillshade.ts +119 -0
  108. package/src/render/draw_line.ts +125 -0
  109. package/src/render/draw_raster.ts +133 -0
  110. package/src/render/draw_sky.ts +44 -0
  111. package/src/render/draw_symbol.test.ts +223 -0
  112. package/src/render/draw_symbol.ts +499 -0
  113. package/src/render/draw_terrain.ts +99 -0
  114. package/src/render/glyph_atlas.ts +83 -0
  115. package/src/render/glyph_manager.test.ts +147 -0
  116. package/src/render/glyph_manager.ts +198 -0
  117. package/src/render/image_atlas.ts +159 -0
  118. package/src/render/image_manager.ts +337 -0
  119. package/src/render/line_atlas.test.ts +38 -0
  120. package/src/render/line_atlas.ts +214 -0
  121. package/src/render/mesh.ts +25 -0
  122. package/src/render/painter.test.ts +51 -0
  123. package/src/render/painter.ts +666 -0
  124. package/src/render/program/background_program.ts +100 -0
  125. package/src/render/program/circle_program.ts +61 -0
  126. package/src/render/program/clipping_mask_program.ts +19 -0
  127. package/src/render/program/collision_program.ts +47 -0
  128. package/src/render/program/debug_program.ts +29 -0
  129. package/src/render/program/fill_extrusion_program.ts +120 -0
  130. package/src/render/program/fill_program.ts +121 -0
  131. package/src/render/program/heatmap_program.ts +76 -0
  132. package/src/render/program/hillshade_program.ts +116 -0
  133. package/src/render/program/line_program.ts +207 -0
  134. package/src/render/program/pattern.ts +102 -0
  135. package/src/render/program/program_uniforms.ts +46 -0
  136. package/src/render/program/raster_program.ts +88 -0
  137. package/src/render/program/sky_program.ts +28 -0
  138. package/src/render/program/symbol_program.ts +266 -0
  139. package/src/render/program/terrain_program.ts +116 -0
  140. package/src/render/program.ts +233 -0
  141. package/src/render/render_to_texture.test.ts +151 -0
  142. package/src/render/render_to_texture.ts +197 -0
  143. package/src/render/terrain.test.ts +322 -0
  144. package/src/render/terrain.ts +464 -0
  145. package/src/render/texture.ts +114 -0
  146. package/src/render/uniform_binding.test.ts +122 -0
  147. package/src/render/uniform_binding.ts +157 -0
  148. package/src/render/update_pattern_positions_in_program.test.ts +74 -0
  149. package/src/render/update_pattern_positions_in_program.ts +50 -0
  150. package/src/render/vertex_array_object.ts +163 -0
  151. package/src/shaders/README.md +42 -0
  152. package/src/shaders/_prelude.fragment.glsl +19 -0
  153. package/src/shaders/_prelude.fragment.glsl.g.ts +2 -0
  154. package/src/shaders/_prelude.vertex.glsl +148 -0
  155. package/src/shaders/_prelude.vertex.glsl.g.ts +2 -0
  156. package/src/shaders/background.fragment.glsl +10 -0
  157. package/src/shaders/background.fragment.glsl.g.ts +2 -0
  158. package/src/shaders/background.vertex.glsl +7 -0
  159. package/src/shaders/background.vertex.glsl.g.ts +2 -0
  160. package/src/shaders/background_pattern.fragment.glsl +28 -0
  161. package/src/shaders/background_pattern.fragment.glsl.g.ts +2 -0
  162. package/src/shaders/background_pattern.vertex.glsl +19 -0
  163. package/src/shaders/background_pattern.vertex.glsl.g.ts +2 -0
  164. package/src/shaders/circle.fragment.glsl +34 -0
  165. package/src/shaders/circle.fragment.glsl.g.ts +2 -0
  166. package/src/shaders/circle.vertex.glsl +68 -0
  167. package/src/shaders/circle.vertex.glsl.g.ts +2 -0
  168. package/src/shaders/clipping_mask.fragment.glsl +3 -0
  169. package/src/shaders/clipping_mask.fragment.glsl.g.ts +2 -0
  170. package/src/shaders/clipping_mask.vertex.glsl +7 -0
  171. package/src/shaders/clipping_mask.vertex.glsl.g.ts +2 -0
  172. package/src/shaders/collision_box.fragment.glsl +20 -0
  173. package/src/shaders/collision_box.fragment.glsl.g.ts +2 -0
  174. package/src/shaders/collision_box.vertex.glsl +27 -0
  175. package/src/shaders/collision_box.vertex.glsl.g.ts +2 -0
  176. package/src/shaders/collision_circle.fragment.glsl +17 -0
  177. package/src/shaders/collision_circle.fragment.glsl.g.ts +2 -0
  178. package/src/shaders/collision_circle.vertex.glsl +59 -0
  179. package/src/shaders/collision_circle.vertex.glsl.g.ts +2 -0
  180. package/src/shaders/debug.fragment.glsl +9 -0
  181. package/src/shaders/debug.fragment.glsl.g.ts +2 -0
  182. package/src/shaders/debug.vertex.glsl +12 -0
  183. package/src/shaders/debug.vertex.glsl.g.ts +2 -0
  184. package/src/shaders/encode_attribute.test.ts +11 -0
  185. package/src/shaders/encode_attribute.ts +13 -0
  186. package/src/shaders/fill.fragment.glsl +13 -0
  187. package/src/shaders/fill.fragment.glsl.g.ts +2 -0
  188. package/src/shaders/fill.vertex.glsl +13 -0
  189. package/src/shaders/fill.vertex.glsl.g.ts +2 -0
  190. package/src/shaders/fill_extrusion.fragment.glsl +9 -0
  191. package/src/shaders/fill_extrusion.fragment.glsl.g.ts +2 -0
  192. package/src/shaders/fill_extrusion.vertex.glsl +84 -0
  193. package/src/shaders/fill_extrusion.vertex.glsl.g.ts +2 -0
  194. package/src/shaders/fill_extrusion_pattern.fragment.glsl +47 -0
  195. package/src/shaders/fill_extrusion_pattern.fragment.glsl.g.ts +2 -0
  196. package/src/shaders/fill_extrusion_pattern.vertex.glsl +96 -0
  197. package/src/shaders/fill_extrusion_pattern.vertex.glsl.g.ts +2 -0
  198. package/src/shaders/fill_outline.fragment.glsl +17 -0
  199. package/src/shaders/fill_outline.fragment.glsl.g.ts +2 -0
  200. package/src/shaders/fill_outline.vertex.glsl +17 -0
  201. package/src/shaders/fill_outline.vertex.glsl.g.ts +2 -0
  202. package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
  203. package/src/shaders/fill_outline_pattern.fragment.glsl.g.ts +2 -0
  204. package/src/shaders/fill_outline_pattern.vertex.glsl +44 -0
  205. package/src/shaders/fill_outline_pattern.vertex.glsl.g.ts +2 -0
  206. package/src/shaders/fill_pattern.fragment.glsl +39 -0
  207. package/src/shaders/fill_pattern.fragment.glsl.g.ts +2 -0
  208. package/src/shaders/fill_pattern.vertex.glsl +39 -0
  209. package/src/shaders/fill_pattern.vertex.glsl.g.ts +2 -0
  210. package/src/shaders/heatmap.fragment.glsl +22 -0
  211. package/src/shaders/heatmap.fragment.glsl.g.ts +2 -0
  212. package/src/shaders/heatmap.vertex.glsl +54 -0
  213. package/src/shaders/heatmap.vertex.glsl.g.ts +2 -0
  214. package/src/shaders/heatmap_texture.fragment.glsl +15 -0
  215. package/src/shaders/heatmap_texture.fragment.glsl.g.ts +2 -0
  216. package/src/shaders/heatmap_texture.vertex.glsl +11 -0
  217. package/src/shaders/heatmap_texture.vertex.glsl.g.ts +2 -0
  218. package/src/shaders/hillshade.fragment.glsl +52 -0
  219. package/src/shaders/hillshade.fragment.glsl.g.ts +2 -0
  220. package/src/shaders/hillshade.vertex.glsl +11 -0
  221. package/src/shaders/hillshade.vertex.glsl.g.ts +2 -0
  222. package/src/shaders/hillshade_prepare.fragment.glsl +77 -0
  223. package/src/shaders/hillshade_prepare.fragment.glsl.g.ts +2 -0
  224. package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
  225. package/src/shaders/hillshade_prepare.vertex.glsl.g.ts +2 -0
  226. package/src/shaders/line.fragment.glsl +30 -0
  227. package/src/shaders/line.fragment.glsl.g.ts +2 -0
  228. package/src/shaders/line.vertex.glsl +89 -0
  229. package/src/shaders/line.vertex.glsl.g.ts +2 -0
  230. package/src/shaders/line_gradient.fragment.glsl +34 -0
  231. package/src/shaders/line_gradient.fragment.glsl.g.ts +2 -0
  232. package/src/shaders/line_gradient.vertex.glsl +92 -0
  233. package/src/shaders/line_gradient.vertex.glsl.g.ts +2 -0
  234. package/src/shaders/line_pattern.fragment.glsl +77 -0
  235. package/src/shaders/line_pattern.fragment.glsl.g.ts +2 -0
  236. package/src/shaders/line_pattern.vertex.glsl +103 -0
  237. package/src/shaders/line_pattern.vertex.glsl.g.ts +2 -0
  238. package/src/shaders/line_sdf.fragment.glsl +45 -0
  239. package/src/shaders/line_sdf.fragment.glsl.g.ts +2 -0
  240. package/src/shaders/line_sdf.vertex.glsl +101 -0
  241. package/src/shaders/line_sdf.vertex.glsl.g.ts +2 -0
  242. package/src/shaders/raster.fragment.glsl +53 -0
  243. package/src/shaders/raster.fragment.glsl.g.ts +2 -0
  244. package/src/shaders/raster.vertex.glsl +21 -0
  245. package/src/shaders/raster.vertex.glsl.g.ts +2 -0
  246. package/src/shaders/shaders.ts +197 -0
  247. package/src/shaders/sky.fragment.glsl +17 -0
  248. package/src/shaders/sky.fragment.glsl.g.ts +2 -0
  249. package/src/shaders/sky.vertex.glsl +5 -0
  250. package/src/shaders/sky.vertex.glsl.g.ts +2 -0
  251. package/src/shaders/symbol_icon.fragment.glsl +17 -0
  252. package/src/shaders/symbol_icon.fragment.glsl.g.ts +2 -0
  253. package/src/shaders/symbol_icon.vertex.glsl +117 -0
  254. package/src/shaders/symbol_icon.vertex.glsl.g.ts +2 -0
  255. package/src/shaders/symbol_sdf.fragment.glsl +58 -0
  256. package/src/shaders/symbol_sdf.fragment.glsl.g.ts +2 -0
  257. package/src/shaders/symbol_sdf.vertex.glsl +142 -0
  258. package/src/shaders/symbol_sdf.vertex.glsl.g.ts +2 -0
  259. package/src/shaders/symbol_text_and_icon.fragment.glsl +68 -0
  260. package/src/shaders/symbol_text_and_icon.fragment.glsl.g.ts +2 -0
  261. package/src/shaders/symbol_text_and_icon.vertex.glsl +140 -0
  262. package/src/shaders/symbol_text_and_icon.vertex.glsl.g.ts +2 -0
  263. package/src/shaders/terrain.fragment.glsl +32 -0
  264. package/src/shaders/terrain.fragment.glsl.g.ts +2 -0
  265. package/src/shaders/terrain.vertex.glsl +17 -0
  266. package/src/shaders/terrain.vertex.glsl.g.ts +2 -0
  267. package/src/shaders/terrain_coords.fragment.glsl +11 -0
  268. package/src/shaders/terrain_coords.fragment.glsl.g.ts +2 -0
  269. package/src/shaders/terrain_coords.vertex.glsl +13 -0
  270. package/src/shaders/terrain_coords.vertex.glsl.g.ts +2 -0
  271. package/src/shaders/terrain_depth.fragment.glsl +15 -0
  272. package/src/shaders/terrain_depth.fragment.glsl.g.ts +2 -0
  273. package/src/shaders/terrain_depth.vertex.glsl +13 -0
  274. package/src/shaders/terrain_depth.vertex.glsl.g.ts +2 -0
  275. package/src/source/canvas_source.test.ts +210 -0
  276. package/src/source/canvas_source.ts +227 -0
  277. package/src/source/geojson_source.test.ts +492 -0
  278. package/src/source/geojson_source.ts +431 -0
  279. package/src/source/geojson_source_diff.test.ts +364 -0
  280. package/src/source/geojson_source_diff.ts +172 -0
  281. package/src/source/geojson_worker_source.test.ts +399 -0
  282. package/src/source/geojson_worker_source.ts +303 -0
  283. package/src/source/geojson_wrapper.test.ts +32 -0
  284. package/src/source/geojson_wrapper.ts +81 -0
  285. package/src/source/image_source.test.ts +235 -0
  286. package/src/source/image_source.ts +338 -0
  287. package/src/source/load_tilejson.ts +47 -0
  288. package/src/source/pixels_to_tile_units.ts +25 -0
  289. package/src/source/protocol_crud.ts +48 -0
  290. package/src/source/query_features.test.ts +31 -0
  291. package/src/source/query_features.ts +252 -0
  292. package/src/source/raster_dem_tile_source.test.ts +158 -0
  293. package/src/source/raster_dem_tile_source.ts +166 -0
  294. package/src/source/raster_dem_tile_worker_source.test.ts +36 -0
  295. package/src/source/raster_dem_tile_worker_source.ts +38 -0
  296. package/src/source/raster_tile_source.test.ts +206 -0
  297. package/src/source/raster_tile_source.ts +227 -0
  298. package/src/source/rtl_text_plugin_main_thread.test.ts +170 -0
  299. package/src/source/rtl_text_plugin_main_thread.ts +89 -0
  300. package/src/source/rtl_text_plugin_status.ts +33 -0
  301. package/src/source/rtl_text_plugin_worker.ts +49 -0
  302. package/src/source/source.test.ts +41 -0
  303. package/src/source/source.ts +186 -0
  304. package/src/source/source_cache.test.ts +2069 -0
  305. package/src/source/source_cache.ts +1102 -0
  306. package/src/source/source_state.ts +157 -0
  307. package/src/source/terrain_source_cache.test.ts +105 -0
  308. package/src/source/terrain_source_cache.ts +204 -0
  309. package/src/source/tile.test.ts +290 -0
  310. package/src/source/tile.ts +478 -0
  311. package/src/source/tile_bounds.ts +34 -0
  312. package/src/source/tile_cache.test.ts +130 -0
  313. package/src/source/tile_cache.ts +208 -0
  314. package/src/source/tile_id.test.ts +112 -0
  315. package/src/source/tile_id.ts +221 -0
  316. package/src/source/vector_tile_source.test.ts +401 -0
  317. package/src/source/vector_tile_source.ts +283 -0
  318. package/src/source/vector_tile_worker_source.test.ts +396 -0
  319. package/src/source/vector_tile_worker_source.ts +199 -0
  320. package/src/source/video_source.test.ts +124 -0
  321. package/src/source/video_source.ts +204 -0
  322. package/src/source/worker.test.ts +233 -0
  323. package/src/source/worker.ts +301 -0
  324. package/src/source/worker_source.ts +117 -0
  325. package/src/source/worker_tile.test.ts +226 -0
  326. package/src/source/worker_tile.ts +208 -0
  327. package/src/style/create_style_layer.ts +39 -0
  328. package/src/style/evaluation_parameters.ts +62 -0
  329. package/src/style/format_section_override.test.ts +62 -0
  330. package/src/style/format_section_override.ts +50 -0
  331. package/src/style/light.test.ts +86 -0
  332. package/src/style/light.ts +135 -0
  333. package/src/style/load_glyph_range.test.ts +40 -0
  334. package/src/style/load_glyph_range.ts +32 -0
  335. package/src/style/load_sprite.test.ts +227 -0
  336. package/src/style/load_sprite.ts +71 -0
  337. package/src/style/parse_glyph_pbf.ts +42 -0
  338. package/src/style/pauseable_placement.ts +138 -0
  339. package/src/style/properties.ts +726 -0
  340. package/src/style/query_utils.test.ts +107 -0
  341. package/src/style/query_utils.ts +70 -0
  342. package/src/style/sky.ts +127 -0
  343. package/src/style/style.test.ts +2654 -0
  344. package/src/style/style.ts +1814 -0
  345. package/src/style/style_glyph.ts +25 -0
  346. package/src/style/style_image.ts +188 -0
  347. package/src/style/style_layer/background_style_layer.ts +17 -0
  348. package/src/style/style_layer/background_style_layer_properties.g.ts +40 -0
  349. package/src/style/style_layer/circle_style_layer.ts +98 -0
  350. package/src/style/style_layer/circle_style_layer_properties.g.ts +76 -0
  351. package/src/style/style_layer/custom_style_layer.ts +233 -0
  352. package/src/style/style_layer/fill_extrusion_style_layer.ts +224 -0
  353. package/src/style/style_layer/fill_extrusion_style_layer_properties.g.ts +55 -0
  354. package/src/style/style_layer/fill_style_layer.test.ts +37 -0
  355. package/src/style/style_layer/fill_style_layer.ts +65 -0
  356. package/src/style/style_layer/fill_style_layer_properties.g.ts +64 -0
  357. package/src/style/style_layer/heatmap_style_layer.ts +74 -0
  358. package/src/style/style_layer/heatmap_style_layer_properties.g.ts +46 -0
  359. package/src/style/style_layer/hillshade_style_layer.ts +21 -0
  360. package/src/style/style_layer/hillshade_style_layer_properties.g.ts +49 -0
  361. package/src/style/style_layer/line_style_layer.test.ts +50 -0
  362. package/src/style/style_layer/line_style_layer.ts +131 -0
  363. package/src/style/style_layer/line_style_layer_properties.g.ts +88 -0
  364. package/src/style/style_layer/overlap_mode.test.ts +57 -0
  365. package/src/style/style_layer/overlap_mode.ts +25 -0
  366. package/src/style/style_layer/raster_style_layer.ts +17 -0
  367. package/src/style/style_layer/raster_style_layer_properties.g.ts +55 -0
  368. package/src/style/style_layer/symbol_style_layer.ts +195 -0
  369. package/src/style/style_layer/symbol_style_layer_properties.g.ts +218 -0
  370. package/src/style/style_layer/typed_style_layer.ts +9 -0
  371. package/src/style/style_layer/variable_text_anchor.test.ts +117 -0
  372. package/src/style/style_layer/variable_text_anchor.ts +163 -0
  373. package/src/style/style_layer.test.ts +372 -0
  374. package/src/style/style_layer.ts +287 -0
  375. package/src/style/style_layer_index.test.ts +99 -0
  376. package/src/style/style_layer_index.ts +78 -0
  377. package/src/style/validate_style.ts +53 -0
  378. package/src/style/zoom_history.ts +40 -0
  379. package/src/symbol/anchor.test.ts +14 -0
  380. package/src/symbol/anchor.ts +22 -0
  381. package/src/symbol/check_max_angle.test.ts +54 -0
  382. package/src/symbol/check_max_angle.ts +76 -0
  383. package/src/symbol/clip_line.test.ts +154 -0
  384. package/src/symbol/clip_line.ts +66 -0
  385. package/src/symbol/collision_feature.test.ts +98 -0
  386. package/src/symbol/collision_feature.ts +114 -0
  387. package/src/symbol/collision_index.test.ts +19 -0
  388. package/src/symbol/collision_index.ts +618 -0
  389. package/src/symbol/cross_tile_symbol_index.test.ts +260 -0
  390. package/src/symbol/cross_tile_symbol_index.ts +367 -0
  391. package/src/symbol/get_anchors.test.ts +113 -0
  392. package/src/symbol/get_anchors.ts +167 -0
  393. package/src/symbol/grid_index.test.ts +75 -0
  394. package/src/symbol/grid_index.ts +414 -0
  395. package/src/symbol/merge_lines.test.ts +30 -0
  396. package/src/symbol/merge_lines.ts +80 -0
  397. package/src/symbol/one_em.ts +3 -0
  398. package/src/symbol/opacity_state.ts +23 -0
  399. package/src/symbol/path_interpolator.test.ts +134 -0
  400. package/src/symbol/path_interpolator.ts +55 -0
  401. package/src/symbol/placement.ts +1371 -0
  402. package/src/symbol/projection.test.ts +171 -0
  403. package/src/symbol/projection.ts +833 -0
  404. package/src/symbol/quads.test.ts +157 -0
  405. package/src/symbol/quads.ts +349 -0
  406. package/src/symbol/shaping.test.ts +360 -0
  407. package/src/symbol/shaping.ts +911 -0
  408. package/src/symbol/symbol_layout.ts +739 -0
  409. package/src/symbol/symbol_size.ts +129 -0
  410. package/src/symbol/symbol_style_layer.test.ts +103 -0
  411. package/src/symbol/transform_text.ts +27 -0
  412. package/src/ui/anchor.ts +27 -0
  413. package/src/ui/camera.test.ts +2301 -0
  414. package/src/ui/camera.ts +1520 -0
  415. package/src/ui/control/attribution_control.test.ts +543 -0
  416. package/src/ui/control/attribution_control.ts +209 -0
  417. package/src/ui/control/control.ts +67 -0
  418. package/src/ui/control/fullscreen_control.test.ts +114 -0
  419. package/src/ui/control/fullscreen_control.ts +189 -0
  420. package/src/ui/control/geolocate_control.test.ts +619 -0
  421. package/src/ui/control/geolocate_control.ts +725 -0
  422. package/src/ui/control/logo_control.test.ts +88 -0
  423. package/src/ui/control/logo_control.ts +86 -0
  424. package/src/ui/control/navigation_control.test.ts +238 -0
  425. package/src/ui/control/navigation_control.ts +294 -0
  426. package/src/ui/control/scale_control.test.ts +52 -0
  427. package/src/ui/control/scale_control.ts +152 -0
  428. package/src/ui/control/terrain_control.test.ts +58 -0
  429. package/src/ui/control/terrain_control.ts +74 -0
  430. package/src/ui/default_locale.ts +25 -0
  431. package/src/ui/events.ts +758 -0
  432. package/src/ui/handler/box_zoom.test.ts +163 -0
  433. package/src/ui/handler/box_zoom.ts +171 -0
  434. package/src/ui/handler/click_zoom.ts +55 -0
  435. package/src/ui/handler/cooperative_gestures.test.ts +338 -0
  436. package/src/ui/handler/cooperative_gestures.ts +111 -0
  437. package/src/ui/handler/dblclick_zoom.test.ts +151 -0
  438. package/src/ui/handler/drag_handler.ts +174 -0
  439. package/src/ui/handler/drag_move_state_manager.ts +115 -0
  440. package/src/ui/handler/drag_pan.test.ts +487 -0
  441. package/src/ui/handler/drag_rotate.test.ts +859 -0
  442. package/src/ui/handler/handler_util.ts +10 -0
  443. package/src/ui/handler/keyboard.test.ts +235 -0
  444. package/src/ui/handler/keyboard.ts +212 -0
  445. package/src/ui/handler/map_event.test.ts +158 -0
  446. package/src/ui/handler/map_event.ts +161 -0
  447. package/src/ui/handler/mouse.ts +92 -0
  448. package/src/ui/handler/mouse_handler_interface.test.ts +111 -0
  449. package/src/ui/handler/mouse_rotate.test.ts +62 -0
  450. package/src/ui/handler/one_finger_touch_drag.ts +45 -0
  451. package/src/ui/handler/one_finger_touch_drag_handler_interface.test.ts +77 -0
  452. package/src/ui/handler/scroll_zoom.test.ts +382 -0
  453. package/src/ui/handler/scroll_zoom.ts +379 -0
  454. package/src/ui/handler/shim/dblclick_zoom.ts +64 -0
  455. package/src/ui/handler/shim/drag_pan.ts +104 -0
  456. package/src/ui/handler/shim/drag_rotate.ts +76 -0
  457. package/src/ui/handler/shim/two_fingers_touch.ts +112 -0
  458. package/src/ui/handler/tap_drag_zoom.test.ts +113 -0
  459. package/src/ui/handler/tap_drag_zoom.ts +112 -0
  460. package/src/ui/handler/tap_recognizer.ts +138 -0
  461. package/src/ui/handler/tap_zoom.ts +98 -0
  462. package/src/ui/handler/touch_pan.ts +115 -0
  463. package/src/ui/handler/transform-provider.ts +44 -0
  464. package/src/ui/handler/two_fingers_touch.test.ts +283 -0
  465. package/src/ui/handler/two_fingers_touch.ts +336 -0
  466. package/src/ui/handler_inertia.ts +157 -0
  467. package/src/ui/handler_manager.ts +637 -0
  468. package/src/ui/hash.test.ts +404 -0
  469. package/src/ui/hash.ts +153 -0
  470. package/src/ui/map.ts +3393 -0
  471. package/src/ui/map_tests/map_animation.test.ts +61 -0
  472. package/src/ui/map_tests/map_basic.test.ts +223 -0
  473. package/src/ui/map_tests/map_bounds.test.ts +123 -0
  474. package/src/ui/map_tests/map_calculate_camera_options.test.ts +113 -0
  475. package/src/ui/map_tests/map_canvas.test.ts +59 -0
  476. package/src/ui/map_tests/map_control.test.ts +61 -0
  477. package/src/ui/map_tests/map_disable_handlers.test.ts +38 -0
  478. package/src/ui/map_tests/map_events.test.ts +1001 -0
  479. package/src/ui/map_tests/map_feature_state.test.ts +421 -0
  480. package/src/ui/map_tests/map_images.test.ts +175 -0
  481. package/src/ui/map_tests/map_is_moving.test.ts +164 -0
  482. package/src/ui/map_tests/map_is_rotating.test.ts +62 -0
  483. package/src/ui/map_tests/map_is_zooming.test.ts +86 -0
  484. package/src/ui/map_tests/map_layer.test.ts +457 -0
  485. package/src/ui/map_tests/map_options.test.ts +64 -0
  486. package/src/ui/map_tests/map_pitch.test.ts +90 -0
  487. package/src/ui/map_tests/map_pixel_ratio.test.ts +75 -0
  488. package/src/ui/map_tests/map_query_rendered_features.test.ts +93 -0
  489. package/src/ui/map_tests/map_render.test.ts +90 -0
  490. package/src/ui/map_tests/map_request_render_frame.test.ts +51 -0
  491. package/src/ui/map_tests/map_resize.test.ts +120 -0
  492. package/src/ui/map_tests/map_style.test.ts +541 -0
  493. package/src/ui/map_tests/map_terrian.test.ts +104 -0
  494. package/src/ui/map_tests/map_webgl.test.ts +72 -0
  495. package/src/ui/map_tests/map_world_copies.test.ts +103 -0
  496. package/src/ui/map_tests/map_zoom.test.ts +95 -0
  497. package/src/ui/marker.test.ts +1149 -0
  498. package/src/ui/marker.ts +880 -0
  499. package/src/ui/popup.test.ts +827 -0
  500. package/src/ui/popup.ts +717 -0
  501. package/src/util/abort_error.ts +21 -0
  502. package/src/util/actor.test.ts +218 -0
  503. package/src/util/actor.ts +241 -0
  504. package/src/util/actor_messages.ts +149 -0
  505. package/src/util/ajax.test.ts +237 -0
  506. package/src/util/ajax.ts +297 -0
  507. package/src/util/browser.test.ts +23 -0
  508. package/src/util/browser.ts +63 -0
  509. package/src/util/color_ramp.test.ts +105 -0
  510. package/src/util/color_ramp.ts +56 -0
  511. package/src/util/config.ts +29 -0
  512. package/src/util/dictionary_coder.ts +23 -0
  513. package/src/util/dispatcher.test.ts +76 -0
  514. package/src/util/dispatcher.ts +78 -0
  515. package/src/util/dom.ts +135 -0
  516. package/src/util/evented.test.ts +231 -0
  517. package/src/util/evented.ts +178 -0
  518. package/src/util/find_pole_of_inaccessibility.test.ts +21 -0
  519. package/src/util/find_pole_of_inaccessibility.ts +130 -0
  520. package/src/util/geolocation_support.test.ts +43 -0
  521. package/src/util/geolocation_support.ts +23 -0
  522. package/src/util/global_worker_pool.ts +65 -0
  523. package/src/util/image.ts +150 -0
  524. package/src/util/image_request.test.ts +408 -0
  525. package/src/util/image_request.ts +246 -0
  526. package/src/util/intersection_tests.ts +206 -0
  527. package/src/util/is_char_in_unicode_block.test.ts +15 -0
  528. package/src/util/is_char_in_unicode_block.ts +345 -0
  529. package/src/util/offscreen_canvas_distorted.test.ts +13 -0
  530. package/src/util/offscreen_canvas_distorted.ts +39 -0
  531. package/src/util/offscreen_canvas_supported.ts +11 -0
  532. package/src/util/performance.ts +117 -0
  533. package/src/util/primitives.test.ts +140 -0
  534. package/src/util/primitives.ts +143 -0
  535. package/src/util/request_manager.ts +42 -0
  536. package/src/util/resolve_tokens.test.ts +45 -0
  537. package/src/util/resolve_tokens.ts +17 -0
  538. package/src/util/script_detection.test.ts +138 -0
  539. package/src/util/script_detection.ts +376 -0
  540. package/src/util/smart_wrap.test.ts +97 -0
  541. package/src/util/smart_wrap.ts +58 -0
  542. package/src/util/struct_array.test.ts +101 -0
  543. package/src/util/struct_array.ts +246 -0
  544. package/src/util/style.test.ts +34 -0
  545. package/src/util/style.ts +28 -0
  546. package/src/util/task_queue.test.ts +114 -0
  547. package/src/util/task_queue.ts +64 -0
  548. package/src/util/test/util.ts +185 -0
  549. package/src/util/throttle.test.ts +42 -0
  550. package/src/util/throttle.ts +28 -0
  551. package/src/util/throttled_invoker.ts +41 -0
  552. package/src/util/transferable_grid_index.test.ts +56 -0
  553. package/src/util/transferable_grid_index.ts +214 -0
  554. package/src/util/util.test.ts +414 -0
  555. package/src/util/util.ts +724 -0
  556. package/src/util/vectortile_to_geojson.ts +72 -0
  557. package/src/util/verticalize_punctuation.ts +110 -0
  558. package/src/util/web_worker.ts +16 -0
  559. package/src/util/web_worker_transfer.test.ts +153 -0
  560. package/src/util/web_worker_transfer.ts +254 -0
  561. package/src/util/webp_supported.ts +63 -0
  562. package/src/util/worker_pool.test.ts +43 -0
  563. package/src/util/worker_pool.ts +58 -0
  564. package/src/util/world_bounds.test.ts +59 -0
  565. package/src/util/world_bounds.ts +46 -0
@@ -0,0 +1,726 @@
1
+ import {clone, extend, easeCubicInOut} from '../util/util';
2
+ import {interpolates, Color, StylePropertySpecification, normalizePropertyExpression,
3
+ Feature,
4
+ FeatureState,
5
+ StylePropertyExpression,
6
+ SourceExpression,
7
+ CompositeExpression, TransitionSpecification,
8
+ PropertyValueSpecification} from '@maplibre/maplibre-gl-style-spec';
9
+ import {register} from '../util/web_worker_transfer';
10
+ import {EvaluationParameters} from './evaluation_parameters';
11
+
12
+ import {CanonicalTileID} from '../source/tile_id';
13
+
14
+ type TimePoint = number;
15
+
16
+ /**
17
+ * A from-to type
18
+ */
19
+ export type CrossFaded<T> = {
20
+ to: T;
21
+ from: T;
22
+ };
23
+
24
+ /**
25
+ * @internal
26
+ * Implementations of the `Property` interface:
27
+ *
28
+ * * Hold metadata about a property that's independent of any specific value: stuff like the type of the value,
29
+ * the default value, etc. This comes from the style specification JSON.
30
+ * * Define behavior that needs to be polymorphic across different properties: "possibly evaluating"
31
+ * an input value (see below), and interpolating between two possibly-evaluted values.
32
+ *
33
+ * The type `T` is the fully-evaluated value type (e.g. `number`, `string`, `Color`).
34
+ * The type `R` is the intermediate "possibly evaluated" value type. See below.
35
+ *
36
+ * There are two main implementations of the interface -- one for properties that allow data-driven values,
37
+ * and one for properties that don't. There are a few "special case" implementations as well: one for properties
38
+ * which cross-fade between two values rather than interpolating, one for `heatmap-color` and `line-gradient`,
39
+ * and one for `light-position`.
40
+ */
41
+ export interface Property<T, R> {
42
+ specification: StylePropertySpecification;
43
+ possiblyEvaluate(
44
+ value: PropertyValue<T, R>,
45
+ parameters: EvaluationParameters,
46
+ canonical?: CanonicalTileID,
47
+ availableImages?: Array<string>
48
+ ): R;
49
+ interpolate(a: R, b: R, t: number): R;
50
+ }
51
+
52
+ /**
53
+ * @internal
54
+ * `PropertyValue` represents the value part of a property key-value unit. It's used to represent both
55
+ * paint and layout property values, and regardless of whether or not their property supports data-driven
56
+ * expressions.
57
+ *
58
+ * `PropertyValue` stores the raw input value as seen in a style or a runtime styling API call, i.e. one of the
59
+ * following:
60
+ *
61
+ * * A constant value of the type appropriate for the property
62
+ * * A function which produces a value of that type (but functions are quasi-deprecated in favor of expressions)
63
+ * * An expression which produces a value of that type
64
+ * * "undefined"/"not present", in which case the property is assumed to take on its default value.
65
+ *
66
+ * In addition to storing the original input value, `PropertyValue` also stores a normalized representation,
67
+ * effectively treating functions as if they are expressions, and constant or default values as if they are
68
+ * (constant) expressions.
69
+ */
70
+ export class PropertyValue<T, R> {
71
+ property: Property<T, R>;
72
+ value: PropertyValueSpecification<T> | void;
73
+ expression: StylePropertyExpression;
74
+
75
+ constructor(property: Property<T, R>, value: PropertyValueSpecification<T> | void) {
76
+ this.property = property;
77
+ this.value = value;
78
+ this.expression = normalizePropertyExpression(value === undefined ? property.specification.default : value, property.specification);
79
+ }
80
+
81
+ isDataDriven(): boolean {
82
+ return this.expression.kind === 'source' || this.expression.kind === 'composite';
83
+ }
84
+
85
+ possiblyEvaluate(
86
+ parameters: EvaluationParameters,
87
+ canonical?: CanonicalTileID,
88
+ availableImages?: Array<string>
89
+ ): R {
90
+ return this.property.possiblyEvaluate(this, parameters, canonical, availableImages);
91
+ }
92
+ }
93
+
94
+ export type TransitionParameters = {
95
+ now: TimePoint;
96
+ transition: TransitionSpecification;
97
+ };
98
+
99
+ /**
100
+ * @internal
101
+ * Paint properties are _transitionable_: they can change in a fluid manner, interpolating or cross-fading between
102
+ * old and new value. The duration of the transition, and the delay before it begins, is configurable.
103
+ *
104
+ * `TransitionablePropertyValue` is a compositional class that stores both the property value and that transition
105
+ * configuration.
106
+ *
107
+ * A `TransitionablePropertyValue` can calculate the next step in the evaluation chain for paint property values:
108
+ * `TransitioningPropertyValue`.
109
+ */
110
+ class TransitionablePropertyValue<T, R> {
111
+ property: Property<T, R>;
112
+ value: PropertyValue<T, R>;
113
+ transition: TransitionSpecification | void;
114
+
115
+ constructor(property: Property<T, R>) {
116
+ this.property = property;
117
+ this.value = new PropertyValue(property, undefined);
118
+ }
119
+
120
+ transitioned(parameters: TransitionParameters, prior: TransitioningPropertyValue<T, R>): TransitioningPropertyValue<T, R> {
121
+ return new TransitioningPropertyValue(this.property, this.value, prior,
122
+ extend({}, parameters.transition, this.transition), parameters.now);
123
+ }
124
+
125
+ untransitioned(): TransitioningPropertyValue<T, R> {
126
+ return new TransitioningPropertyValue(this.property, this.value, null, {}, 0);
127
+ }
128
+ }
129
+
130
+ /**
131
+ * @internal
132
+ * `Transitionable` stores a map of all (property name, `TransitionablePropertyValue`) pairs for paint properties of a
133
+ * given layer type. It can calculate the `TransitioningPropertyValue`s for all of them at once, producing a
134
+ * `Transitioning` instance for the same set of properties.
135
+ */
136
+ export class Transitionable<Props> {
137
+ _properties: Properties<Props>;
138
+ _values: {[K in keyof Props]: TransitionablePropertyValue<any, unknown>};
139
+
140
+ constructor(properties: Properties<Props>) {
141
+ this._properties = properties;
142
+ this._values = (Object.create(properties.defaultTransitionablePropertyValues) as any);
143
+ }
144
+
145
+ getValue<S extends keyof Props, T>(name: S): PropertyValueSpecification<T> | void {
146
+ return clone(this._values[name].value.value);
147
+ }
148
+
149
+ setValue<S extends keyof Props, T>(name: S, value: PropertyValueSpecification<T> | void) {
150
+ if (!Object.prototype.hasOwnProperty.call(this._values, name)) {
151
+ this._values[name] = new TransitionablePropertyValue(this._values[name].property);
152
+ }
153
+ // Note that we do not _remove_ an own property in the case where a value is being reset
154
+ // to the default: the transition might still be non-default.
155
+ this._values[name].value = new PropertyValue(this._values[name].property, value === null ? undefined : clone(value));
156
+ }
157
+
158
+ getTransition<S extends keyof Props>(name: S): TransitionSpecification | void {
159
+ return clone(this._values[name].transition);
160
+ }
161
+
162
+ setTransition<S extends keyof Props>(name: S, value: TransitionSpecification | void) {
163
+ if (!Object.prototype.hasOwnProperty.call(this._values, name)) {
164
+ this._values[name] = new TransitionablePropertyValue(this._values[name].property);
165
+ }
166
+ this._values[name].transition = clone(value) || undefined;
167
+ }
168
+
169
+ serialize() {
170
+ const result: any = {};
171
+ for (const property of Object.keys(this._values)) {
172
+ const value = this.getValue(property as keyof Props);
173
+ if (value !== undefined) {
174
+ result[property] = value;
175
+ }
176
+
177
+ const transition = this.getTransition(property as keyof Props);
178
+ if (transition !== undefined) {
179
+ result[`${property}-transition`] = transition;
180
+ }
181
+ }
182
+ return result;
183
+ }
184
+
185
+ transitioned(parameters: TransitionParameters, prior: Transitioning<Props>): Transitioning<Props> {
186
+ const result = new Transitioning(this._properties);
187
+ for (const property of Object.keys(this._values)) {
188
+ result._values[property] = this._values[property].transitioned(parameters, prior._values[property]);
189
+ }
190
+ return result;
191
+ }
192
+
193
+ untransitioned(): Transitioning<Props> {
194
+ const result = new Transitioning(this._properties);
195
+ for (const property of Object.keys(this._values)) {
196
+ result._values[property] = this._values[property].untransitioned();
197
+ }
198
+ return result;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * @internal
204
+ * `TransitioningPropertyValue` implements the first of two intermediate steps in the evaluation chain of a paint
205
+ * property value. In this step, transitions between old and new values are handled: as long as the transition is in
206
+ * progress, `TransitioningPropertyValue` maintains a reference to the prior value, and interpolates between it and
207
+ * the new value based on the current time and the configured transition duration and delay. The product is the next
208
+ * step in the evaluation chain: the "possibly evaluated" result type `R`. See below for more on this concept.
209
+ */
210
+ class TransitioningPropertyValue<T, R> {
211
+ property: Property<T, R>;
212
+ value: PropertyValue<T, R>;
213
+ prior: TransitioningPropertyValue<T, R>;
214
+ begin: TimePoint;
215
+ end: TimePoint;
216
+
217
+ constructor(property: Property<T, R>,
218
+ value: PropertyValue<T, R>,
219
+ prior: TransitioningPropertyValue<T, R>,
220
+ transition: TransitionSpecification,
221
+ now: TimePoint) {
222
+ this.property = property;
223
+ this.value = value;
224
+ this.begin = now + transition.delay || 0;
225
+ this.end = this.begin + transition.duration || 0;
226
+ if (property.specification.transition && (transition.delay || transition.duration)) {
227
+ this.prior = prior;
228
+ }
229
+ }
230
+
231
+ possiblyEvaluate(
232
+ parameters: EvaluationParameters,
233
+ canonical: CanonicalTileID,
234
+ availableImages: Array<string>
235
+ ): R {
236
+ const now = parameters.now || 0;
237
+ const finalValue = this.value.possiblyEvaluate(parameters, canonical, availableImages);
238
+ const prior = this.prior;
239
+ if (!prior) {
240
+ // No prior value.
241
+ return finalValue;
242
+ } else if (now > this.end) {
243
+ // Transition from prior value is now complete.
244
+ this.prior = null;
245
+ return finalValue;
246
+ } else if (this.value.isDataDriven()) {
247
+ // Transitions to data-driven properties are not supported.
248
+ // We snap immediately to the data-driven value so that, when we perform layout,
249
+ // we see the data-driven function and can use it to populate vertex buffers.
250
+ this.prior = null;
251
+ return finalValue;
252
+ } else if (now < this.begin) {
253
+ // Transition hasn't started yet.
254
+ return prior.possiblyEvaluate(parameters, canonical, availableImages);
255
+ } else {
256
+ // Interpolate between recursively-calculated prior value and final.
257
+ const t = (now - this.begin) / (this.end - this.begin);
258
+ return this.property.interpolate(prior.possiblyEvaluate(parameters, canonical, availableImages), finalValue, easeCubicInOut(t));
259
+ }
260
+ }
261
+ }
262
+
263
+ /**
264
+ * @internal
265
+ * `Transitioning` stores a map of all (property name, `TransitioningPropertyValue`) pairs for paint properties of a
266
+ * given layer type. It can calculate the possibly-evaluated values for all of them at once, producing a
267
+ * `PossiblyEvaluated` instance for the same set of properties.
268
+ */
269
+ export class Transitioning<Props> {
270
+ _properties: Properties<Props>;
271
+ _values: {[K in keyof Props]: PossiblyEvaluatedPropertyValue<unknown>};
272
+
273
+ constructor(properties: Properties<Props>) {
274
+ this._properties = properties;
275
+ this._values = (Object.create(properties.defaultTransitioningPropertyValues) as any);
276
+ }
277
+
278
+ possiblyEvaluate(
279
+ parameters: EvaluationParameters,
280
+ canonical?: CanonicalTileID,
281
+ availableImages?: Array<string>
282
+ ): PossiblyEvaluated<Props, any> {
283
+ const result = new PossiblyEvaluated(this._properties);
284
+ for (const property of Object.keys(this._values)) {
285
+ result._values[property] = this._values[property].possiblyEvaluate(parameters, canonical, availableImages);
286
+ }
287
+ return result;
288
+ }
289
+
290
+ hasTransition() {
291
+ for (const property of Object.keys(this._values)) {
292
+ if (this._values[property].prior) {
293
+ return true;
294
+ }
295
+ }
296
+ return false;
297
+ }
298
+ }
299
+
300
+ // ------- Layout -------
301
+
302
+ /**
303
+ * Because layout properties are not transitionable, they have a simpler representation and evaluation chain than
304
+ * paint properties: `PropertyValue`s are possibly evaluated, producing possibly evaluated values, which are then
305
+ * fully evaluated.
306
+ *
307
+ * `Layout` stores a map of all (property name, `PropertyValue`) pairs for layout properties of a
308
+ * given layer type. It can calculate the possibly-evaluated values for all of them at once, producing a
309
+ * `PossiblyEvaluated` instance for the same set of properties.
310
+ */
311
+ export class Layout<Props> {
312
+ _properties: Properties<Props>;
313
+ _values: {[K in keyof Props]: PropertyValue<any, PossiblyEvaluatedPropertyValue<any>>};
314
+
315
+ constructor(properties: Properties<Props>) {
316
+ this._properties = properties;
317
+ this._values = (Object.create(properties.defaultPropertyValues) as any);
318
+ }
319
+
320
+ hasValue<S extends keyof Props>(name: S) {
321
+ return this._values[name].value !== undefined;
322
+ }
323
+
324
+ getValue<S extends keyof Props>(name: S) {
325
+ return clone(this._values[name].value);
326
+ }
327
+
328
+ setValue<S extends keyof Props>(name: S, value: any) {
329
+ this._values[name] = new PropertyValue(this._values[name].property, value === null ? undefined : clone(value)) as any;
330
+ }
331
+
332
+ serialize() {
333
+ const result: any = {};
334
+ for (const property of Object.keys(this._values)) {
335
+ const value = this.getValue(property as keyof Props);
336
+ if (value !== undefined) {
337
+ result[property] = value;
338
+ }
339
+ }
340
+ return result;
341
+ }
342
+
343
+ possiblyEvaluate(
344
+ parameters: EvaluationParameters,
345
+ canonical?: CanonicalTileID,
346
+ availableImages?: Array<string>
347
+ ): PossiblyEvaluated<Props, any> {
348
+ const result = new PossiblyEvaluated(this._properties);
349
+ for (const property of Object.keys(this._values)) {
350
+ result._values[property] = this._values[property].possiblyEvaluate(parameters, canonical, availableImages);
351
+ }
352
+ return result;
353
+ }
354
+ }
355
+
356
+ // ------- PossiblyEvaluated -------
357
+
358
+ /**
359
+ * "Possibly evaluated value" is an intermediate stage in the evaluation chain for both paint and layout property
360
+ * values. The purpose of this stage is to optimize away unnecessary recalculations for data-driven properties. Code
361
+ * which uses data-driven property values must assume that the value is dependent on feature data, and request that it
362
+ * be evaluated for each feature. But when that property value is in fact a constant or camera function, the calculation
363
+ * will not actually depend on the feature, and we can benefit from returning the prior result of having done the
364
+ * evaluation once, ahead of time, in an intermediate step whose inputs are just the value and "global" parameters
365
+ * such as current zoom level.
366
+ *
367
+ * `PossiblyEvaluatedValue` represents the three possible outcomes of this step: if the input value was a constant or
368
+ * camera expression, then the "possibly evaluated" result is a constant value. Otherwise, the input value was either
369
+ * a source or composite expression, and we must defer final evaluation until supplied a feature. We separate
370
+ * the source and composite cases because they are handled differently when generating GL attributes, buffers, and
371
+ * uniforms.
372
+ *
373
+ * Note that `PossiblyEvaluatedValue` (and `PossiblyEvaluatedPropertyValue`, below) are _not_ used for properties that
374
+ * do not allow data-driven values. For such properties, we know that the "possibly evaluated" result is always a constant
375
+ * scalar value. See below.
376
+ */
377
+ type PossiblyEvaluatedValue<T> = {
378
+ kind: 'constant';
379
+ value: T;
380
+ } | SourceExpression | CompositeExpression;
381
+
382
+ /**
383
+ * @internal
384
+ * `PossiblyEvaluatedPropertyValue` is used for data-driven paint and layout property values. It holds a
385
+ * `PossiblyEvaluatedValue` and the `GlobalProperties` that were used to generate it. You're not allowed to supply
386
+ * a different set of `GlobalProperties` when performing the final evaluation because they would be ignored in the
387
+ * case where the input value was a constant or camera function.
388
+ */
389
+ export class PossiblyEvaluatedPropertyValue<T> {
390
+ property: DataDrivenProperty<T>;
391
+ value: PossiblyEvaluatedValue<T>;
392
+ parameters: EvaluationParameters;
393
+
394
+ constructor(property: DataDrivenProperty<T>, value: PossiblyEvaluatedValue<T>, parameters: EvaluationParameters) {
395
+ this.property = property;
396
+ this.value = value;
397
+ this.parameters = parameters;
398
+ }
399
+
400
+ isConstant(): boolean {
401
+ return this.value.kind === 'constant';
402
+ }
403
+
404
+ constantOr(value: T): T {
405
+ if (this.value.kind === 'constant') {
406
+ return this.value.value;
407
+ } else {
408
+ return value;
409
+ }
410
+ }
411
+
412
+ evaluate(
413
+ feature: Feature,
414
+ featureState: FeatureState,
415
+ canonical?: CanonicalTileID,
416
+ availableImages?: Array<string>
417
+ ): T {
418
+ return this.property.evaluate(this.value, this.parameters, feature, featureState, canonical, availableImages);
419
+ }
420
+ }
421
+
422
+ /**
423
+ * @internal
424
+ * `PossiblyEvaluated` stores a map of all (property name, `R`) pairs for paint or layout properties of a
425
+ * given layer type.
426
+ */
427
+ export class PossiblyEvaluated<Props, PossibleEvaluatedProps> {
428
+ _properties: Properties<Props>;
429
+ _values: PossibleEvaluatedProps;
430
+
431
+ constructor(properties: Properties<Props>) {
432
+ this._properties = properties;
433
+ this._values = Object.create(properties.defaultPossiblyEvaluatedValues);
434
+ }
435
+
436
+ get<S extends keyof PossibleEvaluatedProps>(name: S): PossibleEvaluatedProps[S] {
437
+ return this._values[name];
438
+ }
439
+ }
440
+
441
+ /**
442
+ * @internal
443
+ * An implementation of `Property` for properties that do not permit data-driven (source or composite) expressions.
444
+ * This restriction allows us to declare statically that the result of possibly evaluating this kind of property
445
+ * is in fact always the scalar type `T`, and can be used without further evaluating the value on a per-feature basis.
446
+ */
447
+ export class DataConstantProperty<T> implements Property<T, T> {
448
+ specification: StylePropertySpecification;
449
+
450
+ constructor(specification: StylePropertySpecification) {
451
+ this.specification = specification;
452
+ }
453
+
454
+ possiblyEvaluate(value: PropertyValue<T, T>, parameters: EvaluationParameters): T {
455
+ if (value.isDataDriven()) throw new Error('Value should not be data driven');
456
+ return value.expression.evaluate(parameters);
457
+ }
458
+
459
+ interpolate(a: T, b: T, t: number): T {
460
+ const interpolationType = this.specification.type as keyof typeof interpolates;
461
+ const interpolationFn = interpolates[interpolationType] as ((from: T, to: T, t: number) => T) | undefined;
462
+ if (interpolationFn) {
463
+ return interpolationFn(a, b, t);
464
+ } else {
465
+ return a;
466
+ }
467
+ }
468
+ }
469
+
470
+ /**
471
+ * @internal
472
+ * An implementation of `Property` for properties that permit data-driven (source or composite) expressions.
473
+ * The result of possibly evaluating this kind of property is `PossiblyEvaluatedPropertyValue<T>`; obtaining
474
+ * a scalar value `T` requires further evaluation on a per-feature basis.
475
+ */
476
+ export class DataDrivenProperty<T> implements Property<T, PossiblyEvaluatedPropertyValue<T>> {
477
+ specification: StylePropertySpecification;
478
+ overrides: any;
479
+
480
+ constructor(specification: StylePropertySpecification, overrides?: any) {
481
+ this.specification = specification;
482
+ this.overrides = overrides;
483
+ }
484
+
485
+ possiblyEvaluate(
486
+ value: PropertyValue<T, PossiblyEvaluatedPropertyValue<T>>,
487
+ parameters: EvaluationParameters,
488
+ canonical?: CanonicalTileID,
489
+ availableImages?: Array<string>
490
+ ): PossiblyEvaluatedPropertyValue<T> {
491
+ if (value.expression.kind === 'constant' || value.expression.kind === 'camera') {
492
+ return new PossiblyEvaluatedPropertyValue(this, {kind: 'constant', value: value.expression.evaluate(parameters, null, {}, canonical, availableImages)}, parameters);
493
+ } else {
494
+ return new PossiblyEvaluatedPropertyValue(this, value.expression, parameters);
495
+ }
496
+ }
497
+
498
+ interpolate(
499
+ a: PossiblyEvaluatedPropertyValue<T>,
500
+ b: PossiblyEvaluatedPropertyValue<T>,
501
+ t: number
502
+ ): PossiblyEvaluatedPropertyValue<T> {
503
+ // If either possibly-evaluated value is non-constant, give up: we aren't able to interpolate data-driven values.
504
+ if (a.value.kind !== 'constant' || b.value.kind !== 'constant') {
505
+ return a;
506
+ }
507
+
508
+ // Special case hack solely for fill-outline-color. The undefined value is subsequently handled in
509
+ // FillStyleLayer#recalculate, which sets fill-outline-color to the fill-color value if the former
510
+ // is a PossiblyEvaluatedPropertyValue containing a constant undefined value. In addition to the
511
+ // return value here, the other source of a PossiblyEvaluatedPropertyValue containing a constant
512
+ // undefined value is the "default value" for fill-outline-color held in
513
+ // `Properties#defaultPossiblyEvaluatedValues`, which serves as the prototype of
514
+ // `PossiblyEvaluated#_values`.
515
+ if (a.value.value === undefined || b.value.value === undefined) {
516
+ return new PossiblyEvaluatedPropertyValue(this, {kind: 'constant', value: undefined}, a.parameters);
517
+ }
518
+
519
+ const interpolationType = this.specification.type as keyof typeof interpolates;
520
+ const interpolationFn = interpolates[interpolationType] as ((from: T, to: T, t: number) => T) | undefined;
521
+ if (interpolationFn) {
522
+ const interpolatedValue = interpolationFn(a.value.value, b.value.value, t);
523
+ return new PossiblyEvaluatedPropertyValue(this, {kind: 'constant', value: interpolatedValue}, a.parameters);
524
+ } else {
525
+ return a;
526
+ }
527
+ }
528
+
529
+ evaluate(
530
+ value: PossiblyEvaluatedValue<T>,
531
+ parameters: EvaluationParameters,
532
+ feature: Feature,
533
+ featureState: FeatureState,
534
+ canonical?: CanonicalTileID,
535
+ availableImages?: Array<string>
536
+ ): T {
537
+ if (value.kind === 'constant') {
538
+ return value.value;
539
+ } else {
540
+ return value.evaluate(parameters, feature, featureState, canonical, availableImages);
541
+ }
542
+ }
543
+ }
544
+
545
+ /**
546
+ * @internal
547
+ * An implementation of `Property` for data driven `line-pattern` which are transitioned by cross-fading
548
+ * rather than interpolation.
549
+ */
550
+
551
+ export class CrossFadedDataDrivenProperty<T> extends DataDrivenProperty<CrossFaded<T>> {
552
+
553
+ possiblyEvaluate(
554
+ value: PropertyValue<CrossFaded<T>, PossiblyEvaluatedPropertyValue<CrossFaded<T>>>,
555
+ parameters: EvaluationParameters,
556
+ canonical?: CanonicalTileID,
557
+ availableImages?: Array<string>
558
+ ): PossiblyEvaluatedPropertyValue<CrossFaded<T>> {
559
+ if (value.value === undefined) {
560
+ return new PossiblyEvaluatedPropertyValue(this, {kind: 'constant', value: undefined}, parameters);
561
+ } else if (value.expression.kind === 'constant') {
562
+ const evaluatedValue = value.expression.evaluate(parameters, null, {}, canonical, availableImages);
563
+ const isImageExpression = value.property.specification.type as any === 'resolvedImage';
564
+ const constantValue = isImageExpression && typeof evaluatedValue !== 'string' ? evaluatedValue.name : evaluatedValue;
565
+ const constant = this._calculate(constantValue, constantValue, constantValue, parameters);
566
+ return new PossiblyEvaluatedPropertyValue(this, {kind: 'constant', value: constant}, parameters);
567
+ } else if (value.expression.kind === 'camera') {
568
+ const cameraVal = this._calculate(
569
+ value.expression.evaluate({zoom: parameters.zoom - 1.0}),
570
+ value.expression.evaluate({zoom: parameters.zoom}),
571
+ value.expression.evaluate({zoom: parameters.zoom + 1.0}),
572
+ parameters);
573
+ return new PossiblyEvaluatedPropertyValue(this, {kind: 'constant', value: cameraVal}, parameters);
574
+ } else {
575
+ // source or composite expression
576
+ return new PossiblyEvaluatedPropertyValue(this, value.expression, parameters);
577
+ }
578
+ }
579
+
580
+ evaluate(
581
+ value: PossiblyEvaluatedValue<CrossFaded<T>>,
582
+ globals: EvaluationParameters,
583
+ feature: Feature,
584
+ featureState: FeatureState,
585
+ canonical?: CanonicalTileID,
586
+ availableImages?: Array<string>
587
+ ): CrossFaded<T> {
588
+ if (value.kind === 'source') {
589
+ const constant = value.evaluate(globals, feature, featureState, canonical, availableImages);
590
+ return this._calculate(constant, constant, constant, globals);
591
+ } else if (value.kind === 'composite') {
592
+ return this._calculate(
593
+ value.evaluate({zoom: Math.floor(globals.zoom) - 1.0}, feature, featureState),
594
+ value.evaluate({zoom: Math.floor(globals.zoom)}, feature, featureState),
595
+ value.evaluate({zoom: Math.floor(globals.zoom) + 1.0}, feature, featureState),
596
+ globals);
597
+ } else {
598
+ return value.value;
599
+ }
600
+ }
601
+
602
+ _calculate(min: T, mid: T, max: T, parameters: EvaluationParameters): CrossFaded<T> {
603
+ const z = parameters.zoom;
604
+ return z > parameters.zoomHistory.lastIntegerZoom ? {from: min, to: mid} : {from: max, to: mid};
605
+ }
606
+
607
+ interpolate(a: PossiblyEvaluatedPropertyValue<CrossFaded<T>>): PossiblyEvaluatedPropertyValue<CrossFaded<T>> {
608
+ return a;
609
+ }
610
+ }
611
+ /**
612
+ * @internal
613
+ * An implementation of `Property` for `*-pattern` and `line-dasharray`, which are transitioned by cross-fading
614
+ * rather than interpolation.
615
+ */
616
+ export class CrossFadedProperty<T> implements Property<T, CrossFaded<T>> {
617
+ specification: StylePropertySpecification;
618
+
619
+ constructor(specification: StylePropertySpecification) {
620
+ this.specification = specification;
621
+ }
622
+
623
+ possiblyEvaluate(
624
+ value: PropertyValue<T, CrossFaded<T>>,
625
+ parameters: EvaluationParameters,
626
+ canonical?: CanonicalTileID,
627
+ availableImages?: Array<string>
628
+ ): CrossFaded<T> {
629
+ if (value.value === undefined) {
630
+ return undefined;
631
+ } else if (value.expression.kind === 'constant') {
632
+ const constant = value.expression.evaluate(parameters, null, {}, canonical, availableImages);
633
+ return this._calculate(constant, constant, constant, parameters);
634
+ } else {
635
+ return this._calculate(
636
+ value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom - 1.0), parameters)),
637
+ value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom), parameters)),
638
+ value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom + 1.0), parameters)),
639
+ parameters);
640
+ }
641
+ }
642
+
643
+ _calculate(min: T, mid: T, max: T, parameters: EvaluationParameters): CrossFaded<T> {
644
+ const z = parameters.zoom;
645
+ return z > parameters.zoomHistory.lastIntegerZoom ? {from: min, to: mid} : {from: max, to: mid};
646
+ }
647
+
648
+ interpolate(a?: CrossFaded<T> | null): CrossFaded<T> {
649
+ return a;
650
+ }
651
+ }
652
+
653
+ /**
654
+ * @internal
655
+ * An implementation of `Property` for `heatmap-color` and `line-gradient`. Interpolation is a no-op, and
656
+ * evaluation returns a boolean value in order to indicate its presence, but the real
657
+ * evaluation happens in StyleLayer classes.
658
+ */
659
+
660
+ export class ColorRampProperty implements Property<Color, boolean> {
661
+ specification: StylePropertySpecification;
662
+
663
+ constructor(specification: StylePropertySpecification) {
664
+ this.specification = specification;
665
+ }
666
+
667
+ possiblyEvaluate(
668
+ value: PropertyValue<Color, boolean>,
669
+ parameters: EvaluationParameters,
670
+ canonical?: CanonicalTileID,
671
+ availableImages?: Array<string>
672
+ ): boolean {
673
+ return !!value.expression.evaluate(parameters, null, {}, canonical, availableImages);
674
+ }
675
+
676
+ interpolate(): boolean { return false; }
677
+ }
678
+
679
+ /**
680
+ * @internal
681
+ * `Properties` holds objects containing default values for the layout or paint property set of a given
682
+ * layer type. These objects are immutable, and they are used as the prototypes for the `_values` members of
683
+ * `Transitionable`, `Transitioning`, `Layout`, and `PossiblyEvaluated`. This allows these classes to avoid
684
+ * doing work in the common case where a property has no explicit value set and should be considered to take
685
+ * on the default value: using `for (const property of Object.keys(this._values))`, they can iterate over
686
+ * only the _own_ properties of `_values`, skipping repeated calculation of transitions and possible/final
687
+ * evaluations for defaults, the result of which will always be the same.
688
+ */
689
+ export class Properties<Props> {
690
+ properties: Props;
691
+ defaultPropertyValues: {[K in keyof Props]: PropertyValue<unknown, any>};
692
+ defaultTransitionablePropertyValues: {[K in keyof Props]: TransitionablePropertyValue<unknown, unknown>};
693
+ defaultTransitioningPropertyValues: {[K in keyof Props]: TransitioningPropertyValue<unknown, unknown>};
694
+ defaultPossiblyEvaluatedValues: {[K in keyof Props]: PossiblyEvaluatedPropertyValue<unknown>};
695
+ overridableProperties: Array<string>;
696
+
697
+ constructor(properties: Props) {
698
+ this.properties = properties;
699
+ this.defaultPropertyValues = ({} as any);
700
+ this.defaultTransitionablePropertyValues = ({} as any);
701
+ this.defaultTransitioningPropertyValues = ({} as any);
702
+ this.defaultPossiblyEvaluatedValues = ({} as any);
703
+ this.overridableProperties = ([] as any);
704
+
705
+ for (const property in properties) {
706
+ const prop = properties[property] as any;
707
+ if (prop.specification.overridable) {
708
+ this.overridableProperties.push(property);
709
+ }
710
+ const defaultPropertyValue = this.defaultPropertyValues[property] =
711
+ new PropertyValue(prop, undefined);
712
+ const defaultTransitionablePropertyValue = this.defaultTransitionablePropertyValues[property] =
713
+ new TransitionablePropertyValue(prop);
714
+ this.defaultTransitioningPropertyValues[property] =
715
+ defaultTransitionablePropertyValue.untransitioned();
716
+ this.defaultPossiblyEvaluatedValues[property] =
717
+ defaultPropertyValue.possiblyEvaluate({} as any);
718
+ }
719
+ }
720
+ }
721
+
722
+ register('DataDrivenProperty', DataDrivenProperty);
723
+ register('DataConstantProperty', DataConstantProperty);
724
+ register('CrossFadedDataDrivenProperty', CrossFadedDataDrivenProperty);
725
+ register('CrossFadedProperty', CrossFadedProperty);
726
+ register('ColorRampProperty', ColorRampProperty);