@maplibre/geojson-vt 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,39 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 MapLibre contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ --------------------------------------------------------------------------------
24
+
25
+ ISC License
26
+
27
+ Copyright (c) 2024, Mapbox
28
+
29
+ Permission to use, copy, modify, and/or distribute this software for any purpose
30
+ with or without fee is hereby granted, provided that the above copyright notice
31
+ and this permission notice appear in all copies.
32
+
33
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
34
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
35
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
36
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
37
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
39
+ THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://maplibre.org/img/maplibre-logos/maplibre-logo-for-dark-bg.svg">
4
+ <source media="(prefers-color-scheme: light)" srcset="https://maplibre.org/img/maplibre-logos/maplibre-logo-for-light-bg.svg">
5
+ <img alt="MapLibre Logo" src="https://maplibre.org/img/maplibre-logos/maplibre-logo-for-light-bg.svg" width="200">
6
+ </picture>
7
+ </p>
8
+
9
+ ## geojson-vt &mdash; GeoJSON Vector Tiles
10
+
11
+ A highly efficient JavaScript library for **slicing GeoJSON data into vector tiles on the fly**,
12
+ primarily designed to enable rendering and interacting with large geospatial datasets
13
+ on the browser side (without a server).
14
+
15
+ Created to power GeoJSON in [MapLibre GL JS](https://github.com/maplibre/maplibre-gl-js),
16
+ but can be useful in other visualization platforms
17
+ like [Leaflet](https://github.com/Leaflet/Leaflet), [OpenLayers](https://openlayers.org/) and [d3](https://github.com/mbostock/d3),
18
+ as well as Node.js server applications.
19
+
20
+ Resulting tiles conform to the JSON equivalent
21
+ of the [vector tile specification](https://github.com/mapbox/vector-tile-spec/).
22
+ To make data rendering and interaction fast, the tiles are simplified,
23
+ retaining the minimum level of detail appropriate for each zoom level
24
+ (simplifying shapes, filtering out tiny polygons and polylines).
25
+
26
+ ### Demo
27
+
28
+ Here's **geojson-vt** action in [MapLibre GL JS](https://github.com/maplibre/maplibre-gl-js),
29
+ dynamically loading a 100Mb US zip codes GeoJSON with 5.4 million points:
30
+
31
+ ![](https://cloud.githubusercontent.com/assets/25395/5360312/86028d8e-7f91-11e4-811f-87f24acb09ca.gif)
32
+
33
+ There's a convenient [debug page](http://maplibre.github.io/geojson-vt/debug/) to test out **geojson-vt** on different data.
34
+ Just drag any GeoJSON on the page, watching the console.
35
+
36
+ ![](https://cloud.githubusercontent.com/assets/25395/5363235/41955c6e-7fa8-11e4-9575-a66ef54cb6d9.gif)
37
+
38
+ ### Usage
39
+
40
+ ```js
41
+ // build an initial index of tiles
42
+ var tileIndex = geojsonvt(geoJSON);
43
+
44
+ // request a particular tile
45
+ var features = tileIndex.getTile(z, x, y).features;
46
+
47
+ // show an array of tile coordinates created so far
48
+ console.log(tileIndex.tileCoords); // [{z: 0, x: 0, y: 0}, ...]
49
+ ```
50
+
51
+ ### Options
52
+
53
+ You can fine-tune the results with an options object,
54
+ although the defaults are sensible and work well for most use cases.
55
+
56
+ ```js
57
+ var tileIndex = geojsonvt(data, {
58
+ maxZoom: 14, // max zoom to preserve detail on; can't be higher than 24
59
+ tolerance: 3, // simplification tolerance (higher means simpler)
60
+ extent: 4096, // tile extent (both width and height)
61
+ buffer: 64, // tile buffer on each side
62
+ debug: 0, // logging level (0 to disable, 1 or 2)
63
+ lineMetrics: false, // whether to enable line metrics tracking for LineString/MultiLineString features
64
+ promoteId: null, // name of a feature property to promote to feature.id. Cannot be used with `generateId`
65
+ generateId: false, // whether to generate feature ids. Cannot be used with `promoteId`
66
+ updateable: false, // whether the tile index can be updated (with the caveat of a stored simplified copy)
67
+ indexMaxZoom: 5, // max zoom in the initial tile index
68
+ indexMaxPoints: 100000 // max number of points per tile in the index
69
+ });
70
+ ```
71
+
72
+ By default, tiles at zoom levels above `indexMaxZoom` are generated on the fly, but you can pre-generate all possible tiles for `data` by setting `indexMaxZoom` and `maxZoom` to the same value, setting `indexMaxPoints` to `0`, and then accessing the resulting tile coordinates from the `tileCoords` property of `tileIndex`.
73
+
74
+ The `promoteId` and `generateId` options ignore existing `id` values on the feature objects.
75
+
76
+ GeoJSON-VT only operates on zoom levels up to 24.
77
+
78
+ ### Update
79
+
80
+ For incremental updates to the tile index, you can use `updateData` to change features without having to recreate a fresh index. `updateData` takes a diff object as a parameter with the following properties:
81
+
82
+ ```js
83
+ var diff = {
84
+ removeAll: false, // set to true to clear all features
85
+ remove: ['id1', 'id2'], // array of feature ids to remove
86
+ add: [feature1, feature2], // array of GeoJSON features to add
87
+ update: [ // array of feature update objects
88
+ {
89
+ id: 'feature1', // required - id of feature to update
90
+ newGeometry: {type: 'Point', ...}, // new geometry for the feature
91
+ removeAllProperties: false, // remove all properties
92
+ removeProperties: ['prop1', 'prop2'], // array of property keys to remove
93
+ addOrUpdateProperties: [ // array of properties to add/update
94
+ {key: 'name', value: 'New Name'},
95
+ {key: 'population', value: 5000}
96
+ ]
97
+ }
98
+ ]
99
+ };
100
+
101
+ tileIndex.updateData(diff);
102
+ ```
103
+
104
+ All properties in the diff are optional, but at least one operation should be specified. Remove operations are applied before add/update operations.
105
+
106
+ To use `updateData`, the index must be created with the `updateable: true` option.
107
+
108
+ ### Install
109
+
110
+ Install using NPM (`npm install geojson-vt`), then:
111
+
112
+ ```js
113
+ // import as a ES module
114
+ import geojsonvt from 'geojson-vt';
115
+
116
+ // import from a CDN in the browser:
117
+ import geojsonvt from 'https://esm.run/geojson-vt';
118
+ ```
119
+
120
+ Or use a browser build directly:
121
+
122
+ ```html
123
+ <script src="https://unpkg.com/geojson-vt/geojson-vt.js"></script>
124
+ ```
125
+
126
+ ### Getting Involved
127
+
128
+ Join the #maplibre slack channel at OSMUS: get an invite at https://slack.openstreetmap.us/