map

The map namespace turns the canvas into a geographic view: nodes are placed on lat/lng coordinates, tiles from a slippy map provider render underneath, and the camera respects either a flat (planar) or spherical (globe) projection.

The namespace also owns the bidirectional projection helpers between screen, world, and lat/lng coordinate spaces, plus a pluggable geocoder for searching locations by name.

Enable / disable

api.map.enableMap("planar");        // flat slippy-map projection
api.map.enableMap("spherical");     // globe (3D Earth)
api.map.disableMap();               // back to abstract space

getMode() returns the current "planar" | "spherical" | null. isEnabled() is the convenience boolean.

When the map is enabled, the camera switches projection mode and the engine installs a MapCoordinateProvider that positions nodes by their lat/lng property pair (default "lat" / "lng").

Positioning nodes geographically

await api.map.positionNodesByGeo({
  latProperty: "lat",
  lngProperty: "lng",
});

await api.map.applyGeoLayout();     // commit to layout history
await api.map.releaseGeoLayout();   // free the lock so other layouts can run

Nodes without lat/lng coordinates fall back to their pre-map positions. getNodeGeoPosition(id) reads the current geo-coords for an individual node.

Tile providers

The engine ships with a few free providers ("osm", "carto-light", "carto-dark", …) and accepts custom ones:

api.map.setProvider("carto-dark");
api.map.registerProvider("my-corp", {
  urlFn: ({ x, y, z }) => `https://tiles.example.com/${z}/${x}/${y}.png`,
});
api.map.setProvider("my-corp");

listProviders() returns every registered id; getProvider(id) reads the descriptor; unregisterProvider(id) removes a custom entry. resolveTileUrl(...) is exposed for tooling that needs to compute tile URLs outside the render loop.

Geocoders

Search lat/lng by name or address:

api.map.setGeocoder("nominatim");                 // default
const hits = await api.map.search("Paris, France");
if (hits[0]) {
  await api.map.flyToBounds(hits[0].bounds);
}

registerGeocoder(...) plugs in custom providers (e.g. corporate geocoder, paid HERE/Google adapter). listGeocoders() / getActiveGeocoder() introspect available choices.

Camera helpers (map-aware)

The standard api.camera.* operations work in map mode, but a few helpers are specific to geographic viewing:

Method Purpose
flyTo(latLng, opts?) Animate to a specific lat/lng point
flyToBounds(geoBounds, opts?) Animate to fit a { north, south, east, west } rectangle
fitToNodes(ids?) Same as camera.flyToNodes but in geo-coords
getCenter() / getZoomLevel() / setZoomLevel Slippy-map-style center + integer zoom level

Pitch (planar only)

Planar maps support a tilted camera; spherical (globe) ignores pitch.

api.map.setPitch(45);                  // degrees from top-down
const cur = api.map.getPitch();        // 45
const { min, max } = api.map.pitchBounds();

Coordinate projections

Four sibling helpers let host UI position overlays accurately:

api.map.latLngToWorld({ lat, lng })  // → { x, y, z }   for placing 3D content
api.map.latLngToScreen({ lat, lng }) // → { x, y }      for HTML overlays
api.map.worldToLatLng({ x, y, z })   // → { lat, lng }  inverse
api.map.screenToLatLng({ x, y })     // → { lat, lng }  e.g. on click

All return null when the map isn't enabled.

Transitions

transition(toMode, opts?) animates between map modes (planar ↔ spherical, or on ↔ off) instead of snapping. cancelTransition() aborts an in-flight transition; isTransitioning() reports state.

Methods