@loaders.gl/mvt 3.1.0-alpha.5 → 3.1.0-beta.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 +1 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2277 -0
- package/dist/es5/lib/parse-mvt.js.map +1 -1
- package/dist/es5/mvt-loader.js +1 -1
- package/dist/es5/mvt-loader.js.map +1 -1
- package/dist/esm/lib/parse-mvt.js.map +1 -1
- package/dist/esm/mvt-loader.js +1 -1
- package/dist/esm/mvt-loader.js.map +1 -1
- package/dist/helpers/binary-util-functions.d.ts +1 -0
- package/dist/helpers/binary-util-functions.d.ts.map +1 -0
- package/dist/helpers/binary-util-functions.js +116 -0
- package/dist/helpers/mapbox-util-functions.d.ts +1 -0
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
- package/dist/helpers/mapbox-util-functions.js +82 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts +1 -0
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/features-to-binary.js +353 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +1 -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 +159 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +1 -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 +91 -0
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +1 -0
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile.js +29 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +170 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +89 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.js +29 -0
- package/dist/lib/parse-mvt.d.ts +2 -1
- package/dist/lib/parse-mvt.d.ts.map +1 -0
- package/dist/lib/parse-mvt.js +142 -0
- package/dist/lib/types.d.ts +1 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/dist/mvt-loader.d.ts +1 -0
- package/dist/mvt-loader.d.ts.map +1 -0
- package/dist/mvt-loader.js +45 -0
- package/dist/mvt-worker.js +2286 -3
- package/dist/workers/mvt-worker.d.ts +1 -0
- package/dist/workers/mvt-worker.d.ts.map +1 -0
- package/dist/workers/mvt-worker.js +5 -0
- package/package.json +6 -7
- package/src/lib/parse-mvt.ts +1 -1
- package/dist/dist.min.js +0 -4
- package/dist/dist.min.js.map +0 -1
- package/dist/mvt-worker.js.map +0 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mapbox_util_functions_1 = require("../../helpers/mapbox-util-functions");
|
|
4
|
+
class VectorTileFeature {
|
|
5
|
+
constructor(pbf, end, extent, keys, values) {
|
|
6
|
+
// Public
|
|
7
|
+
this.properties = {};
|
|
8
|
+
this.extent = extent;
|
|
9
|
+
this.type = 0;
|
|
10
|
+
this.id = null;
|
|
11
|
+
// Private
|
|
12
|
+
this._pbf = pbf;
|
|
13
|
+
this._geometry = -1;
|
|
14
|
+
this._keys = keys;
|
|
15
|
+
this._values = values;
|
|
16
|
+
pbf.readFields(mapbox_util_functions_1.readFeature, this, end);
|
|
17
|
+
}
|
|
18
|
+
static get types() {
|
|
19
|
+
return ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line complexity, max-statements
|
|
22
|
+
loadGeometry() {
|
|
23
|
+
const pbf = this._pbf;
|
|
24
|
+
pbf.pos = this._geometry;
|
|
25
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
26
|
+
let cmd = 1;
|
|
27
|
+
let length = 0;
|
|
28
|
+
let x = 0;
|
|
29
|
+
let y = 0;
|
|
30
|
+
const lines = [];
|
|
31
|
+
let line;
|
|
32
|
+
while (pbf.pos < end) {
|
|
33
|
+
if (length <= 0) {
|
|
34
|
+
const cmdLen = pbf.readVarint();
|
|
35
|
+
cmd = cmdLen & 0x7;
|
|
36
|
+
length = cmdLen >> 3;
|
|
37
|
+
}
|
|
38
|
+
length--;
|
|
39
|
+
if (cmd === 1 || cmd === 2) {
|
|
40
|
+
x += pbf.readSVarint();
|
|
41
|
+
y += pbf.readSVarint();
|
|
42
|
+
if (cmd === 1) {
|
|
43
|
+
// moveTo
|
|
44
|
+
if (line)
|
|
45
|
+
lines.push(line);
|
|
46
|
+
line = [];
|
|
47
|
+
}
|
|
48
|
+
if (line)
|
|
49
|
+
line.push([x, y]);
|
|
50
|
+
}
|
|
51
|
+
else if (cmd === 7) {
|
|
52
|
+
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
53
|
+
if (line) {
|
|
54
|
+
line.push(line[0].slice()); // closePolygon
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throw new Error(`unknown command ${cmd}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (line)
|
|
62
|
+
lines.push(line);
|
|
63
|
+
return lines;
|
|
64
|
+
}
|
|
65
|
+
// eslint-disable-next-line max-statements
|
|
66
|
+
bbox() {
|
|
67
|
+
const pbf = this._pbf;
|
|
68
|
+
pbf.pos = this._geometry;
|
|
69
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
70
|
+
let cmd = 1;
|
|
71
|
+
let length = 0;
|
|
72
|
+
let x = 0;
|
|
73
|
+
let y = 0;
|
|
74
|
+
let x1 = Infinity;
|
|
75
|
+
let x2 = -Infinity;
|
|
76
|
+
let y1 = Infinity;
|
|
77
|
+
let y2 = -Infinity;
|
|
78
|
+
while (pbf.pos < end) {
|
|
79
|
+
if (length <= 0) {
|
|
80
|
+
const cmdLen = pbf.readVarint();
|
|
81
|
+
cmd = cmdLen & 0x7;
|
|
82
|
+
length = cmdLen >> 3;
|
|
83
|
+
}
|
|
84
|
+
length--;
|
|
85
|
+
if (cmd === 1 || cmd === 2) {
|
|
86
|
+
x += pbf.readSVarint();
|
|
87
|
+
y += pbf.readSVarint();
|
|
88
|
+
if (x < x1)
|
|
89
|
+
x1 = x;
|
|
90
|
+
if (x > x2)
|
|
91
|
+
x2 = x;
|
|
92
|
+
if (y < y1)
|
|
93
|
+
y1 = y;
|
|
94
|
+
if (y > y2)
|
|
95
|
+
y2 = y;
|
|
96
|
+
}
|
|
97
|
+
else if (cmd !== 7) {
|
|
98
|
+
throw new Error(`unknown command ${cmd}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return [x1, y1, x2, y2];
|
|
102
|
+
}
|
|
103
|
+
_toGeoJSON(transform) {
|
|
104
|
+
let coords = this.loadGeometry();
|
|
105
|
+
let type = VectorTileFeature.types[this.type];
|
|
106
|
+
let i;
|
|
107
|
+
let j;
|
|
108
|
+
// eslint-disable-next-line default-case
|
|
109
|
+
switch (this.type) {
|
|
110
|
+
case 1:
|
|
111
|
+
const points = [];
|
|
112
|
+
for (i = 0; i < coords.length; i++) {
|
|
113
|
+
points[i] = coords[i][0];
|
|
114
|
+
}
|
|
115
|
+
coords = points;
|
|
116
|
+
transform(coords, this);
|
|
117
|
+
break;
|
|
118
|
+
case 2:
|
|
119
|
+
for (i = 0; i < coords.length; i++) {
|
|
120
|
+
transform(coords[i], this);
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
case 3:
|
|
124
|
+
coords = (0, mapbox_util_functions_1.classifyRings)(coords);
|
|
125
|
+
for (i = 0; i < coords.length; i++) {
|
|
126
|
+
for (j = 0; j < coords[i].length; j++) {
|
|
127
|
+
transform(coords[i][j], this);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
if (coords.length === 1) {
|
|
133
|
+
coords = coords[0];
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
type = `Multi${type}`;
|
|
137
|
+
}
|
|
138
|
+
const result = {
|
|
139
|
+
type: 'Feature',
|
|
140
|
+
geometry: {
|
|
141
|
+
type,
|
|
142
|
+
coordinates: coords
|
|
143
|
+
},
|
|
144
|
+
properties: this.properties
|
|
145
|
+
};
|
|
146
|
+
if (this.id !== null) {
|
|
147
|
+
result.id = this.id;
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
toGeoJSON(options) {
|
|
152
|
+
if (typeof options === 'function') {
|
|
153
|
+
return this._toGeoJSON(options);
|
|
154
|
+
}
|
|
155
|
+
const { x, y, z } = options;
|
|
156
|
+
const size = this.extent * Math.pow(2, z);
|
|
157
|
+
const x0 = this.extent * x;
|
|
158
|
+
const y0 = this.extent * y;
|
|
159
|
+
function project(line) {
|
|
160
|
+
for (let j = 0; j < line.length; j++) {
|
|
161
|
+
const p = line[j];
|
|
162
|
+
p[0] = ((p[0] + x0) * 360) / size - 180;
|
|
163
|
+
const y2 = 180 - ((p[1] + y0) * 360) / size;
|
|
164
|
+
p[1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return this._toGeoJSON(project);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.default = VectorTileFeature;
|
|
@@ -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,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable indent */
|
|
3
|
+
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const vector_tile_feature_1 = __importDefault(require("./vector-tile-feature"));
|
|
9
|
+
class VectorTileLayer {
|
|
10
|
+
constructor(pbf, end) {
|
|
11
|
+
// Public
|
|
12
|
+
this.version = 1;
|
|
13
|
+
this.name = '';
|
|
14
|
+
this.extent = 4096;
|
|
15
|
+
this.length = 0;
|
|
16
|
+
// Private
|
|
17
|
+
this._pbf = pbf;
|
|
18
|
+
this._keys = [];
|
|
19
|
+
this._values = [];
|
|
20
|
+
this._features = [];
|
|
21
|
+
pbf.readFields(readLayer, this, end);
|
|
22
|
+
this.length = this._features.length;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* return feature `i` from this layer as a `VectorTileFeature`
|
|
26
|
+
* @param index
|
|
27
|
+
* @returns feature
|
|
28
|
+
*/
|
|
29
|
+
feature(i) {
|
|
30
|
+
if (i < 0 || i >= this._features.length) {
|
|
31
|
+
throw new Error('feature index out of bounds');
|
|
32
|
+
}
|
|
33
|
+
this._pbf.pos = this._features[i];
|
|
34
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
35
|
+
return new vector_tile_feature_1.default(this._pbf, end, this.extent, this._keys, this._values);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.default = VectorTileLayer;
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param tag
|
|
42
|
+
* @param layer
|
|
43
|
+
* @param pbf
|
|
44
|
+
*/
|
|
45
|
+
function readLayer(tag, layer, pbf) {
|
|
46
|
+
if (layer && pbf) {
|
|
47
|
+
if (tag === 15)
|
|
48
|
+
layer.version = pbf.readVarint();
|
|
49
|
+
else if (tag === 1)
|
|
50
|
+
layer.name = pbf.readString();
|
|
51
|
+
else if (tag === 5)
|
|
52
|
+
layer.extent = pbf.readVarint();
|
|
53
|
+
else if (tag === 2)
|
|
54
|
+
layer._features.push(pbf.pos);
|
|
55
|
+
else if (tag === 3)
|
|
56
|
+
layer._keys.push(pbf.readString());
|
|
57
|
+
else if (tag === 4)
|
|
58
|
+
layer._values.push(readValueMessage(pbf));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param pbf
|
|
64
|
+
* @returns value
|
|
65
|
+
*/
|
|
66
|
+
function readValueMessage(pbf) {
|
|
67
|
+
let value = null;
|
|
68
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
69
|
+
while (pbf.pos < end) {
|
|
70
|
+
const tag = pbf.readVarint() >> 3;
|
|
71
|
+
value =
|
|
72
|
+
tag === 1
|
|
73
|
+
? pbf.readString()
|
|
74
|
+
: tag === 2
|
|
75
|
+
? pbf.readFloat()
|
|
76
|
+
: tag === 3
|
|
77
|
+
? pbf.readDouble()
|
|
78
|
+
: tag === 4
|
|
79
|
+
? pbf.readVarint64()
|
|
80
|
+
: tag === 5
|
|
81
|
+
? pbf.readVarint()
|
|
82
|
+
: tag === 6
|
|
83
|
+
? pbf.readSVarint()
|
|
84
|
+
: tag === 7
|
|
85
|
+
? pbf.readBoolean()
|
|
86
|
+
: null;
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
@@ -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,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const vector_tile_layer_1 = __importDefault(require("./vector-tile-layer"));
|
|
8
|
+
class VectorTile {
|
|
9
|
+
constructor(pbf, end) {
|
|
10
|
+
this.layers = pbf.readFields(readTile, {}, end);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = VectorTile;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param tag
|
|
17
|
+
* @param layers
|
|
18
|
+
* @param pbf
|
|
19
|
+
*/
|
|
20
|
+
function readTile(tag, layers, pbf) {
|
|
21
|
+
if (tag === 3) {
|
|
22
|
+
if (pbf) {
|
|
23
|
+
const layer = new vector_tile_layer_1.default(pbf, pbf.readVarint() + pbf.pos);
|
|
24
|
+
if (layer.length && layers) {
|
|
25
|
+
layers[layer.name] = layer;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
package/dist/lib/parse-mvt.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MvtBinaryCoordinates, MvtMapboxCoordinates } from '../lib/types';
|
|
2
|
-
import { LoaderOptions } from '@loaders.gl/loader-utils
|
|
2
|
+
import { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
3
3
|
/**
|
|
4
4
|
* Parse MVT arrayBuffer and return GeoJSON.
|
|
5
5
|
*
|
|
@@ -82,3 +82,4 @@ export default function parseMVT(arrayBuffer: ArrayBuffer, options?: LoaderOptio
|
|
|
82
82
|
}[];
|
|
83
83
|
};
|
|
84
84
|
} | (MvtBinaryCoordinates | MvtMapboxCoordinates)[];
|
|
85
|
+
//# 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":"AAMA,OAAO,EAAC,oBAAoB,EAAE,oBAAoB,EAAa,MAAM,cAAc,CAAC;AAGpF,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oDAyDjF"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// import {VectorTile} from '@mapbox/vector-tile';
|
|
7
|
+
const vector_tile_1 = __importDefault(require("./mapbox-vector-tile/vector-tile"));
|
|
8
|
+
const vector_tile_2 = __importDefault(require("./binary-vector-tile/vector-tile"));
|
|
9
|
+
const features_to_binary_1 = require("./binary-vector-tile/features-to-binary");
|
|
10
|
+
const pbf_1 = __importDefault(require("pbf"));
|
|
11
|
+
/**
|
|
12
|
+
* Parse MVT arrayBuffer and return GeoJSON.
|
|
13
|
+
*
|
|
14
|
+
* @param arrayBuffer A MVT arrayBuffer
|
|
15
|
+
* @param options
|
|
16
|
+
* @returns A GeoJSON geometry object or a binary representation
|
|
17
|
+
*/
|
|
18
|
+
function parseMVT(arrayBuffer, options) {
|
|
19
|
+
options = normalizeOptions(options);
|
|
20
|
+
const features = [];
|
|
21
|
+
if (options) {
|
|
22
|
+
const binary = options.gis.format === 'binary';
|
|
23
|
+
const firstPassData = {
|
|
24
|
+
pointPositionsCount: 0,
|
|
25
|
+
pointFeaturesCount: 0,
|
|
26
|
+
linePositionsCount: 0,
|
|
27
|
+
linePathsCount: 0,
|
|
28
|
+
lineFeaturesCount: 0,
|
|
29
|
+
polygonPositionsCount: 0,
|
|
30
|
+
polygonObjectsCount: 0,
|
|
31
|
+
polygonRingsCount: 0,
|
|
32
|
+
polygonFeaturesCount: 0
|
|
33
|
+
};
|
|
34
|
+
if (arrayBuffer.byteLength > 0) {
|
|
35
|
+
const tile = binary
|
|
36
|
+
? new vector_tile_2.default(new pbf_1.default(arrayBuffer))
|
|
37
|
+
: new vector_tile_1.default(new pbf_1.default(arrayBuffer));
|
|
38
|
+
const loaderOptions = options.mvt;
|
|
39
|
+
const selectedLayers = Array.isArray(loaderOptions.layers)
|
|
40
|
+
? loaderOptions.layers
|
|
41
|
+
: Object.keys(tile.layers);
|
|
42
|
+
selectedLayers.forEach((layerName) => {
|
|
43
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
44
|
+
const featureOptions = { ...loaderOptions, layerName };
|
|
45
|
+
if (!vectorTileLayer) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
49
|
+
const vectorTileFeature = vectorTileLayer.feature(i, firstPassData);
|
|
50
|
+
const decodedFeature = binary
|
|
51
|
+
? getDecodedFeatureBinary(vectorTileFeature, featureOptions)
|
|
52
|
+
: getDecodedFeature(vectorTileFeature, featureOptions);
|
|
53
|
+
features.push(decodedFeature);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (binary) {
|
|
58
|
+
const data = (0, features_to_binary_1.featuresToBinary)(features, firstPassData);
|
|
59
|
+
// Add the original byteLength (as a reasonable approximation of the size of the binary data)
|
|
60
|
+
// TODO decide where to store extra fields like byteLength (header etc) and document
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
data.byteLength = arrayBuffer.byteLength;
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return features;
|
|
67
|
+
}
|
|
68
|
+
exports.default = parseMVT;
|
|
69
|
+
/**
|
|
70
|
+
* @param options
|
|
71
|
+
* @returns options
|
|
72
|
+
*/
|
|
73
|
+
function normalizeOptions(options) {
|
|
74
|
+
if (options) {
|
|
75
|
+
options = {
|
|
76
|
+
...options,
|
|
77
|
+
mvt: options.mvt || {},
|
|
78
|
+
gis: options.gis || {}
|
|
79
|
+
};
|
|
80
|
+
// Validate
|
|
81
|
+
const wgs84Coordinates = options.coordinates === 'wgs84';
|
|
82
|
+
const { tileIndex } = options;
|
|
83
|
+
const hasTileIndex = tileIndex &&
|
|
84
|
+
Number.isFinite(tileIndex.x) &&
|
|
85
|
+
Number.isFinite(tileIndex.y) &&
|
|
86
|
+
Number.isFinite(tileIndex.z);
|
|
87
|
+
if (wgs84Coordinates && !hasTileIndex) {
|
|
88
|
+
throw new Error('MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return options;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @param feature
|
|
95
|
+
* @param options
|
|
96
|
+
* @returns decoded feature
|
|
97
|
+
*/
|
|
98
|
+
function getDecodedFeature(feature, options) {
|
|
99
|
+
const decodedFeature = feature.toGeoJSON(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
|
|
100
|
+
// Add layer name to GeoJSON properties
|
|
101
|
+
if (options.layerProperty) {
|
|
102
|
+
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
103
|
+
}
|
|
104
|
+
return decodedFeature;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @param feature
|
|
108
|
+
* @param options
|
|
109
|
+
* @returns decoded binary feature
|
|
110
|
+
*/
|
|
111
|
+
function getDecodedFeatureBinary(feature, options) {
|
|
112
|
+
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
113
|
+
// Add layer name to GeoJSON properties
|
|
114
|
+
if (options.layerProperty) {
|
|
115
|
+
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
116
|
+
}
|
|
117
|
+
return decodedFeature;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @param line
|
|
121
|
+
* @param feature
|
|
122
|
+
*/
|
|
123
|
+
function transformToLocalCoordinates(line, feature) {
|
|
124
|
+
// This function transforms local coordinates in a
|
|
125
|
+
// [0 - bufferSize, this.extent + bufferSize] range to a
|
|
126
|
+
// [0 - (bufferSize / this.extent), 1 + (bufferSize / this.extent)] range.
|
|
127
|
+
// The resulting extent would be 1.
|
|
128
|
+
const { extent } = feature;
|
|
129
|
+
for (let i = 0; i < line.length; i++) {
|
|
130
|
+
const p = line[i];
|
|
131
|
+
p[0] /= extent;
|
|
132
|
+
p[1] /= extent;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function transformToLocalCoordinatesBinary(data, feature) {
|
|
136
|
+
// For the binary code path, the feature data is just
|
|
137
|
+
// one big flat array, so we just divide each value
|
|
138
|
+
const { extent } = feature;
|
|
139
|
+
for (let i = 0, il = data.length; i < il; ++i) {
|
|
140
|
+
data[i] /= extent;
|
|
141
|
+
}
|
|
142
|
+
}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"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"}
|
package/dist/mvt-loader.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvt-loader.d.ts","sourceRoot":"","sources":["../src/mvt-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAOvE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAsB7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAKvB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MVTLoader = exports.MVTWorkerLoader = void 0;
|
|
7
|
+
const parse_mvt_1 = __importDefault(require("./lib/parse-mvt"));
|
|
8
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
9
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
10
|
+
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
11
|
+
/**
|
|
12
|
+
* Worker loader for the Mapbox Vector Tile format
|
|
13
|
+
*/
|
|
14
|
+
exports.MVTWorkerLoader = {
|
|
15
|
+
name: 'Mapbox Vector Tile',
|
|
16
|
+
id: 'mvt',
|
|
17
|
+
module: 'mvt',
|
|
18
|
+
version: VERSION,
|
|
19
|
+
// Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
|
|
20
|
+
extensions: ['mvt', 'pbf'],
|
|
21
|
+
mimeTypes: [
|
|
22
|
+
'application/vnd.mapbox-vector-tile',
|
|
23
|
+
'application/x-protobuf'
|
|
24
|
+
// 'application/octet-stream'
|
|
25
|
+
],
|
|
26
|
+
worker: true,
|
|
27
|
+
category: 'geometry',
|
|
28
|
+
options: {
|
|
29
|
+
mvt: {
|
|
30
|
+
coordinates: 'local',
|
|
31
|
+
layerProperty: 'layerName',
|
|
32
|
+
layers: null,
|
|
33
|
+
tileIndex: null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Loader for the Mapbox Vector Tile format
|
|
39
|
+
*/
|
|
40
|
+
exports.MVTLoader = {
|
|
41
|
+
...exports.MVTWorkerLoader,
|
|
42
|
+
parse: async (arrayBuffer, options) => (0, parse_mvt_1.default)(arrayBuffer, options),
|
|
43
|
+
parseSync: parse_mvt_1.default,
|
|
44
|
+
binary: true
|
|
45
|
+
};
|