Initial commit

This commit is contained in:
2026-04-15 17:08:39 +02:00
parent ae164c47a8
commit 47fd1c2b7a
1819 changed files with 685388 additions and 0 deletions

27
node_modules/@mapbox/vector-tile/LICENSE.txt generated vendored Normal file
View File

@@ -0,0 +1,27 @@
Copyright (c) 2024, Mapbox
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Mapbox nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

95
node_modules/@mapbox/vector-tile/README.md generated vendored Normal file
View File

@@ -0,0 +1,95 @@
# vector-tile
This library reads [Mapbox Vector Tiles](https://github.com/mapbox/vector-tile-spec) and allows access to the layers and features.
## Example
```js
import {VectorTile} from '@mapbox/vector-tile';
import Protobuf from 'pbf';
const tile = new VectorTile(new Protobuf(data));
// Contains a map of all layers
tile.layers;
const landuse = tile.layers.landuse;
// Amount of features in this layer
landuse.length;
// Returns the first feature
landuse.feature(0);
```
Vector tiles contained in [serialtiles-spec](https://github.com/mapbox/serialtiles-spec)
are gzip-encoded, so a complete example of parsing them with the native
zlib module would be:
```js
import {VectorTile} from '@mapbox/vector-tile';
import Protobuf from 'pbf';
import {gunzipSync} from 'zlib';
const buffer = gunzipSync(data);
const tile = new VectorTile(new Protobuf(buffer));
```
## Install
To install:
npm install @mapbox/vector-tile
## API Reference
### VectorTile
An object that parses vector tile data and makes it readable.
#### Constructor
- **new VectorTile(protobuf[, end])** —
parses the vector tile data contained in the given [Protobuf](https://github.com/mapbox/pbf) object,
saving resulting layers in the created object as a `layers` property. Optionally accepts end index.
#### Properties
- **layers** (Object) &mdash; an object containing parsed layers in the form of `{<name>: <layer>, ...}`,
where each layer is a `VectorTileLayer` object.
### VectorTileLayer
An object that contains the data for a single vector tile layer.
#### Properties
- **version** (`Number`, default: `1`)
- **name** (`String`) &mdash; layer name
- **extent** (`Number`, default: `4096`) &mdash; tile extent size
- **length** (`Number`) &mdash; number of features in the layer
#### Methods
- **feature(i)** &mdash; get a feature (`VectorTileFeature`) by the given index from the layer.
### VectorTileFeature
An object that contains the data for a single feature.
#### Properties
- **type** (`Number`) &mdash; type of the feature (also see `VectorTileFeature.types`)
- **extent** (`Number`) &mdash; feature extent size
- **id** (`Number`) &mdash; feature identifier, if present
- **properties** (`Object`) &mdash; object literal with feature properties
#### Methods
- **loadGeometry()** &mdash; parses feature geometry and returns an array of
[Point](https://github.com/mapbox/point-geometry) arrays (with each point having `x` and `y` properties)
- **bbox()** &mdash; calculates and returns the bounding box of the feature in the form `[x1, y1, x2, y2]`
- **toGeoJSON(x, y, z)** &mdash; returns a GeoJSON representation of the feature. (`x`, `y`, and `z` refer to the containing tile's index.)

81
node_modules/@mapbox/vector-tile/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,81 @@
/** classifies an array of rings into polygons with outer rings and holes
* @param {Point[][]} rings
*/
export function classifyRings(rings: Point[][]): Point[][][];
/** @import Pbf from 'pbf' */
/** @import {Feature} from 'geojson' */
export class VectorTileFeature {
/**
* @param {Pbf} pbf
* @param {number} end
* @param {number} extent
* @param {string[]} keys
* @param {(number | string | boolean)[]} values
*/
constructor(pbf: Pbf, end: number, extent: number, keys: string[], values: (number | string | boolean)[]);
/** @type {Record<string, number | string | boolean>} */
properties: Record<string, number | string | boolean>;
extent: number;
/** @type {0 | 1 | 2 | 3} */
type: 0 | 1 | 2 | 3;
/** @type {number | undefined} */
id: number | undefined;
/** @private */
private _pbf;
/** @private */
private _geometry;
/** @private */
private _keys;
/** @private */
private _values;
loadGeometry(): Point[][];
bbox(): number[];
/**
* @param {number} x
* @param {number} y
* @param {number} z
* @return {Feature}
*/
toGeoJSON(x: number, y: number, z: number): Feature;
}
export namespace VectorTileFeature {
let types: ["Unknown", "Point", "LineString", "Polygon"];
}
export class VectorTileLayer {
/**
* @param {Pbf} pbf
* @param {number} [end]
*/
constructor(pbf: Pbf, end?: number);
version: number;
name: string;
extent: number;
length: number;
/** @private */
private _pbf;
/** @private
* @type {string[]} */
private _keys;
/** @private
* @type {(number | string | boolean)[]} */
private _values;
/** @private
* @type {number[]} */
private _features;
/** return feature `i` from this layer as a `VectorTileFeature`
* @param {number} i
*/
feature(i: number): VectorTileFeature;
}
export class VectorTile {
/**
* @param {Pbf} pbf
* @param {number} [end]
*/
constructor(pbf: Pbf, end?: number);
/** @type {Record<string, VectorTileLayer>} */
layers: Record<string, VectorTileLayer>;
}
import Point from '@mapbox/point-geometry';
import type { Feature } from 'geojson';
import type Pbf from 'pbf';

388
node_modules/@mapbox/vector-tile/index.js generated vendored Normal file
View File

@@ -0,0 +1,388 @@
import Point from '@mapbox/point-geometry';
/** @import Pbf from 'pbf' */
/** @import {Feature} from 'geojson' */
export class VectorTileFeature {
/**
* @param {Pbf} pbf
* @param {number} end
* @param {number} extent
* @param {string[]} keys
* @param {(number | string | boolean)[]} values
*/
constructor(pbf, end, extent, keys, values) {
// Public
/** @type {Record<string, number | string | boolean>} */
this.properties = {};
this.extent = extent;
/** @type {0 | 1 | 2 | 3} */
this.type = 0;
/** @type {number | undefined} */
this.id = undefined;
/** @private */
this._pbf = pbf;
/** @private */
this._geometry = -1;
/** @private */
this._keys = keys;
/** @private */
this._values = values;
pbf.readFields(readFeature, this, end);
}
loadGeometry() {
const pbf = this._pbf;
pbf.pos = this._geometry;
const end = pbf.readVarint() + pbf.pos;
/** @type Point[][] */
const lines = [];
/** @type Point[] | undefined */
let line;
let cmd = 1;
let length = 0;
let x = 0;
let y = 0;
while (pbf.pos < end) {
if (length <= 0) {
const cmdLen = pbf.readVarint();
cmd = cmdLen & 0x7;
length = cmdLen >> 3;
}
length--;
if (cmd === 1 || cmd === 2) {
x += pbf.readSVarint();
y += pbf.readSVarint();
if (cmd === 1) { // moveTo
if (line) lines.push(line);
line = [];
}
if (line) line.push(new Point(x, y));
} else if (cmd === 7) {
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
if (line) {
line.push(line[0].clone()); // closePolygon
}
} else {
throw new Error(`unknown command ${cmd}`);
}
}
if (line) lines.push(line);
return lines;
}
bbox() {
const pbf = this._pbf;
pbf.pos = this._geometry;
const end = pbf.readVarint() + pbf.pos;
let cmd = 1,
length = 0,
x = 0,
y = 0,
x1 = Infinity,
x2 = -Infinity,
y1 = Infinity,
y2 = -Infinity;
while (pbf.pos < end) {
if (length <= 0) {
const cmdLen = pbf.readVarint();
cmd = cmdLen & 0x7;
length = cmdLen >> 3;
}
length--;
if (cmd === 1 || cmd === 2) {
x += pbf.readSVarint();
y += pbf.readSVarint();
if (x < x1) x1 = x;
if (x > x2) x2 = x;
if (y < y1) y1 = y;
if (y > y2) y2 = y;
} else if (cmd !== 7) {
throw new Error(`unknown command ${cmd}`);
}
}
return [x1, y1, x2, y2];
}
/**
* @param {number} x
* @param {number} y
* @param {number} z
* @return {Feature}
*/
toGeoJSON(x, y, z) {
const size = this.extent * Math.pow(2, z),
x0 = this.extent * x,
y0 = this.extent * y,
vtCoords = this.loadGeometry();
/** @param {Point} p */
function projectPoint(p) {
return [
(p.x + x0) * 360 / size - 180,
360 / Math.PI * Math.atan(Math.exp((1 - (p.y + y0) * 2 / size) * Math.PI)) - 90
];
}
/** @param {Point[]} line */
function projectLine(line) {
return line.map(projectPoint);
}
/** @type {Feature["geometry"]} */
let geometry;
if (this.type === 1) {
const points = [];
for (const line of vtCoords) {
points.push(line[0]);
}
const coordinates = projectLine(points);
geometry = points.length === 1 ?
{type: 'Point', coordinates: coordinates[0]} :
{type: 'MultiPoint', coordinates};
} else if (this.type === 2) {
const coordinates = vtCoords.map(projectLine);
geometry = coordinates.length === 1 ?
{type: 'LineString', coordinates: coordinates[0]} :
{type: 'MultiLineString', coordinates};
} else if (this.type === 3) {
const polygons = classifyRings(vtCoords);
const coordinates = [];
for (const polygon of polygons) {
coordinates.push(polygon.map(projectLine));
}
geometry = coordinates.length === 1 ?
{type: 'Polygon', coordinates: coordinates[0]} :
{type: 'MultiPolygon', coordinates};
} else {
throw new Error('unknown feature type');
}
/** @type {Feature} */
const result = {
type: 'Feature',
geometry,
properties: this.properties
};
if (this.id != null) {
result.id = this.id;
}
return result;
}
}
/** @type {['Unknown', 'Point', 'LineString', 'Polygon']} */
VectorTileFeature.types = ['Unknown', 'Point', 'LineString', 'Polygon'];
/**
* @param {number} tag
* @param {VectorTileFeature} feature
* @param {Pbf} pbf
*/
function readFeature(tag, feature, pbf) {
if (tag === 1) feature.id = pbf.readVarint();
else if (tag === 2) readTag(pbf, feature);
else if (tag === 3) feature.type = /** @type {0 | 1 | 2 | 3} */ (pbf.readVarint());
// @ts-expect-error TS2341 deliberately accessing a private property
else if (tag === 4) feature._geometry = pbf.pos;
}
/**
* @param {Pbf} pbf
* @param {VectorTileFeature} feature
*/
function readTag(pbf, feature) {
const end = pbf.readVarint() + pbf.pos;
while (pbf.pos < end) {
// @ts-expect-error TS2341 deliberately accessing a private property
const key = feature._keys[pbf.readVarint()];
// @ts-expect-error TS2341 deliberately accessing a private property
const value = feature._values[pbf.readVarint()];
feature.properties[key] = value;
}
}
/** classifies an array of rings into polygons with outer rings and holes
* @param {Point[][]} rings
*/
export function classifyRings(rings) {
const len = rings.length;
if (len <= 1) return [rings];
const polygons = [];
let polygon, ccw;
for (let i = 0; i < len; i++) {
const area = signedArea(rings[i]);
if (area === 0) continue;
if (ccw === undefined) ccw = area < 0;
if (ccw === area < 0) {
if (polygon) polygons.push(polygon);
polygon = [rings[i]];
} else if (polygon) {
polygon.push(rings[i]);
}
}
if (polygon) polygons.push(polygon);
return polygons;
}
/** @param {Point[]} ring */
function signedArea(ring) {
let sum = 0;
for (let i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) {
p1 = ring[i];
p2 = ring[j];
sum += (p2.x - p1.x) * (p1.y + p2.y);
}
return sum;
}
export class VectorTileLayer {
/**
* @param {Pbf} pbf
* @param {number} [end]
*/
constructor(pbf, end) {
// Public
this.version = 1;
this.name = '';
this.extent = 4096;
this.length = 0;
/** @private */
this._pbf = pbf;
/** @private
* @type {string[]} */
this._keys = [];
/** @private
* @type {(number | string | boolean)[]} */
this._values = [];
/** @private
* @type {number[]} */
this._features = [];
pbf.readFields(readLayer, this, end);
this.length = this._features.length;
}
/** return feature `i` from this layer as a `VectorTileFeature`
* @param {number} i
*/
feature(i) {
if (i < 0 || i >= this._features.length) throw new Error('feature index out of bounds');
this._pbf.pos = this._features[i];
const end = this._pbf.readVarint() + this._pbf.pos;
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
}
}
/**
* @param {number} tag
* @param {VectorTileLayer} layer
* @param {Pbf} pbf
*/
function readLayer(tag, layer, pbf) {
if (tag === 15) layer.version = pbf.readVarint();
else if (tag === 1) layer.name = pbf.readString();
else if (tag === 5) layer.extent = pbf.readVarint();
// @ts-expect-error TS2341 deliberately accessing a private property
else if (tag === 2) layer._features.push(pbf.pos);
// @ts-expect-error TS2341 deliberately accessing a private property
else if (tag === 3) layer._keys.push(pbf.readString());
// @ts-expect-error TS2341 deliberately accessing a private property
else if (tag === 4) layer._values.push(readValueMessage(pbf));
}
/**
* @param {Pbf} pbf
*/
function readValueMessage(pbf) {
let value = null;
const end = pbf.readVarint() + pbf.pos;
while (pbf.pos < end) {
const tag = pbf.readVarint() >> 3;
value = tag === 1 ? pbf.readString() :
tag === 2 ? pbf.readFloat() :
tag === 3 ? pbf.readDouble() :
tag === 4 ? pbf.readVarint64() :
tag === 5 ? pbf.readVarint() :
tag === 6 ? pbf.readSVarint() :
tag === 7 ? pbf.readBoolean() : null;
}
if (value == null) {
throw new Error('unknown feature value');
}
return value;
}
export class VectorTile {
/**
* @param {Pbf} pbf
* @param {number} [end]
*/
constructor(pbf, end) {
/** @type {Record<string, VectorTileLayer>} */
this.layers = pbf.readFields(readTile, {}, end);
}
}
/**
* @param {number} tag
* @param {Record<string, VectorTileLayer>} layers
* @param {Pbf} pbf
*/
function readTile(tag, layers, pbf) {
if (tag === 3) {
const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
if (layer.length) layers[layer.name] = layer;
}
}

34
node_modules/@mapbox/vector-tile/package.json generated vendored Normal file
View File

@@ -0,0 +1,34 @@
{
"name": "@mapbox/vector-tile",
"description": "Parses vector tiles",
"repository": {
"url": "git+https://github.com/mapbox/vector-tile-js.git"
},
"version": "2.0.4",
"type": "module",
"exports": "./index.js",
"license": "BSD-3-Clause",
"main": "index.js",
"types": "index.d.ts",
"dependencies": {
"@mapbox/point-geometry": "~1.1.0",
"@types/geojson": "^7946.0.16",
"pbf": "^4.0.1"
},
"devDependencies": {
"benchmark": "^2.1.4",
"eslint": "^9.29.0",
"eslint-config-mourner": "^4.0.2",
"typescript": "^5.8.3"
},
"scripts": {
"lint": "eslint index.js test/*.js",
"pretest": "npm run lint",
"test": "tsc && node --test",
"cov": "node --test --experimental-test-coverage",
"prepublishOnly": "npm test"
},
"files": [
"index.d.ts"
]
}