Geo mode
Switch the viewer between LOCAL and GEO placement, know why the switch can fail, and add basemaps, terrain and 3D Tiles as GIS layers.
The viewer places models in one of two modes. In LOCAL mode every model sits where its own coordinates put it, which is right for the discipline models of one project. In GEO mode every model is placed by its Geo reference, so models from different sites land at their true relative positions and GIS layers (basemaps, terrain, 3D Tiles) can be drawn under and around them.
Before you start#
Every model you load in GEO mode needs a geo reference (Set the geo reference). Loading a model without one switches the viewer back to LOCAL.
Steps#
-
Switch the mode.
setModereturnstruewhen the mode changed andfalsewhen it did not: when the viewer already was in that mode, when a loaded model has no geo reference, or when the viewer is offline (GEO mode needs the map services).JavaScript#if (!viewer.setMode("GEO")) { console.warn("Still in", viewer.getMode()); // "LOCAL" | "GEO" } viewer.addModeChangeListener((mode) => console.log("now in", mode)); -
Add GIS layers. A layer is registered once with an id and shown or hidden with
toggleGisLayer; it is loaded when the first geo-referenced model is in the viewer.JavaScript#viewer.addGisLayer("osm", { name: "OpenStreetMap", type: "TMS", url: "https://tile.openstreetmap.org/", // the viewer appends zoom/x/y.png maxZoomLevel: 18, visible: true }); viewer.addGisLayer("terrain", { name: "Terrain", type: "TERRAIN", url: "https://example.org/terrain/", // a quantized-mesh service with layer.json heightDatum: "orthometric" }); viewer.toggleGisLayer("terrain", true);OpenStreetMap's tile servers are for light use: their tile usage policy forbids bulk downloading and requires the attribution "© OpenStreetMap contributors" on the map. The viewer draws no attribution, so the page around it shows it; an application with many users takes its tiles from its own or a commercial tile service.
typeis one ofTMS,WMS,WMTS(imagery),TERRAIN(a quantized-mesh height service) and3DTILES(urlis the set'stileset.json). The imagery types work on the Web Mercator tile grid (EPSG:3857) and needmaxZoomLevel, the zoom level of their tiles; the viewer lowers it when the area around the models does not fit in one texture.TMSrequestsurlfollowed byzoom/x/y.png, with row 0 at the north edge (the OpenStreetMap scheme), sourlends with a/. For a service whose tile URLs have another shape, give aurlBuilder(settings, zoom, x, y)that returns the URL of one tile; it replaces the default URL of every imagery type.WMSasks the service for one 256 × 256 pixel GetMap image per tile, in EPSG:3857, which the service must offer.urlis the service address andparams.layers(required) the comma-separated layer names.params.styles(default: the default style),params.version("1.1.1", the default, or"1.3.0"),params.format(default"image/png") andparams.transparent(defaulttrue, so that where the service draws nothing the layer underneath shows) are optional, and any other key inparamsis passed on as a GetMap parameter.WMTSneeds aurlBuilder; without one the layer fails to load. The service's tile matrix set must be Web Mercator (GoogleMapsCompatibleorEPSG:3857): the builder gets the zoom, the column and the row of a tile and turns the zoom into the TileMatrix identifier that the service's capabilities list.
JavaScript#viewer.addGisLayer("parcels", { // the Dutch cadastral map, registered hidden name: "Kadastrale kaart", type: "WMS", url: "https://service.pdok.nl/kadaster/kadastralekaart/wms/v5_0", params: {layers: "Kadastralekaart"}, maxZoomLevel: 18 }); viewer.addGisLayer("brt", { name: "BRT achtergrondkaart", type: "WMTS", url: "https://service.pdok.nl/kadaster/brt-achtergrondkaart/wmts/v2_0", maxZoomLevel: 18, urlBuilder: (settings, zoom, x, y) => settings.url + "?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=standaard&STYLE=default&FORMAT=image/png" + "&TILEMATRIXSET=EPSG:3857&TILEMATRIX=" + String(zoom).padStart(2, "0") // PDOK names them 00 to 19 + "&TILECOL=" + x + "&TILEROW=" + y });Imagery drapes over a
TERRAINlayer named in itsterrainproperty, or over whichever terrain is visible; a terrain that imagery drapes over is not drawn on its own.heightDatumsays what the service's heights are measured from:"orthometric"(national datum, the default) or"ellipsoid"(the Cesium convention, for which the viewer subtracts the geoid height where it has a table);heightOffsetMetersadds a constant.snapToZeroputs a flat layer at the model's lowest point instead of the geo reference's elevation, andtranslationMmshifts a layer, for instance to draw a basemap slightly below theIfcSite. -
After changing a geo reference, tell the viewer:
viewer.updateModel(versionUuid)re-reads the version and moves the model without reloading it.
In LOCAL mode two models can be too far apart to view together (one near the origin, one 500 km away). Compare im_metadata.transformedBoundsMm of the versions before loading them; in GEO mode compare their geo references with Get the geo reference.
Check#
viewer.getMode() returns "GEO", the basemap tiles appear under the model, and setMode("LOCAL") moves the model back to its own origin.