GeoJsonPrimitive

open external class GeoJsonPrimitive(options: GeoJsonPrimitiveConstructorOptions? = definedExternally)(source)

Lightweight GeoJSON loader that converts features directly into BufferPointCollection, BufferPolylineCollection, and BufferPolygonCollection.

Unlike GeoJsonDataSource, this path does not create entities. Instead, it exposes high-throughput buffer primitive collections that can be added directly to Scene.primitives.

// Load GeoJSON
const loader = await GeoJsonPrimitive.fromUrl("./data.geojson");
viewer.scene.primitives.add(loader);
// Access GeoJSON features and properties
loader.points; // BufferPointCollection | undefined
loader.polylines; // BufferPolylineCollection | undefined
loader.polygons; // BufferPolygonCollection | undefined
loader.ids; // source feature IDs
loader.properties; // source feature properties
// Style GeoJSON
const material = new BufferPolylineMaterial({
color: Color.RED,
width: 4,
});

const polyline = new BufferPolyline();
const count = primitive.polylines.primitiveCount;
for (let i = 0; i < count; i++) {
primitive.polylines.get(i, polyline);

const properties = primitive.getProperties(polyline.featureId);
if (properties.myCustomProperty === true) {
polyline.setMaterial(material);
}
}

See also

Constructors

Link copied to clipboard
constructor(options: GeoJsonPrimitiveConstructorOptions? = definedExternally)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Feature count represented by the loaded collections.

Link copied to clipboard

Lookup table from integer ID generated by GeoJsonPrimitive, to integer or string Feature ID from GeoJSON source.

Link copied to clipboard

Buffer point collection for point geometries.

Link copied to clipboard

Buffer polygon collection for polygon geometries.

Link copied to clipboard

Buffer polyline collection for linestring geometries.

Link copied to clipboard

Source GeoJSON properties, indexed by generated integer ID.

Link copied to clipboard
val url: String?

Loader source URL when created via GeoJsonPrimitive.fromUrl.