@loaders.gl/mvt 4.0.0-alpha.4 → 4.0.0-alpha.5
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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/dist.min.js +2289 -0
- package/dist/helpers/binary-util-functions.d.ts +35 -0
- package/dist/helpers/binary-util-functions.d.ts.map +1 -0
- package/dist/helpers/binary-util-functions.js +8 -5
- package/dist/helpers/binary-util-functions.js.map +1 -1
- package/dist/helpers/mapbox-util-functions.d.ts +29 -0
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +41 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +31 -30
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +2 -2
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +27 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/parse-mvt.d.ts +17 -0
- package/dist/lib/parse-mvt.d.ts.map +1 -0
- package/dist/lib/parse-mvt.js +6 -5
- package/dist/lib/parse-mvt.js.map +1 -1
- package/dist/lib/types.d.ts +28 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/mvt-loader.d.ts +10 -0
- package/dist/mvt-loader.d.ts.map +1 -0
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-worker.js +103 -98
- package/dist/workers/mvt-worker.d.ts +2 -0
- package/dist/workers/mvt-worker.d.ts.map +1 -0
- package/package.json +8 -7
- package/src/helpers/binary-util-functions.ts +9 -7
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +36 -44
- package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
- package/src/lib/parse-mvt.ts +11 -9
- package/src/lib/types.ts +0 -69
- package/dist/lib/binary-vector-tile/features-to-binary.js +0 -327
- package/dist/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Protobuf from 'pbf';
|
|
2
|
+
import { FlatIndexedGeometry, FlatPolygon } from '@loaders.gl/schema';
|
|
3
|
+
import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
|
|
4
|
+
/**
|
|
5
|
+
* Classifies an array of rings into polygons with outer rings and holes
|
|
6
|
+
* The function also detects holes which have zero area and
|
|
7
|
+
* removes them. In doing so it modifies the input
|
|
8
|
+
* `geom.data` array to remove the unneeded data
|
|
9
|
+
*
|
|
10
|
+
* @param geometry
|
|
11
|
+
* @returns object
|
|
12
|
+
*/
|
|
13
|
+
export declare function classifyRings(geom: FlatIndexedGeometry): FlatPolygon;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param data
|
|
17
|
+
* @param x0
|
|
18
|
+
* @param y0
|
|
19
|
+
* @param size
|
|
20
|
+
*/
|
|
21
|
+
export declare function project(data: number[], x0: number, y0: number, size: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* All code below is unchanged from the original Mapbox implemenation
|
|
24
|
+
*
|
|
25
|
+
* @param tag
|
|
26
|
+
* @param feature
|
|
27
|
+
* @param pbf
|
|
28
|
+
*/
|
|
29
|
+
export declare function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Protobuf): void;
|
|
30
|
+
/**
|
|
31
|
+
* @param pbf
|
|
32
|
+
* @param feature
|
|
33
|
+
*/
|
|
34
|
+
export declare function readTag(pbf: Protobuf, feature: VectorTileFeature): void;
|
|
35
|
+
//# sourceMappingURL=binary-util-functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-util-functions.d.ts","sourceRoot":"","sources":["../../src/helpers/binary-util-functions.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,OAAO,EAAC,mBAAmB,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AACpE,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAE9E;;;;;;;;GAQG;AAEH,wBAAgB,aAAa,CAAC,IAAI,EAAE,mBAAmB,GAAG,WAAW,CA4DpE;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAMlF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAO1F;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAQvE"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { getPolygonSignedArea } from '@math.gl/polygon';
|
|
2
2
|
export function classifyRings(geom) {
|
|
3
|
-
const len = geom.
|
|
3
|
+
const len = geom.indices.length;
|
|
4
|
+
const type = 'Polygon';
|
|
4
5
|
|
|
5
6
|
if (len <= 1) {
|
|
6
7
|
return {
|
|
8
|
+
type,
|
|
7
9
|
data: geom.data,
|
|
8
10
|
areas: [[getPolygonSignedArea(geom.data)]],
|
|
9
|
-
|
|
11
|
+
indices: [geom.indices]
|
|
10
12
|
};
|
|
11
13
|
}
|
|
12
14
|
|
|
@@ -18,8 +20,8 @@ export function classifyRings(geom) {
|
|
|
18
20
|
let offset = 0;
|
|
19
21
|
|
|
20
22
|
for (let endIndex, i = 0, startIndex; i < len; i++) {
|
|
21
|
-
startIndex = geom.
|
|
22
|
-
endIndex = geom.
|
|
23
|
+
startIndex = geom.indices[i] - offset;
|
|
24
|
+
endIndex = geom.indices[i + 1] - offset || geom.data.length;
|
|
23
25
|
const shape = geom.data.slice(startIndex, endIndex);
|
|
24
26
|
const area = getPolygonSignedArea(shape);
|
|
25
27
|
|
|
@@ -50,8 +52,9 @@ export function classifyRings(geom) {
|
|
|
50
52
|
if (ringAreas) areas.push(ringAreas);
|
|
51
53
|
if (polygon.length) polygons.push(polygon);
|
|
52
54
|
return {
|
|
55
|
+
type,
|
|
53
56
|
areas,
|
|
54
|
-
|
|
57
|
+
indices: polygons,
|
|
55
58
|
data: geom.data
|
|
56
59
|
};
|
|
57
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/helpers/binary-util-functions.ts"],"names":["getPolygonSignedArea","classifyRings","geom","len","
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/binary-util-functions.ts"],"names":["getPolygonSignedArea","classifyRings","geom","len","indices","length","type","data","areas","polygons","ringAreas","polygon","ccw","offset","endIndex","i","startIndex","shape","slice","area","before","after","concat","undefined","push","project","x0","y0","size","j","jl","y2","Math","PI","atan","exp","readFeature","tag","feature","pbf","id","readVarint","readTag","_geometry","pos","end","key","_keys","value","_values","properties"],"mappings":"AACA,SAAQA,oBAAR,QAAmC,kBAAnC;AAcA,OAAO,SAASC,aAAT,CAAuBC,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AJ,EAAhB,CAAd;;AACAH,IAAAA,OAAO,CAACY,UAAR,CAAmBJ,GAAnB,IAA0BE,KAA1B;AACD;AACF","sourcesContent":["import Protobuf from 'pbf';\nimport {getPolygonSignedArea} from '@math.gl/polygon';\nimport {FlatIndexedGeometry, FlatPolygon} from '@loaders.gl/schema';\nimport VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';\n\n/**\n * Classifies an array of rings into polygons with outer rings and holes\n * The function also detects holes which have zero area and\n * removes them. In doing so it modifies the input\n * `geom.data` array to remove the unneeded data\n *\n * @param geometry\n * @returns object\n */\n// eslint-disable-next-line max-statements\nexport function classifyRings(geom: FlatIndexedGeometry): FlatPolygon {\n const len = geom.indices.length;\n const type = 'Polygon';\n\n if (len <= 1) {\n return {\n type,\n data: geom.data,\n areas: [[getPolygonSignedArea(geom.data)]],\n indices: [geom.indices]\n };\n }\n\n const areas: any[] = [];\n const polygons: any[] = [];\n let ringAreas: number[] = [];\n let polygon: number[] = [];\n let ccw: boolean | undefined;\n let offset = 0;\n\n for (let endIndex: number, i = 0, startIndex: number; i < len; i++) {\n startIndex = geom.indices[i] - offset;\n\n endIndex = geom.indices[i + 1] - offset || geom.data.length;\n const shape = geom.data.slice(startIndex, endIndex);\n const area = getPolygonSignedArea(shape);\n\n if (area === 0) {\n // This polygon has no area, so remove it from the shape\n // Remove the section from the data array\n const before = geom.data.slice(0, startIndex);\n const after = geom.data.slice(endIndex);\n geom.data = before.concat(after);\n\n // Need to offset any remaining indices as we have\n // modified the data buffer\n offset += endIndex - startIndex;\n\n // Do not add this index to the output and process next shape\n continue; // eslint-disable-line no-continue\n }\n\n if (ccw === undefined) ccw = area < 0;\n\n if (ccw === area < 0) {\n if (polygon.length) {\n areas.push(ringAreas);\n polygons.push(polygon);\n }\n polygon = [startIndex];\n ringAreas = [area];\n } else {\n ringAreas.push(area);\n polygon.push(startIndex);\n }\n }\n if (ringAreas) areas.push(ringAreas);\n if (polygon.length) polygons.push(polygon);\n\n return {type, areas, indices: polygons, data: geom.data};\n}\n\n/**\n *\n * @param data\n * @param x0\n * @param y0\n * @param size\n */\nexport function project(data: number[], x0: number, y0: number, size: number): void {\n for (let j = 0, jl = data.length; j < jl; j += 2) {\n data[j] = ((data[j] + x0) * 360) / size - 180;\n const y2 = 180 - ((data[j + 1] + y0) * 360) / size;\n data[j + 1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;\n }\n}\n\n/**\n * All code below is unchanged from the original Mapbox implemenation\n *\n * @param tag\n * @param feature\n * @param pbf\n */\nexport function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Protobuf): void {\n if (feature && pbf) {\n if (tag === 1) feature.id = pbf.readVarint();\n else if (tag === 2) readTag(pbf, feature);\n else if (tag === 3) feature.type = pbf.readVarint();\n else if (tag === 4) feature._geometry = pbf.pos;\n }\n}\n\n/**\n * @param pbf\n * @param feature\n */\nexport function readTag(pbf: Protobuf, feature: VectorTileFeature): void {\n const end = pbf.readVarint() + pbf.pos;\n\n while (pbf.pos < end) {\n const key = feature._keys[pbf.readVarint()];\n const value = feature._values[pbf.readVarint()];\n feature.properties[key] = value;\n }\n}\n"],"file":"binary-util-functions.js"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Protobuf from 'pbf';
|
|
2
|
+
import { MvtMapboxGeometry } from '../lib/types';
|
|
3
|
+
import VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';
|
|
4
|
+
/**
|
|
5
|
+
* Classifies an array of rings into polygons with outer rings and holes
|
|
6
|
+
* @param rings
|
|
7
|
+
* @returns polygons
|
|
8
|
+
*/
|
|
9
|
+
export declare function classifyRings(rings: MvtMapboxGeometry): MvtMapboxGeometry[] | number[][][];
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param ring
|
|
13
|
+
* @returns sum
|
|
14
|
+
*/
|
|
15
|
+
export declare function signedArea(ring: number[][]): number;
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param tag
|
|
19
|
+
* @param feature
|
|
20
|
+
* @param pbf
|
|
21
|
+
*/
|
|
22
|
+
export declare function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Protobuf): void;
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param pbf
|
|
26
|
+
* @param feature
|
|
27
|
+
*/
|
|
28
|
+
export declare function readTag(pbf: Protobuf, feature: VectorTileFeature): void;
|
|
29
|
+
//# sourceMappingURL=mapbox-util-functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapbox-util-functions.d.ts","sourceRoot":"","sources":["../../src/helpers/mapbox-util-functions.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAC/C,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAE9E;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,sCAuBrD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,UAQ1C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAO1F;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAQvE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Protobuf from 'pbf';
|
|
2
|
+
import { FlatFeature, FlatIndexedGeometry, GeojsonGeometryInfo } from '@loaders.gl/schema';
|
|
3
|
+
import { classifyRings } from '../../helpers/binary-util-functions';
|
|
4
|
+
export declare const TEST_EXPORTS: {
|
|
5
|
+
classifyRings: typeof classifyRings;
|
|
6
|
+
};
|
|
7
|
+
export default class VectorTileFeature {
|
|
8
|
+
properties: {
|
|
9
|
+
[x: string]: string | number | boolean | null;
|
|
10
|
+
};
|
|
11
|
+
extent: any;
|
|
12
|
+
type: number;
|
|
13
|
+
id: number | null;
|
|
14
|
+
_pbf: Protobuf;
|
|
15
|
+
_geometry: number;
|
|
16
|
+
_keys: string[];
|
|
17
|
+
_values: (string | number | boolean | null)[];
|
|
18
|
+
_geometryInfo: GeojsonGeometryInfo;
|
|
19
|
+
constructor(pbf: Protobuf, end: number, extent: any, keys: string[], values: (string | number | boolean | null)[], geometryInfo: GeojsonGeometryInfo);
|
|
20
|
+
loadGeometry(): FlatIndexedGeometry;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param transform
|
|
24
|
+
* @returns result
|
|
25
|
+
*/
|
|
26
|
+
_toBinaryCoordinates(transform: any): {
|
|
27
|
+
type: "Feature";
|
|
28
|
+
geometry: import("@loaders.gl/schema").FlatGeometry;
|
|
29
|
+
id?: string | number | undefined;
|
|
30
|
+
properties: import("geojson").GeoJsonProperties;
|
|
31
|
+
bbox?: import("geojson").BBox | undefined;
|
|
32
|
+
};
|
|
33
|
+
toBinaryCoordinates(options: {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
z: number;
|
|
37
|
+
} | ((data: number[], feature: {
|
|
38
|
+
extent: any;
|
|
39
|
+
}) => void)): FlatFeature;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=vector-tile-feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AAEA,OAAO,Q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-11,11 +11,7 @@ export const TEST_EXPORTS = {
|
|
|
11
11
|
classifyRings
|
|
12
12
|
};
|
|
13
13
|
export default class VectorTileFeature {
|
|
14
|
-
|
|
15
|
-
return ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
constructor(pbf, end, extent, keys, values, firstPassData) {
|
|
14
|
+
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
19
15
|
_defineProperty(this, "properties", void 0);
|
|
20
16
|
|
|
21
17
|
_defineProperty(this, "extent", void 0);
|
|
@@ -32,7 +28,7 @@ export default class VectorTileFeature {
|
|
|
32
28
|
|
|
33
29
|
_defineProperty(this, "_values", void 0);
|
|
34
30
|
|
|
35
|
-
_defineProperty(this, "
|
|
31
|
+
_defineProperty(this, "_geometryInfo", void 0);
|
|
36
32
|
|
|
37
33
|
this.properties = {};
|
|
38
34
|
this.extent = extent;
|
|
@@ -42,7 +38,7 @@ export default class VectorTileFeature {
|
|
|
42
38
|
this._geometry = -1;
|
|
43
39
|
this._keys = keys;
|
|
44
40
|
this._values = values;
|
|
45
|
-
this.
|
|
41
|
+
this._geometryInfo = geometryInfo;
|
|
46
42
|
pbf.readFields(readFeature, this, end);
|
|
47
43
|
}
|
|
48
44
|
|
|
@@ -55,7 +51,7 @@ export default class VectorTileFeature {
|
|
|
55
51
|
x = 0;
|
|
56
52
|
y = 0;
|
|
57
53
|
i = 0;
|
|
58
|
-
const
|
|
54
|
+
const indices = [];
|
|
59
55
|
const data = [];
|
|
60
56
|
|
|
61
57
|
while (pbf.pos < endPos) {
|
|
@@ -72,14 +68,14 @@ export default class VectorTileFeature {
|
|
|
72
68
|
y += pbf.readSVarint();
|
|
73
69
|
|
|
74
70
|
if (cmd === 1) {
|
|
75
|
-
|
|
71
|
+
indices.push(i);
|
|
76
72
|
}
|
|
77
73
|
|
|
78
74
|
data.push(x, y);
|
|
79
75
|
i += 2;
|
|
80
76
|
} else if (cmd === 7) {
|
|
81
77
|
if (i > 0) {
|
|
82
|
-
const start =
|
|
78
|
+
const start = indices[indices.length - 1];
|
|
83
79
|
data.push(data[start], data[start + 1]);
|
|
84
80
|
i += 2;
|
|
85
81
|
}
|
|
@@ -90,50 +86,55 @@ export default class VectorTileFeature {
|
|
|
90
86
|
|
|
91
87
|
return {
|
|
92
88
|
data,
|
|
93
|
-
|
|
89
|
+
indices
|
|
94
90
|
};
|
|
95
91
|
}
|
|
96
92
|
|
|
97
93
|
_toBinaryCoordinates(transform) {
|
|
98
|
-
|
|
94
|
+
const geom = this.loadGeometry();
|
|
95
|
+
let geometry;
|
|
99
96
|
transform(geom.data, this);
|
|
100
97
|
const coordLength = 2;
|
|
101
98
|
|
|
102
99
|
switch (this.type) {
|
|
103
100
|
case 1:
|
|
104
|
-
this.
|
|
105
|
-
this.
|
|
101
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
102
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
103
|
+
geometry = {
|
|
104
|
+
type: 'Point',
|
|
105
|
+
...geom
|
|
106
|
+
};
|
|
106
107
|
break;
|
|
107
108
|
|
|
108
109
|
case 2:
|
|
109
|
-
this.
|
|
110
|
-
this.
|
|
111
|
-
this.
|
|
110
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
111
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
112
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
113
|
+
geometry = {
|
|
114
|
+
type: 'LineString',
|
|
115
|
+
...geom
|
|
116
|
+
};
|
|
112
117
|
break;
|
|
113
118
|
|
|
114
119
|
case 3:
|
|
115
|
-
|
|
116
|
-
this.
|
|
117
|
-
this.
|
|
120
|
+
geometry = classifyRings(geom);
|
|
121
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
122
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
118
123
|
|
|
119
|
-
for (const
|
|
120
|
-
this.
|
|
124
|
+
for (const indices of geometry.indices) {
|
|
125
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
121
126
|
}
|
|
122
127
|
|
|
123
|
-
this.
|
|
124
|
-
geom = classified;
|
|
128
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
125
129
|
break;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
geom.type = VectorTileFeature.types[this.type];
|
|
129
130
|
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
default:
|
|
132
|
+
throw new Error("Invalid geometry type: ".concat(this.type));
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
const result = {
|
|
135
136
|
type: 'Feature',
|
|
136
|
-
geometry
|
|
137
|
+
geometry,
|
|
137
138
|
properties: this.properties
|
|
138
139
|
};
|
|
139
140
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":["classifyRings","project","readFeature","endPos","cmd","cmdLen","length","x","y","i","TEST_EXPORTS","VectorTileFeature","types","constructor","pbf","end","extent","keys","values","firstPassData","properties","type","id","_pbf","_geometry","_keys","_values","_firstPassData","readFields","loadGeometry","pos","readVarint","lines","data","readSVarint","push","start","Error","_toBinaryCoordinates","transform","geom","coordLength","pointFeaturesCount","pointPositionsCount","lineFeaturesCount","linePathsCount","linePositionsCount","classified","polygonFeaturesCount","polygonObjectsCount","polygonRingsCount","polygonPositionsCount","result","geometry","toBinaryCoordinates","options"],"mappings":";AAIA,SAAQA,aAAR,EAAuBC,OAAvB,EAAgCC,WAAhC,QAAkD,qCAAlD;AAGA,IAAIC,MAAJ;AACA,IAAIC,GAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AAEA,OAAO,MAAMC,YAAY,GAAG;AAC1BV,EAAAA;AAD0B,CAArB;AAIP,eAAe,MAAMW,iBAAN,CAAwB;AAUrB,aAALC,KAAK,GAAG;AAC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DE,EAAAA,mBAAmB,CACjBC,OADiB,EAEK;AACtB,QAAI,OAAOA,OAAP,KAAmB,UAAvB,EAAmC;AACjC,aAAO,KAAKjB,oBAAL,CAA0BiB,OAA1B,CAAP;AACD;;AACD,WAAO,KAAKjB,oBAAL,CAA0BrC,OAA1B,CAAP;AACD;;AArLoC","sourcesContent":["// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport Protobuf from 'pbf';\nimport {MvtBinaryCoordinates, MvtBinaryGeometry, MvtFirstPassedData} from '../types';\nimport {classifyRings, project, readFeature} from '../../helpers/binary-util-functions';\n\n// Reduce GC by reusing variables\nlet endPos: number;\nlet cmd: number;\nlet cmdLen: number;\nlet length: number;\nlet x: number;\nlet y: number;\nlet i: number;\n\nexport const TEST_EXPORTS = {\n classifyRings\n};\n\nexport default class VectorTileFeature {\n properties: {[x: string]: string | number | boolean | null};\n extent: any;\n type: number;\n id: number | null;\n _pbf: Protobuf;\n _geometry: number;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n _firstPassData: MvtFirstPassedData;\n static get types() {\n return ['Unknown', 'Point', 'LineString', 'Polygon'];\n }\n\n // eslint-disable-next-line max-params\n constructor(\n pbf: Protobuf,\n end: number,\n extent: any,\n keys: string[],\n values: (string | number | boolean | null)[],\n firstPassData: MvtFirstPassedData\n ) {\n // Public\n this.properties = {};\n this.extent = extent;\n this.type = 0;\n this.id = null;\n\n // Private\n this._pbf = pbf;\n this._geometry = -1;\n this._keys = keys;\n this._values = values;\n this._firstPassData = firstPassData;\n\n pbf.readFields(readFeature, this, end);\n }\n\n // eslint-disable-next-line complexity, max-statements\n loadGeometry(): MvtBinaryGeometry {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n endPos = pbf.readVarint() + pbf.pos;\n cmd = 1;\n length = 0;\n x = 0;\n y = 0;\n i = 0;\n\n // Note: I attempted to replace the `data` array with a\n // Float32Array, but performance was worse, both using\n // `set()` and direct index access. Also, we cannot\n // know how large the buffer should be, so it would\n // increase memory usage\n const lines: number[] = []; // Indices where lines start\n const data: number[] = []; // Flat array of coordinate data\n\n while (pbf.pos < endPos) {\n if (length <= 0) {\n cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n\n if (cmd === 1) {\n // New line\n lines.push(i);\n }\n data.push(x, y);\n i += 2;\n } else if (cmd === 7) {\n // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90\n if (i > 0) {\n const start = lines[lines.length - 1]; // start index of polygon\n data.push(data[start], data[start + 1]); // closePolygon\n i += 2;\n }\n } else {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n return {data, lines};\n }\n\n /**\n *\n * @param transform\n * @returns result\n */\n _toBinaryCoordinates(transform) {\n // Expands the protobuf data to an intermediate `lines`\n // data format, which maps closely to the binary data buffers.\n // It is similar to GeoJSON, but rather than storing the coordinates\n // in multidimensional arrays, we have a 1D `data` with all the\n // coordinates, and then index into this using the `lines`\n // parameter, e.g.\n //\n // geometry: {\n // type: 'Point', data: [1,2], lines: [0]\n // }\n // geometry: {\n // type: 'LineString', data: [1,2,3,4,...], lines: [0]\n // }\n // geometry: {\n // type: 'Polygon', data: [1,2,3,4,...], lines: [[0, 2]]\n // }\n // Thus the lines member lets us look up the relevant range\n // from the data array.\n // The Multi* versions of the above types share the same data\n // structure, just with multiple elements in the lines array\n let geom = this.loadGeometry();\n\n // Apply the supplied transformation to data\n transform(geom.data, this);\n\n const coordLength = 2;\n\n // eslint-disable-next-line default-case\n switch (this.type) {\n case 1: // Point\n this._firstPassData.pointFeaturesCount++;\n this._firstPassData.pointPositionsCount += geom.lines.length;\n break;\n\n case 2: // LineString\n this._firstPassData.lineFeaturesCount++;\n this._firstPassData.linePathsCount += geom.lines.length;\n this._firstPassData.linePositionsCount += geom.data.length / coordLength;\n break;\n\n case 3: // Polygon\n const classified = classifyRings(geom);\n\n // Unlike Point & LineString geom.lines is a 2D array, thanks\n // to the classifyRings method\n this._firstPassData.polygonFeaturesCount++;\n this._firstPassData.polygonObjectsCount += classified.lines.length;\n\n for (const lines of classified.lines) {\n this._firstPassData.polygonRingsCount += lines.length;\n }\n this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;\n\n geom = classified;\n break;\n }\n\n geom.type = VectorTileFeature.types[this.type];\n if (geom.lines.length > 1) {\n geom.type = `Multi${geom.type}`;\n }\n\n const result: MvtBinaryCoordinates = {\n type: 'Feature',\n geometry: geom,\n properties: this.properties\n };\n\n if (this.id !== null) {\n result.id = this.id;\n }\n\n return result;\n }\n\n toBinaryCoordinates(\n options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)\n ): MvtBinaryCoordinates {\n if (typeof options === 'function') {\n return this._toBinaryCoordinates(options);\n }\n return this._toBinaryCoordinates(project);\n }\n}\n"],"file":"vector-tile-feature.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":["classifyRings","project","readFeature","endPos","cmd","cmdLen","length","x","y","i","TEST_EXPORTS","VectorTileFeature","constructor","pbf","end","extent","keys","values","geometryInfo","properties","type","id","_pbf","_geometry","_keys","_values","_geometryInfo","readFields","loadGeometry","pos","readVarint","indices","data","readSVarint","push","start","Error","_toBinaryCoordinates","transform","geom","geometry","coordLength","pointFeaturesCount","pointPositionsCount","lineFeaturesCount","linePathsCount","linePositionsCount","polygonFeaturesCount","polygonObjectsCount","polygonRingsCount","polygonPositionsCount","result","toBinaryCoordinates","options"],"mappings":";AAIA,SAAQA,aAAR,EAAuBC,OAAvB,EAAgCC,WAAhC,QAAkD,qCAAlD;AAGA,IAAIC,MAAJ;AACA,IAAIC,GAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AAEA,OAAO,MAAMC,YAAY,GAAG;AAC1BV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iB,EAEJ;AACb,QAAI,OAAOA,OAAP,KAAmB,UAAvB,EAAmC;AACjC,aAAO,KAAKhB,oBAAL,CAA0BgB,OAA1B,CAAP;AACD;;AACD,WAAO,KAAKhB,oBAAL,CAA0BpC,OAA1B,CAAP;AACD;;AA7KoC","sourcesContent":["// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport Protobuf from 'pbf';\nimport {FlatFeature, FlatIndexedGeometry, GeojsonGeometryInfo} from '@loaders.gl/schema';\nimport {classifyRings, project, readFeature} from '../../helpers/binary-util-functions';\n\n// Reduce GC by reusing variables\nlet endPos: number;\nlet cmd: number;\nlet cmdLen: number;\nlet length: number;\nlet x: number;\nlet y: number;\nlet i: number;\n\nexport const TEST_EXPORTS = {\n classifyRings\n};\n\nexport default class VectorTileFeature {\n properties: {[x: string]: string | number | boolean | null};\n extent: any;\n type: number;\n id: number | null;\n _pbf: Protobuf;\n _geometry: number;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n _geometryInfo: GeojsonGeometryInfo;\n\n // eslint-disable-next-line max-params\n constructor(\n pbf: Protobuf,\n end: number,\n extent: any,\n keys: string[],\n values: (string | number | boolean | null)[],\n geometryInfo: GeojsonGeometryInfo\n ) {\n // Public\n this.properties = {};\n this.extent = extent;\n this.type = 0;\n this.id = null;\n\n // Private\n this._pbf = pbf;\n this._geometry = -1;\n this._keys = keys;\n this._values = values;\n this._geometryInfo = geometryInfo;\n\n pbf.readFields(readFeature, this, end);\n }\n\n // eslint-disable-next-line complexity, max-statements\n loadGeometry(): FlatIndexedGeometry {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n endPos = pbf.readVarint() + pbf.pos;\n cmd = 1;\n length = 0;\n x = 0;\n y = 0;\n i = 0;\n\n // Note: I attempted to replace the `data` array with a\n // Float32Array, but performance was worse, both using\n // `set()` and direct index access. Also, we cannot\n // know how large the buffer should be, so it would\n // increase memory usage\n const indices: number[] = []; // Indices where geometries start\n const data: number[] = []; // Flat array of coordinate data\n\n while (pbf.pos < endPos) {\n if (length <= 0) {\n cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n\n if (cmd === 1) {\n // New line\n indices.push(i);\n }\n data.push(x, y);\n i += 2;\n } else if (cmd === 7) {\n // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90\n if (i > 0) {\n const start = indices[indices.length - 1]; // start index of polygon\n data.push(data[start], data[start + 1]); // closePolygon\n i += 2;\n }\n } else {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n return {data, indices};\n }\n\n /**\n *\n * @param transform\n * @returns result\n */\n _toBinaryCoordinates(transform) {\n // Expands the protobuf data to an intermediate Flat GeoJSON\n // data format, which maps closely to the binary data buffers.\n // It is similar to GeoJSON, but rather than storing the coordinates\n // in multidimensional arrays, we have a 1D `data` with all the\n // coordinates, and then index into this using the `indices`\n // parameter, e.g.\n //\n // geometry: {\n // type: 'Point', data: [1,2], indices: [0]\n // }\n // geometry: {\n // type: 'LineString', data: [1,2,3,4,...], indices: [0]\n // }\n // geometry: {\n // type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]\n // }\n // Thus the indices member lets us look up the relevant range\n // from the data array.\n // The Multi* versions of the above types share the same data\n // structure, just with multiple elements in the indices array\n const geom = this.loadGeometry();\n let geometry;\n\n // Apply the supplied transformation to data\n transform(geom.data, this);\n\n const coordLength = 2;\n\n // eslint-disable-next-line default-case\n switch (this.type) {\n case 1: // Point\n this._geometryInfo.pointFeaturesCount++;\n this._geometryInfo.pointPositionsCount += geom.indices.length;\n geometry = {type: 'Point', ...geom};\n break;\n\n case 2: // LineString\n this._geometryInfo.lineFeaturesCount++;\n this._geometryInfo.linePathsCount += geom.indices.length;\n this._geometryInfo.linePositionsCount += geom.data.length / coordLength;\n geometry = {type: 'LineString', ...geom};\n break;\n\n case 3: // Polygon\n geometry = classifyRings(geom);\n\n // Unlike Point & LineString geom.indices is a 2D array, thanks\n // to the classifyRings method\n this._geometryInfo.polygonFeaturesCount++;\n this._geometryInfo.polygonObjectsCount += geometry.indices.length;\n\n for (const indices of geometry.indices) {\n this._geometryInfo.polygonRingsCount += indices.length;\n }\n this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;\n\n break;\n default:\n throw new Error(`Invalid geometry type: ${this.type}`);\n }\n\n const result: FlatFeature = {type: 'Feature', geometry, properties: this.properties};\n\n if (this.id !== null) {\n result.id = this.id;\n }\n\n return result;\n }\n\n toBinaryCoordinates(\n options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)\n ): FlatFeature {\n if (typeof options === 'function') {\n return this._toBinaryCoordinates(options);\n }\n return this._toBinaryCoordinates(project);\n }\n}\n"],"file":"vector-tile-feature.js"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import VectorTileFeature from './vector-tile-feature';
|
|
2
|
+
import Protobuf from 'pbf';
|
|
3
|
+
import { GeojsonGeometryInfo } from '@loaders.gl/schema';
|
|
4
|
+
export default class VectorTileLayer {
|
|
5
|
+
version: number;
|
|
6
|
+
name: string;
|
|
7
|
+
extent: number;
|
|
8
|
+
length: number;
|
|
9
|
+
_pbf: Protobuf;
|
|
10
|
+
_keys: string[];
|
|
11
|
+
_values: (string | number | boolean | null)[];
|
|
12
|
+
_features: number[];
|
|
13
|
+
constructor(pbf: Protobuf, end: number);
|
|
14
|
+
/**
|
|
15
|
+
* return feature `i` from this layer as a `VectorTileFeature`
|
|
16
|
+
*
|
|
17
|
+
* @param index
|
|
18
|
+
* @param geometryInfo
|
|
19
|
+
* @returns {VectorTileFeature}
|
|
20
|
+
*/
|
|
21
|
+
feature(i: number, geometryInfo: GeojsonGeometryInfo): VectorTileFeature;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=vector-tile-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AACtD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,SAAS,EAAE,MAAM,EAAE,CAAC;gBACR,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM;IAkBtC;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,mBAAmB,GAAG,iBAAiB;CAiBzE"}
|
|
@@ -30,7 +30,7 @@ export default class VectorTileLayer {
|
|
|
30
30
|
this.length = this._features.length;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
feature(i,
|
|
33
|
+
feature(i, geometryInfo) {
|
|
34
34
|
if (i < 0 || i >= this._features.length) {
|
|
35
35
|
throw new Error('feature index out of bounds');
|
|
36
36
|
}
|
|
@@ -39,7 +39,7 @@ export default class VectorTileLayer {
|
|
|
39
39
|
|
|
40
40
|
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
41
41
|
|
|
42
|
-
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values,
|
|
42
|
+
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":["VectorTileFeature","VectorTileLayer","constructor","pbf","end","version","name","extent","length","_pbf","_keys","_values","_features","readFields","readLayer","feature","i","
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":["VectorTileFeature","VectorTileLayer","constructor","pbf","end","version","name","extent","length","_pbf","_keys","_values","_features","readFields","readLayer","feature","i","geometryInfo","Error","pos","readVarint","tag","layer","readString","push","readValueMessage","value","readFloat","readDouble","readVarint64","readSVarint","readBoolean"],"mappings":";AAGA,OAAOA,iBAAP,MAA8B,uBAA9B;AAIA,eAAe,MAAMC,eAAN,CAAsB;AASnCC,EAAAA,WAAW,CAACC,GAAD,EAAgBC,GAAhB,EAA6B;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAEtC,SAAKC,OAAL,GAAe,CAAf;AACA,SAAKC,IAAL,GAAY,EAAZ;AACA,SAAKC,MAAL,GAAc,IAAd;AACA,SAAKC,MAAL,GAAc,CAAd;AAGA,SAAKC,IAAL,GAAYN,GAAZ;AACA,SAAKO,KAAL,GAAa,EAAb;AACA,SAAKC,OAAL,GAAe,EAAf;AACA,SAAKC,SAAL,GAAiB,EAAjB;AAEAT,IAAAA,GAAG,CAACU,UAAJ,CAAeC,SAAf,EAA0B,IAA1B,EAAgCV,GAAhC;AAEA,SAAKI,MAAL,GAAc,KAAKI,SAAL,CAAeJ,MAA7B;AACD;;AASDO,EAAAA,OAAO,CAACC,CAAD,EAAYC,YAAZ,EAAkE;AACvE,QAAID,CAAC,GAAG,CAAJ,IAASA,CAAC,IAAI,KAAKJ,SAAL,CAAeJ,MAAjC,EAAyC;AACvC,YAAM,IAAIU,KAAJ,CAAU,6BAAV,CAAN;AACD;;AAED,SAAKT,IAAL,CAAUU,GAAV,GAAgB,KAAKP,SAAL,CAAeI,CAAf,CAAhB;;AAEA,UAAMZ,GAAG,GAAG,KAAKK,IA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hC;AAEAM,IAAAA,KAAK,GACHL,GAAG,KAAK,CAAR,GACIlB,GAAG,CAACoB,UAAJ,EADJ,GAEIF,GAAG,KAAK,CAAR,GACAlB,GAAG,CAACwB,SAAJ,EADA,GAEAN,GAAG,KAAK,CAAR,GACAlB,GAAG,CAACyB,UAAJ,EADA,GAEAP,GAAG,KAAK,CAAR,GACAlB,GAAG,CAAC0B,YAAJ,EADA,GAEAR,GAAG,KAAK,CAAR,GACAlB,GAAG,CAACiB,UAAJ,EADA,GAEAC,GAAG,KAAK,CAAR,GACAlB,GAAG,CAAC2B,WAAJ,EADA,GAEAT,GAAG,KAAK,CAAR,GACAlB,GAAG,CAAC4B,WAAJ,EADA,GAEA,IAfN;AAgBD;;AAED,SAAOL,KAAP;AACD","sourcesContent":["/* eslint-disable indent */\n// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport VectorTileFeature from './vector-tile-feature';\nimport Protobuf from 'pbf';\nimport {GeojsonGeometryInfo} from '@loaders.gl/schema';\n\nexport default class VectorTileLayer {\n version: number;\n name: string;\n extent: number;\n length: number;\n _pbf: Protobuf;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n _features: number[];\n constructor(pbf: Protobuf, end: number) {\n // Public\n this.version = 1;\n this.name = '';\n this.extent = 4096;\n this.length = 0;\n\n // Private\n this._pbf = pbf;\n this._keys = [];\n this._values = [];\n this._features = [];\n\n pbf.readFields(readLayer, this, end);\n\n this.length = this._features.length;\n }\n\n /**\n * return feature `i` from this layer as a `VectorTileFeature`\n *\n * @param index\n * @param geometryInfo\n * @returns {VectorTileFeature}\n */\n feature(i: number, geometryInfo: GeojsonGeometryInfo): VectorTileFeature {\n if (i < 0 || i >= this._features.length) {\n throw new Error('feature index out of bounds');\n }\n\n this._pbf.pos = this._features[i];\n\n const end = this._pbf.readVarint() + this._pbf.pos;\n return new VectorTileFeature(\n this._pbf,\n end,\n this.extent,\n this._keys,\n this._values,\n geometryInfo\n );\n }\n}\n\n/**\n *\n * @param tag\n * @param layer\n * @param pbf\n */\nfunction readLayer(tag: number, layer?: VectorTileLayer, pbf?: Protobuf): void {\n if (layer && pbf) {\n if (tag === 15) layer.version = pbf.readVarint();\n else if (tag === 1) layer.name = pbf.readString();\n else if (tag === 5) layer.extent = pbf.readVarint();\n else if (tag === 2) layer._features.push(pbf.pos);\n else if (tag === 3) layer._keys.push(pbf.readString());\n else if (tag === 4) layer._values.push(readValueMessage(pbf));\n }\n}\n\n/**\n *\n * @param pbf\n * @returns value\n */\nfunction readValueMessage(pbf: Protobuf) {\n let value: string | number | boolean | null = null;\n const end = pbf.readVarint() + pbf.pos;\n\n while (pbf.pos < end) {\n const tag = pbf.readVarint() >> 3;\n\n value =\n tag === 1\n ? pbf.readString()\n : tag === 2\n ? pbf.readFloat()\n : tag === 3\n ? pbf.readDouble()\n : tag === 4\n ? pbf.readVarint64()\n : tag === 5\n ? pbf.readVarint()\n : tag === 6\n ? pbf.readSVarint()\n : tag === 7\n ? pbf.readBoolean()\n : null;\n }\n\n return value;\n}\n"],"file":"vector-tile-layer.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,MAAM,qBAAqB,CAAC;AAClD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,MAAM,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;KAAC,CAAC;gBAC3B,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM;CAGxC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Protobuf from 'pbf';
|
|
2
|
+
import { MvtMapboxCoordinates, MvtMapboxGeometry } from '../types';
|
|
3
|
+
export default class VectorTileFeature {
|
|
4
|
+
properties: {
|
|
5
|
+
[x: string]: string | number | boolean | null;
|
|
6
|
+
};
|
|
7
|
+
extent: any;
|
|
8
|
+
type: number;
|
|
9
|
+
id: number | null;
|
|
10
|
+
_pbf: Protobuf;
|
|
11
|
+
_geometry: number;
|
|
12
|
+
_keys: string[];
|
|
13
|
+
_values: (string | number | boolean | null)[];
|
|
14
|
+
static get types(): string[];
|
|
15
|
+
constructor(pbf: Protobuf, end: number, extent: any, keys: string[], values: (string | number | boolean | null)[]);
|
|
16
|
+
loadGeometry(): MvtMapboxGeometry;
|
|
17
|
+
bbox(): number[];
|
|
18
|
+
_toGeoJSON(transform: any): MvtMapboxCoordinates;
|
|
19
|
+
toGeoJSON(options: {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
z: number;
|
|
23
|
+
} | ((data: number[], feature: {
|
|
24
|
+
extent: any;
|
|
25
|
+
}) => void)): MvtMapboxCoordinates;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=vector-tile-feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,UAAU,CAAC;AAGjE,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,MAAM,KAAK,KAAK,aAEf;gBAGC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE;IAkB9C,YAAY,IAAI,iBAAiB;IA+CjC,IAAI;IAsCJ,UAAU,CAAC,SAAS,KAAA;IAuDpB,SAAS,CACP,OAAO,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE;QAAC,MAAM,EAAE,GAAG,CAAA;KAAC,KAAK,IAAI,CAAC,GAC9F,oBAAoB;CAmBxB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Protobuf from 'pbf';
|
|
2
|
+
import VectorTileFeature from './vector-tile-feature';
|
|
3
|
+
export default class VectorTileLayer {
|
|
4
|
+
version: number;
|
|
5
|
+
name: string;
|
|
6
|
+
extent: number;
|
|
7
|
+
length: number;
|
|
8
|
+
_pbf: Protobuf;
|
|
9
|
+
_keys: string[];
|
|
10
|
+
_values: (string | number | boolean | null)[];
|
|
11
|
+
_features: number[];
|
|
12
|
+
constructor(pbf: Protobuf, end: number);
|
|
13
|
+
/**
|
|
14
|
+
* return feature `i` from this layer as a `VectorTileFeature`
|
|
15
|
+
* @param index
|
|
16
|
+
* @returns feature
|
|
17
|
+
*/
|
|
18
|
+
feature(i: number): VectorTileFeature;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=vector-tile-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAGA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AAEtD,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,SAAS,EAAE,MAAM,EAAE,CAAC;gBACR,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM;IAkBtC;;;;OAIG;IAEH,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,iBAAiB;CAUtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,MAAM,qBAAqB,CAAC;AAClD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,MAAM,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;KAAC,CAAC;gBAC3B,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM;CAGxC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MvtMapboxCoordinates } from '../lib/types';
|
|
2
|
+
import { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
3
|
+
/**
|
|
4
|
+
* Parse MVT arrayBuffer and return GeoJSON.
|
|
5
|
+
*
|
|
6
|
+
* @param arrayBuffer A MVT arrayBuffer
|
|
7
|
+
* @param options
|
|
8
|
+
* @returns A GeoJSON geometry object or a binary representation
|
|
9
|
+
*/
|
|
10
|
+
export default function parseMVT(arrayBuffer: ArrayBuffer, options?: LoaderOptions): (MvtMapboxCoordinates | {
|
|
11
|
+
type: "Feature";
|
|
12
|
+
geometry: import("@loaders.gl/schema").FlatGeometry;
|
|
13
|
+
id?: string | number | undefined;
|
|
14
|
+
properties: import("geojson").GeoJsonProperties;
|
|
15
|
+
bbox?: import("geojson").BBox | undefined;
|
|
16
|
+
})[] | import("@loaders.gl/schema").BinaryFeatures;
|
|
17
|
+
//# sourceMappingURL=parse-mvt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,oBAAoB,EAAa,MAAM,cAAc,CAAC;AAGnE,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,aAAa;;;;;;mDA0DjF"}
|
package/dist/lib/parse-mvt.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import VectorTile from './mapbox-vector-tile/vector-tile';
|
|
2
2
|
import BinaryVectorTile from './binary-vector-tile/vector-tile';
|
|
3
|
-
import {
|
|
3
|
+
import { flatGeojsonToBinary } from '@loaders.gl/gis';
|
|
4
4
|
import Protobuf from 'pbf';
|
|
5
5
|
export default function parseMVT(arrayBuffer, options) {
|
|
6
6
|
options = normalizeOptions(options);
|
|
@@ -8,7 +8,8 @@ export default function parseMVT(arrayBuffer, options) {
|
|
|
8
8
|
|
|
9
9
|
if (options) {
|
|
10
10
|
const binary = options.gis.format === 'binary';
|
|
11
|
-
const
|
|
11
|
+
const geometryInfo = {
|
|
12
|
+
coordLength: 2,
|
|
12
13
|
pointPositionsCount: 0,
|
|
13
14
|
pointFeaturesCount: 0,
|
|
14
15
|
linePositionsCount: 0,
|
|
@@ -35,7 +36,7 @@ export default function parseMVT(arrayBuffer, options) {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
38
|
-
const vectorTileFeature = vectorTileLayer.feature(i,
|
|
39
|
+
const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
|
|
39
40
|
const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
|
|
40
41
|
features.push(decodedFeature);
|
|
41
42
|
}
|
|
@@ -43,7 +44,7 @@ export default function parseMVT(arrayBuffer, options) {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
if (binary) {
|
|
46
|
-
const data =
|
|
47
|
+
const data = flatGeojsonToBinary(features, geometryInfo);
|
|
47
48
|
data.byteLength = arrayBuffer.byteLength;
|
|
48
49
|
return data;
|
|
49
50
|
}
|
|
@@ -85,7 +86,7 @@ function getDecodedFeature(feature, options) {
|
|
|
85
86
|
function getDecodedFeatureBinary(feature, options) {
|
|
86
87
|
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
87
88
|
|
|
88
|
-
if (options.layerProperty) {
|
|
89
|
+
if (options.layerProperty && decodedFeature.properties) {
|
|
89
90
|
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
90
91
|
}
|
|
91
92
|
|