@thatopen/services 0.35.0 β†’ 0.35.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 (110) hide show
  1. package/README.md +66 -66
  2. package/dist/cli.js.map +1 -1
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.es.js.map +1 -1
  5. package/dist/vite-env.d.ts +1 -1
  6. package/docs/ai-quickstart.md +548 -548
  7. package/docs/builtin/paths.json +130 -130
  8. package/docs/cli/create.md +29 -29
  9. package/docs/cli/local-server.md +38 -38
  10. package/docs/cli/login.md +32 -32
  11. package/docs/cli/mcp.md +46 -46
  12. package/docs/cli/publish.md +31 -31
  13. package/docs/cli/run.md +26 -26
  14. package/docs/cli/serve.md +43 -43
  15. package/docs/cli/swap.md +30 -30
  16. package/docs/cloud/GaussianSplatConverter.md +43 -43
  17. package/docs/cloud/PointCloudConverter.md +53 -53
  18. package/docs/flow-architecture.md +393 -393
  19. package/docs/flow-plugin-guide.md +354 -354
  20. package/docs/platform-token.md +81 -81
  21. package/docs/rate-limits.md +133 -133
  22. package/docs/recipes-guide.md +243 -243
  23. package/docs/revit-collab-quickstart.md +445 -445
  24. package/docs/rhino-interop-quickstart.md +387 -387
  25. package/docs/sheet-sets-guide.md +69 -69
  26. package/package.json +1 -1
  27. package/resources/AGENTS.md +57 -57
  28. package/src/built-in/CDEManager/example.ts +214 -214
  29. package/src/built-in/CDEManager/examples/FileEditing/example.ts +226 -226
  30. package/src/built-in/CDEManager/examples/FileMoves/example.ts +186 -186
  31. package/src/built-in/CDEManager/examples/FileOperations/example.ts +295 -295
  32. package/src/built-in/CDEManager/examples/FileTransfers/example.ts +210 -210
  33. package/src/built-in/CDEManager/examples/FolderManagement/example.ts +230 -230
  34. package/src/built-in/CDEManager/examples/MetadataSchema/example.ts +230 -230
  35. package/src/built-in/CDEManager/examples/MetadataViews/example.ts +166 -166
  36. package/src/built-in/CDEManager/examples/ProjectConfig/example.ts +177 -177
  37. package/src/built-in/ClashesManager/example.ts +283 -283
  38. package/src/built-in/GISManager/example.ts +355 -355
  39. package/src/built-in/ProjectManager/example.ts +124 -124
  40. package/src/built-in/UIManager/src/app/example.ts +97 -97
  41. package/src/built-in/UIManager/src/app/examples/AppState/example.ts +140 -140
  42. package/src/built-in/UIManager/src/app/examples/Banner/example.ts +159 -159
  43. package/src/built-in/UIManager/src/app/examples/Contexts/example.ts +123 -123
  44. package/src/built-in/UIManager/src/app/examples/FileDrop/example.ts +124 -124
  45. package/src/built-in/UIManager/src/app/examples/FloatingLayout/example.ts +90 -90
  46. package/src/built-in/UIManager/src/app/examples/Modal/example.ts +163 -163
  47. package/src/built-in/UIManager/src/app/examples/Notifications/example.ts +133 -133
  48. package/src/built-in/UIManager/src/app/examples/ProjectFileStorage/example.ts +150 -150
  49. package/src/built-in/UIManager/src/app/examples/Sidebar/example.ts +105 -105
  50. package/src/built-in/UIManager/src/clashes-panel/example.ts +183 -183
  51. package/src/built-in/UIManager/src/gis-panel/example.ts +163 -163
  52. package/src/built-in/UIManager/src/gis-properties-panel/example.ts +168 -168
  53. package/src/built-in/UIManager/src/git-history-panel/example.ts +70 -70
  54. package/src/built-in/UIManager/src/map-panel/example.ts +189 -189
  55. package/src/built-in/UIManager/src/models-list/example.ts +181 -181
  56. package/src/built-in/UIManager/src/settings-panel/example.ts +303 -303
  57. package/src/built-in/UIManager/src/topics-panel/example.ts +170 -170
  58. package/src/built-in/UIManager/src/viewer/example.ts +182 -182
  59. package/src/built-in/UIManager/src/viewer-toolbar/example.ts +376 -376
  60. package/src/built-in/index.ts +2995 -2995
  61. package/src/cli/templates/app/README.md +250 -250
  62. package/src/cli/templates/app/index.html +35 -35
  63. package/src/cli/templates/app/package.json +32 -32
  64. package/src/cli/templates/app/src/app.ts +37 -37
  65. package/src/cli/templates/app/src/assets/tool-placeholder.ts +50 -50
  66. package/src/cli/templates/app/src/bim-components/CloudRunner/index.ts +95 -95
  67. package/src/cli/templates/app/src/bim-components/CloudRunner/src/index.ts +1 -1
  68. package/src/cli/templates/app/src/bim-components/CloudRunner/src/types.ts +5 -5
  69. package/src/cli/templates/app/src/bim-components/index.ts +1 -1
  70. package/src/cli/templates/app/src/globals.ts +1 -1
  71. package/src/cli/templates/app/src/main.history.ts +191 -191
  72. package/src/cli/templates/app/src/main.ts +226 -226
  73. package/src/cli/templates/app/src/setups/channel.ts +76 -76
  74. package/src/cli/templates/app/src/setups/reality-capture/lib/hidden-tiles-plugin.ts +88 -88
  75. package/src/cli/templates/app/src/setups/reality-capture/lib/point-tile-plugin.ts +166 -166
  76. package/src/cli/templates/app/src/setups/reality-capture/lib/render-frame.ts +31 -31
  77. package/src/cli/templates/app/src/setups/reality-capture/lib/splat-tile-plugin.ts +51 -51
  78. package/src/cli/templates/app/src/setups/reality-capture-viewer.ts +1383 -1383
  79. package/src/cli/templates/app/src/ui-components/app-info-section/index.ts +26 -26
  80. package/src/cli/templates/app/src/ui-components/app-info-section/src/index.ts +1 -1
  81. package/src/cli/templates/app/src/ui-components/app-info-section/src/types.ts +15 -15
  82. package/src/cli/templates/app/src/ui-components/cloud-runner-section/index.ts +37 -37
  83. package/src/cli/templates/app/src/ui-components/cloud-runner-section/src/index.ts +1 -1
  84. package/src/cli/templates/app/src/ui-components/cloud-runner-section/src/types.ts +14 -14
  85. package/src/cli/templates/app/src/ui-components/index.ts +2 -2
  86. package/src/cli/templates/app/tsconfig.json +16 -16
  87. package/src/cli/templates/app/vite.config.js +57 -57
  88. package/src/cli/templates/cloud-component/README.md +205 -205
  89. package/src/cli/templates/cloud-component/_thatopen +5 -5
  90. package/src/cli/templates/cloud-component/declarations.json +4 -4
  91. package/src/cli/templates/cloud-component/package.json +21 -21
  92. package/src/cli/templates/cloud-component/src/main.ts +70 -70
  93. package/src/cli/templates/cloud-component/tsconfig.json +16 -16
  94. package/src/cli/templates/cloud-component/vite.config.js +46 -46
  95. package/src/cli/templates/shared/AGENTS.md +8 -8
  96. package/src/cli/templates/shared/CLAUDE.md +1 -1
  97. package/src/cli/templates/shared/_gitignore +5 -5
  98. package/src/core/examples/.env.example +7 -7
  99. package/src/core/examples/apps.ts +67 -67
  100. package/src/core/examples/batch-reads.ts +99 -99
  101. package/src/core/examples/channel.ts +65 -65
  102. package/src/core/examples/components.ts +91 -91
  103. package/src/core/examples/execution.ts +75 -75
  104. package/src/core/examples/file-metadata.ts +94 -94
  105. package/src/core/examples/files.ts +81 -81
  106. package/src/core/examples/folders.ts +82 -82
  107. package/src/core/examples/hidden-files.ts +88 -88
  108. package/src/core/examples/history.ts +103 -103
  109. package/src/core/examples/icons.ts +68 -68
  110. package/src/core/examples/permissions.ts +87 -87
