@loaders.gl/mvt 4.2.0-alpha.5 → 4.2.0-beta.1
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/dist/dist.dev.js +70 -18
- package/dist/dist.min.js +1 -1
- package/dist/helpers/binary-util-functions.d.ts +3 -3
- package/dist/helpers/binary-util-functions.d.ts.map +1 -1
- package/dist/helpers/binary-util-functions.js +3 -0
- package/dist/helpers/mapbox-util-functions.d.ts +1 -1
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -1
- package/dist/helpers/mapbox-util-functions.js +3 -0
- package/dist/index.cjs +64 -18
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +13 -2
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +5 -5
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +16 -5
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +3 -3
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile.js +7 -3
- package/dist/lib/geojson-tiler/clip.js +3 -0
- package/dist/lib/geojson-tiler/geojson-tiler.js +6 -5
- package/dist/lib/geojson-tiler/wrap.js +3 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +12 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +2 -2
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +13 -4
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +2 -2
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.js +6 -2
- package/dist/lib/parse-mvt.d.ts +2 -2
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +7 -4
- package/dist/lib/types.d.ts +0 -10
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +3 -0
- package/dist/mvt-loader.d.ts +63 -6
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +7 -9
- package/dist/mvt-source.js +8 -3
- package/dist/mvt-worker.js +50 -11
- package/dist/tilejson-loader.d.ts +2 -3
- package/dist/tilejson-loader.d.ts.map +1 -1
- package/dist/tilejson-loader.js +3 -1
- package/dist/workers/mvt-worker.js +3 -0
- package/package.json +6 -6
- package/src/helpers/binary-util-functions.ts +7 -3
- package/src/helpers/mapbox-util-functions.ts +5 -1
- package/src/index.ts +1 -1
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +5 -1
- package/src/lib/binary-vector-tile/vector-tile-layer.ts +11 -7
- package/src/lib/binary-vector-tile/vector-tile.ts +13 -5
- package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +5 -1
- package/src/lib/mapbox-vector-tile/vector-tile-layer.ts +6 -2
- package/src/lib/mapbox-vector-tile/vector-tile.ts +6 -2
- package/src/lib/parse-mvt.ts +13 -8
- package/src/lib/types.ts +3 -11
- package/src/mvt-loader.ts +35 -22
- package/src/tilejson-loader.ts +5 -2
- package/src/workers/mvt-worker.ts +4 -0
package/dist/mvt-worker.js
CHANGED
|
@@ -1673,6 +1673,14 @@
|
|
|
1673
1673
|
|
|
1674
1674
|
// src/lib/mapbox-vector-tile/vector-tile-feature.ts
|
|
1675
1675
|
var VectorTileFeature = class {
|
|
1676
|
+
properties;
|
|
1677
|
+
extent;
|
|
1678
|
+
type;
|
|
1679
|
+
id;
|
|
1680
|
+
_pbf;
|
|
1681
|
+
_geometry;
|
|
1682
|
+
_keys;
|
|
1683
|
+
_values;
|
|
1676
1684
|
static get types() {
|
|
1677
1685
|
return ["Unknown", "Point", "LineString", "Polygon"];
|
|
1678
1686
|
}
|
|
@@ -1832,6 +1840,14 @@
|
|
|
1832
1840
|
|
|
1833
1841
|
// src/lib/mapbox-vector-tile/vector-tile-layer.ts
|
|
1834
1842
|
var VectorTileLayer = class {
|
|
1843
|
+
version;
|
|
1844
|
+
name;
|
|
1845
|
+
extent;
|
|
1846
|
+
length;
|
|
1847
|
+
_pbf;
|
|
1848
|
+
_keys;
|
|
1849
|
+
_values;
|
|
1850
|
+
_features;
|
|
1835
1851
|
constructor(pbf, end) {
|
|
1836
1852
|
this.version = 1;
|
|
1837
1853
|
this.name = "";
|
|
@@ -1886,6 +1902,7 @@
|
|
|
1886
1902
|
|
|
1887
1903
|
// src/lib/mapbox-vector-tile/vector-tile.ts
|
|
1888
1904
|
var VectorTile = class {
|
|
1905
|
+
layers;
|
|
1889
1906
|
constructor(pbf, end) {
|
|
1890
1907
|
this.layers = pbf.readFields(readTile, {}, end);
|
|
1891
1908
|
}
|
|
@@ -1987,7 +2004,16 @@
|
|
|
1987
2004
|
var x;
|
|
1988
2005
|
var y;
|
|
1989
2006
|
var i;
|
|
1990
|
-
var
|
|
2007
|
+
var BinaryVectorTileFeature = class {
|
|
2008
|
+
properties;
|
|
2009
|
+
extent;
|
|
2010
|
+
type;
|
|
2011
|
+
id;
|
|
2012
|
+
_pbf;
|
|
2013
|
+
_geometry;
|
|
2014
|
+
_keys;
|
|
2015
|
+
_values;
|
|
2016
|
+
_geometryInfo;
|
|
1991
2017
|
// eslint-disable-next-line max-params
|
|
1992
2018
|
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
1993
2019
|
this.properties = {};
|
|
@@ -2093,7 +2119,15 @@
|
|
|
2093
2119
|
};
|
|
2094
2120
|
|
|
2095
2121
|
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
2096
|
-
var
|
|
2122
|
+
var BinaryVectorTileLayer = class {
|
|
2123
|
+
version;
|
|
2124
|
+
name;
|
|
2125
|
+
extent;
|
|
2126
|
+
length;
|
|
2127
|
+
_pbf;
|
|
2128
|
+
_keys;
|
|
2129
|
+
_values;
|
|
2130
|
+
_features;
|
|
2097
2131
|
constructor(pbf, end) {
|
|
2098
2132
|
this.version = 1;
|
|
2099
2133
|
this.name = "";
|
|
@@ -2107,11 +2141,11 @@
|
|
|
2107
2141
|
this.length = this._features.length;
|
|
2108
2142
|
}
|
|
2109
2143
|
/**
|
|
2110
|
-
* return feature `i` from this layer as a `
|
|
2144
|
+
* return feature `i` from this layer as a `BinaryVectorTileFeature`
|
|
2111
2145
|
*
|
|
2112
2146
|
* @param index
|
|
2113
2147
|
* @param geometryInfo
|
|
2114
|
-
* @returns {
|
|
2148
|
+
* @returns {BinaryVectorTileFeature}
|
|
2115
2149
|
*/
|
|
2116
2150
|
feature(i2, geometryInfo) {
|
|
2117
2151
|
if (i2 < 0 || i2 >= this._features.length) {
|
|
@@ -2119,7 +2153,7 @@
|
|
|
2119
2153
|
}
|
|
2120
2154
|
this._pbf.pos = this._features[i2];
|
|
2121
2155
|
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
2122
|
-
return new
|
|
2156
|
+
return new BinaryVectorTileFeature(
|
|
2123
2157
|
this._pbf,
|
|
2124
2158
|
end,
|
|
2125
2159
|
this.extent,
|
|
@@ -2156,7 +2190,8 @@
|
|
|
2156
2190
|
}
|
|
2157
2191
|
|
|
2158
2192
|
// src/lib/binary-vector-tile/vector-tile.ts
|
|
2159
|
-
var
|
|
2193
|
+
var BinaryVectorTile = class {
|
|
2194
|
+
layers;
|
|
2160
2195
|
constructor(pbf, end) {
|
|
2161
2196
|
this.layers = pbf.readFields(readTile2, {}, end);
|
|
2162
2197
|
}
|
|
@@ -2164,7 +2199,7 @@
|
|
|
2164
2199
|
function readTile2(tag, layers, pbf) {
|
|
2165
2200
|
if (tag === 3) {
|
|
2166
2201
|
if (pbf) {
|
|
2167
|
-
const layer = new
|
|
2202
|
+
const layer = new BinaryVectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
|
|
2168
2203
|
if (layer.length && layers) {
|
|
2169
2204
|
layers[layer.name] = layer;
|
|
2170
2205
|
}
|
|
@@ -2220,7 +2255,7 @@
|
|
|
2220
2255
|
if (arrayBuffer.byteLength <= 0) {
|
|
2221
2256
|
return [features, geometryInfo];
|
|
2222
2257
|
}
|
|
2223
|
-
const tile = new
|
|
2258
|
+
const tile = new BinaryVectorTile(new import_pbf.default(arrayBuffer));
|
|
2224
2259
|
const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
2225
2260
|
selectedLayers.forEach((layerName) => {
|
|
2226
2261
|
const vectorTileLayer = tile.layers[layerName];
|
|
@@ -2279,7 +2314,7 @@
|
|
|
2279
2314
|
}
|
|
2280
2315
|
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
2281
2316
|
const decodedFeature = feature.toBinaryCoordinates(
|
|
2282
|
-
// @ts-expect-error
|
|
2317
|
+
// @ts-expect-error
|
|
2283
2318
|
options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary
|
|
2284
2319
|
);
|
|
2285
2320
|
if (options.layerProperty && decodedFeature.properties) {
|
|
@@ -2303,8 +2338,10 @@
|
|
|
2303
2338
|
}
|
|
2304
2339
|
|
|
2305
2340
|
// src/mvt-loader.ts
|
|
2306
|
-
var VERSION = true ? "4.2.0-alpha.
|
|
2341
|
+
var VERSION = true ? "4.2.0-alpha.6" : "latest";
|
|
2307
2342
|
var MVTWorkerLoader = {
|
|
2343
|
+
dataType: null,
|
|
2344
|
+
batchType: null,
|
|
2308
2345
|
name: "Mapbox Vector Tile",
|
|
2309
2346
|
id: "mvt",
|
|
2310
2347
|
module: "mvt",
|
|
@@ -2395,7 +2432,9 @@
|
|
|
2395
2432
|
}
|
|
2396
2433
|
getParentPort().then((parentPort2) => {
|
|
2397
2434
|
if (parentPort2) {
|
|
2398
|
-
parentPort2.on("message",
|
|
2435
|
+
parentPort2.on("message", (message) => {
|
|
2436
|
+
handleMessage(message);
|
|
2437
|
+
});
|
|
2399
2438
|
parentPort2.on("exit", () => console.debug("Node worker closing"));
|
|
2400
2439
|
} else {
|
|
2401
2440
|
globalThis.onmessage = handleMessage;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TileJSON } from "./lib/parse-tilejson.js";
|
|
1
|
+
import type { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
3
2
|
export type TileJSONLoaderOptions = LoaderOptions & {
|
|
4
3
|
/** Options for the TileJSONLoader */
|
|
5
4
|
tilejson?: {
|
|
@@ -10,5 +9,5 @@ export type TileJSONLoaderOptions = LoaderOptions & {
|
|
|
10
9
|
/**
|
|
11
10
|
* Loader for TileJSON metadata
|
|
12
11
|
*/
|
|
13
|
-
export declare const TileJSONLoader:
|
|
12
|
+
export declare const TileJSONLoader: any;
|
|
14
13
|
//# sourceMappingURL=tilejson-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tilejson-loader.d.ts","sourceRoot":"","sources":["../src/tilejson-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"tilejson-loader.d.ts","sourceRoot":"","sources":["../src/tilejson-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAmB,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAQ9E,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAAG;IAClD,qCAAqC;IACrC,QAAQ,CAAC,EAAE;QACT,kCAAkC;QAClC,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,KA4BkD,CAAC"}
|
package/dist/tilejson-loader.js
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
import { parseTileJSON } from "./lib/parse-tilejson.js";
|
|
5
5
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
6
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
-
const VERSION = typeof "4.2.0-alpha.
|
|
7
|
+
const VERSION = typeof "4.2.0-alpha.6" !== 'undefined' ? "4.2.0-alpha.6" : 'latest';
|
|
8
8
|
/**
|
|
9
9
|
* Loader for TileJSON metadata
|
|
10
10
|
*/
|
|
11
11
|
export const TileJSONLoader = {
|
|
12
|
+
dataType: null,
|
|
13
|
+
batchType: null,
|
|
12
14
|
name: 'TileJSON',
|
|
13
15
|
id: 'tilejson',
|
|
14
16
|
module: 'pmtiles',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/mvt",
|
|
3
3
|
"description": "Loader for Mapbox Vector Tiles",
|
|
4
|
-
"version": "4.2.0-
|
|
4
|
+
"version": "4.2.0-beta.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@loaders.gl/gis": "4.2.0-
|
|
45
|
-
"@loaders.gl/images": "4.2.0-
|
|
46
|
-
"@loaders.gl/loader-utils": "4.2.0-
|
|
47
|
-
"@loaders.gl/schema": "4.2.0-
|
|
44
|
+
"@loaders.gl/gis": "4.2.0-beta.1",
|
|
45
|
+
"@loaders.gl/images": "4.2.0-beta.1",
|
|
46
|
+
"@loaders.gl/loader-utils": "4.2.0-beta.1",
|
|
47
|
+
"@loaders.gl/schema": "4.2.0-beta.1",
|
|
48
48
|
"@math.gl/polygon": "^4.0.0",
|
|
49
49
|
"pbf": "^3.2.1"
|
|
50
50
|
},
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@loaders.gl/core": "^4.0.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "c386a9196516fe3ff24847b40e6c77be039cf905"
|
|
58
58
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
1
5
|
import Protobuf from 'pbf';
|
|
2
6
|
import {getPolygonSignedArea} from '@math.gl/polygon';
|
|
3
7
|
import {FlatIndexedGeometry, FlatPolygon} from '@loaders.gl/schema';
|
|
4
|
-
import
|
|
8
|
+
import {BinaryVectorTileFeature} from '../lib/binary-vector-tile/vector-tile-feature';
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Classifies an array of rings into polygons with outer rings and holes
|
|
@@ -97,7 +101,7 @@ export function project(data: number[], x0: number, y0: number, size: number): v
|
|
|
97
101
|
* @param feature
|
|
98
102
|
* @param pbf
|
|
99
103
|
*/
|
|
100
|
-
export function readFeature(tag: number, feature?:
|
|
104
|
+
export function readFeature(tag: number, feature?: BinaryVectorTileFeature, pbf?: Protobuf): void {
|
|
101
105
|
if (feature && pbf) {
|
|
102
106
|
if (tag === 1) feature.id = pbf.readVarint();
|
|
103
107
|
else if (tag === 2) readTag(pbf, feature);
|
|
@@ -110,7 +114,7 @@ export function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Prot
|
|
|
110
114
|
* @param pbf
|
|
111
115
|
* @param feature
|
|
112
116
|
*/
|
|
113
|
-
export function readTag(pbf: Protobuf, feature:
|
|
117
|
+
export function readTag(pbf: Protobuf, feature: BinaryVectorTileFeature): void {
|
|
114
118
|
const end = pbf.readVarint() + pbf.pos;
|
|
115
119
|
|
|
116
120
|
while (pbf.pos < end) {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
1
5
|
import Protobuf from 'pbf';
|
|
2
6
|
import {MVTMapboxGeometry} from '../lib/types';
|
|
3
|
-
import VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';
|
|
7
|
+
import {VectorTileFeature} from '../lib/mapbox-vector-tile/vector-tile-feature';
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Classifies an array of rings into polygons with outer rings and holes
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
export type {MVTLoaderOptions} from './
|
|
5
|
+
export type {MVTLoaderOptions} from './mvt-loader';
|
|
6
6
|
export {MVTLoader, MVTWorkerLoader} from './mvt-loader';
|
|
7
7
|
|
|
8
8
|
export type {TileJSON} from './lib/parse-tilejson';
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
1
5
|
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
2
6
|
|
|
3
7
|
import Protobuf from 'pbf';
|
|
@@ -17,7 +21,7 @@ export const TEST_EXPORTS = {
|
|
|
17
21
|
classifyRings
|
|
18
22
|
};
|
|
19
23
|
|
|
20
|
-
export
|
|
24
|
+
export class BinaryVectorTileFeature {
|
|
21
25
|
properties: {[x: string]: string | number | boolean | null};
|
|
22
26
|
extent: any;
|
|
23
27
|
type: number;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
1
5
|
/* eslint-disable indent */
|
|
2
6
|
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
3
7
|
|
|
4
|
-
import
|
|
8
|
+
import {BinaryVectorTileFeature} from './vector-tile-feature';
|
|
5
9
|
import Protobuf from 'pbf';
|
|
6
10
|
import {GeojsonGeometryInfo} from '@loaders.gl/schema';
|
|
7
11
|
|
|
8
|
-
export
|
|
12
|
+
export class BinaryVectorTileLayer {
|
|
9
13
|
version: number;
|
|
10
14
|
name: string;
|
|
11
15
|
extent: number;
|
|
@@ -33,13 +37,13 @@ export default class VectorTileLayer {
|
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
/**
|
|
36
|
-
* return feature `i` from this layer as a `
|
|
40
|
+
* return feature `i` from this layer as a `BinaryVectorTileFeature`
|
|
37
41
|
*
|
|
38
42
|
* @param index
|
|
39
43
|
* @param geometryInfo
|
|
40
|
-
* @returns {
|
|
44
|
+
* @returns {BinaryVectorTileFeature}
|
|
41
45
|
*/
|
|
42
|
-
feature(i: number, geometryInfo: GeojsonGeometryInfo):
|
|
46
|
+
feature(i: number, geometryInfo: GeojsonGeometryInfo): BinaryVectorTileFeature {
|
|
43
47
|
if (i < 0 || i >= this._features.length) {
|
|
44
48
|
throw new Error('feature index out of bounds');
|
|
45
49
|
}
|
|
@@ -47,7 +51,7 @@ export default class VectorTileLayer {
|
|
|
47
51
|
this._pbf.pos = this._features[i];
|
|
48
52
|
|
|
49
53
|
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
50
|
-
return new
|
|
54
|
+
return new BinaryVectorTileFeature(
|
|
51
55
|
this._pbf,
|
|
52
56
|
end,
|
|
53
57
|
this.extent,
|
|
@@ -64,7 +68,7 @@ export default class VectorTileLayer {
|
|
|
64
68
|
* @param layer
|
|
65
69
|
* @param pbf
|
|
66
70
|
*/
|
|
67
|
-
function readLayer(tag: number, layer?:
|
|
71
|
+
function readLayer(tag: number, layer?: BinaryVectorTileLayer, pbf?: Protobuf): void {
|
|
68
72
|
if (layer && pbf) {
|
|
69
73
|
if (tag === 15) layer.version = pbf.readVarint();
|
|
70
74
|
else if (tag === 1) layer.name = pbf.readString();
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
1
5
|
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
2
6
|
|
|
3
|
-
import
|
|
7
|
+
import {BinaryVectorTileLayer} from './vector-tile-layer';
|
|
4
8
|
import Protobuf from 'pbf';
|
|
5
9
|
|
|
6
|
-
export
|
|
7
|
-
layers: {[x: string]:
|
|
10
|
+
export class BinaryVectorTile {
|
|
11
|
+
layers: {[x: string]: BinaryVectorTileLayer};
|
|
8
12
|
constructor(pbf: Protobuf, end?: number) {
|
|
9
13
|
this.layers = pbf.readFields(readTile, {}, end);
|
|
10
14
|
}
|
|
@@ -16,10 +20,14 @@ export default class VectorTile {
|
|
|
16
20
|
* @param layers
|
|
17
21
|
* @param pbf
|
|
18
22
|
*/
|
|
19
|
-
function readTile(
|
|
23
|
+
function readTile(
|
|
24
|
+
tag: number,
|
|
25
|
+
layers?: {[x: string]: BinaryVectorTileLayer},
|
|
26
|
+
pbf?: Protobuf
|
|
27
|
+
): void {
|
|
20
28
|
if (tag === 3) {
|
|
21
29
|
if (pbf) {
|
|
22
|
-
const layer = new
|
|
30
|
+
const layer = new BinaryVectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
|
|
23
31
|
if (layer.length && layers) {
|
|
24
32
|
layers[layer.name] = layer;
|
|
25
33
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
1
5
|
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
2
6
|
import Protobuf from 'pbf';
|
|
3
7
|
import {MVTMapboxCoordinates, MVTMapboxGeometry} from '../types';
|
|
4
8
|
import {readFeature, classifyRings} from '../../helpers/mapbox-util-functions';
|
|
5
9
|
|
|
6
|
-
export
|
|
10
|
+
export class VectorTileFeature {
|
|
7
11
|
properties: {[x: string]: string | number | boolean | null};
|
|
8
12
|
extent: any;
|
|
9
13
|
type: number;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
1
5
|
/* eslint-disable indent */
|
|
2
6
|
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
3
7
|
|
|
4
8
|
import Protobuf from 'pbf';
|
|
5
|
-
import VectorTileFeature from './vector-tile-feature';
|
|
9
|
+
import {VectorTileFeature} from './vector-tile-feature';
|
|
6
10
|
|
|
7
|
-
export
|
|
11
|
+
export class VectorTileLayer {
|
|
8
12
|
version: number;
|
|
9
13
|
name: string;
|
|
10
14
|
extent: number;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
1
5
|
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
2
6
|
|
|
3
|
-
import VectorTileLayer from './vector-tile-layer';
|
|
7
|
+
import {VectorTileLayer} from './vector-tile-layer';
|
|
4
8
|
import Protobuf from 'pbf';
|
|
5
9
|
|
|
6
|
-
export
|
|
10
|
+
export class VectorTile {
|
|
7
11
|
layers: {[x: string]: VectorTileLayer};
|
|
8
12
|
constructor(pbf: Protobuf, end?: number) {
|
|
9
13
|
this.layers = pbf.readFields(readTile, {}, end);
|
package/src/lib/parse-mvt.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
1
5
|
import {flatGeojsonToBinary} from '@loaders.gl/gis';
|
|
2
6
|
import type {
|
|
3
7
|
FlatFeature,
|
|
@@ -8,12 +12,13 @@ import type {
|
|
|
8
12
|
} from '@loaders.gl/schema';
|
|
9
13
|
import Protobuf from 'pbf';
|
|
10
14
|
|
|
11
|
-
import type {MVTMapboxCoordinates, MVTOptions
|
|
15
|
+
import type {MVTMapboxCoordinates, MVTOptions} from '../lib/types';
|
|
16
|
+
import type {MVTLoaderOptions} from '../mvt-loader';
|
|
12
17
|
|
|
13
|
-
import VectorTile from './mapbox-vector-tile/vector-tile';
|
|
14
|
-
import BinaryVectorTile from './binary-vector-tile/vector-tile';
|
|
15
|
-
import
|
|
16
|
-
import VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';
|
|
18
|
+
import {VectorTile} from './mapbox-vector-tile/vector-tile';
|
|
19
|
+
import {BinaryVectorTile} from './binary-vector-tile/vector-tile';
|
|
20
|
+
import {BinaryVectorTileFeature} from './binary-vector-tile/vector-tile-feature';
|
|
21
|
+
import {VectorTileFeature as VectorTileFeatureMapBox} from './mapbox-vector-tile/vector-tile-feature';
|
|
17
22
|
|
|
18
23
|
/**
|
|
19
24
|
* Parse MVT arrayBuffer and return GeoJSON.
|
|
@@ -22,7 +27,7 @@ import VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';
|
|
|
22
27
|
* @param options
|
|
23
28
|
* @returns A GeoJSON geometry object or a binary representation
|
|
24
29
|
*/
|
|
25
|
-
export
|
|
30
|
+
export function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions) {
|
|
26
31
|
const mvtOptions = normalizeOptions(options);
|
|
27
32
|
|
|
28
33
|
const shape: string | undefined =
|
|
@@ -179,12 +184,12 @@ function getDecodedFeature(
|
|
|
179
184
|
* @returns decoded binary feature
|
|
180
185
|
*/
|
|
181
186
|
function getDecodedFeatureBinary(
|
|
182
|
-
feature:
|
|
187
|
+
feature: BinaryVectorTileFeature,
|
|
183
188
|
options: MVTOptions,
|
|
184
189
|
layerName: string
|
|
185
190
|
): FlatFeature {
|
|
186
191
|
const decodedFeature = feature.toBinaryCoordinates(
|
|
187
|
-
// @ts-expect-error
|
|
192
|
+
// @ts-expect-error
|
|
188
193
|
options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary
|
|
189
194
|
);
|
|
190
195
|
|
package/src/lib/types.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
2
4
|
|
|
3
5
|
/** For local coordinates, the tileIndex is not required */
|
|
4
6
|
type MVTLocalCoordinatesOptions = {
|
|
@@ -55,13 +57,3 @@ export type MVTMapboxCoordinates = {
|
|
|
55
57
|
properties: {[x: string]: string | number | boolean | null};
|
|
56
58
|
id?: number;
|
|
57
59
|
};
|
|
58
|
-
|
|
59
|
-
export type MVTLoaderOptions = LoaderOptions & {
|
|
60
|
-
mvt?: MVTOptions;
|
|
61
|
-
gis?: {
|
|
62
|
-
/** `true`: parser will output the data in binary format. Equivalent to loading the data as GeoJSON and then applying geojsonToBinary */
|
|
63
|
-
binary?: boolean;
|
|
64
|
-
/** @deprecated. Use options.mvt.shape */
|
|
65
|
-
format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
66
|
-
};
|
|
67
|
-
};
|
package/src/mvt-loader.ts
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// GeoJsonProperties
|
|
9
|
-
// } from '@loaders.gl/schema';
|
|
10
|
-
import parseMVT from './lib/parse-mvt';
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
6
|
+
import {parseMVT} from './lib/parse-mvt';
|
|
7
|
+
import type {MVTOptions} from './lib/types';
|
|
11
8
|
|
|
12
9
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
13
10
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
14
11
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
15
12
|
|
|
13
|
+
export type MVTLoaderOptions = LoaderOptions & {
|
|
14
|
+
mvt?: MVTOptions & {
|
|
15
|
+
/** Override the URL to the worker bundle (by default loads from unpkg.com) */
|
|
16
|
+
workerUrl?: string;
|
|
17
|
+
};
|
|
18
|
+
gis?: {
|
|
19
|
+
/** `true`: parser will output the data in binary format. Equivalent to loading the data as GeoJSON and then applying geojsonToBinary */
|
|
20
|
+
binary?: boolean;
|
|
21
|
+
/** @deprecated. Use options.mvt.shape */
|
|
22
|
+
format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
16
26
|
/**
|
|
17
27
|
* Worker loader for the Mapbox Vector Tile format
|
|
18
28
|
*/
|
|
19
|
-
export const MVTWorkerLoader
|
|
20
|
-
|
|
21
|
-
never,
|
|
22
|
-
|
|
23
|
-
> = {
|
|
29
|
+
export const MVTWorkerLoader = {
|
|
30
|
+
dataType: null as any,
|
|
31
|
+
batchType: null as never,
|
|
32
|
+
|
|
24
33
|
name: 'Mapbox Vector Tile',
|
|
25
34
|
id: 'mvt',
|
|
26
35
|
module: 'mvt',
|
|
@@ -44,18 +53,22 @@ export const MVTWorkerLoader: Loader<
|
|
|
44
53
|
tileIndex: null
|
|
45
54
|
}
|
|
46
55
|
}
|
|
47
|
-
}
|
|
56
|
+
} as const satisfies Loader<
|
|
57
|
+
any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
|
|
58
|
+
never,
|
|
59
|
+
MVTLoaderOptions
|
|
60
|
+
>;
|
|
48
61
|
|
|
49
62
|
/**
|
|
50
63
|
* Loader for the Mapbox Vector Tile format
|
|
51
64
|
*/
|
|
52
|
-
export const MVTLoader
|
|
53
|
-
any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
|
|
54
|
-
never,
|
|
55
|
-
MVTLoaderOptions
|
|
56
|
-
> = {
|
|
65
|
+
export const MVTLoader = {
|
|
57
66
|
...MVTWorkerLoader,
|
|
58
67
|
parse: async (arrayBuffer, options?: MVTLoaderOptions) => parseMVT(arrayBuffer, options),
|
|
59
68
|
parseSync: parseMVT,
|
|
60
69
|
binary: true
|
|
61
|
-
}
|
|
70
|
+
} as const satisfies LoaderWithParser<
|
|
71
|
+
any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
|
|
72
|
+
never,
|
|
73
|
+
MVTLoaderOptions
|
|
74
|
+
>;
|
package/src/tilejson-loader.ts
CHANGED
|
@@ -21,7 +21,10 @@ export type TileJSONLoaderOptions = LoaderOptions & {
|
|
|
21
21
|
/**
|
|
22
22
|
* Loader for TileJSON metadata
|
|
23
23
|
*/
|
|
24
|
-
export const TileJSONLoader
|
|
24
|
+
export const TileJSONLoader = {
|
|
25
|
+
dataType: null as unknown as TileJSON,
|
|
26
|
+
batchType: null as never,
|
|
27
|
+
|
|
25
28
|
name: 'TileJSON',
|
|
26
29
|
id: 'tilejson',
|
|
27
30
|
module: 'pmtiles',
|
|
@@ -46,4 +49,4 @@ export const TileJSONLoader: LoaderWithParser<TileJSON, never, TileJSONLoaderOpt
|
|
|
46
49
|
const tilejsonOptions = {...TileJSONLoader.options.tilejson, ...options?.tilejson};
|
|
47
50
|
return parseTileJSON(json, tilejsonOptions) as TileJSON;
|
|
48
51
|
}
|
|
49
|
-
}
|
|
52
|
+
} as const satisfies LoaderWithParser<TileJSON, never, TileJSONLoaderOptions>;
|