# three-geojson-geometry

> ThreeJS geometry for stroking GeoJSON objects on a sphere

Latest version **2.1.1** (published 2025-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install three-geojson-geometry
pnpm add three-geojson-geometry
yarn add three-geojson-geometry
bun add three-geojson-geometry
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2025-01-10 |
| First published | 2019-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 3 |
| Unpacked size | 711.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 86 |
| Author | Vasco Asturiano |
| Maintainers | vasturiano |
| Keywords | 3d, three, polygons, sphere, stroke, webgl, geojson |

## Links

- npm: https://www.npmjs.com/package/three-geojson-geometry
- Repository: https://github.com/vasturiano/three-geojson-geometry
- Issues: https://github.com/vasturiano/three-geojson-geometry/issues
- npm.io page: https://npm.io/package/three-geojson-geometry

## Dependencies (3)

- [d3-geo](https://npm.io/package/d3-geo.md) 1 - 3
- [earcut](https://npm.io/package/earcut.md) 3
- [d3-interpolate](https://npm.io/package/d3-interpolate.md) 1 - 3

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.1 (latest) — 2025-01-10
- 2.1.0 — 2025-01-04
- 2.0.0 — 2024-12-13
- 1.3.3 — 2024-08-04
- 1.3.2 — 2024-02-08
- 1.3.1 — 2023-02-08
- 1.3.0 — 2023-02-06
- 1.2.0 — 2023-02-06
- 1.1.8 — 2022-09-27
- 1.1.7 — 2022-02-09
- 1.1.6 — 2021-11-11
- 1.1.5 — 2021-07-08
- 1.1.4 — 2021-06-19
- 1.1.3 — 2021-04-25
- 1.1.2 — 2021-01-28
- … 13 more at https://npm.io/package/three-geojson-geometry/versions

## README

ThreeJS GeoJSON Geometry
========================

[![NPM package][npm-img]][npm-url]
[![Build Size][build-size-img]][build-size-url]
[![NPM Downloads][npm-downloads-img]][npm-downloads-url]

A ThreeJS geometry class for stroking GeoJSON objects on a sphere. 

<p align="center">
  <a href="//vasturiano.github.io/three-geojson-geometry/example/countries/"><img width="80%" src="https://vasturiano.github.io/three-geojson-geometry/example/countries/preview.png"></a>
</p>

## Quick start

```js
import GeoJsonGeometry from 'three-geojson-geometry';
```
or using a *script* tag
```html
<script src="//unpkg.com/three-geojson-geometry"></script>
```
then
```js
const myLine = new THREE.Line(
  new GeoJsonGeometry(geoJson),
  new THREE.LineBasicMaterial({ color: 'blue' })
);

```

## API reference

### Constructor

<b>GeoJsonGeometry</b>(<b>geoJson</b>: <i>GeoJson object</i>, <b>radius</b>: <i>Float</i>, <b>resolution</b>: <i>Float</i>)

* <b>geoJson</b>: A GeoJson `geometry` object. It's recommended to split the geometries at the [anti-meridian](https://en.wikipedia.org/wiki/180th_meridian). Each `coordinates` point is expected to include longitude and latitude in that order. Altitude may be included as a third optional element, interpreted as elevation above the surface in regular cartesian units.
* <b>radius</b>: Radius of the sphere surface to draw the poygon on. Default is `1`.
* <b>resolution</b>: Resolution of the sphere, in lat/lng degrees. If the angular distance between two adjacent line points is larger than this value, the line segment will be interpolated in order to approximate the curvature of the sphere surface. Lower values yield more perfectly curved lines, at the cost of performance. Default is `5`.

### Properties

<b>.parameters</b>: <i>Object</i>

An object with a property for each of the constructor parameters. Any modification after instantiation does not change the geometry.

### Groups

When generating `Polygon` or `MultiPolygon` geometries, two groups are provided to which different materials can be applied.

* <b>0</b>: The outer ring of the polygon.
* <b>1</b>: The polygon inner holes (if any).

### Object types

Different geoJson types should be represented using different ThreeJS object types:
* `Point` and `MultiPoints` - Use `THREE.Points`
* `LineString` and `Polygon` - Use `THREE.Line`
* `MultiLineString` and `MultiPolygon` - Use `THREE.LineSegments`


[npm-img]: https://img.shields.io/npm/v/three-geojson-geometry
[npm-url]: https://npmjs.org/package/three-geojson-geometry
[build-size-img]: https://img.shields.io/bundlephobia/minzip/three-geojson-geometry
[build-size-url]: https://bundlephobia.com/result?p=three-geojson-geometry
[npm-downloads-img]: https://img.shields.io/npm/dt/three-geojson-geometry
[npm-downloads-url]: https://www.npmtrends.com/three-geojson-geometry

---
_Source: https://npm.io/package/three-geojson-geometry · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
