Skip to content

GeoJSON Source

A geojson source provides vector data from a GeoJSON document, either fetched from a URL or given inline. Render it with a vector layer.

PropertyTypeDefaultDescription
type"geojson"(required)Source type.
urlstring—URL to fetch the GeoJSON from. Mutually exclusive with data. Takes precedence when both are given.
dataFeatureCollection | Feature | Geometry—Inline GeoJSON document. Used when url is not given.
crsstring—Coordinate reference system of the data.
tiledbooleanfalseBuild a tiled spatial index (GeoJSON-VT) for large datasets.
lineMetricsbooleanfalseMeasure where each point of a line lies along the whole line, which a polyline gradient needs. Without it, the lines draw with color instead of a gradient. Leave it off when no layer of the source has a gradient: it adds work and memory for every line.
import ThreeView from "@navaramap/three";
// From a URL
const roads = view.addSource({
type: "geojson",
url: "https://example.com/roads.geojson",
});
view.addLayer({ type: "vector", source: roads, polyline: { color: 0xffffff } });
// Inline
const pins = view.addSource({
type: "geojson",
data: {
type: "FeatureCollection",
features: [
{ type: "Feature", geometry: { type: "Point", coordinates: [139.767, 35.681] }, properties: {} },
],
},
});
view.addLayer({ type: "vector", source: pins, point: { color: 0xff0000, size: 8 } });

A polyline gradient needs lineMetrics: true on the source. The source reads it when its layers are built: update() with another value reloads them.

import ThreeView, { Color } from "@navaramap/three";
const route = view.addSource({
type: "geojson",
url: "https://example.com/route.geojson",
lineMetrics: true,
});
view.addLayer({
type: "vector",
source: route,
polyline: {
width: 6,
gradient: [
{ progress: 0, color: new Color().setStyle("#2979ff") },
{ progress: 1, color: new Color().setStyle("#d50000") },
],
},
});