Vector Layer
A vector layer renders the features of a geojson or vector-tile source with per-geometry materials (points, lines, polygons, and so on).
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
type | "vector" | Layer type (required). |
source | Source | string | The geojson / vector-tile source to render (required). |
sourceLayers | string[] | For vector-tile sources: which source layers within the tileset to render. Ignored for GeoJSON. |
Render options (materials)
Section titled “Render options (materials)”Specify one or more, depending on the geometry types present:
| Material | Config key | Default geometry |
|---|---|---|
| PointMaterial | point | Point, MultiPoint |
| BillboardMaterial | billboard | Point (icon display) |
| TextMaterial | text | Point (label display) |
| PolylineMaterial | polyline | LineString, MultiLineString |
| PolygonMaterial | polygon | Polygon, MultiPolygon |
By default each material renders only the geometry listed above. The geometryTypes option widens this per material, so one source geometry can render as several representations at once. See Deriving representations with geometryTypes.
Examples
Section titled “Examples”GeoJSON features
Section titled “GeoJSON features”import ThreeView, { Color } from "@navaramap/three";
const view = new ThreeView(/* options */);await view.init();
const points = view.addSource({ type: "geojson", data: { type: "FeatureCollection", features: [ { type: "Feature", properties: {}, geometry: { type: "Point", coordinates: [139.7051, 35.6927] }, }, ], },});
view.addLayer({ type: "vector", source: points, point: { color: new Color().setHex(0xffffff), size: 0.1, sizeInMeters: true, clampToGround: true, },});Vector tiles with a sub-layer filter
Section titled “Vector tiles with a sub-layer filter”Reference one vector-tile source from several layers and pick which source layers each one renders with sourceLayers. Because they share a source, the tiles are fetched only once.
const tiles = view.addSource({ type: "vector-tile", url: "https://example.com/tiles/{z}/{x}/{y}.mvt", maxZoom: 16,});
// Water areasview.addLayer({ type: "vector", source: tiles, sourceLayers: ["waterarea"], polygon: { color: new Color().setStyle("#00aaff"), clampToGround: true },});
// Buildingsview.addLayer({ type: "vector", source: tiles, sourceLayers: ["building"], polygon: { color: new Color().setStyle("#555555"), clampToGround: true },});Deriving representations with geometryTypes
Section titled “Deriving representations with geometryTypes”The point, billboard, text, and polyline materials accept a geometryTypes array listing the source geometry categories they consume: point-like materials take "point", "line", or "polygon", while polyline takes "line" or "polygon". When the array is omitted, each material consumes only its native category (["point"] for point-like materials and ["line"] for polyline). Setting the array replaces the default, so include the native category when you still want it.
Derivation is downward only:
polylinewith"polygon": every polygon boundary ring (the outer ring and any holes) renders as a closed polyline at the ring’s base height. Extruded side edges are not included, so use the polygon material’soutlinefor extruded polygons.pointwith"line": one point per line-string vertex by default.billboard/textwith"line": one per line string by default, at its first vertex, as MapLibre places a symbol at a point on a line. Theplacementoption can place them along the line instead. See Placing labels and sprites along lines.pointwith"polygon": one point per polygon-ring vertex (the closing duplicate vertex is skipped).billboard/textwith"polygon": one billboard or label per polygon, placed inside it at the point farthest from its edges, so it never lands in a hole or a narrow part. Each part of a MultiPolygon gets its own. This matches how MapLibre places a symbol on a polygon.
// Data mixing LineString and Polygon features:// polygons render filled with their boundaries stroked, and// lines render as polylines with the same material.view.addLayer({ type: "vector", source, polygon: { color: new Color().setStyle("#2d6a4f"), clampToGround: true }, polyline: { color: new Color().setStyle("#ffffff"), width: 2, clampToGround: true, geometryTypes: ["line", "polygon"], },});Each derived representation is a full-featured instance of its material. A boundary polyline supports width, clampToGround, and per-feature styling exactly like a polyline built from line geometry, and it carries the source feature’s properties.
geometryTypes applies when geometry is built, so set it at layer creation. Calling layer.update() with a new value only affects tiles loaded afterwards. Tiles already on screen keep the geometry they were built with, so re-create the layer to change the derivation everywhere.
On tiled rendering paths (vector tile sources, or materials with tiled / clampToGround), derivation walks each tile’s clipped rings. Boundary polylines handle this automatically: edges introduced by tile clipping are dropped, so tile outlines never render through polygon interiors. Points derived from polygon vertices on vector tiles can still appear at clip-introduced vertices near tile edges. If that matters, prefer an untiled GeoJSON layer for point derivation. A polygon that spans several vector tiles gets a billboard or label in each tile that holds part of it.
Outlining clamped polygons
Section titled “Outlining clamped polygons”A polyline material with geometryTypes: ["polygon"] next to the polygon material of a clamped layer draws a line along every ring of each polygon, holes included. An edge shared by two neighboring polygons gets a line too, so neighboring polygons of the same color stay distinguishable. On a vector tile source, the edges that tile clipping adds are not drawn.
import ThreeView, { Color } from "@navaramap/three";import { DefaultPlugin, type DefaultDescriptions,} from "@navaramap/three-default-plugin";import { TileJsonPlugin } from "@navaramap/three-plugins";
const view = new ThreeView<DefaultDescriptions>({ container });view.addPlugin(new DefaultPlugin());const tilejson = new TileJsonPlugin();view.addPlugin(tilejson);await view.init();
view.setCamera({ lng: 139.7622, lat: 35.6745, height: 600, heading: 30, pitch: -60, roll: 0,});
// A basemap for the polygons to drape on, lit by an ambient light.view.addLight({ ambient: {} });const basemap = await tilejson.addSource({ type: "raster-tile", url: "https://papers.reearth.land/styles/protomaps-light/tilejson.json",});view.addLayer({ type: "raster", source: basemap });
// OpenMapTiles building footprints.// Credit: OpenFreeMap © OpenMapTiles Data from OpenStreetMap (https://openfreemap.org/)const tiles = await tilejson.addSource({ type: "vector-tile", url: "https://tiles.openfreemap.org/planet",});
view.addLayer({ type: "vector", source: tiles, sourceLayers: ["building"], polygon: { color: new Color().setStyle("#8a93a6"), clampToGround: true, }, polyline: { color: new Color().setStyle("#f4f7ff"), width: 1.5, clampToGround: true, geometryTypes: ["polygon"], },});Placing labels and sprites along lines
Section titled “Placing labels and sprites along lines”With "line" or "polygon" in geometryTypes, the point, billboard, and text materials also accept placement:
"point"(the default): one point marker per line-string vertex, and one billboard or label per line string, at its first vertex. Polygons are handled as described in Deriving representations with geometryTypes."line": objects repeat along the line everyspacing, evenly spaced regardless of where the vertices are. Polygon boundary rings, holes included, are followed the same way. On vector tiles, ring edges introduced by tile clipping are skipped."line-center": a single object at the halfway point along each line string or polygon ring.
Text placed along a line follows the curve word by word, like a street name: each word turns to match the line under it, and the letters within a word stay straight. A label that would overrun its line or bend more than maxAngle is hidden, and a label that would read upside down is flipped unless keepUpright is false. Both are decided again as the camera moves. Billboards and points turn to the line’s direction through rotateToLine.
spacing is in screen pixels on both vector tile and GeoJSON sources. Objects thin out as the camera pulls back and fill in as it moves closer, so the gap on screen stays between one and two times spacing. Objects never slide along the line: they only appear or disappear.
// Street names along road lines from a vector tile sourceview.addLayer({ type: "vector", source: roads, text: { font: "Arsenal", geometryTypes: ["line"], placement: "line", spacing: 250, // Screen pixels textFacing: "flat", size: 14, sizeInMeters: false, clampToGround: true, },});Like geometryTypes, placement, spacing, and rotateToLine apply when geometry is built, so set them at layer creation. See TextMaterial, BillboardMaterial, and PointMaterial for the full list of options.
Related Resources
Section titled “Related Resources”- GeoJSON Source / Vector Tile Source
- PointMaterial / PolygonMaterial / PolylineMaterial: detailed material settings