@@ -1,355 +1,355 @@
1
- /* MD
2
- ## GISManager
3
- ---
4
- Georeferenced BIM projects need their surroundings: the real terrain and
5
- buildings around the model, and the project's GIS layers (parcels, networks,
6
- boundaries) drawn at the right place in the 3D scene and on a 2D map.
7
-
8
- GISManager is the component that owns all of that. It streams Cesium Ion 3D
9
- Tiles (Google Photorealistic 3D Tiles by default) around the project origin,
10
- loads vector layers (shapefile zip or GeoJSON) declared in the project's
11
- layer manifest, and renders a 2D minimap with markers.
12
-
13
- This tutorial covers initializing the manager from the platform client;
14
- enabling the 3D tiles; the layer manifest and how heights, styles and
15
- coordinate systems are read; selecting and focusing features; and the 2D
16
- minimap with its markers. The recommended UI is provided by `top-gis-panel`,
17
- `top-map-panel` and `top-gis-properties-panel`.
18
-
19
- GISManager reads the project origin from `ProjectManager`, so initialize
20
- `ProjectManager` first.
21
-
22
- ### πŸ–– Importing our libraries
23
- */
24
-
25
- import * as OBC from "@thatopen/components";
26
- import * as OBF from "@thatopen/components-front";
27
- import * as BUI from "@thatopen/ui";
28
- import * as THREE from "three";
29
- import * as FRAGS from "@thatopen/fragments";
30
- import { PlatformClient, GISManager, ProjectManager } from "@thatopen/services";
31
-
32
-
33
- /* MD
34
- ### πŸš€ Initializing GISManager
35
- Both components are set up through the platform client.
36
- `client.setup(...)` resolves the shared `OBC.Components` instance.
37
- */
38
-
39
- const client = PlatformClient.fromPlatformContext();
40
-
41
- const { components } = (await client.setup(
42
- { OBC, OBF, BUI, THREE, FRAGS },
43
- { uuid: ProjectManager.uuid },
44
- { uuid: GISManager.uuid },
45
- )) as { components: OBC.Components };
46
-
47
- await components.get(ProjectManager).init(client);
48
-
49
- const gis = components.get(GISManager);
50
-
51
- /* MD
52
- `init(client)` restores the project origin from `ProjectManager` and reads
53
- the project's layer manifest (see below). It never throws: with no project or
54
- no stored file the manager just keeps its defaults, and an empty layer list.
55
- */
56
-
57
- await gis.init(client);
58
- console.log("layers:", gis.vectorLayersConfig);
59
-
60
- /* MD
61
- ### 🌍 3D tiles
62
- Streaming the tiles needs a Cesium Ion token. The component does not persist
63
- the token anywhere: your application provides it (from its own settings, or
64
- typed by the user in `top-gis-panel`) before enabling the tiles.
65
-
66
- `enableTiles()` resolves once the first tiles are loaded and rejects with a
67
- readable message if the token is invalid or has no access to the tileset (the
68
- same message is also fired through `onLoadError`).
69
- */
70
-
71
- gis.onLoadError.add((message) => console.warn("GIS tiles:", message));
72
-
73
- gis.apiToken = "<your Cesium Ion token>";
74
- await gis.enableTiles();
75
-
76
- /* MD
77
- `onStateChanged` fires whenever the token, origin, tiles visibility, tiles
78
- offset or tiles opacity change, with a plain snapshot of all of them.
79
- `setTilesOpacity(0.5)` makes the tiles see-through (1 = opaque), which lets
80
- you see vector layers that run underground. `disableTiles()` unloads
81
- everything.
82
-
83
- On hosts whose engine supports the deferred postproduction pipeline, the
84
- tiles and the vector layers are drawn through an occlusion pass, which is what
85
- makes the see-through effect possible. On other hosts they are added to the
86
- scene directly and stay opaque. You do not need to do anything for this: the
87
- component detects it.
88
-
89
- On those deferred hosts the tiles also dissolve gradually near the camera's far
90
- plane instead of ending in a hard edge. `horizonFade` is the fraction of the far
91
- distance over which this happens: with the default `0.8` and a far plane at
92
- 1000, the tiles are fully visible up to 200 and fully transparent at 1000. It
93
- combines with the see-through opacity, and `0` turns it off. While the map is
94
- loaded the fade is a fraction of `mapFar` (see below), not of the camera's own
95
- far plane.
96
-
97
- While the tiles are loaded, the empty background behind them is also painted
98
- as a sky: a gradient from `skyHorizonColor` (default `#d7e3ee`, a light hazy
99
- blue) at the horizon to `skyZenithColor` (default `#6a9bd1`) straight up, so
100
- the tiles dissolve into the horizon colour. Set `sky = false` to keep the
101
- background as it is. Like the fade, it only exists on deferred hosts.
102
-
103
- To let the map reach the horizon, `GISManager` takes over the far plane of the
104
- world's cameras while the tiles are loaded: `mapFar`, `10000` by default. With
105
- the default `horizonFade` of `0.8` the map is fully visible up to 2 km and
106
- fades out until 10 km. A far plane the application or the user set is only
107
- remembered while the map is loaded and comes back when `disableTiles()` runs
108
- (a larger far set by code that grows it, for example when it loads a large
109
- point cloud, is respected, and kept). Setting `mapFar` while the map is loaded
110
- applies immediately. This works on every host, deferred or not.
111
- */
112
-
113
- gis.horizonFade = 0.4;
114
- gis.mapFar = 15000;
115
- gis.skyHorizonColor = "#e8d9c5";
116
- gis.skyZenithColor = new THREE.Color(0x4f86c6);
117
- gis.sky = true;
118
-
119
- gis.onStateChanged.add((state) => console.log("tiles visible:", state.tilesVisible));
120
- gis.setTilesOpacity(0.6);
121
-
122
- /* MD
123
- A small East/North/Up correction (in metres) can be applied to the tiles to
124
- compensate for the tileset's own positioning error. Persist it with
125
- `saveTilesOffset()`; it is stored in the same file as the layer manifest and
126
- restored by `init`.
127
- */
128
-
129
- gis.onOffsetSaveComplete.add((success) => console.log("offset saved:", success));
130
- gis.setTilesOffset(0.5, -0.3, 0);
131
- gis.saveTilesOffset();
132
-
133
- /* MD
134
- ### πŸ—‚οΈ The layer manifest
135
- The vector layers of a project are declared in one JSON file,
136
- `{GISManager.uuid}.json`, stored loose in the project's `__project_data`
137
- folder. `init(client)` reads it into `gis.vectorLayersConfig`; it only holds
138
- metadata (the geometry stays in the layer's own file, referenced by `fileId`
139
- and downloaded when the layer is loaded).
140
-
141
- There is no user interface to register layers yet: the manifest is written by
142
- your application (or by hand). The component only reads it, and rewrites it
143
- (keeping `layers` as they are) when the tiles offset is saved.
144
-
145
- Each entry of `layers` has:
146
-
147
- - `id` β€” unique id, used by every API below.
148
- - `name` β€” display name (shown by the panels).
149
- - `fileId` β€” id of the layer's file in the project.
150
- - `type` β€” `"shapefile"` (a zip with the `.shp`, `.dbf`, `.prj`… files) or
151
- `"geojson"`. If it is missing or unrecognised the downloaded bytes decide:
152
- a zip signature means shapefile, a leading `{` means GeoJSON.
153
- - `style` β€” `stroke` (CSS colour), `stroke-width` (pixels), `fill` (CSS
154
- colour, polygons) and `fill-opacity` (0 to 1). All optional.
155
- - `height` β€” optional, how features get their height (next section).
156
-
157
- Here is a complete manifest with a points layer whose vertices carry their
158
- own height, and a lines layer whose heights come from its attributes:
159
-
160
- ```json
161
- {
162
- "layers": [
163
- {
164
- "id": "manholes",
165
- "name": "Manholes",
166
- "fileId": "<file id of manholes.zip>",
167
- "type": "shapefile",
168
- "style": { "stroke": "#ffb300", "stroke-width": 6 },
169
- "height": { "source": "geometry" }
170
- },
171
- {
172
- "id": "pipes",
173
- "name": "Pipes",
174
- "fileId": "<file id of pipes.geojson>",
175
- "type": "geojson",
176
- "style": { "stroke": "#1e88e5", "stroke-width": 3 },
177
- "height": {
178
- "source": "attributes",
179
- "startProperty": "z_start",
180
- "endProperty": "z_end",
181
- "startDepthProperty": "depth_start",
182
- "endDepthProperty": "depth_end",
183
- "nodeLayers": ["manholes"],
184
- "nodeSnapDistance": 0.5
185
- }
186
- }
187
- ],
188
- "tilesOffset": { "east": 0.5, "north": -0.3, "up": 0 }
189
- }
190
- ```
191
-
192
- Once `init` has read it, every layer can be loaded and unloaded by id.
193
- `loadVectorLayer` downloads and parses the file; it never throws, failures
194
- are reported through `onVectorLayerError`.
195
- */
196
-
197
- gis.onLayersLoaded.add((layers) => console.log("manifest read:", layers.length, "layers"));
198
- gis.onVectorLayerError.add(({ id, message }) => console.warn(`Layer ${id}:`, message));
199
-
200
- await gis.loadVectorLayer("manholes");
201
- await gis.loadVectorLayer("pipes");
202
-
203
- console.log("loaded:", gis.vectorLayers.isLayerLoaded("pipes"));
204
-
205
- gis.unloadVectorLayer("manholes");
206
-
207
- /* MD
208
- ### πŸ“ Layer heights
209
- The `height` option of a layer decides at what height its features are drawn:
210
-
211
- - **No `height`** β€” the layer is drawn flat, at the origin's height.
212
- - **`{ "source": "geometry" }`** β€” every vertex is placed at its own Z (the
213
- third GeoJSON coordinate). If any vertex of the layer has no Z, the whole
214
- layer is drawn flat instead (with a console warning).
215
- - **`{ "source": "attributes", … }`** β€” for line features only (other
216
- geometry types are drawn flat). A line gets a height at its first vertex
217
- and at its last one, and the vertices in between are interpolated along
218
- the line. Each end is resolved in this order:
219
- 1. its own height property (`startProperty` / `endProperty`);
220
- 2. otherwise the surface height of the nearest node minus its depth
221
- property (`startDepthProperty` / `endDepthProperty`). Nodes are the
222
- points with a Z found in the layers listed in `nodeLayers`, and
223
- "nearest" means within `nodeSnapDistance` metres (0.5 by default) of
224
- the line end;
225
- 3. otherwise the height resolved for the other end (the line is drawn
226
- level);
227
- 4. otherwise the surface height of the nearest node.
228
-
229
- A property counts as missing when it is not a finite number or is exactly
230
- `0`. Rules 1 and 2 are tried on both ends before rule 3 is applied, so a
231
- copied height never comes from another copy. A line for which no rule can
232
- give a height to both ends is not drawn (one console warning per layer
233
- summarizes how many).
234
-
235
- All heights are orthometric (the usual survey heights above the geoid). The
236
- component adds the project's geoid undulation, taken from the `ProjectManager`
237
- CRS, to place them in the scene, and re-places the loaded layers if it changes.
238
- */
239
-
240
- /* MD
241
- ### 🧭 GeoJSON coordinate systems
242
- Shapefiles are read with their `.prj`. For GeoJSON layers, the coordinate
243
- system comes from the legacy `crs` member of the file:
244
-
245
- - Longitude/latitude (`CRS84`, or `EPSG:4326`) is read as it is.
246
- - `EPSG:3857` and the UTM zones (`EPSG:326xx`, `327xx`, `258xx` and `269xx`)
247
- are reprojected to longitude/latitude when the layer loads.
248
- - Any other declared CRS is rejected, and so are projected coordinates in a
249
- file that declares no `crs`.
250
-
251
- A rejected layer is not loaded, and the reason (for example `Unsupported CRS
252
- "EPSG:2154"…`) is delivered through `onVectorLayerError`, which is what the
253
- GIS panel shows as a toast.
254
- */
255
-
256
- /* MD
257
- ### πŸ–±οΈ Selection and focus
258
- Clicking a feature in the 3D view selects it. `onFeatureSelected` delivers
259
- the selection (`layerId`, `layerName`, `featureIndex`, `geometryType` and the
260
- feature's `properties`), or `null` when the selection is cleared. The current
261
- selection can also be read at any time from `gis.vectorLayers.selection`.
262
-
263
- Your application can select a feature too, optionally flying the camera to
264
- it. `onFocusRequested` fires with the bounding sphere the camera is sent to,
265
- which is how the 2D map follows.
266
- */
267
-
268
- gis.onFeatureSelected.add((selection) => {
269
- if (!selection) return console.log("selection cleared");
270
- console.log(selection.layerName, selection.geometryType, selection.properties);
271
- });
272
-
273
- gis.onFocusRequested.add(({ layerId, featureIndex, sphere }) => {
274
- console.log("focusing", layerId, featureIndex, "radius:", sphere.radius);
275
- });
276
-
277
- gis.selectVectorFeature("pipes", 0, { focus: true });
278
- gis.vectorLayers.clearSelection();
279
-
280
- /* MD
281
- ### πŸ—ΊοΈ The 2D minimap
282
- `gis.minimap` renders a top-down, north-up image of the 3D tiles that
283
- `top-map-panel` draws together with the vector layers, the camera and the
284
- markers.
285
-
286
- `captureMap()` takes the picture. The 3D tiles must be loaded (without them
287
- the image is empty). The captured area is the bounding box of all the
288
- manifest's layers, whether they are displayed or not; with no usable layers it
289
- is a square of `2 * halfExtent` metres (250 by default) centred on the origin.
290
- The image has a fixed side of `resolution` pixels (2048 by default, limited by
291
- the GPU), so the larger the area, the coarser the map.
292
- */
293
-
294
- gis.minimap.onCaptured.add((capture) => console.log("map captured:", capture.size, "px"));
295
-
296
- gis.minimap.halfExtent = 400;
297
- gis.minimap.resolution = 4096;
298
- const capture = await gis.minimap.captureMap();
299
- document.body.appendChild(capture.image);
300
-
301
- /* MD
302
- `worldToMap` converts a scene position into normalized image coordinates
303
- (0 to 1, origin at the top-left), and `mapToWorld` does the opposite for a
304
- horizontal plane at a given height. Both return `null` until a map has been
305
- captured.
306
- */
307
-
308
- const point = gis.vectorLayers.geoToWorld(gis.latitude, gis.longitude, gis.height);
309
- const onMap = gis.minimap.worldToMap(point);
310
- console.log("origin on the map:", onMap);
311
- console.log("back to the scene:", onMap && gis.minimap.mapToWorld(onMap.x, onMap.y, point.y));
312
-
313
- /* MD
314
- ### πŸ“ Minimap markers
315
- Markers are HTML elements drawn over the map by `top-map-panel`. They live in
316
- the minimap, not in the panel, so they survive the panel being recreated.
317
-
318
- A marker has an `id`, a scene `position` (read on every redraw, so changing
319
- it moves the marker), an optional `label` and an optional `createElement`
320
- factory. Without the factory the panel draws a default badge with the label
321
- and reports its clicks through `onMarkerClicked`. With it, the marker is your
322
- own element and it owns its click behaviour. It is a factory and not an
323
- element because each panel needs its own DOM node.
324
-
325
- `geoToWorld(lat, lon, height)` turns a geographic position into a scene
326
- position.
327
- */
328
-
329
- gis.minimap.onMarkersChanged.add(({ kind, id }) => console.log("markers:", kind, id));
330
- gis.minimap.onMarkerClicked.add((id) => console.log("clicked:", id));
331
-
332
- gis.minimap.addMarker({
333
- id: "site-office",
334
- label: "Site office",
335
- position: gis.vectorLayers.geoToWorld(gis.latitude, gis.longitude, gis.height),
336
- });
337
-
338
- gis.minimap.addMarker({
339
- id: "crane",
340
- position: new THREE.Vector3(-20, 0, 35),
341
- createElement: () => {
342
- const pin = document.createElement("div");
343
- pin.textContent = "πŸ—οΈ";
344
- pin.style.fontSize = "1.4rem";
345
- pin.style.cursor = "pointer";
346
- pin.onclick = () => console.log("crane clicked");
347
- return pin;
348
- },
349
- });
350
-
351
- gis.minimap.updateMarker("site-office", { label: "Main office" });
352
- console.log("markers:", [...gis.minimap.markers.keys()]);
353
-
354
- gis.minimap.removeMarker("crane");
355
- gis.minimap.clearMarkers();
1
+ /* MD
2
+ ## GISManager
3
+ ---
4
+ Georeferenced BIM projects need their surroundings: the real terrain and
5
+ buildings around the model, and the project's GIS layers (parcels, networks,
6
+ boundaries) drawn at the right place in the 3D scene and on a 2D map.
7
+
8
+ GISManager is the component that owns all of that. It streams Cesium Ion 3D
9
+ Tiles (Google Photorealistic 3D Tiles by default) around the project origin,
10
+ loads vector layers (shapefile zip or GeoJSON) declared in the project's
11
+ layer manifest, and renders a 2D minimap with markers.
12
+
13
+ This tutorial covers initializing the manager from the platform client;
14
+ enabling the 3D tiles; the layer manifest and how heights, styles and
15
+ coordinate systems are read; selecting and focusing features; and the 2D
16
+ minimap with its markers. The recommended UI is provided by `top-gis-panel`,
17
+ `top-map-panel` and `top-gis-properties-panel`.
18
+
19
+ GISManager reads the project origin from `ProjectManager`, so initialize
20
+ `ProjectManager` first.
21
+
22
+ ### πŸ–– Importing our libraries
23
+ */
24
+
25
+ import * as OBC from "@thatopen/components";
26
+ import * as OBF from "@thatopen/components-front";
27
+ import * as BUI from "@thatopen/ui";
28
+ import * as THREE from "three";
29
+ import * as FRAGS from "@thatopen/fragments";
30
+ import { PlatformClient, GISManager, ProjectManager } from "@thatopen/services";
31
+
32
+
33
+ /* MD
34
+ ### πŸš€ Initializing GISManager
35
+ Both components are set up through the platform client.
36
+ `client.setup(...)` resolves the shared `OBC.Components` instance.
37
+ */
38
+
39
+ const client = PlatformClient.fromPlatformContext();
40
+
41
+ const { components } = (await client.setup(
42
+ { OBC, OBF, BUI, THREE, FRAGS },
43
+ { uuid: ProjectManager.uuid },
44
+ { uuid: GISManager.uuid },
45
+ )) as { components: OBC.Components };
46
+
47
+ await components.get(ProjectManager).init(client);
48
+
49
+ const gis = components.get(GISManager);
50
+
51
+ /* MD
52
+ `init(client)` restores the project origin from `ProjectManager` and reads
53
+ the project's layer manifest (see below). It never throws: with no project or
54
+ no stored file the manager just keeps its defaults, and an empty layer list.
55
+ */
56
+
57
+ await gis.init(client);
58
+ console.log("layers:", gis.vectorLayersConfig);
59
+
60
+ /* MD
61
+ ### 🌍 3D tiles
62
+ Streaming the tiles needs a Cesium Ion token. The component does not persist
63
+ the token anywhere: your application provides it (from its own settings, or
64
+ typed by the user in `top-gis-panel`) before enabling the tiles.
65
+
66
+ `enableTiles()` resolves once the first tiles are loaded and rejects with a
67
+ readable message if the token is invalid or has no access to the tileset (the
68
+ same message is also fired through `onLoadError`).
69
+ */
70
+
71
+ gis.onLoadError.add((message) => console.warn("GIS tiles:", message));
72
+
73
+ gis.apiToken = "<your Cesium Ion token>";
74
+ await gis.enableTiles();
75
+
76
+ /* MD
77
+ `onStateChanged` fires whenever the token, origin, tiles visibility, tiles
78
+ offset or tiles opacity change, with a plain snapshot of all of them.
79
+ `setTilesOpacity(0.5)` makes the tiles see-through (1 = opaque), which lets
80
+ you see vector layers that run underground. `disableTiles()` unloads
81
+ everything.
82
+
83
+ On hosts whose engine supports the deferred postproduction pipeline, the
84
+ tiles and the vector layers are drawn through an occlusion pass, which is what
85
+ makes the see-through effect possible. On other hosts they are added to the
86
+ scene directly and stay opaque. You do not need to do anything for this: the
87
+ component detects it.
88
+
89
+ On those deferred hosts the tiles also dissolve gradually near the camera's far
90
+ plane instead of ending in a hard edge. `horizonFade` is the fraction of the far
91
+ distance over which this happens: with the default `0.8` and a far plane at
92
+ 1000, the tiles are fully visible up to 200 and fully transparent at 1000. It
93
+ combines with the see-through opacity, and `0` turns it off. While the map is
94
+ loaded the fade is a fraction of `mapFar` (see below), not of the camera's own
95
+ far plane.
96
+
97
+ While the tiles are loaded, the empty background behind them is also painted
98
+ as a sky: a gradient from `skyHorizonColor` (default `#d7e3ee`, a light hazy
99
+ blue) at the horizon to `skyZenithColor` (default `#6a9bd1`) straight up, so
100
+ the tiles dissolve into the horizon colour. Set `sky = false` to keep the
101
+ background as it is. Like the fade, it only exists on deferred hosts.
102
+
103
+ To let the map reach the horizon, `GISManager` takes over the far plane of the
104
+ world's cameras while the tiles are loaded: `mapFar`, `10000` by default. With
105
+ the default `horizonFade` of `0.8` the map is fully visible up to 2 km and
106
+ fades out until 10 km. A far plane the application or the user set is only
107
+ remembered while the map is loaded and comes back when `disableTiles()` runs
108
+ (a larger far set by code that grows it, for example when it loads a large
109
+ point cloud, is respected, and kept). Setting `mapFar` while the map is loaded
110
+ applies immediately. This works on every host, deferred or not.
111
+ */
112
+
113
+ gis.horizonFade = 0.4;
114
+ gis.mapFar = 15000;
115
+ gis.skyHorizonColor = "#e8d9c5";
116
+ gis.skyZenithColor = new THREE.Color(0x4f86c6);
117
+ gis.sky = true;
118
+
119
+ gis.onStateChanged.add((state) => console.log("tiles visible:", state.tilesVisible));
120
+ gis.setTilesOpacity(0.6);
121
+
122
+ /* MD
123
+ A small East/North/Up correction (in metres) can be applied to the tiles to
124
+ compensate for the tileset's own positioning error. Persist it with
125
+ `saveTilesOffset()`; it is stored in the same file as the layer manifest and
126
+ restored by `init`.
127
+ */
128
+
129
+ gis.onOffsetSaveComplete.add((success) => console.log("offset saved:", success));
130
+ gis.setTilesOffset(0.5, -0.3, 0);
131
+ gis.saveTilesOffset();
132
+
133
+ /* MD
134
+ ### πŸ—‚οΈ The layer manifest
135
+ The vector layers of a project are declared in one JSON file,
136
+ `{GISManager.uuid}.json`, stored loose in the project's `__project_data`
137
+ folder. `init(client)` reads it into `gis.vectorLayersConfig`; it only holds
138
+ metadata (the geometry stays in the layer's own file, referenced by `fileId`
139
+ and downloaded when the layer is loaded).
140
+
141
+ There is no user interface to register layers yet: the manifest is written by
142
+ your application (or by hand). The component only reads it, and rewrites it
143
+ (keeping `layers` as they are) when the tiles offset is saved.
144
+
145
+ Each entry of `layers` has:
146
+
147
+ - `id` β€” unique id, used by every API below.
148
+ - `name` β€” display name (shown by the panels).
149
+ - `fileId` β€” id of the layer's file in the project.
150
+ - `type` β€” `"shapefile"` (a zip with the `.shp`, `.dbf`, `.prj`… files) or
151
+ `"geojson"`. If it is missing or unrecognised the downloaded bytes decide:
152
+ a zip signature means shapefile, a leading `{` means GeoJSON.
153
+ - `style` β€” `stroke` (CSS colour), `stroke-width` (pixels), `fill` (CSS
154
+ colour, polygons) and `fill-opacity` (0 to 1). All optional.
155
+ - `height` β€” optional, how features get their height (next section).
156
+
157
+ Here is a complete manifest with a points layer whose vertices carry their
158
+ own height, and a lines layer whose heights come from its attributes:
159
+
160
+ ```json
161
+ {
162
+ "layers": [
163
+ {
164
+ "id": "manholes",
165
+ "name": "Manholes",
166
+ "fileId": "<file id of manholes.zip>",
167
+ "type": "shapefile",
168
+ "style": { "stroke": "#ffb300", "stroke-width": 6 },
169
+ "height": { "source": "geometry" }
170
+ },
171
+ {
172
+ "id": "pipes",
173
+ "name": "Pipes",
174
+ "fileId": "<file id of pipes.geojson>",
175
+ "type": "geojson",
176
+ "style": { "stroke": "#1e88e5", "stroke-width": 3 },
177
+ "height": {
178
+ "source": "attributes",
179
+ "startProperty": "z_start",
180
+ "endProperty": "z_end",
181
+ "startDepthProperty": "depth_start",
182
+ "endDepthProperty": "depth_end",
183
+ "nodeLayers": ["manholes"],
184
+ "nodeSnapDistance": 0.5
185
+ }
186
+ }
187
+ ],
188
+ "tilesOffset": { "east": 0.5, "north": -0.3, "up": 0 }
189
+ }
190
+ ```
191
+
192
+ Once `init` has read it, every layer can be loaded and unloaded by id.
193
+ `loadVectorLayer` downloads and parses the file; it never throws, failures
194
+ are reported through `onVectorLayerError`.
195
+ */
196
+
197
+ gis.onLayersLoaded.add((layers) => console.log("manifest read:", layers.length, "layers"));
198
+ gis.onVectorLayerError.add(({ id, message }) => console.warn(`Layer ${id}:`, message));
199
+
200
+ await gis.loadVectorLayer("manholes");
201
+ await gis.loadVectorLayer("pipes");
202
+
203
+ console.log("loaded:", gis.vectorLayers.isLayerLoaded("pipes"));
204
+
205
+ gis.unloadVectorLayer("manholes");
206
+
207
+ /* MD
208
+ ### πŸ“ Layer heights
209
+ The `height` option of a layer decides at what height its features are drawn:
210
+
211
+ - **No `height`** β€” the layer is drawn flat, at the origin's height.
212
+ - **`{ "source": "geometry" }`** β€” every vertex is placed at its own Z (the
213
+ third GeoJSON coordinate). If any vertex of the layer has no Z, the whole
214
+ layer is drawn flat instead (with a console warning).
215
+ - **`{ "source": "attributes", … }`** β€” for line features only (other
216
+ geometry types are drawn flat). A line gets a height at its first vertex
217
+ and at its last one, and the vertices in between are interpolated along
218
+ the line. Each end is resolved in this order:
219
+ 1. its own height property (`startProperty` / `endProperty`);
220
+ 2. otherwise the surface height of the nearest node minus its depth
221
+ property (`startDepthProperty` / `endDepthProperty`). Nodes are the
222
+ points with a Z found in the layers listed in `nodeLayers`, and
223
+ "nearest" means within `nodeSnapDistance` metres (0.5 by default) of
224
+ the line end;
225
+ 3. otherwise the height resolved for the other end (the line is drawn
226
+ level);
227
+ 4. otherwise the surface height of the nearest node.
228
+
229
+ A property counts as missing when it is not a finite number or is exactly
230
+ `0`. Rules 1 and 2 are tried on both ends before rule 3 is applied, so a
231
+ copied height never comes from another copy. A line for which no rule can
232
+ give a height to both ends is not drawn (one console warning per layer
233
+ summarizes how many).
234
+
235
+ All heights are orthometric (the usual survey heights above the geoid). The
236
+ component adds the project's geoid undulation, taken from the `ProjectManager`
237
+ CRS, to place them in the scene, and re-places the loaded layers if it changes.
238
+ */
239
+
240
+ /* MD
241
+ ### 🧭 GeoJSON coordinate systems
242
+ Shapefiles are read with their `.prj`. For GeoJSON layers, the coordinate
243
+ system comes from the legacy `crs` member of the file:
244
+
245
+ - Longitude/latitude (`CRS84`, or `EPSG:4326`) is read as it is.
246
+ - `EPSG:3857` and the UTM zones (`EPSG:326xx`, `327xx`, `258xx` and `269xx`)
247
+ are reprojected to longitude/latitude when the layer loads.
248
+ - Any other declared CRS is rejected, and so are projected coordinates in a
249
+ file that declares no `crs`.
250
+
251
+ A rejected layer is not loaded, and the reason (for example `Unsupported CRS
252
+ "EPSG:2154"…`) is delivered through `onVectorLayerError`, which is what the
253
+ GIS panel shows as a toast.
254
+ */
255
+
256
+ /* MD
257
+ ### πŸ–±οΈ Selection and focus
258
+ Clicking a feature in the 3D view selects it. `onFeatureSelected` delivers
259
+ the selection (`layerId`, `layerName`, `featureIndex`, `geometryType` and the
260
+ feature's `properties`), or `null` when the selection is cleared. The current
261
+ selection can also be read at any time from `gis.vectorLayers.selection`.
262
+
263
+ Your application can select a feature too, optionally flying the camera to
264
+ it. `onFocusRequested` fires with the bounding sphere the camera is sent to,
265
+ which is how the 2D map follows.
266
+ */
267
+
268
+ gis.onFeatureSelected.add((selection) => {
269
+ if (!selection) return console.log("selection cleared");
270
+ console.log(selection.layerName, selection.geometryType, selection.properties);
271
+ });
272
+
273
+ gis.onFocusRequested.add(({ layerId, featureIndex, sphere }) => {
274
+ console.log("focusing", layerId, featureIndex, "radius:", sphere.radius);
275
+ });
276
+
277
+ gis.selectVectorFeature("pipes", 0, { focus: true });
278
+ gis.vectorLayers.clearSelection();
279
+
280
+ /* MD
281
+ ### πŸ—ΊοΈ The 2D minimap
282
+ `gis.minimap` renders a top-down, north-up image of the 3D tiles that
283
+ `top-map-panel` draws together with the vector layers, the camera and the
284
+ markers.
285
+
286
+ `captureMap()` takes the picture. The 3D tiles must be loaded (without them
287
+ the image is empty). The captured area is the bounding box of all the
288
+ manifest's layers, whether they are displayed or not; with no usable layers it
289
+ is a square of `2 * halfExtent` metres (250 by default) centred on the origin.
290
+ The image has a fixed side of `resolution` pixels (2048 by default, limited by
291
+ the GPU), so the larger the area, the coarser the map.
292
+ */
293
+
294
+ gis.minimap.onCaptured.add((capture) => console.log("map captured:", capture.size, "px"));
295
+
296
+ gis.minimap.halfExtent = 400;
297
+ gis.minimap.resolution = 4096;
298
+ const capture = await gis.minimap.captureMap();
299
+ document.body.appendChild(capture.image);
300
+
301
+ /* MD
302
+ `worldToMap` converts a scene position into normalized image coordinates
303
+ (0 to 1, origin at the top-left), and `mapToWorld` does the opposite for a
304
+ horizontal plane at a given height. Both return `null` until a map has been
305
+ captured.
306
+ */
307
+
308
+ const point = gis.vectorLayers.geoToWorld(gis.latitude, gis.longitude, gis.height);
309
+ const onMap = gis.minimap.worldToMap(point);
310
+ console.log("origin on the map:", onMap);
311
+ console.log("back to the scene:", onMap && gis.minimap.mapToWorld(onMap.x, onMap.y, point.y));
312
+
313
+ /* MD
314
+ ### πŸ“ Minimap markers
315
+ Markers are HTML elements drawn over the map by `top-map-panel`. They live in
316
+ the minimap, not in the panel, so they survive the panel being recreated.
317
+
318
+ A marker has an `id`, a scene `position` (read on every redraw, so changing
319
+ it moves the marker), an optional `label` and an optional `createElement`
320
+ factory. Without the factory the panel draws a default badge with the label
321
+ and reports its clicks through `onMarkerClicked`. With it, the marker is your
322
+ own element and it owns its click behaviour. It is a factory and not an
323
+ element because each panel needs its own DOM node.
324
+
325
+ `geoToWorld(lat, lon, height)` turns a geographic position into a scene
326
+ position.
327
+ */
328
+
329
+ gis.minimap.onMarkersChanged.add(({ kind, id }) => console.log("markers:", kind, id));
330
+ gis.minimap.onMarkerClicked.add((id) => console.log("clicked:", id));
331
+
332
+ gis.minimap.addMarker({
333
+ id: "site-office",
334
+ label: "Site office",
335
+ position: gis.vectorLayers.geoToWorld(gis.latitude, gis.longitude, gis.height),
336
+ });
337
+
338
+ gis.minimap.addMarker({
339
+ id: "crane",
340
+ position: new THREE.Vector3(-20, 0, 35),
341
+ createElement: () => {
342
+ const pin = document.createElement("div");
343
+ pin.textContent = "πŸ—οΈ";
344
+ pin.style.fontSize = "1.4rem";
345
+ pin.style.cursor = "pointer";
346
+ pin.onclick = () => console.log("crane clicked");
347
+ return pin;
348
+ },
349
+ });
350
+
351
+ gis.minimap.updateMarker("site-office", { label: "Main office" });
352
+ console.log("markers:", [...gis.minimap.markers.keys()]);
353
+
354
+ gis.minimap.removeMarker("crane");
355
+ gis.minimap.clearMarkers();