Skip to content

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).

PropertyTypeDescription
type"vector"Layer type (required).
sourceSource | stringThe geojson / vector-tile source to render (required).
sourceLayersstring[]For vector-tile sources: which source layers within the tileset to render. Ignored for GeoJSON.

Specify one or more, depending on the geometry types present:

MaterialConfig keySupported geometry
PointMaterialpointPoint, MultiPoint
BillboardMaterialbillboardPoint (icon display)
TextMaterialtextPoint (label display)
PolylineMaterialpolylineLineString, MultiLineString
PolygonMaterialpolygonPolygon, MultiPolygon
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,
},
});

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 areas
view.addLayer({
type: "vector",
source: tiles,
sourceLayers: ["waterarea"],
polygon: { color: new Color().setStyle("#00aaff"), clampToGround: true },
});
// Buildings
view.addLayer({
type: "vector",
source: tiles,
sourceLayers: ["building"],
polygon: { color: new Color().setStyle("#555555"), clampToGround: true },
});