Three.js shape loaders for GeoJSON (readable html) and WKT formats. Supports generation of three.js line geometry in addition to flat and extruded tringulated meshes.
Uses @turfjs/unkink-polygon and wellknown parser. World GeoJSON file courtesy of geojson-maps.
Note
This project is not hosted on npm and must be installed via Github repository.
// load the content
const result = await new GeoJSON().loadAsync( url );
// extract polygon lines and project them onto the globe
const transformer = new GeoJSONTransformer();
result.polygons.forEach( polygon => {
const line = polygon.getLineObject();
transformer.transformGeometry( line.geometry );
scene.add( line );
} );
{
// list of features in the file
features: Array<Feature>,
// list of all geometries in the file
geometries: Array<Polygon|LineString|Points>,
// lists of specific geometry types
polygons: Array<Polygon>,
lines: Array<LineString>,
points: Array<Points>,
}
Feature
Definition of a feature that includes properties originally defined in the GeoJSON file.
{
type: 'Feature',
id: string | null,
properties: object,
// list of all geometries in the feature
geometries: Array<Polygon|LineString|Points>,
// lists of specific geometry types
polygons: Array<Polygon>,
lines: Array<LineString>,
points: Array<Points>,
}
Points
Definition of a parsed set of point geometry.
{
type: string,
feature: Feature,
data: Vector3 | Array<Vector3>,
}
LineString
Definition of a parsed set of line string geometry.
{
type: string,
feature: Feature,
// function for building three.js LineSegments from the line data
getLineObject( options: {
flat = false: boolean,
} ): LineSegments,
}
Polygon
Definition of a parsed set of polygon geometry.
{
type: string,
feature: Feature,
// functions for building three.js LineSegments and Mesh from the line data
getLineObject( options: {
flat = false: boolean,
} ): LineSegments,
getMeshObject( options: {
thickness = 0: number,
offset = 0: number,
generateNormals = true: boolean,
flat = false: boolean,
} ): Mesh,
}
decomposePolygons = true: boolean
If true then self-intersecting polygons are decomposed into individual parts to enable triangulation.
fetchOptions = {}: object
Options passed to fetch.
loadAsync( url: string ): Promise<GeoJSONResult>
Loads and parses a geojson file.
parse( content: string | object ): GeoJSONResult
Parses geojson content. Takes a raw or stringified json object.
extends GeoJSONLoader
Loads and converts the WKT file to GeoJSON using [mapbox's wellknown](wellknown parser](https://github.com/mapbox/wellknown)) package, then parses it using the GeoJSONLoader parse function.
Utility for transforming points and geometry from lat / lon values to an ellipsoidal projection.
constructor( ellipsoid = WGS84_ELLIPSOID: Ellipsoid )
transformPoint( point: Vector3, target: Vector3 ): Vector3
Transforms a point in the GeoJSON lon, lat, height format to a cartesian value.
transformGeometry( geometry: BufferGeometry ): BufferGeometry
Transforms geometry position attribute buffer to cartesian frame in-place assuming the values are in the GeoJSON lon, lat, height format.