@tangram.gl/tangram-renderer 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (321) hide show
  1. package/README.md +60 -2
  2. package/dist/core.js +36923 -0
  3. package/dist/core.js.map +6 -0
  4. package/dist/index.js +32 -0
  5. package/dist/loaders-gl-worker.js +82 -0
  6. package/dist/loaders-gl-worker.js.map +6 -0
  7. package/dist/map-logic.js +2 -0
  8. package/dist/map-logic.js.map +6 -0
  9. package/dist/projected-basemaps-worker.js +3 -0
  10. package/dist/projected-basemaps-worker.js.map +6 -0
  11. package/dist/shader-modules.js +141 -0
  12. package/dist/shader-modules.js.map +6 -0
  13. package/dist/style-schema.js +126 -0
  14. package/dist/style-schema.js.map +6 -0
  15. package/dist/tangram-style.schema.json +882 -0
  16. package/dist/tangram.debug.mjs +37139 -0
  17. package/dist/tangram.debug.mjs.map +6 -0
  18. package/dist/tangram.min.mjs +4950 -0
  19. package/dist/types/builders/earcut.d.ts +15 -0
  20. package/dist/types/core.d.ts +29 -0
  21. package/dist/types/gl/constants.d.ts +2 -0
  22. package/dist/types/gl/globe_mesh.d.ts +48 -0
  23. package/dist/types/gl/glsl.d.ts +17 -0
  24. package/dist/types/gl/vertex-constants.d.ts +4 -0
  25. package/dist/types/gl/vertex-types.d.ts +34 -0
  26. package/dist/types/gl/vertex_data.d.ts +32 -0
  27. package/dist/types/gl/vertex_elements.d.ts +8 -0
  28. package/dist/types/gl/vertex_layout.d.ts +32 -0
  29. package/dist/types/glsl.d.ts +14 -0
  30. package/dist/types/gpu/luma_device_renderer.d.ts +66 -0
  31. package/dist/types/gpu/resource_lifecycle.d.ts +4 -0
  32. package/dist/types/gpu/tangram_gpu_backend.d.ts +151 -0
  33. package/dist/types/index.d.ts +155 -0
  34. package/dist/types/lights/light-definitions.d.ts +121 -0
  35. package/dist/types/map-logic/draped-terrain-bounds.d.ts +41 -0
  36. package/dist/types/map-logic/globe-terrain-preparation.d.ts +85 -0
  37. package/dist/types/map-logic/globe-terrain.d.ts +54 -0
  38. package/dist/types/map-logic/index.d.ts +33 -0
  39. package/dist/types/map-logic/label-identity.d.ts +22 -0
  40. package/dist/types/map-logic/label-placement.d.ts +32 -0
  41. package/dist/types/map-logic/screen-bounds.d.ts +15 -0
  42. package/dist/types/map-logic/terrain-data.d.ts +55 -0
  43. package/dist/types/map-logic/terrain-error.d.ts +51 -0
  44. package/dist/types/map-logic/terrain-ground-topology.d.ts +26 -0
  45. package/dist/types/map-logic/terrain-height-field.d.ts +59 -0
  46. package/dist/types/map-logic/terrain-navigation.d.ts +27 -0
  47. package/dist/types/map-logic/terrain-neighborhood.d.ts +5 -0
  48. package/dist/types/map-logic/terrain-query.d.ts +33 -0
  49. package/dist/types/map-logic/terrain-resource-budget.d.ts +51 -0
  50. package/dist/types/map-logic/terrain-transition-topology.d.ts +23 -0
  51. package/dist/types/map-logic/tile-build-queue.d.ts +51 -0
  52. package/dist/types/map-logic/tile-cache-policy.d.ts +46 -0
  53. package/dist/types/map-logic/tile-residency.d.ts +17 -0
  54. package/dist/types/map-logic/triangle-query-index.d.ts +87 -0
  55. package/dist/types/procedures/js-yaml.d.ts +15 -0
  56. package/dist/types/procedures/mesh-projector.d.ts +107 -0
  57. package/dist/types/procedures/mvt-dependencies.d.ts +20 -0
  58. package/dist/types/procedures/projected-coordinate-transform.d.ts +27 -0
  59. package/dist/types/procedures/projection-batch-executor.d.ts +53 -0
  60. package/dist/types/procedures/scene-yaml-legacy.d.ts +6 -0
  61. package/dist/types/procedures/terrain-draping.d.ts +165 -0
  62. package/dist/types/procedures/terrain-globe.d.ts +6 -0
  63. package/dist/types/procedures/terrain-styled-topology.d.ts +34 -0
  64. package/dist/types/procedures/web-mercator-legacy.d.ts +4 -0
  65. package/dist/types/procedures/web-mercator-math.d.ts +4 -0
  66. package/dist/types/scene/globals.d.ts +11 -0
  67. package/dist/types/scene/ground_footprint.d.ts +16 -0
  68. package/dist/types/scene/host_frame.d.ts +54 -0
  69. package/dist/types/scene/projection_math.d.ts +52 -0
  70. package/dist/types/scene/scene-resource-types.d.ts +177 -0
  71. package/dist/types/scene/scene_bundle.d.ts +69 -0
  72. package/dist/types/scene/visibility_adapter.d.ts +106 -0
  73. package/dist/types/selection/draped-terrain-surface.d.ts +78 -0
  74. package/dist/types/selection/terrain_surface.d.ts +149 -0
  75. package/dist/types/shader-modules/globe-horizon.d.ts +15 -0
  76. package/dist/types/shader-modules/height-decode.d.ts +13 -0
  77. package/dist/types/shader-modules/hillshade.d.ts +13 -0
  78. package/dist/types/shader-modules/index.d.ts +6 -0
  79. package/dist/types/shader-modules/planar.d.ts +12 -0
  80. package/dist/types/shader-modules/sphere-map.d.ts +13 -0
  81. package/dist/types/shader-modules/triplanar.d.ts +15 -0
  82. package/dist/types/sources/decoded_tile_store.d.ts +95 -0
  83. package/dist/types/sources/tile_source_metadata.d.ts +32 -0
  84. package/dist/types/styles/text/fontfaceobserver.d.ts +10 -0
  85. package/dist/types/tile/tile_id.d.ts +37 -0
  86. package/dist/types/tile/tile_traversal_adapter.d.ts +63 -0
  87. package/dist/types/types.d.ts +293 -0
  88. package/dist/types/utils/geo.d.ts +57 -0
  89. package/dist/types/utils/hash.d.ts +1 -0
  90. package/dist/types/utils/log.d.ts +27 -0
  91. package/dist/types/utils/props.d.ts +6 -0
  92. package/dist/types/utils/subscribe.d.ts +10 -0
  93. package/dist/types/utils/thread.d.ts +6 -0
  94. package/dist/types/utils/urls.d.ts +26 -0
  95. package/dist/types/utils/utils.d.ts +26 -0
  96. package/dist/types/utils/version.d.ts +2 -0
  97. package/dist/types/utils/worker-types.d.ts +68 -0
  98. package/dist/types/utils/worker_broker.d.ts +3 -0
  99. package/package.json +103 -3
  100. package/src/builders/common.ts +41 -0
  101. package/src/builders/earcut.d.ts +15 -0
  102. package/src/builders/geometry-types.ts +60 -0
  103. package/src/builders/points.ts +115 -0
  104. package/src/builders/polygons.ts +225 -0
  105. package/src/builders/polylines.ts +682 -0
  106. package/src/builders/wireframe.ts +31 -0
  107. package/src/core.d.ts +29 -0
  108. package/src/core.ts +33 -0
  109. package/src/experimental/loaders-gl-worker.ts +19 -0
  110. package/src/experimental/projected-basemaps-worker.ts +13 -0
  111. package/src/experimental/projected-mesh-cache.ts +137 -0
  112. package/src/experimental/projected-mesh-domain.ts +110 -0
  113. package/src/experimental/projected-mesh-refinement.ts +193 -0
  114. package/src/experimental/projected-mesh.ts +399 -0
  115. package/src/experimental/projected-normal.ts +26 -0
  116. package/src/experimental/projected-symbol-mesh.ts +74 -0
  117. package/src/gl/constants.ts +18 -0
  118. package/src/gl/context.ts +103 -0
  119. package/src/gl/extensions.ts +30 -0
  120. package/src/gl/globe_mesh.ts +285 -0
  121. package/src/gl/glsl.ts +257 -0
  122. package/src/gl/mesh-types.ts +56 -0
  123. package/src/gl/render_state.ts +111 -0
  124. package/src/gl/shader_program.ts +1310 -0
  125. package/src/gl/texture.ts +814 -0
  126. package/src/gl/uniform_buffer.ts +340 -0
  127. package/src/gl/vao.ts +154 -0
  128. package/src/gl/vbo_mesh.ts +349 -0
  129. package/src/gl/vertex-constants.ts +19 -0
  130. package/src/gl/vertex-types.ts +35 -0
  131. package/src/gl/vertex_data.ts +126 -0
  132. package/src/gl/vertex_elements.ts +54 -0
  133. package/src/gl/vertex_layout.ts +241 -0
  134. package/src/glsl.d.ts +14 -0
  135. package/src/gpu/luma_device_renderer.ts +579 -0
  136. package/src/gpu/pixel_readback.ts +51 -0
  137. package/src/gpu/resource_lifecycle.ts +32 -0
  138. package/src/gpu/tangram_gpu_backend.ts +195 -0
  139. package/src/index.d.ts +155 -0
  140. package/src/index.ts +105 -0
  141. package/src/labels/collision-types.ts +94 -0
  142. package/src/labels/collision.ts +273 -0
  143. package/src/labels/collision_grid.ts +61 -0
  144. package/src/labels/intersect.ts +30 -0
  145. package/src/labels/label-types.ts +91 -0
  146. package/src/labels/label.ts +207 -0
  147. package/src/labels/label_line.ts +801 -0
  148. package/src/labels/label_point.ts +131 -0
  149. package/src/labels/main-pass-types.ts +73 -0
  150. package/src/labels/main_pass.ts +221 -0
  151. package/src/labels/point_anchor.ts +100 -0
  152. package/src/labels/point_placement.ts +150 -0
  153. package/src/labels/projected-pass.ts +259 -0
  154. package/src/labels/repeat_group.ts +72 -0
  155. package/src/lights/ambient_light.glsl +18 -0
  156. package/src/lights/directional_light.glsl +39 -0
  157. package/src/lights/geographic-lights.ts +21 -0
  158. package/src/lights/light-definitions.ts +285 -0
  159. package/src/lights/light.ts +590 -0
  160. package/src/lights/lighting-uniforms.ts +80 -0
  161. package/src/lights/lighting-wgsl.ts +116 -0
  162. package/src/lights/material.glsl +237 -0
  163. package/src/lights/material.ts +145 -0
  164. package/src/lights/native-falloff.ts +37 -0
  165. package/src/lights/point_light.glsl +96 -0
  166. package/src/lights/spot_light.glsl +111 -0
  167. package/src/map-logic/draped-terrain-bounds.ts +71 -0
  168. package/src/map-logic/globe-terrain-preparation.ts +217 -0
  169. package/src/map-logic/globe-terrain.ts +296 -0
  170. package/src/map-logic/index.ts +37 -0
  171. package/src/map-logic/label-identity.ts +36 -0
  172. package/src/map-logic/label-placement.ts +117 -0
  173. package/src/map-logic/screen-bounds.ts +34 -0
  174. package/src/map-logic/terrain-data.ts +107 -0
  175. package/src/map-logic/terrain-error.ts +134 -0
  176. package/src/map-logic/terrain-ground-topology.ts +164 -0
  177. package/src/map-logic/terrain-height-field.ts +254 -0
  178. package/src/map-logic/terrain-navigation.ts +50 -0
  179. package/src/map-logic/terrain-neighborhood.ts +43 -0
  180. package/src/map-logic/terrain-query.ts +51 -0
  181. package/src/map-logic/terrain-resource-budget.ts +124 -0
  182. package/src/map-logic/terrain-transition-topology.ts +164 -0
  183. package/src/map-logic/tile-build-queue.ts +110 -0
  184. package/src/map-logic/tile-cache-policy.ts +89 -0
  185. package/src/map-logic/tile-residency.ts +50 -0
  186. package/src/map-logic/triangle-query-index.ts +265 -0
  187. package/src/procedures/js-yaml.d.ts +15 -0
  188. package/src/procedures/mesh-projector.ts +191 -0
  189. package/src/procedures/mlt-loaders.ts +55 -0
  190. package/src/procedures/mvt-dependencies.d.ts +20 -0
  191. package/src/procedures/mvt-legacy.ts +150 -0
  192. package/src/procedures/mvt-loaders.ts +53 -0
  193. package/src/procedures/mvt-parser.ts +48 -0
  194. package/src/procedures/mvt-properties.ts +36 -0
  195. package/src/procedures/mvt-tile-provider.ts +72 -0
  196. package/src/procedures/pmtiles-loader.ts +75 -0
  197. package/src/procedures/projected-coordinate-transform.ts +79 -0
  198. package/src/procedures/projection-batch-executor.ts +140 -0
  199. package/src/procedures/scene-yaml-legacy.ts +16 -0
  200. package/src/procedures/scene-yaml-loaders.ts +10 -0
  201. package/src/procedures/terrain-draping.ts +713 -0
  202. package/src/procedures/terrain-globe.ts +32 -0
  203. package/src/procedures/terrain-styled-topology.ts +184 -0
  204. package/src/procedures/web-mercator-legacy.ts +24 -0
  205. package/src/procedures/web-mercator-math.ts +50 -0
  206. package/src/scene/camera.ts +298 -0
  207. package/src/scene/camera_base.ts +116 -0
  208. package/src/scene/classic_scene.ts +20 -0
  209. package/src/scene/external_camera.ts +101 -0
  210. package/src/scene/globals.ts +120 -0
  211. package/src/scene/ground_footprint.ts +139 -0
  212. package/src/scene/host_frame.ts +326 -0
  213. package/src/scene/projected_tile_lod.ts +125 -0
  214. package/src/scene/projection_math.ts +142 -0
  215. package/src/scene/projection_shaders.ts +183 -0
  216. package/src/scene/renderer.ts +516 -0
  217. package/src/scene/scene-resource-types.ts +174 -0
  218. package/src/scene/scene.ts +2378 -0
  219. package/src/scene/scene_bundle.ts +304 -0
  220. package/src/scene/scene_debug.ts +129 -0
  221. package/src/scene/scene_loader.ts +402 -0
  222. package/src/scene/scene_worker.ts +528 -0
  223. package/src/scene/view.ts +683 -0
  224. package/src/scene/visibility_adapter.ts +319 -0
  225. package/src/scene/worker_url.ts +15 -0
  226. package/src/selection/draped-terrain-surface.ts +377 -0
  227. package/src/selection/selection-types.ts +79 -0
  228. package/src/selection/selection.ts +542 -0
  229. package/src/selection/selection_fragment.glsl +18 -0
  230. package/src/selection/selection_globals.glsl +9 -0
  231. package/src/selection/selection_pixels.ts +59 -0
  232. package/src/selection/selection_vertex.glsl +15 -0
  233. package/src/selection/terrain_surface.ts +298 -0
  234. package/src/shader-modules/globe-horizon.ts +52 -0
  235. package/src/shader-modules/height-decode.ts +41 -0
  236. package/src/shader-modules/hillshade.ts +70 -0
  237. package/src/shader-modules/index.ts +10 -0
  238. package/src/shader-modules/planar.ts +24 -0
  239. package/src/shader-modules/sphere-map.ts +38 -0
  240. package/src/shader-modules/triplanar.ts +45 -0
  241. package/src/sources/aligned_tile_source.ts +122 -0
  242. package/src/sources/data_source.ts +655 -0
  243. package/src/sources/decoded_tile_store.ts +245 -0
  244. package/src/sources/geojson.ts +300 -0
  245. package/src/sources/mvt.ts +247 -0
  246. package/src/sources/raster.ts +341 -0
  247. package/src/sources/shared_tile_source_adapter.ts +117 -0
  248. package/src/sources/sources.ts +10 -0
  249. package/src/sources/tile_source_adapter.ts +84 -0
  250. package/src/sources/tile_source_metadata.ts +65 -0
  251. package/src/sources/tile_source_state.ts +112 -0
  252. package/src/sources/topojson.ts +90 -0
  253. package/src/styles/feature_annotations.ts +16 -0
  254. package/src/styles/filter.ts +190 -0
  255. package/src/styles/geometry-style-types.ts +209 -0
  256. package/src/styles/globe_visibility_wgsl.ts +22 -0
  257. package/src/styles/layer-types.ts +45 -0
  258. package/src/styles/layer.ts +586 -0
  259. package/src/styles/lines/dasharray.ts +49 -0
  260. package/src/styles/lines/lines.ts +707 -0
  261. package/src/styles/lines/lines_wgsl.ts +224 -0
  262. package/src/styles/points/point-runtime-types.ts +125 -0
  263. package/src/styles/points/points.ts +1079 -0
  264. package/src/styles/points/points_fragment.glsl +126 -0
  265. package/src/styles/points/points_vertex.glsl +230 -0
  266. package/src/styles/points/points_wgsl.ts +189 -0
  267. package/src/styles/polygons/polygons.ts +268 -0
  268. package/src/styles/polygons/polygons_fragment.glsl +173 -0
  269. package/src/styles/polygons/polygons_vertex.glsl +213 -0
  270. package/src/styles/polygons/polygons_wgsl.ts +127 -0
  271. package/src/styles/property-types.ts +125 -0
  272. package/src/styles/raster/raster.ts +33 -0
  273. package/src/styles/raster/raster_globals.glsl +46 -0
  274. package/src/styles/style-mixing-types.ts +101 -0
  275. package/src/styles/style-runtime-types.ts +220 -0
  276. package/src/styles/style-schema.ts +133 -0
  277. package/src/styles/style.ts +1033 -0
  278. package/src/styles/style_globals.glsl +69 -0
  279. package/src/styles/style_manager.ts +464 -0
  280. package/src/styles/style_parser.ts +620 -0
  281. package/src/styles/text/font_manager.ts +180 -0
  282. package/src/styles/text/fontfaceobserver.d.ts +10 -0
  283. package/src/styles/text/text-types.ts +220 -0
  284. package/src/styles/text/text.ts +378 -0
  285. package/src/styles/text/text_canvas.ts +773 -0
  286. package/src/styles/text/text_labels.ts +436 -0
  287. package/src/styles/text/text_segments.ts +142 -0
  288. package/src/styles/text/text_settings.ts +228 -0
  289. package/src/styles/text/text_wgsl.ts +159 -0
  290. package/src/styles/text/text_wrap.ts +194 -0
  291. package/src/tile/globe_tile_preload.ts +40 -0
  292. package/src/tile/tangram_tileset_2d.ts +108 -0
  293. package/src/tile/tile-build-types.ts +155 -0
  294. package/src/tile/tile.ts +807 -0
  295. package/src/tile/tile_id.ts +172 -0
  296. package/src/tile/tile_manager.ts +889 -0
  297. package/src/tile/tile_pyramid.ts +119 -0
  298. package/src/tile/tile_resource_cache.ts +91 -0
  299. package/src/tile/tile_traversal_adapter.ts +132 -0
  300. package/src/types.ts +332 -0
  301. package/src/utils/debounce.ts +17 -0
  302. package/src/utils/debug_settings.ts +43 -0
  303. package/src/utils/errors.ts +12 -0
  304. package/src/utils/functions.ts +95 -0
  305. package/src/utils/geo.ts +364 -0
  306. package/src/utils/hash.ts +14 -0
  307. package/src/utils/log.ts +108 -0
  308. package/src/utils/media_capture.ts +193 -0
  309. package/src/utils/merge.ts +44 -0
  310. package/src/utils/obb.ts +134 -0
  311. package/src/utils/props.ts +43 -0
  312. package/src/utils/slice.ts +14 -0
  313. package/src/utils/subscribe.ts +58 -0
  314. package/src/utils/task.ts +154 -0
  315. package/src/utils/thread.ts +26 -0
  316. package/src/utils/urls.ts +223 -0
  317. package/src/utils/utils.ts +310 -0
  318. package/src/utils/vector.ts +197 -0
  319. package/src/utils/version.ts +8 -0
  320. package/src/utils/worker-types.ts +79 -0
  321. package/src/utils/worker_broker.ts +523 -0
