Loader and parser for the GeoJSON format.
import { MeshNormalMaterial } from 'three';
import { GeoJSONLoader } from 'three-geojson';
// scene, camera and renderer are initialized here
// a square with a square hole
const result = new GeoJSONLoader().parse( {
type: 'Polygon',
coordinates: [
[ [ - 1, - 1 ], [ 1, - 1 ], [ 1, 1 ], [ - 1, 1 ], [ - 1, - 1 ] ],
[ [ - 0.5, - 0.5 ], [ - 0.5, 0.5 ], [ 0.5, 0.5 ], [ 0.5, - 0.5 ], [ - 0.5, - 0.5 ] ],
],
} );
const mesh = result.polygons[ 0 ].getMeshObject( { thickness: 0.4 } );
mesh.material = new MeshNormalMaterial();
mesh.rotation.x = - Math.PI / 2;
scene.add( mesh );Properties
fetchOptions: Object = {}
Options passed to fetch when loading a file.
Methods
static getLineObject(
objects: Array<(Polygon|LineString)>,
options?: LineOptions
): LineSegmentsReturns a line that merges the result of all the provided Polygons and LineStrings. Each result is defined as a separate group in the resulting geometry.
static getMeshObject(
objects: Array<Polygon>,
options?: MeshOptions
): MeshReturns a mesh that merges the result of all the provided Polygons. Each result is defined as a separate group in the resulting geometry in top cap, bottom cap, side geometry order.
loadAsync( url: string ): Promise<GeoJSONResult>Loads and parses a GeoJSON file.
parse( json: string | Object ): GeoJSONResultParses GeoJSON content. Takes a raw or stringified json object.