v0.0.14
three-geojson
Utilities for parsing and rendering GeoJSON data as three.js geometry. Simplifies the visualization of geographic vector data including polygons, lines, and points with support for ellipsoidal projections.
visualizationgeospatial
import { AmbientLight, DirectionalLight, Group, Mesh, MeshStandardMaterial, SphereGeometry } from 'three';
import { WGS84_ELLIPSOID } from '3d-tiles-renderer/three';
import { GeoJSONLoader } from 'three-geojson';
// scene, camera and renderer are initialized here
const URL = 'https://raw.githubusercontent.com/gkjohnson/three-geojson/v0.0.14/example/world.geojson';
const light = new DirectionalLight( 0xffffff, 2.75 );
light.position.set( 1, 2, 0 );
scene.add( light, new AmbientLight( 0xffffff, 1 ) );
const result = await new GeoJSONLoader().loadAsync( URL );
// geographic data is Z up and in meters; scale the Earth down to a radius of 1.5
const globe = new Group();
globe.rotation.x = - Math.PI / 2;
globe.scale.setScalar( 1.5 / 6378137 );
scene.add( globe );
// a dark ellipsoid under the countries
const base = new Mesh( new SphereGeometry( 1, 100, 50 ), new MeshStandardMaterial( { color: 0x222222 } ) );
base.scale.copy( WGS84_ELLIPSOID.radius );
globe.add( base );
// every country extruded 150km up from the ellipsoid, resampled every 2.5 degrees
const material = new MeshStandardMaterial( { polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 } );
for ( const polygon of result.polygons ) {
const mesh = polygon.getMeshObject( { ellipsoid: WGS84_ELLIPSOID, thickness: 1.5e5, resolution: 2.5 } );
mesh.material = material;
globe.add( mesh );
}Install
npm install github:gkjohnson/three-geojson#v0.0.14Changelog
0.0.14
Fixed
- Static GeoJSONLoader.getLineObject not assigning material groups to the merged geometry.
0.0.13
Fixed
- "fetchOptions" not being passed to fetch when loading a file.
Added
- static GeoJSONLoader.getMeshObject and getLineObject functions.