@@ -0,0 +1,117 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import DataSource from './data_source';
6
+ import {MVTSource} from './mvt';
7
+ import {GeoJSONTileSource} from './geojson';
8
+ import {RasterTileSource} from './raster';
9
+ import Utils from '../utils/utils';
10
+ import AlignedTangramTileSource from './aligned_tile_source';
11
+ import TangramTileSourceAdapter from './tile_source_adapter';
12
+ import type {TileSourceContext} from './tile_source_adapter';
13
+ import {applyTilePayload, getTileSourceRequest, updateTileSourceRequest} from './tile_source_state';
14
+ import type {DecodedTilePayload, TileSourceRequestState} from './tile_source_state';
15
+ import DecodedTileStore, {createTileLeaseAbortError} from './decoded_tile_store';
16
+ import type {DecodedTileLease, DecodedTileStoreOptions} from './decoded_tile_store';
17
+
18
+ /** Acquisition anchors copied from worker messages, without mesh or build ownership. */
19
+ export interface SharedTileContext extends TileSourceContext {
20
+ /** Legacy diagnostic identity; never part of shared data identity. */
21
+ key: string;
22
+ /** Tile northwest in EPSG:3857 meters. */
23
+ min: {x: number; y: number};
24
+ /** Tile southeast in EPSG:3857 meters. */
25
+ max: {x: number; y: number};
26
+ /** Per-consumer detached diagnostic fields. */
27
+ debug?: Record<string, unknown>;
28
+ }
29
+
30
+ /** Reusable content and acquisition diagnostics, excluding live request IDs and consumer contexts. */
31
+ interface SharedTileResult {
32
+ /** Original postprocessed geometry, winding, seam padding and attached rasters. */
33
+ readonly payload: DecodedTilePayload;
34
+ /** Resolved legacy provider error and URL; never ownership of a cancellation ID. */
35
+ readonly diagnostics: Pick<TileSourceRequestState, 'error' | 'url'>;
36
+ /** Detached timing fields; each consumer receives its own debug shell. */
37
+ readonly debug: Readonly<Record<string, unknown>>;
38
+ }
39
+
40
+ /** Only exact built-in tiled pipelines without custom hooks participate in production sharing. */
41
+ export function supportsSharedTileAcquisition(source: unknown): source is DataSource {
42
+ if (!(source instanceof DataSource) || source.transform || source.preprocess || source.scripts?.length) return false;
43
+ if (Object.getOwnPropertyNames(source).some(name => typeof Reflect.get(source, name) === 'function')) return false;
44
+ if (source instanceof MVTSource && Object.getPrototypeOf(source) === MVTSource.prototype) {
45
+ return source.decoder === 'tangram' && !source.tile_provider &&
46
+ source.load === MVTSource.prototype.load && source.parseSourceData === MVTSource.prototype.parseSourceData;
47
+ }
48
+ if (source instanceof GeoJSONTileSource && Object.getPrototypeOf(source) === GeoJSONTileSource.prototype) {
49
+ return source.load === GeoJSONTileSource.prototype.load && source.parseSourceData === GeoJSONTileSource.prototype.parseSourceData;
50
+ }
51
+ return source instanceof RasterTileSource && Object.getPrototypeOf(source) === RasterTileSource.prototype && source.load === RasterTileSource.prototype.load;
52
+ }
53
+
54
+ /** Worker-local ownership bridge; custom sources continue through the original first-match procedure. */
55
+ export default class SharedTileSourceAdapter<TileT extends SharedTileContext> {
56
+ /** No unreferenced warm cache; content stays alive only while worker tile leases need it. */
57
+ readonly store: DecodedTileStore<SharedTileResult>;
58
+ /** Worker tile identity owns its own lease, never the underlying request's cancellation ID. */
59
+ private leases = new WeakMap<TileT, DecodedTileLease<SharedTileResult>>();
60
+ /** Workers with imported external scripts cannot assume built-in prototype purity. */
61
+ readonly sharingEnabled: boolean;
62
+
63
+ /** Enable only known built-in pipelines; external worker scripts conservatively disable sharing. */
64
+ constructor(sharingEnabled = true, options: DecodedTileStoreOptions = {}) {
65
+ this.sharingEnabled = sharingEnabled;
66
+ this.store = new DecodedTileStore<SharedTileResult>(result => result.payload.byteLength, options);
67
+ }
68
+
69
+ /** Acquire compatible decoded content or preserve the original custom-source loading path. */
70
+ loadTile(tile: TileT, source: DataSource | undefined, getRetainedTiles: () => Iterable<TileT>): Promise<TileT> {
71
+ this.releaseTile(tile);
72
+ if (!this.sharingEnabled || !supportsSharedTileAcquisition(source)) {
73
+ return new TangramTileSourceAdapter(source, getRetainedTiles).getTileData({index: tile.coords, id: tile.key, context: tile});
74
+ }
75
+ const context: SharedTileContext = {source: tile.source, key: tile.key, coords: {...tile.coords},
76
+ min: {...tile.min}, max: {...tile.max}, debug: {}};
77
+ const lease = this.store.acquireTile({source, key: tile.coords.key, load: async signal => {
78
+ // The worker's traversal already applied display/bounds policy. Do not re-filter by data zoom.
79
+ const aligned = new AlignedTangramTileSource({load: destination => source.load(destination),
80
+ copyTileData: (reference, destination) => source.copyTileData(reference, destination),
81
+ getMetadata: () => source.getMetadata()}, {createContext: () => context, cancel: destination => {
82
+ const request = getTileSourceRequest(destination);
83
+ if (request.requestId) Utils.cancelRequest(request.requestId);
84
+ updateTileSourceRequest(destination, {requestId: null});
85
+ }});
86
+ const payload = await aligned.getTileData({index: context.coords, id: context.key,
87
+ bbox: {left: context.min.x, top: context.min.y, right: context.max.x, bottom: context.max.y}, signal});
88
+ if (!payload) throw new Error('Shared tile acquisition unexpectedly returned no payload');
89
+ const request = getTileSourceRequest(context);
90
+ return {payload, diagnostics: {error: request.error, url: request.url}, debug: {...context.debug}};
91
+ }});
92
+ this.leases.set(tile, lease);
93
+ return lease.promise.then(result => {
94
+ if (this.leases.get(tile) !== lease || !lease.isActive()) throw createTileLeaseAbortError();
95
+ applyTilePayload(tile, result.payload);
96
+ updateTileSourceRequest(tile, result.diagnostics);
97
+ tile.debug = {...tile.debug, ...result.debug};
98
+ return tile;
99
+ }).catch(error => {
100
+ if (this.leases.get(tile) === lease) this.releaseTile(tile);
101
+ throw error;
102
+ });
103
+ }
104
+
105
+ /** Release this tile's interest; the final consumer alone cancels pending acquisition. */
106
+ releaseTile(tile: TileT): void {
107
+ const lease = this.leases.get(tile);
108
+ this.leases.delete(tile);
109
+ lease?.release();
110
+ }
111
+
112
+ /** Invalidate one source instance while preserving unchanged sources and style-only rebuilds. */
113
+ invalidateSource(source: object): void { this.store.invalidateSource(source); }
114
+
115
+ /** Release all content and pending work at worker reinitialization or explicit teardown. */
116
+ finalize(): void { this.store.finalize(); this.leases = new WeakMap(); }
117
+ }
@@ -0,0 +1,10 @@
1
+ // Tangram
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) 2013-2016 Brett Camper and Mapzen
4
+ // Copyright (c) 2026 vis.gl contributors
5
+
6
+ // add all data source types
7
+ import './geojson';
8
+ import './topojson';
9
+ import './mvt';
10
+ import './raster';
@@ -0,0 +1,84 @@
1
+ // Tangram
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) 2013-2016 Brett Camper and Mapzen
4
+ // Copyright (c) 2026 vis.gl contributors
5
+
6
+ import type {TileCoordinates} from '../tile/tile_id';
7
+ import {captureTilePayload} from './tile_source_state';
8
+ import type {TileDataContext} from './tile_source_state';
9
+
10
+ /** Worker-side request context; contains source data, never main-thread GPU meshes. */
11
+ export interface TileSourceContext extends TileDataContext {
12
+ /** Scene source identity, kept distinct from data and style tile identity. */
13
+ source: string;
14
+ /** Source-normalized data coordinates; style zoom must not enter data-reuse matching. */
15
+ coords: TileCoordinates & {key: string};
16
+ /** Whether source data is available for reuse. */
17
+ loaded?: boolean;
18
+ }
19
+
20
+ /** Existing source procedures, preserved until individual loaders.gl switches pass conformance. */
21
+ export interface LegacyTileDataSource<TileT extends TileSourceContext> {
22
+ /** Load and postprocess data into the live worker context. */
23
+ load(tile: TileT): Promise<TileT>;
24
+ /** Reuse decoded source data while preserving the destination's style/build identity. */
25
+ copyTileData(reference: TileT, destination: TileT): TileT;
26
+ }
27
+
28
+ /**
29
+ * Index/id request envelope analogous to loaders.gl's getTileData parameters.
30
+ * The required context is Tangram-specific: this is not yet a loaders.gl TileSource.
31
+ */
32
+ export interface TangramTileDataRequest<TileT extends TileSourceContext> {
33
+ /** Data index, not the source/style mesh-cache key. */
34
+ readonly index: TileCoordinates;
35
+ /** Destination build identity; not used to decide decoded-data reuse. */
36
+ readonly id: string;
37
+ /** Live legacy context, retained so request IDs and cancellation stay on the worker's tile. */
38
+ readonly context: TileT;
39
+ }
40
+
41
+ /** Preserve the worker's legacy enumerable-property order without allocating a table snapshot. */
42
+ export function* iterateSourceTiles<TileT>(tiles: Readonly<Record<string, TileT>>): Iterable<TileT> {
43
+ for (const key in tiles) yield tiles[key];
44
+ }
45
+
46
+ /**
47
+ * Data acquisition/reuse seam with no renderer, traversal, or GPU dependency.
48
+ *
49
+ * Keep the mutable context and resolved-versus-rejected error behavior intact.
50
+ * Publish a decoded payload record while retaining the legacy context facade.
51
+ * The separate aligned source bridge supplies metadata and AbortSignal translation.
52
+ */
53
+ export default class TangramTileSourceAdapter<TileT extends TileSourceContext> {
54
+ /** Current legacy source; undefined preserves the missing-source worker behavior. */
55
+ private readonly source: LegacyTileDataSource<TileT> | undefined;
56
+ /** Read the current worker table at request time, never a stale registry snapshot. */
57
+ private readonly getRetainedTiles: () => Iterable<TileT>;
58
+
59
+ /** Bind one source to a caller-owned decoded-data registry. */
60
+ constructor(source: LegacyTileDataSource<TileT> | undefined, getRetainedTiles: () => Iterable<TileT>) {
61
+ this.source = source;
62
+ this.getRetainedTiles = getRetainedTiles;
63
+ }
64
+
65
+ /** Acquire source data using the original first-match reuse and loading procedures. */
66
+ getTileData({context}: TangramTileDataRequest<TileT>): Promise<TileT> {
67
+ if (this.source) {
68
+ for (const reference of this.getRetainedTiles()) {
69
+ if (reference.source === context.source && reference.coords.key === context.coords.key && reference.loaded) {
70
+ const destination = this.source.copyTileData(reference, context);
71
+ captureTilePayload(destination);
72
+ return Promise.resolve(destination);
73
+ }
74
+ }
75
+ return this.source.load(context).then(destination => {
76
+ captureTilePayload(destination);
77
+ return destination;
78
+ });
79
+ }
80
+ context.source_data = {};
81
+ captureTilePayload(context);
82
+ return Promise.resolve(context);
83
+ }
84
+ }
@@ -0,0 +1,65 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /** Source metadata subset structurally compatible with loaders.gl TileSourceMetadata. */
6
+ export interface TangramTileSourceMetadata {
7
+ /** Source/container format, not a promise to select a different parser. */
8
+ format?: string;
9
+ /** Encoded tile MIME type, separate from archive format and decoder selection. */
10
+ tileMIMEType?: string;
11
+ /** Human-readable source name. */
12
+ name?: string;
13
+ /** Provider credits; consumers must sanitize before rendering HTML. */
14
+ attributions?: string[];
15
+ /** Minimum advertised data level. */
16
+ minZoom?: number;
17
+ /** Maximum advertised data level. */
18
+ maxZoom?: number;
19
+ /** Geographic bounds, retaining antimeridian-crossing west/east ordering. */
20
+ boundingBox?: [[number, number], [number, number]];
21
+ }
22
+
23
+ /** Configuration plus discovered metadata, without depending on the DataSource implementation. */
24
+ export interface SourceMetadataInput {
25
+ /** Original scene source options. */
26
+ config: Record<string, unknown>;
27
+ /** Logical scene source name. */
28
+ name: string;
29
+ /** Effective legacy data levels. */
30
+ zooms: readonly number[];
31
+ /** Effective legacy data ceiling. */
32
+ max_zoom: number;
33
+ /** Authored and discovered provider credits. */
34
+ getAttributions(): string[];
35
+ }
36
+
37
+ /** Normalize metadata for new consumers without changing legacy source layout or URL resolution. */
38
+ export function createTileSourceMetadata(source: SourceMetadataInput, discovered: Record<string, unknown> = {}): TangramTileSourceMetadata {
39
+ const config = source.config;
40
+ const bounds = config.bounds ?? discovered.bounds ?? discovered.boundingBox;
41
+ const metadata: TangramTileSourceMetadata = {name: typeof discovered.name === 'string' ? discovered.name : source.name, attributions: source.getAttributions(),
42
+ minZoom: source.zooms[0], maxZoom: source.max_zoom};
43
+ const format = discovered.format ?? config.type;
44
+ if (typeof format === 'string') metadata.format = format;
45
+ if (typeof discovered.tileMIMEType === 'string') metadata.tileMIMEType = discovered.tileMIMEType;
46
+ const maximum = discovered.maxzoom ?? discovered.maxZoom;
47
+ const minimum = discovered.minzoom ?? discovered.minZoom;
48
+ if (config.zooms === undefined && config.max_zoom === undefined && validZoom(maximum)) metadata.maxZoom = maximum;
49
+ if (config.zooms === undefined && validZoom(minimum)) metadata.minZoom = minimum;
50
+ if (metadata.minZoom !== undefined && metadata.maxZoom !== undefined && metadata.minZoom > metadata.maxZoom) {
51
+ metadata.minZoom = source.zooms[0];
52
+ metadata.maxZoom = source.max_zoom;
53
+ }
54
+ const flattened = Array.isArray(bounds) && bounds.length === 2 && bounds.every(value => Array.isArray(value) && value.length === 2) ? bounds.flat() : bounds;
55
+ if (Array.isArray(flattened) && flattened.length === 4 && flattened.every(value => typeof value === 'number' && Number.isFinite(value)) &&
56
+ Math.abs(flattened[0]) <= 180 && Math.abs(flattened[2]) <= 180 && flattened[1] >= -90 && flattened[3] <= 90 && flattened[1] <= flattened[3]) {
57
+ metadata.boundingBox = [[flattened[0], flattened[1]], [flattened[2], flattened[3]]];
58
+ }
59
+ return metadata;
60
+ }
61
+
62
+ /** Reject unusable advertised levels rather than passing NaN or infinite values to traversal. */
63
+ function validZoom(value: unknown): value is number {
64
+ return typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 30;
65
+ }
@@ -0,0 +1,112 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /** Legacy compatibility envelope; network bookkeeping is not reusable decoded content. */
6
+ export interface TileSourceData {
7
+ /** Postprocessed source layers, shared by the existing overzoom path. */
8
+ layers?: Record<string, unknown>;
9
+ /** Legacy cancellation identity. */
10
+ request_id?: string | null;
11
+ /** Resolved provider error, retained for the legacy warn-and-continue path. */
12
+ error?: string | null;
13
+ /** Resolved source URL. */
14
+ url?: string;
15
+ }
16
+
17
+ /** Worker-side structural surface; no scene, styles or GPU content. */
18
+ export interface TileDataContext {
19
+ /** Temporary legacy data facade used by existing parsers and transforms. */
20
+ source_data?: TileSourceData;
21
+ /** Attached raster identities. */
22
+ rasters?: string[];
23
+ /** Seam padding already applied during postprocessing. */
24
+ pad_scale?: number;
25
+ /** Source polygon winding after postprocessing. */
26
+ default_winding?: string | null;
27
+ }
28
+
29
+ /** Reusable decoded content, deliberately excluding URLs, errors and cancellation IDs. */
30
+ export interface DecodedTilePayload {
31
+ /** Tangram-local layer references (4096-unit tiles, negative local Y); not geographic GeoJSON. */
32
+ readonly layers?: Record<string, unknown>;
33
+ /** Detached list of attached raster sources. */
34
+ readonly rasters: readonly string[];
35
+ /** Seam padding retained when rebinding content to a style/build tile. */
36
+ readonly padScale?: number;
37
+ /** Polygon winding retained when rebinding content. */
38
+ readonly defaultWinding?: string | null;
39
+ /** Optional decoded-content allocation estimate supplied by an owning adapter, never encoded response bytes. */
40
+ readonly byteLength?: number;
41
+ }
42
+
43
+ /** Per-request mutable state, never shared with an overzoom payload. */
44
+ export interface TileSourceRequestState {
45
+ /** Source-owned cancellation hook for providers that do not use legacy XHR request IDs. */
46
+ cancel?: () => void;
47
+ /** Legacy cancellation identity, when a provider exposes one. */
48
+ requestId?: string | null;
49
+ /** Resolved provider error, distinct from a thrown/rejected load. */
50
+ error?: string | null;
51
+ /** Resolved source URL. */
52
+ url?: string;
53
+ }
54
+
55
+ /** Request records follow context lifetime without entering worker messages. */
56
+ const requestStates = new WeakMap<TileDataContext, TileSourceRequestState>();
57
+ /** Decoded records follow context lifetime without retaining evicted worker tiles. */
58
+ const payloads = new WeakMap<TileDataContext, DecodedTilePayload>();
59
+ /** Aborted aligned requests can cancel IDs assigned after asynchronous URL resolution. */
60
+ const cancellationListeners = new WeakMap<TileDataContext, () => void>();
61
+
62
+ /** Read request state, including writes by an unmodified custom legacy source. */
63
+ export function getTileSourceRequest(context: TileDataContext): TileSourceRequestState {
64
+ const state = requestStates.get(context) ?? {};
65
+ const legacy = context.source_data;
66
+ state.requestId = legacy?.request_id;
67
+ state.error = legacy?.error;
68
+ state.url = legacy?.url;
69
+ requestStates.set(context, state);
70
+ return state;
71
+ }
72
+
73
+ /** Write separated request state and preserve the legacy parser/cancellation facade. */
74
+ export function updateTileSourceRequest(context: TileDataContext, changes: Partial<TileSourceRequestState>): void {
75
+ const state = getTileSourceRequest(context);
76
+ Object.assign(state, changes);
77
+ const legacy = context.source_data ??= {};
78
+ if ('requestId' in changes) legacy.request_id = changes.requestId;
79
+ if ('error' in changes) legacy.error = changes.error;
80
+ if ('url' in changes) legacy.url = changes.url;
81
+ if (changes.requestId || changes.cancel) cancellationListeners.get(context)?.();
82
+ }
83
+
84
+ /** Keep a cancellation hook attached until the legacy load settles, including late request IDs. */
85
+ export function bindTileSourceCancellation(context: TileDataContext, cancel: () => void): () => void {
86
+ cancellationListeners.set(context, cancel);
87
+ return () => { if (cancellationListeners.get(context) === cancel) cancellationListeners.delete(context); };
88
+ }
89
+
90
+ /** Publish postprocessed content without cloning or freezing legacy feature objects. */
91
+ export function captureTilePayload(context: TileDataContext): DecodedTilePayload {
92
+ const payload: DecodedTilePayload = {layers: context.source_data?.layers,
93
+ rasters: [...(context.rasters ?? [])], padScale: context.pad_scale, defaultWinding: context.default_winding};
94
+ getTileSourceRequest(context);
95
+ payloads.set(context, payload);
96
+ return payload;
97
+ }
98
+
99
+ /** Retrieve the last decoded publication, without retaining request/build state in the payload. */
100
+ export function getTilePayload(context: TileDataContext): DecodedTilePayload | undefined {
101
+ return payloads.get(context);
102
+ }
103
+
104
+ /** Bind reusable content to a new build context with fresh request state. */
105
+ export function applyTilePayload(context: TileDataContext, payload: DecodedTilePayload): void {
106
+ context.source_data = {layers: payload.layers};
107
+ context.rasters = [...payload.rasters];
108
+ context.pad_scale = payload.padScale;
109
+ context.default_winding = payload.defaultWinding;
110
+ requestStates.set(context, {});
111
+ payloads.set(context, payload);
112
+ }
@@ -0,0 +1,90 @@
1
+ // Tangram
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) 2013-2016 Brett Camper and Mapzen
4
+ // Copyright (c) 2026 vis.gl contributors
5
+
6
+ import DataSource from './data_source';
7
+ import {GeoJSONSource, GeoJSONTileSource} from './geojson';
8
+
9
+ import * as topojson from 'topojson-client';
10
+
11
+ type SourceConfig = Record<string, any>;
12
+
13
+ /**
14
+ TopoJSON standalone (non-tiled) source
15
+ Uses geojson-vt split into tiles client-side
16
+ */
17
+
18
+ export class TopoJSONSource extends GeoJSONSource {
19
+
20
+ parseSourceData (tile?: any, source?: any, response?: any): void {
21
+ if (!tile || !source) {
22
+ throw new Error('TopoJSON source parsing requires a tile and source data');
23
+ }
24
+ let data = typeof response === 'string' ? JSON.parse(response) : response;
25
+ data = this.toGeoJSON(data);
26
+
27
+ let layers = this.getLayers(data);
28
+ super.preprocessLayers(layers, tile);
29
+ source.layers = layers;
30
+ }
31
+
32
+ toGeoJSON (data: any): any {
33
+ // Single layer
34
+ if (data.objects &&
35
+ Object.keys(data.objects).length === 1) {
36
+ let layer = Object.keys(data.objects)[0];
37
+ data = getTopoJSONFeature(data, data.objects[layer]);
38
+ }
39
+ // Multiple layers
40
+ else {
41
+ let layers: Record<string, any> = {};
42
+ for (let key in data.objects) {
43
+ layers[key] = getTopoJSONFeature(data, data.objects[key]);
44
+ }
45
+ data = layers;
46
+ }
47
+ return data;
48
+ }
49
+
50
+ }
51
+
52
+ function getTopoJSONFeature (topology: any, object: any): any {
53
+ let feature = topojson.feature(topology, object);
54
+
55
+ // Convert single feature to a feature collection
56
+ if (feature.type === 'Feature') {
57
+ feature = {
58
+ type: 'FeatureCollection',
59
+ features: [feature]
60
+ };
61
+ }
62
+ return feature;
63
+ }
64
+
65
+
66
+ /**
67
+ TopoJSON vector tiles
68
+ @class TopoJSONTileSource
69
+ */
70
+ export class TopoJSONTileSource extends GeoJSONTileSource {
71
+
72
+ constructor(source: SourceConfig, sources?: Record<string, unknown>) {
73
+ super(source, sources);
74
+ }
75
+
76
+ parseSourceData (tile?: any, source?: any, response?: any): void {
77
+ if (!tile || !source) {
78
+ throw new Error('TopoJSON tile parsing requires a tile and source data');
79
+ }
80
+ let data = typeof response === 'string' ? JSON.parse(response) : response;
81
+ data = TopoJSONSource.prototype.toGeoJSON(data);
82
+ this.prepareGeoJSON(data, tile, source);
83
+ }
84
+
85
+ }
86
+
87
+ // Check for URL tile pattern, if not found, treat as standalone GeoJSON/TopoJSON object
88
+ DataSource.register('TopoJSON', (source: SourceConfig) => {
89
+ return TopoJSONTileSource.urlHasTilePattern(source.url) ? TopoJSONTileSource : TopoJSONSource;
90
+ });
@@ -0,0 +1,16 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /** Shared feature visibility keeps the legacy aggregate-generation semantics without mutating content. */
6
+ const renderedGenerations = new WeakMap<object, number>();
7
+
8
+ /** Mark successful built-in geometry generation in sidecar state, never on decoded features. */
9
+ export function markFeatureRendered(feature: object, generation: number): void {
10
+ renderedGenerations.set(feature, generation);
11
+ }
12
+
13
+ /** Read built-in sidecar visibility, falling back to annotations supplied by legacy custom code. */
14
+ export function getFeatureRenderedGeneration(feature: object): unknown {
15
+ return renderedGenerations.get(feature) ?? ('generation' in feature ? feature.generation : undefined);
16
+ }