@loaders.gl/mvt 4.3.1 → 4.4.0-alpha.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 +151 -93
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +74 -78
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/pojo-parser/mvt-constants.d.ts +116 -0
- package/dist/lib/pojo-parser/mvt-constants.d.ts.map +1 -0
- package/dist/lib/pojo-parser/mvt-constants.js +126 -0
- package/dist/lib/pojo-parser/mvt-types.d.ts +17 -0
- package/dist/lib/pojo-parser/mvt-types.d.ts.map +1 -0
- package/dist/lib/pojo-parser/mvt-types.js +4 -0
- package/dist/lib/pojo-parser/parse-geometry-from-pbf.d.ts +77 -0
- package/dist/lib/pojo-parser/parse-geometry-from-pbf.d.ts.map +1 -0
- package/dist/lib/pojo-parser/parse-geometry-from-pbf.js +234 -0
- package/dist/lib/pojo-parser/parse-mvt-from-pbf.d.ts +25 -0
- package/dist/lib/pojo-parser/parse-mvt-from-pbf.d.ts.map +1 -0
- package/dist/lib/pojo-parser/parse-mvt-from-pbf.js +262 -0
- package/dist/lib/vector-tile/vector-tile-feature.d.ts +2 -1
- package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/vector-tile/vector-tile-layer.d.ts +1 -1
- package/dist/lib/vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/mvt-format.d.ts +12 -0
- package/dist/mvt-format.d.ts.map +1 -0
- package/dist/mvt-format.js +20 -0
- package/dist/mvt-loader.d.ts +12 -12
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +3 -13
- package/dist/mvt-source.d.ts +22 -24
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +14 -23
- package/dist/mvt-worker.js +20 -15
- package/dist/table-tile-source.d.ts +38 -38
- package/dist/table-tile-source.d.ts.map +1 -1
- package/dist/table-tile-source.js +54 -53
- package/dist/tilejson-loader.js +1 -1
- package/package.json +7 -7
- package/src/index.ts +2 -2
- package/src/lib/parse-mvt.ts +2 -8
- package/src/lib/pojo-parser/mvt-constants.ts +135 -0
- package/src/lib/pojo-parser/mvt-types.ts +22 -0
- package/src/lib/pojo-parser/parse-geometry-from-pbf.ts +285 -0
- package/src/lib/pojo-parser/parse-mvt-from-pbf.ts +310 -0
- package/src/lib/vector-tile/vector-tile-feature.ts +2 -6
- package/src/lib/vector-tile/vector-tile-layer.ts +1 -1
- package/src/mvt-format.ts +23 -0
- package/src/mvt-loader.ts +2 -13
- package/src/mvt-source.ts +33 -38
- package/src/table-tile-source.ts +116 -96
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { TileJSON } from "./lib/parse-tilejson.js";
|
|
|
4
4
|
export { MVTLoader, MVTWorkerLoader } from "./mvt-loader.js";
|
|
5
5
|
export type { MVTLoaderOptions } from "./mvt-loader.js";
|
|
6
6
|
export { MVTSource } from "./mvt-source.js";
|
|
7
|
-
export type { MVTTileSource,
|
|
7
|
+
export type { MVTTileSource, MVTSourceOptions } from "./mvt-source.js";
|
|
8
|
+
export type { TableTileSourceOptions, TableVectorTileSource } from "./table-tile-source.js";
|
|
8
9
|
export { TableTileSource } from "./table-tile-source.js";
|
|
9
|
-
export type { DynamicVectorTileSource, DynamicVectorTileSourceProps } from "./table-tile-source.js";
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,cAAc,EAAC,6BAA0B;AACjD,YAAY,EAAC,qBAAqB,EAAC,6BAA0B;AAC7D,YAAY,EAAC,QAAQ,EAAC,gCAA6B;AAInD,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,wBAAqB;AACxD,YAAY,EAAC,gBAAgB,EAAC,wBAAqB;AAInD,OAAO,EAAC,SAAS,EAAC,wBAAqB;AACvC,YAAY,EAAC,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,cAAc,EAAC,6BAA0B;AACjD,YAAY,EAAC,qBAAqB,EAAC,6BAA0B;AAC7D,YAAY,EAAC,QAAQ,EAAC,gCAA6B;AAInD,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,wBAAqB;AACxD,YAAY,EAAC,gBAAgB,EAAC,wBAAqB;AAInD,OAAO,EAAC,SAAS,EAAC,wBAAqB;AACvC,YAAY,EAAC,aAAa,EAAE,gBAAgB,EAAC,wBAAqB;AAIlE,YAAY,EAAC,sBAAsB,EAAE,qBAAqB,EAAC,+BAA4B;AACvF,OAAO,EAAC,eAAe,EAAC,+BAA4B"}
|
package/dist/index.js
CHANGED
|
@@ -7,5 +7,4 @@ export { TileJSONLoader } from "./tilejson-loader.js";
|
|
|
7
7
|
export { MVTLoader, MVTWorkerLoader } from "./mvt-loader.js";
|
|
8
8
|
// MVTSource
|
|
9
9
|
export { MVTSource } from "./mvt-source.js";
|
|
10
|
-
// TableTileSource (dynamically tiles a table)
|
|
11
10
|
export { TableTileSource } from "./table-tile-source.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAC,MAAM,oBAAoB,CAAC;AAQpG,OAAO,KAAK,EAAC,gBAAgB,EAAC,yBAAsB;AAGpD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,gBAAgB;;;EAyB5E"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MVT spec constants
|
|
3
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
4
|
+
*/
|
|
5
|
+
export declare enum TileInfo {
|
|
6
|
+
/** repeated Layer */
|
|
7
|
+
layers = 3
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* MVT spec constants
|
|
11
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
12
|
+
* @note Layers are described in section 4.1 of the specification
|
|
13
|
+
*/
|
|
14
|
+
export declare enum LayerInfo {
|
|
15
|
+
/**
|
|
16
|
+
* Any compliant implementation must first read the version
|
|
17
|
+
* number encoded in this message and choose the correct
|
|
18
|
+
* implementation for this version number before proceeding to
|
|
19
|
+
* decode other parts of this message.
|
|
20
|
+
* required uint32 [ default = 1 ];
|
|
21
|
+
*/
|
|
22
|
+
version = 15,
|
|
23
|
+
/** PBF: required string */
|
|
24
|
+
name = 1,
|
|
25
|
+
/** The actual features in this tile.
|
|
26
|
+
* PBF: repeated Feature
|
|
27
|
+
*/
|
|
28
|
+
features = 2,
|
|
29
|
+
/**
|
|
30
|
+
* Dictionary encoding for keys
|
|
31
|
+
* PBF: repeated string
|
|
32
|
+
*/
|
|
33
|
+
keys = 3,
|
|
34
|
+
/**
|
|
35
|
+
* Dictionary encoding for values
|
|
36
|
+
* PBF: repeated Value
|
|
37
|
+
*/
|
|
38
|
+
values = 4,
|
|
39
|
+
/**
|
|
40
|
+
* Although this is an "optional" field it is required by the specification.
|
|
41
|
+
* See https://github.com/mapbox/vector-tile-spec/issues/47
|
|
42
|
+
* PBF: optional uint32 [ default = 4096 ];
|
|
43
|
+
*/
|
|
44
|
+
extent = 5
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
48
|
+
* Features are described in section 4.2 of the specification
|
|
49
|
+
*/
|
|
50
|
+
export declare enum FeatureInfo {
|
|
51
|
+
/** optional uint64 [ default = 0 ]; */
|
|
52
|
+
id = 1,
|
|
53
|
+
/**
|
|
54
|
+
* Tags of this feature are encoded as repeated pairs of integers.
|
|
55
|
+
* A detailed description of tags is located in sections 4.2 and 4.4 of the specification
|
|
56
|
+
* repeated uint32 [ packed = true ];
|
|
57
|
+
*/
|
|
58
|
+
tags = 2,
|
|
59
|
+
/**
|
|
60
|
+
* The type of geometry stored in this feature.
|
|
61
|
+
* GeomType [ default = UNKNOWN ];
|
|
62
|
+
*/
|
|
63
|
+
type = 3,
|
|
64
|
+
/**
|
|
65
|
+
* Contains a stream of commands and parameters (vertices).
|
|
66
|
+
* A detailed description on geometry encoding is located in
|
|
67
|
+
* section 4.3 of the specification.
|
|
68
|
+
* repeated uint32 [ packed = true ];
|
|
69
|
+
*/
|
|
70
|
+
geometry = 4
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* GeomType is described in section 4.3.4 of the specification
|
|
74
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
75
|
+
* */
|
|
76
|
+
export declare enum GeometryType {
|
|
77
|
+
UNKNOWN = 0,
|
|
78
|
+
POINT = 1,
|
|
79
|
+
LINESTRING = 2,
|
|
80
|
+
POLYGON = 3
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Variant type encoding
|
|
84
|
+
* The use of values is described in section 4.1 of the specification
|
|
85
|
+
* @note Exactly one of these values must be present in a valid message
|
|
86
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
87
|
+
*/
|
|
88
|
+
export declare enum PropertyType {
|
|
89
|
+
/** string */
|
|
90
|
+
string_value = 1,//
|
|
91
|
+
/** float */
|
|
92
|
+
float_value = 2,
|
|
93
|
+
/** double */
|
|
94
|
+
double_value = 3,
|
|
95
|
+
/** int64 */
|
|
96
|
+
int_value = 4,
|
|
97
|
+
/** uint64 */
|
|
98
|
+
uint_value = 5,
|
|
99
|
+
/** sint64 */
|
|
100
|
+
sint_value = 6,
|
|
101
|
+
/** bool */
|
|
102
|
+
bool_value = 7
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* "Turtle graphics" style geometry commands
|
|
106
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
107
|
+
*/
|
|
108
|
+
export declare enum Command {
|
|
109
|
+
/** 2 Parameters: dX, dY */
|
|
110
|
+
MoveTo = 1,
|
|
111
|
+
/** 2 Parameters dX, dY */
|
|
112
|
+
LineTo = 2,
|
|
113
|
+
/** No parameters */
|
|
114
|
+
ClosePath = 7
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=mvt-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvt-constants.d.ts","sourceRoot":"","sources":["../../../src/lib/pojo-parser/mvt-constants.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,oBAAY,QAAQ;IAClB,qBAAqB;IACrB,MAAM,IAAI;CACX;AAED;;;;GAIG;AACH,oBAAY,SAAS;IACnB;;;;;;OAMG;IACH,OAAO,KAAK;IAEZ,2BAA2B;IAC3B,IAAI,IAAI;IAER;;OAEG;IACH,QAAQ,IAAI;IAEZ;;;OAGG;IACH,IAAI,IAAI;IAER;;;OAGG;IACH,MAAM,IAAI;IAEV;;;;OAIG;IACH,MAAM,IAAI;CAGX;AAED;;;GAGG;AACH,oBAAY,WAAW;IACrB,uCAAuC;IACvC,EAAE,IAAI;IAEN;;;;OAIG;IACH,IAAI,IAAI;IAER;;;OAGG;IACH,IAAI,IAAI;IAER;;;;;OAKG;IACH,QAAQ,IAAI;CACb;AAED;;;KAGK;AACL,oBAAY,YAAY;IACtB,OAAO,IAAI;IACX,KAAK,IAAI;IACT,UAAU,IAAI;IACd,OAAO,IAAI;CACZ;AAED;;;;;GAKG;AACH,oBAAY,YAAY;IACtB,aAAa;IACb,YAAY,IAAI,CAAE,EAAE;IACpB,YAAY;IACZ,WAAW,IAAI;IACf,aAAa;IACb,YAAY,IAAI;IAChB,YAAY;IACZ,SAAS,IAAI;IACb,aAAa;IACb,UAAU,IAAI;IACd,aAAa;IACb,UAAU,IAAI;IACd,WAAW;IACX,UAAU,IAAI;CAEf;AAED;;;GAGG;AACH,oBAAY,OAAO;IACjB,2BAA2B;IAC3B,MAAM,IAAI;IACV,0BAA0B;IAC1B,MAAM,IAAI;IACV,oBAAoB;IACpB,SAAS,IAAI;CACd"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* MVT spec constants
|
|
6
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
7
|
+
*/
|
|
8
|
+
export var TileInfo;
|
|
9
|
+
(function (TileInfo) {
|
|
10
|
+
/** repeated Layer */
|
|
11
|
+
TileInfo[TileInfo["layers"] = 3] = "layers";
|
|
12
|
+
})(TileInfo || (TileInfo = {}));
|
|
13
|
+
/**
|
|
14
|
+
* MVT spec constants
|
|
15
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
16
|
+
* @note Layers are described in section 4.1 of the specification
|
|
17
|
+
*/
|
|
18
|
+
export var LayerInfo;
|
|
19
|
+
(function (LayerInfo) {
|
|
20
|
+
/**
|
|
21
|
+
* Any compliant implementation must first read the version
|
|
22
|
+
* number encoded in this message and choose the correct
|
|
23
|
+
* implementation for this version number before proceeding to
|
|
24
|
+
* decode other parts of this message.
|
|
25
|
+
* required uint32 [ default = 1 ];
|
|
26
|
+
*/
|
|
27
|
+
LayerInfo[LayerInfo["version"] = 15] = "version";
|
|
28
|
+
/** PBF: required string */
|
|
29
|
+
LayerInfo[LayerInfo["name"] = 1] = "name";
|
|
30
|
+
/** The actual features in this tile.
|
|
31
|
+
* PBF: repeated Feature
|
|
32
|
+
*/
|
|
33
|
+
LayerInfo[LayerInfo["features"] = 2] = "features";
|
|
34
|
+
/**
|
|
35
|
+
* Dictionary encoding for keys
|
|
36
|
+
* PBF: repeated string
|
|
37
|
+
*/
|
|
38
|
+
LayerInfo[LayerInfo["keys"] = 3] = "keys";
|
|
39
|
+
/**
|
|
40
|
+
* Dictionary encoding for values
|
|
41
|
+
* PBF: repeated Value
|
|
42
|
+
*/
|
|
43
|
+
LayerInfo[LayerInfo["values"] = 4] = "values";
|
|
44
|
+
/**
|
|
45
|
+
* Although this is an "optional" field it is required by the specification.
|
|
46
|
+
* See https://github.com/mapbox/vector-tile-spec/issues/47
|
|
47
|
+
* PBF: optional uint32 [ default = 4096 ];
|
|
48
|
+
*/
|
|
49
|
+
LayerInfo[LayerInfo["extent"] = 5] = "extent";
|
|
50
|
+
// extensions 16 to max;
|
|
51
|
+
})(LayerInfo || (LayerInfo = {}));
|
|
52
|
+
/**
|
|
53
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
54
|
+
* Features are described in section 4.2 of the specification
|
|
55
|
+
*/
|
|
56
|
+
export var FeatureInfo;
|
|
57
|
+
(function (FeatureInfo) {
|
|
58
|
+
/** optional uint64 [ default = 0 ]; */
|
|
59
|
+
FeatureInfo[FeatureInfo["id"] = 1] = "id";
|
|
60
|
+
/**
|
|
61
|
+
* Tags of this feature are encoded as repeated pairs of integers.
|
|
62
|
+
* A detailed description of tags is located in sections 4.2 and 4.4 of the specification
|
|
63
|
+
* repeated uint32 [ packed = true ];
|
|
64
|
+
*/
|
|
65
|
+
FeatureInfo[FeatureInfo["tags"] = 2] = "tags";
|
|
66
|
+
/**
|
|
67
|
+
* The type of geometry stored in this feature.
|
|
68
|
+
* GeomType [ default = UNKNOWN ];
|
|
69
|
+
*/
|
|
70
|
+
FeatureInfo[FeatureInfo["type"] = 3] = "type";
|
|
71
|
+
/**
|
|
72
|
+
* Contains a stream of commands and parameters (vertices).
|
|
73
|
+
* A detailed description on geometry encoding is located in
|
|
74
|
+
* section 4.3 of the specification.
|
|
75
|
+
* repeated uint32 [ packed = true ];
|
|
76
|
+
*/
|
|
77
|
+
FeatureInfo[FeatureInfo["geometry"] = 4] = "geometry";
|
|
78
|
+
})(FeatureInfo || (FeatureInfo = {}));
|
|
79
|
+
/**
|
|
80
|
+
* GeomType is described in section 4.3.4 of the specification
|
|
81
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
82
|
+
* */
|
|
83
|
+
export var GeometryType;
|
|
84
|
+
(function (GeometryType) {
|
|
85
|
+
GeometryType[GeometryType["UNKNOWN"] = 0] = "UNKNOWN";
|
|
86
|
+
GeometryType[GeometryType["POINT"] = 1] = "POINT";
|
|
87
|
+
GeometryType[GeometryType["LINESTRING"] = 2] = "LINESTRING";
|
|
88
|
+
GeometryType[GeometryType["POLYGON"] = 3] = "POLYGON";
|
|
89
|
+
})(GeometryType || (GeometryType = {}));
|
|
90
|
+
/**
|
|
91
|
+
* Variant type encoding
|
|
92
|
+
* The use of values is described in section 4.1 of the specification
|
|
93
|
+
* @note Exactly one of these values must be present in a valid message
|
|
94
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
95
|
+
*/
|
|
96
|
+
export var PropertyType;
|
|
97
|
+
(function (PropertyType) {
|
|
98
|
+
/** string */
|
|
99
|
+
PropertyType[PropertyType["string_value"] = 1] = "string_value";
|
|
100
|
+
/** float */
|
|
101
|
+
PropertyType[PropertyType["float_value"] = 2] = "float_value";
|
|
102
|
+
/** double */
|
|
103
|
+
PropertyType[PropertyType["double_value"] = 3] = "double_value";
|
|
104
|
+
/** int64 */
|
|
105
|
+
PropertyType[PropertyType["int_value"] = 4] = "int_value";
|
|
106
|
+
/** uint64 */
|
|
107
|
+
PropertyType[PropertyType["uint_value"] = 5] = "uint_value";
|
|
108
|
+
/** sint64 */
|
|
109
|
+
PropertyType[PropertyType["sint_value"] = 6] = "sint_value";
|
|
110
|
+
/** bool */
|
|
111
|
+
PropertyType[PropertyType["bool_value"] = 7] = "bool_value";
|
|
112
|
+
// extensions 8 to max;
|
|
113
|
+
})(PropertyType || (PropertyType = {}));
|
|
114
|
+
/**
|
|
115
|
+
* "Turtle graphics" style geometry commands
|
|
116
|
+
* @see https://github.com/mapbox/vector-tile-spec/blob/master/2.1/README.md
|
|
117
|
+
*/
|
|
118
|
+
export var Command;
|
|
119
|
+
(function (Command) {
|
|
120
|
+
/** 2 Parameters: dX, dY */
|
|
121
|
+
Command[Command["MoveTo"] = 1] = "MoveTo";
|
|
122
|
+
/** 2 Parameters dX, dY */
|
|
123
|
+
Command[Command["LineTo"] = 2] = "LineTo";
|
|
124
|
+
/** No parameters */
|
|
125
|
+
Command[Command["ClosePath"] = 7] = "ClosePath";
|
|
126
|
+
})(Command || (Command = {}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Schema, FlatIndexedGeometry } from '@loaders.gl/schema';
|
|
2
|
+
export type MVTTile = {
|
|
3
|
+
layers: Record<string, MVTLayer>;
|
|
4
|
+
};
|
|
5
|
+
export type MVTLayer = {
|
|
6
|
+
version: number;
|
|
7
|
+
name: string;
|
|
8
|
+
extent: number;
|
|
9
|
+
length: number;
|
|
10
|
+
schema: Schema;
|
|
11
|
+
columns: Record<string, (string | number | boolean | null)[]>;
|
|
12
|
+
idColumn: number[];
|
|
13
|
+
boundingBoxColumn: [number, number, number, number][];
|
|
14
|
+
geometryTypeColumn: number[];
|
|
15
|
+
geometryColumn: FlatIndexedGeometry[];
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=mvt-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvt-types.d.ts","sourceRoot":"","sources":["../../../src/lib/pojo-parser/mvt-types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAEpE,MAAM,MAAM,OAAO,GAAG;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9D,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACtD,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,cAAc,EAAE,mBAAmB,EAAE,CAAC;CACvC,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { FlatIndexedGeometry } from '@loaders.gl/schema';
|
|
2
|
+
import Protobuf from 'pbf';
|
|
3
|
+
type GeometryCommand = {
|
|
4
|
+
type: 'moveto' | 'lineto' | 'closepath';
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function makeMVTGeometryCommandIterator(pbf: Protobuf): IterableIterator<GeometryCommand>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a bounding box from the feature geometry at the current position
|
|
11
|
+
* @todo - Reparses the entire PBF geometry - replace with a generic bounding box calculation on parsed data?
|
|
12
|
+
*/
|
|
13
|
+
export declare function readBoundingBoxFromPBF(pbf: Protobuf): [number, number, number, number];
|
|
14
|
+
/**
|
|
15
|
+
* Extract intermediate Flat GeoJSON
|
|
16
|
+
* data format, which maps closely to the binary data buffers.
|
|
17
|
+
* It is similar to GeoJSON, but rather than storing the coordinates
|
|
18
|
+
* in multidimensional arrays, we have a 1D `data` with all the
|
|
19
|
+
* coordinates, and then index into this using the `indices`
|
|
20
|
+
* parameter, e.g.
|
|
21
|
+
*
|
|
22
|
+
* geometry: {
|
|
23
|
+
* type: 'Point', data: [1,2], indices: [0]
|
|
24
|
+
* }
|
|
25
|
+
* geometry: {
|
|
26
|
+
* type: 'LineString', data: [1,2,3,4,...], indices: [0]
|
|
27
|
+
* }
|
|
28
|
+
* geometry: {
|
|
29
|
+
* type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
|
|
30
|
+
* }
|
|
31
|
+
* Thus the indices member lets us look up the relevant range
|
|
32
|
+
* from the data array.
|
|
33
|
+
* The Multi* versions of the above types share the same data
|
|
34
|
+
* structure, just with multiple elements in the indices array
|
|
35
|
+
*/
|
|
36
|
+
export declare function loadFlatGeometryFromPBF(pbf: Protobuf): FlatIndexedGeometry;
|
|
37
|
+
export {};
|
|
38
|
+
/**
|
|
39
|
+
* Load a GeoJSON style Geometry from the raw PBF
|
|
40
|
+
*
|
|
41
|
+
function readGeoJSONGeometryFromPBF(pbf): number[][][] {
|
|
42
|
+
const lines: number[][][] = [];
|
|
43
|
+
let line: number[][] | undefined;
|
|
44
|
+
|
|
45
|
+
for (const command of makeMVTGeometryCommandIterator(pbf)) {
|
|
46
|
+
switch (command.type) {
|
|
47
|
+
case 'moveto':
|
|
48
|
+
// moveTo
|
|
49
|
+
if (line) lines.push(line);
|
|
50
|
+
line = [];
|
|
51
|
+
if (line) line.push([command.x, command.y]);
|
|
52
|
+
break;
|
|
53
|
+
|
|
54
|
+
case 'lineto':
|
|
55
|
+
if (line) line.push([command.x, command.y]);
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case 'closepath':
|
|
59
|
+
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
60
|
+
if (line) {
|
|
61
|
+
line.push(line[0].slice()); // closePolygon
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
|
|
65
|
+
default:
|
|
66
|
+
// just for eslint
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (line) {
|
|
71
|
+
lines.push(line);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return lines;
|
|
75
|
+
}
|
|
76
|
+
*/
|
|
77
|
+
//# sourceMappingURL=parse-geometry-from-pbf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-geometry-from-pbf.d.ts","sourceRoot":"","sources":["../../../src/lib/pojo-parser/parse-geometry-from-pbf.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAIV,mBAAmB,EAEpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,QAAQ,MAAM,KAAK,CAAC;AAa3B,KAAK,eAAe,GAAG;IAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AAEvF,wBAAiB,8BAA8B,CAAC,GAAG,EAAE,QAAQ,GAAG,gBAAgB,CAAC,eAAe,CAAC,CA0ChG;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAuBtF;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,QAAQ,GAAG,mBAAmB,CAuC1E;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsCE"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
import * as MVT from "./mvt-constants.js";
|
|
5
|
+
export function* makeMVTGeometryCommandIterator(pbf) {
|
|
6
|
+
const endPos = pbf.readVarint() + pbf.pos;
|
|
7
|
+
let cmd = 1;
|
|
8
|
+
let cmdLen;
|
|
9
|
+
let length = 0;
|
|
10
|
+
// Note: We reuse and return the same command object to avoid creating new objects
|
|
11
|
+
const command = { type: 'closepath', x: 0, y: 0 };
|
|
12
|
+
while (pbf.pos < endPos) {
|
|
13
|
+
if (length <= 0) {
|
|
14
|
+
cmdLen = pbf.readVarint();
|
|
15
|
+
cmd = cmdLen & 0x7;
|
|
16
|
+
length = cmdLen >> 3;
|
|
17
|
+
}
|
|
18
|
+
length--;
|
|
19
|
+
switch (cmd) {
|
|
20
|
+
case MVT.Command.MoveTo:
|
|
21
|
+
command.type = 'moveto';
|
|
22
|
+
command.x += pbf.readSVarint();
|
|
23
|
+
command.y += pbf.readSVarint();
|
|
24
|
+
yield command;
|
|
25
|
+
break;
|
|
26
|
+
case MVT.Command.LineTo:
|
|
27
|
+
command.type = 'lineto';
|
|
28
|
+
command.x += pbf.readSVarint();
|
|
29
|
+
command.y += pbf.readSVarint();
|
|
30
|
+
yield command;
|
|
31
|
+
break;
|
|
32
|
+
case MVT.Command.ClosePath:
|
|
33
|
+
command.type = 'moveto';
|
|
34
|
+
yield command;
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
throw new Error(`unknown command ${cmd}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a bounding box from the feature geometry at the current position
|
|
43
|
+
* @todo - Reparses the entire PBF geometry - replace with a generic bounding box calculation on parsed data?
|
|
44
|
+
*/
|
|
45
|
+
export function readBoundingBoxFromPBF(pbf) {
|
|
46
|
+
let x1 = Infinity;
|
|
47
|
+
let x2 = -Infinity;
|
|
48
|
+
let y1 = Infinity;
|
|
49
|
+
let y2 = -Infinity;
|
|
50
|
+
for (const command of makeMVTGeometryCommandIterator(pbf)) {
|
|
51
|
+
switch (command.type) {
|
|
52
|
+
case 'moveto':
|
|
53
|
+
case 'lineto':
|
|
54
|
+
if (command.x < x1)
|
|
55
|
+
x1 = command.x;
|
|
56
|
+
if (command.x > x2)
|
|
57
|
+
x2 = command.x;
|
|
58
|
+
if (command.y < y1)
|
|
59
|
+
y1 = command.y;
|
|
60
|
+
if (command.y > y2)
|
|
61
|
+
y2 = command.y;
|
|
62
|
+
break;
|
|
63
|
+
case 'closepath':
|
|
64
|
+
default:
|
|
65
|
+
// ignore
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return [x1, y1, x2, y2];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Extract intermediate Flat GeoJSON
|
|
72
|
+
* data format, which maps closely to the binary data buffers.
|
|
73
|
+
* It is similar to GeoJSON, but rather than storing the coordinates
|
|
74
|
+
* in multidimensional arrays, we have a 1D `data` with all the
|
|
75
|
+
* coordinates, and then index into this using the `indices`
|
|
76
|
+
* parameter, e.g.
|
|
77
|
+
*
|
|
78
|
+
* geometry: {
|
|
79
|
+
* type: 'Point', data: [1,2], indices: [0]
|
|
80
|
+
* }
|
|
81
|
+
* geometry: {
|
|
82
|
+
* type: 'LineString', data: [1,2,3,4,...], indices: [0]
|
|
83
|
+
* }
|
|
84
|
+
* geometry: {
|
|
85
|
+
* type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
|
|
86
|
+
* }
|
|
87
|
+
* Thus the indices member lets us look up the relevant range
|
|
88
|
+
* from the data array.
|
|
89
|
+
* The Multi* versions of the above types share the same data
|
|
90
|
+
* structure, just with multiple elements in the indices array
|
|
91
|
+
*/
|
|
92
|
+
// eslint-disable-next-line complexity, max-statements
|
|
93
|
+
export function loadFlatGeometryFromPBF(pbf) {
|
|
94
|
+
// Note: I attempted to replace the `data` array with a
|
|
95
|
+
// Float32Array, but performance was worse, both using
|
|
96
|
+
// `set()` and direct index access. Also, we cannot
|
|
97
|
+
// know how large the buffer should be, so it would
|
|
98
|
+
// increase memory usage
|
|
99
|
+
const indices = []; // Indices where geometries start
|
|
100
|
+
const data = []; // Flat array of coordinate data
|
|
101
|
+
let i = 0;
|
|
102
|
+
for (const command of makeMVTGeometryCommandIterator(pbf)) {
|
|
103
|
+
switch (command.type) {
|
|
104
|
+
case 'moveto':
|
|
105
|
+
// New line
|
|
106
|
+
indices.push(i);
|
|
107
|
+
data.push(command.x, command.y);
|
|
108
|
+
i += 2;
|
|
109
|
+
break;
|
|
110
|
+
case 'lineto':
|
|
111
|
+
data.push(command.x, command.y);
|
|
112
|
+
i += 2;
|
|
113
|
+
break;
|
|
114
|
+
case 'closepath':
|
|
115
|
+
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
116
|
+
if (i > 0) {
|
|
117
|
+
const start = indices[indices.length - 1]; // start index of polygon
|
|
118
|
+
data.push(data[start], data[start + 1]); // closePolygon
|
|
119
|
+
i += 2;
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
// just for eslint
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return { data, indices };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Load a GeoJSON style Geometry from the raw PBF
|
|
130
|
+
*
|
|
131
|
+
function readGeoJSONGeometryFromPBF(pbf): number[][][] {
|
|
132
|
+
const lines: number[][][] = [];
|
|
133
|
+
let line: number[][] | undefined;
|
|
134
|
+
|
|
135
|
+
for (const command of makeMVTGeometryCommandIterator(pbf)) {
|
|
136
|
+
switch (command.type) {
|
|
137
|
+
case 'moveto':
|
|
138
|
+
// moveTo
|
|
139
|
+
if (line) lines.push(line);
|
|
140
|
+
line = [];
|
|
141
|
+
if (line) line.push([command.x, command.y]);
|
|
142
|
+
break;
|
|
143
|
+
|
|
144
|
+
case 'lineto':
|
|
145
|
+
if (line) line.push([command.x, command.y]);
|
|
146
|
+
break;
|
|
147
|
+
|
|
148
|
+
case 'closepath':
|
|
149
|
+
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
150
|
+
if (line) {
|
|
151
|
+
line.push(line[0].slice()); // closePolygon
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
|
|
155
|
+
default:
|
|
156
|
+
// just for eslint
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (line) {
|
|
161
|
+
lines.push(line);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return lines;
|
|
165
|
+
}
|
|
166
|
+
*/
|
|
167
|
+
// export class VectorTileFeature implements MVTFeature {
|
|
168
|
+
// properties: Record<string, string | number | boolean | null>;
|
|
169
|
+
// extent: any;
|
|
170
|
+
// type: number;
|
|
171
|
+
// id: number | null;
|
|
172
|
+
// _pbf: Protobuf;
|
|
173
|
+
// _geometryPos: number;
|
|
174
|
+
// _keys: string[];
|
|
175
|
+
// _values: (string | number | boolean | null)[];
|
|
176
|
+
// _geometryInfo: GeojsonGeometryInfo;
|
|
177
|
+
// static types = MVT_GEOMETRY_TYPES;
|
|
178
|
+
// // eslint-disable-next-line max-params
|
|
179
|
+
// constructor(
|
|
180
|
+
// pbf: Protobuf,
|
|
181
|
+
// end: number,
|
|
182
|
+
// extent: any,
|
|
183
|
+
// keys: string[],
|
|
184
|
+
// values: (string | number | boolean | null)[],
|
|
185
|
+
// geometryInfo?: GeojsonGeometryInfo
|
|
186
|
+
// ) {
|
|
187
|
+
// // Public
|
|
188
|
+
// this.properties = {};
|
|
189
|
+
// this.extent = extent;
|
|
190
|
+
// this.type = 0;
|
|
191
|
+
// this.id = null;
|
|
192
|
+
// // Private
|
|
193
|
+
// this._pbf = pbf;
|
|
194
|
+
// this._geometryPos = -1;
|
|
195
|
+
// this._keys = keys;
|
|
196
|
+
// this._values = values;
|
|
197
|
+
// // Only used by binary tiles
|
|
198
|
+
// this._geometryInfo = geometryInfo!;
|
|
199
|
+
// pbf.readFields(readFeatureFromPBF, this, end);
|
|
200
|
+
// }
|
|
201
|
+
// toGeoJSONFeature(
|
|
202
|
+
// coordinates: 'wgs84' | 'local',
|
|
203
|
+
// tileIndex?: {x: number; y: number; z: number}
|
|
204
|
+
// ): Feature {
|
|
205
|
+
// return readGeoJSONFeatureFromPBF(this, coordinates, this.extent, tileIndex);
|
|
206
|
+
// }
|
|
207
|
+
// /**
|
|
208
|
+
// *
|
|
209
|
+
// * @param options
|
|
210
|
+
// * @returns
|
|
211
|
+
// */
|
|
212
|
+
// toBinaryFeature(
|
|
213
|
+
// coordinates: 'wgs84' | 'local',
|
|
214
|
+
// tileIndex?: {x: number; y: number; z: number}
|
|
215
|
+
// ): FlatFeature {
|
|
216
|
+
// return readFlatFeatureFromPBF(this, coordinates, this.extent, tileIndex);
|
|
217
|
+
// }
|
|
218
|
+
// /** Read a bounding box from the feature */
|
|
219
|
+
// bbox() {
|
|
220
|
+
// this._pbf.pos = this._geometryPos;
|
|
221
|
+
// return readBoundingBoxFromPBF(this._pbf);
|
|
222
|
+
// }
|
|
223
|
+
// // Geometry helpers
|
|
224
|
+
// /** Parses protobuf data to nested "GeoJSON like" coordinates array */
|
|
225
|
+
// loadGeometry(): number[][][] {
|
|
226
|
+
// this._pbf.pos = this._geometryPos;
|
|
227
|
+
// return readGeoJSONGeometryFromPBF(this._pbf);
|
|
228
|
+
// }
|
|
229
|
+
// /** Parses protobuf data to an intermediate "Flat GeoJSON" data format */
|
|
230
|
+
// loadFlatGeometry(): FlatIndexedGeometry {
|
|
231
|
+
// this._pbf.pos = this._geometryPos;
|
|
232
|
+
// return loadFlatGeometryFromPBF(this._pbf);
|
|
233
|
+
// }
|
|
234
|
+
// }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Protobuf from 'pbf';
|
|
2
|
+
import type { MVTTile, MVTLayer } from "./mvt-types.js";
|
|
3
|
+
export type MVTLayerData = {
|
|
4
|
+
/** Layer being built */
|
|
5
|
+
layer: MVTLayer;
|
|
6
|
+
currentFeature: number;
|
|
7
|
+
/** list of all keys in layer: Temporary, used when building up the layer */
|
|
8
|
+
keys: string[];
|
|
9
|
+
/** single list of all values in all columns - Temporary values used when building up the layer */
|
|
10
|
+
values: (string | number | boolean | null)[];
|
|
11
|
+
types: number[];
|
|
12
|
+
columnTypes: number[];
|
|
13
|
+
columnNullable: boolean[];
|
|
14
|
+
/** list of all feature start positions in the PBF - Temporary values used when building up the layer */
|
|
15
|
+
featurePositions: number[];
|
|
16
|
+
/** list of all geometry start positions in the PBF - Temporary values used when building up the layer */
|
|
17
|
+
geometryPositions: number[];
|
|
18
|
+
};
|
|
19
|
+
/** Parse an MVT tile from an ArrayBuffer */
|
|
20
|
+
export declare function parseMVT(arrayBuffer: ArrayBuffer | Uint8Array): MVTTile;
|
|
21
|
+
/** Parse an MVT tile from a PBF buffer */
|
|
22
|
+
export declare function parseMVTTile(pbf: Protobuf, end?: number): MVTTile;
|
|
23
|
+
/** Parse an MVT layer from BPF at current position */
|
|
24
|
+
export declare function parseLayer(pbf: Protobuf, end: number): MVTLayer;
|
|
25
|
+
//# sourceMappingURL=parse-mvt-from-pbf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-mvt-from-pbf.d.ts","sourceRoot":"","sources":["../../../src/lib/pojo-parser/parse-mvt-from-pbf.ts"],"names":[],"mappings":"AAMA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,OAAO,KAAK,EAAC,OAAO,EAAE,QAAQ,EAAC,uBAAoB;AAInD,MAAM,MAAM,YAAY,GAAG;IACzB,wBAAwB;IACxB,KAAK,EAAE,QAAQ,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,4EAA4E;IAC5E,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,kGAAkG;IAClG,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC7C,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE,OAAO,EAAE,CAAC;IAC1B,wGAAwG;IACxG,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,yGAAyG;IACzG,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B,CAAC;AA0BF,4CAA4C;AAC5C,wBAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,GAAG,OAAO,CAGvE;AAED,0CAA0C;AAC1C,wBAAgB,YAAY,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CASjE;AA2BD,sDAAsD;AACtD,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,QAAQ,CAwB/D"}
|