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);Content copied to clipboard
// 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 propertiesContent copied to clipboard
// 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);
}
}Content copied to clipboard
See also
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
Loader source URL when created via GeoJsonPrimitive.fromUrl.