@loaders.gl/mvt 4.3.2 → 4.4.0-alpha.2
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
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// This code is inspired by https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
5
|
+
import Protobuf from 'pbf';
|
|
6
|
+
import * as MVT from "./mvt-constants.js";
|
|
7
|
+
import { readBoundingBoxFromPBF, loadFlatGeometryFromPBF } from "./parse-geometry-from-pbf.js";
|
|
8
|
+
const DEFAULT_LAYER = {
|
|
9
|
+
version: 1,
|
|
10
|
+
name: '',
|
|
11
|
+
extent: 4096,
|
|
12
|
+
length: 0,
|
|
13
|
+
schema: { fields: [], metadata: {} },
|
|
14
|
+
columns: {},
|
|
15
|
+
idColumn: [],
|
|
16
|
+
geometryTypeColumn: [],
|
|
17
|
+
geometryColumn: [],
|
|
18
|
+
boundingBoxColumn: []
|
|
19
|
+
};
|
|
20
|
+
const DEFAULT_LAYER_DATA = {
|
|
21
|
+
currentFeature: 0,
|
|
22
|
+
keys: [],
|
|
23
|
+
values: [],
|
|
24
|
+
types: [],
|
|
25
|
+
columnTypes: [],
|
|
26
|
+
columnNullable: [],
|
|
27
|
+
featurePositions: [],
|
|
28
|
+
geometryPositions: []
|
|
29
|
+
};
|
|
30
|
+
/** Parse an MVT tile from an ArrayBuffer */
|
|
31
|
+
export function parseMVT(arrayBuffer) {
|
|
32
|
+
const pbf = new Protobuf(arrayBuffer);
|
|
33
|
+
return parseMVTTile(pbf);
|
|
34
|
+
}
|
|
35
|
+
/** Parse an MVT tile from a PBF buffer */
|
|
36
|
+
export function parseMVTTile(pbf, end) {
|
|
37
|
+
const tile = { layers: {} };
|
|
38
|
+
try {
|
|
39
|
+
pbf.readFields(readTileFieldFromPBF, tile, end);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
// eslint-disable-next-line no-console
|
|
43
|
+
console.warn(error);
|
|
44
|
+
}
|
|
45
|
+
return tile;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Protobuf read callback for a top-level tile object's PBF tags
|
|
49
|
+
* @param tag
|
|
50
|
+
* @param layers
|
|
51
|
+
* @param pbf
|
|
52
|
+
*/
|
|
53
|
+
function readTileFieldFromPBF(tag, tile, pbf) {
|
|
54
|
+
if (!pbf || !tile) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
switch (tag) {
|
|
58
|
+
case MVT.TileInfo.layers:
|
|
59
|
+
// get the byte length and end of the layer
|
|
60
|
+
const byteLength = pbf.readVarint();
|
|
61
|
+
const end = byteLength + pbf.pos;
|
|
62
|
+
const layer = parseLayer(pbf, end);
|
|
63
|
+
tile.layers[layer.name] = layer;
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
// ignore? log?
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Parse an MVT layer from BPF at current position */
|
|
70
|
+
export function parseLayer(pbf, end) {
|
|
71
|
+
const layerData = { layer: { ...DEFAULT_LAYER }, ...DEFAULT_LAYER_DATA };
|
|
72
|
+
pbf.readFields(readLayerFieldFromPBF, layerData, end);
|
|
73
|
+
// Read features
|
|
74
|
+
for (let featureIndex = 0; featureIndex < layerData.featurePositions.length; featureIndex++) {
|
|
75
|
+
// Determine start and end of feature in PBF
|
|
76
|
+
const featurePosition = layerData.featurePositions[featureIndex];
|
|
77
|
+
pbf.pos = featurePosition;
|
|
78
|
+
const byteLength = pbf.readVarint();
|
|
79
|
+
const end = byteLength + pbf.pos;
|
|
80
|
+
layerData.currentFeature = featureIndex;
|
|
81
|
+
pbf.readFields(readFeatureFieldFromPBF, layerData, end);
|
|
82
|
+
readBoundingBoxesFromPDF(pbf, layerData);
|
|
83
|
+
readGeometriesFromPBF(pbf, layerData);
|
|
84
|
+
}
|
|
85
|
+
// Post processing
|
|
86
|
+
const { layer } = layerData;
|
|
87
|
+
layer.length = layerData.featurePositions.length;
|
|
88
|
+
layer.schema = makeMVTSchema(layerData);
|
|
89
|
+
return layer;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* @param tag
|
|
94
|
+
* @param layer
|
|
95
|
+
* @param pbf
|
|
96
|
+
*/
|
|
97
|
+
function readLayerFieldFromPBF(tag, layerData, pbf) {
|
|
98
|
+
if (!layerData || !pbf) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
switch (tag) {
|
|
102
|
+
case MVT.LayerInfo.version:
|
|
103
|
+
layerData.layer.version = pbf.readVarint();
|
|
104
|
+
break;
|
|
105
|
+
case MVT.LayerInfo.name:
|
|
106
|
+
layerData.layer.name = pbf.readString();
|
|
107
|
+
break;
|
|
108
|
+
case MVT.LayerInfo.extent:
|
|
109
|
+
layerData.layer.extent = pbf.readVarint();
|
|
110
|
+
break;
|
|
111
|
+
case MVT.LayerInfo.features:
|
|
112
|
+
layerData.featurePositions.push(pbf.pos);
|
|
113
|
+
break;
|
|
114
|
+
case MVT.LayerInfo.keys:
|
|
115
|
+
layerData.keys.push(pbf.readString());
|
|
116
|
+
break;
|
|
117
|
+
case MVT.LayerInfo.values:
|
|
118
|
+
const [value, type] = parseValues(pbf);
|
|
119
|
+
layerData.values.push(value);
|
|
120
|
+
layerData.types.push(type);
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
// ignore? Log?
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* @param pbf
|
|
128
|
+
* @returns value
|
|
129
|
+
*/
|
|
130
|
+
function parseValues(pbf) {
|
|
131
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
132
|
+
let value = null;
|
|
133
|
+
// not a valid property type so we use it to detect multiple values
|
|
134
|
+
let type = -1;
|
|
135
|
+
// TODO - can we have multiple values?
|
|
136
|
+
while (pbf.pos < end) {
|
|
137
|
+
if (type !== -1) {
|
|
138
|
+
throw new Error('MVT: Multiple values not supported');
|
|
139
|
+
}
|
|
140
|
+
type = pbf.readVarint() >> 3;
|
|
141
|
+
value = readValueFromPBF(pbf, type);
|
|
142
|
+
}
|
|
143
|
+
return [value, type];
|
|
144
|
+
}
|
|
145
|
+
/** Read a type tagged value from the protobuf at current position */
|
|
146
|
+
function readValueFromPBF(pbf, type) {
|
|
147
|
+
switch (type) {
|
|
148
|
+
case MVT.PropertyType.string_value:
|
|
149
|
+
return pbf.readString();
|
|
150
|
+
case MVT.PropertyType.float_value:
|
|
151
|
+
return pbf.readFloat();
|
|
152
|
+
case MVT.PropertyType.double_value:
|
|
153
|
+
return pbf.readDouble();
|
|
154
|
+
case MVT.PropertyType.int_value:
|
|
155
|
+
return pbf.readVarint64();
|
|
156
|
+
case MVT.PropertyType.uint_value:
|
|
157
|
+
return pbf.readVarint();
|
|
158
|
+
case MVT.PropertyType.sint_value:
|
|
159
|
+
return pbf.readSVarint();
|
|
160
|
+
case MVT.PropertyType.bool_value:
|
|
161
|
+
return pbf.readBoolean();
|
|
162
|
+
default:
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
*
|
|
168
|
+
* @param tag
|
|
169
|
+
* @param feature
|
|
170
|
+
* @param pbf
|
|
171
|
+
*/
|
|
172
|
+
function readFeatureFieldFromPBF(tag, layerData, pbf) {
|
|
173
|
+
if (!pbf || !layerData) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
switch (tag) {
|
|
177
|
+
case MVT.FeatureInfo.id:
|
|
178
|
+
const id = pbf.readVarint();
|
|
179
|
+
layerData.layer.idColumn[layerData.currentFeature] = id;
|
|
180
|
+
break;
|
|
181
|
+
case MVT.FeatureInfo.tags:
|
|
182
|
+
parseColumnValues(pbf, layerData);
|
|
183
|
+
break;
|
|
184
|
+
case MVT.FeatureInfo.type:
|
|
185
|
+
const type = pbf.readVarint();
|
|
186
|
+
layerData.layer.geometryTypeColumn[layerData.currentFeature] = type;
|
|
187
|
+
break;
|
|
188
|
+
case MVT.FeatureInfo.geometry:
|
|
189
|
+
layerData.geometryPositions[layerData.currentFeature] = pbf.pos;
|
|
190
|
+
break;
|
|
191
|
+
default:
|
|
192
|
+
// ignore? log?
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
*
|
|
197
|
+
* @param pbf
|
|
198
|
+
* @param feature
|
|
199
|
+
*/
|
|
200
|
+
function parseColumnValues(pbf, layerData) {
|
|
201
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
202
|
+
while (pbf.pos < end) {
|
|
203
|
+
const keyIndex = pbf.readVarint();
|
|
204
|
+
const valueIndex = pbf.readVarint();
|
|
205
|
+
const columnName = layerData.keys[keyIndex];
|
|
206
|
+
const value = layerData.values[valueIndex];
|
|
207
|
+
layerData.columnTypes[columnName] = layerData.types[valueIndex];
|
|
208
|
+
layerData.columnNullable[columnName] ||= value === null;
|
|
209
|
+
layerData.layer.columns[columnName] ||= [];
|
|
210
|
+
layerData.layer.columns[columnName].push(value);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Geometry readers
|
|
214
|
+
function readBoundingBoxesFromPDF(pbf, layerData) {
|
|
215
|
+
for (let row = 0; row < layerData.geometryPositions.length; row++) {
|
|
216
|
+
pbf.pos = layerData.geometryPositions[row];
|
|
217
|
+
const boundingBox = readBoundingBoxFromPBF(pbf);
|
|
218
|
+
layerData.layer.boundingBoxColumn[row] = boundingBox;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function readGeometriesFromPBF(pbf, layerData) {
|
|
222
|
+
for (let row = 0; row < layerData.geometryPositions.length; row++) {
|
|
223
|
+
pbf.pos = layerData.geometryPositions[row];
|
|
224
|
+
const flatGeometry = loadFlatGeometryFromPBF(pbf);
|
|
225
|
+
layerData.layer.geometryColumn[row] = flatGeometry;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// Schema Builder
|
|
229
|
+
function makeMVTSchema(layerData) {
|
|
230
|
+
const { keys, columnTypes, columnNullable } = layerData;
|
|
231
|
+
const fields = [];
|
|
232
|
+
for (let i = 0; i < keys.length; i++) {
|
|
233
|
+
const key = keys[i];
|
|
234
|
+
const nullable = columnNullable[key];
|
|
235
|
+
switch (columnTypes[key]) {
|
|
236
|
+
case MVT.PropertyType.string_value:
|
|
237
|
+
fields.push({ name: keys[i], type: 'utf8', nullable });
|
|
238
|
+
break;
|
|
239
|
+
case MVT.PropertyType.float_value:
|
|
240
|
+
fields.push({ name: keys[i], type: 'float32', nullable });
|
|
241
|
+
break;
|
|
242
|
+
case MVT.PropertyType.double_value:
|
|
243
|
+
fields.push({ name: keys[i], type: 'float64', nullable });
|
|
244
|
+
break;
|
|
245
|
+
case MVT.PropertyType.int_value:
|
|
246
|
+
fields.push({ name: keys[i], type: 'int32', nullable });
|
|
247
|
+
break;
|
|
248
|
+
case MVT.PropertyType.uint_value:
|
|
249
|
+
fields.push({ name: keys[i], type: 'uint32', nullable });
|
|
250
|
+
break;
|
|
251
|
+
case MVT.PropertyType.sint_value:
|
|
252
|
+
fields.push({ name: keys[i], type: 'int32', nullable });
|
|
253
|
+
break;
|
|
254
|
+
case MVT.PropertyType.bool_value:
|
|
255
|
+
fields.push({ name: keys[i], type: 'bool', nullable });
|
|
256
|
+
break;
|
|
257
|
+
default:
|
|
258
|
+
// ignore?
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return { fields, metadata: {} };
|
|
262
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Feature, FlatFeature, FlatIndexedGeometry
|
|
1
|
+
import type { Feature, FlatFeature, FlatIndexedGeometry } from '@loaders.gl/schema';
|
|
2
|
+
import type { GeojsonGeometryInfo } from '@loaders.gl/gis';
|
|
2
3
|
import Protobuf from 'pbf';
|
|
3
4
|
export declare class VectorTileFeature {
|
|
4
5
|
properties: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAClF,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AACzD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAU3B,qBAAa,iBAAiB;IAC5B,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,aAAa,EAAE,mBAAmB,CAAC;IAEnC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAiD;gBAI/E,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,EAC5C,YAAY,CAAC,EAAE,mBAAmB;IAoBpC,gBAAgB,CACd,WAAW,EAAE,OAAO,GAAG,OAAO,EAC9B,SAAS,CAAC,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAC5C,OAAO;IAaV;;;;OAIG;IACH,eAAe,CACb,WAAW,EAAE,OAAO,GAAG,OAAO,EAC9B,SAAS,CAAC,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAC5C,WAAW;IAcd,2CAA2C;IAE3C,IAAI;IAwCJ;;;;OAIG;IACH,oBAAoB,CAClB,IAAI,EAAE,mBAAmB,EACzB,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI;;;;;;;IAsDrD,YAAY,IAAI,MAAM,EAAE,EAAE,EAAE;IAkD5B;;;;;;;;;;;;;;;;;;;;;OAqBG;IAEH,gBAAgB,IAAI,mBAAmB;CAqDxC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Protobuf from 'pbf';
|
|
2
2
|
import { VectorTileFeature } from "./vector-tile-feature.js";
|
|
3
|
-
import { GeojsonGeometryInfo } from '@loaders.gl/
|
|
3
|
+
import { GeojsonGeometryInfo } from '@loaders.gl/gis';
|
|
4
4
|
export declare class VectorTileLayer {
|
|
5
5
|
version: number;
|
|
6
6
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAOA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,iBAAiB,EAAC,iCAA8B;AACxD,OAAO,EAAC,mBAAmB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAOA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,iBAAiB,EAAC,iCAA8B;AACxD,OAAO,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AAEpD,qBAAa,eAAe;IAC1B,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;gBAER,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM;IAkBtC;;;;OAIG;IACH,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,iBAAiB;IAW/C;;;;;;OAMG;IACH,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,mBAAmB,GAAG,iBAAiB;CAiBlF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker loader for the Mapbox Vector Tile format
|
|
3
|
+
*/
|
|
4
|
+
export declare const MVTFormat: {
|
|
5
|
+
readonly name: "Mapbox Vector Tile";
|
|
6
|
+
readonly id: "mvt";
|
|
7
|
+
readonly module: "mvt";
|
|
8
|
+
readonly extensions: ["mvt", "pbf"];
|
|
9
|
+
readonly mimeTypes: ["application/vnd.mapbox-vector-tile", "application/x-protobuf"];
|
|
10
|
+
readonly category: "geometry";
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=mvt-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvt-format.d.ts","sourceRoot":"","sources":["../src/mvt-format.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;CAaK,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* Worker loader for the Mapbox Vector Tile format
|
|
6
|
+
*/
|
|
7
|
+
export const MVTFormat = {
|
|
8
|
+
name: 'Mapbox Vector Tile',
|
|
9
|
+
id: 'mvt',
|
|
10
|
+
module: 'mvt',
|
|
11
|
+
// Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
|
|
12
|
+
extensions: ['mvt', 'pbf'],
|
|
13
|
+
mimeTypes: [
|
|
14
|
+
// https://www.iana.org/assignments/media-types/application/vnd.mapbox-vector-tile
|
|
15
|
+
'application/vnd.mapbox-vector-tile',
|
|
16
|
+
'application/x-protobuf'
|
|
17
|
+
// 'application/octet-stream'
|
|
18
|
+
],
|
|
19
|
+
category: 'geometry'
|
|
20
|
+
};
|
package/dist/mvt-loader.d.ts
CHANGED
|
@@ -32,14 +32,8 @@ export type MVTLoaderOptions = LoaderOptions & {
|
|
|
32
32
|
export declare const MVTWorkerLoader: {
|
|
33
33
|
readonly dataType: any;
|
|
34
34
|
readonly batchType: never;
|
|
35
|
-
readonly name: "Mapbox Vector Tile";
|
|
36
|
-
readonly id: "mvt";
|
|
37
|
-
readonly module: "mvt";
|
|
38
35
|
readonly version: any;
|
|
39
|
-
readonly extensions: ["mvt", "pbf"];
|
|
40
|
-
readonly mimeTypes: ["application/vnd.mapbox-vector-tile", "application/x-protobuf"];
|
|
41
36
|
readonly worker: true;
|
|
42
|
-
readonly category: "geometry";
|
|
43
37
|
readonly options: {
|
|
44
38
|
readonly mvt: {
|
|
45
39
|
readonly shape: "geojson";
|
|
@@ -49,6 +43,12 @@ export declare const MVTWorkerLoader: {
|
|
|
49
43
|
readonly tileIndex: never;
|
|
50
44
|
};
|
|
51
45
|
};
|
|
46
|
+
readonly name: "Mapbox Vector Tile";
|
|
47
|
+
readonly id: "mvt";
|
|
48
|
+
readonly module: "mvt";
|
|
49
|
+
readonly extensions: ["mvt", "pbf"];
|
|
50
|
+
readonly mimeTypes: ["application/vnd.mapbox-vector-tile", "application/x-protobuf"];
|
|
51
|
+
readonly category: "geometry";
|
|
52
52
|
};
|
|
53
53
|
/**
|
|
54
54
|
* Loader for the Mapbox Vector Tile format
|
|
@@ -62,14 +62,8 @@ export declare const MVTLoader: {
|
|
|
62
62
|
readonly binary: true;
|
|
63
63
|
readonly dataType: any;
|
|
64
64
|
readonly batchType: never;
|
|
65
|
-
readonly name: "Mapbox Vector Tile";
|
|
66
|
-
readonly id: "mvt";
|
|
67
|
-
readonly module: "mvt";
|
|
68
65
|
readonly version: any;
|
|
69
|
-
readonly extensions: ["mvt", "pbf"];
|
|
70
|
-
readonly mimeTypes: ["application/vnd.mapbox-vector-tile", "application/x-protobuf"];
|
|
71
66
|
readonly worker: true;
|
|
72
|
-
readonly category: "geometry";
|
|
73
67
|
readonly options: {
|
|
74
68
|
readonly mvt: {
|
|
75
69
|
readonly shape: "geojson";
|
|
@@ -79,5 +73,11 @@ export declare const MVTLoader: {
|
|
|
79
73
|
readonly tileIndex: never;
|
|
80
74
|
};
|
|
81
75
|
};
|
|
76
|
+
readonly name: "Mapbox Vector Tile";
|
|
77
|
+
readonly id: "mvt";
|
|
78
|
+
readonly module: "mvt";
|
|
79
|
+
readonly extensions: ["mvt", "pbf"];
|
|
80
|
+
readonly mimeTypes: ["application/vnd.mapbox-vector-tile", "application/x-protobuf"];
|
|
81
|
+
readonly category: "geometry";
|
|
82
82
|
};
|
|
83
83
|
//# sourceMappingURL=mvt-loader.d.ts.map
|
package/dist/mvt-loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mvt-loader.d.ts","sourceRoot":"","sources":["../src/mvt-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA2B,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEtF,OAAO,EAAC,QAAQ,EAAC,2BAAwB;
|
|
1
|
+
{"version":3,"file":"mvt-loader.d.ts","sourceRoot":"","sources":["../src/mvt-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA2B,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEtF,OAAO,EAAC,QAAQ,EAAC,2BAAwB;AAOzC,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE;QACJ,6BAA6B;QAC7B,KAAK,CAAC,EAAE,eAAe,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;QACtF,sHAAsH;QACtH,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;QAChC,uJAAuJ;QACvJ,SAAS,CAAC,EAAE;YAAC,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAA;SAAC,CAAC;QAC9C,0GAA0G;QAC1G,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAChC,gJAAgJ;QAChJ,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAClB,8EAA8E;QAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,8DAA8D;QAC9D,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,yCAAyC;QACzC,MAAM,CAAC,EAAE,eAAe,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;KACxF,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe;uBAER,GAAG;wBACF,KAAK;;;;;;;;;;;;;;;;;;CAgBzB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS;yDAEiB,gBAAgB;;;;;;uBAxBnC,GAAG;wBACF,KAAK;;;;;;;;;;;;;;;;;;CA8BzB,CAAC"}
|
package/dist/mvt-loader.js
CHANGED
|
@@ -3,29 +3,19 @@
|
|
|
3
3
|
// Copyright vis.gl contributors
|
|
4
4
|
// import type {MVTOptions} from './lib/types';
|
|
5
5
|
import { parseMVT } from "./lib/parse-mvt.js";
|
|
6
|
+
import { MVTFormat } from "./mvt-format.js";
|
|
6
7
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
7
8
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
8
|
-
const VERSION = typeof "4.
|
|
9
|
+
const VERSION = typeof "4.4.0-alpha.1" !== 'undefined' ? "4.4.0-alpha.1" : 'latest';
|
|
9
10
|
/**
|
|
10
11
|
* Worker loader for the Mapbox Vector Tile format
|
|
11
12
|
*/
|
|
12
13
|
export const MVTWorkerLoader = {
|
|
14
|
+
...MVTFormat,
|
|
13
15
|
dataType: null,
|
|
14
16
|
batchType: null,
|
|
15
|
-
name: 'Mapbox Vector Tile',
|
|
16
|
-
id: 'mvt',
|
|
17
|
-
module: 'mvt',
|
|
18
17
|
version: VERSION,
|
|
19
|
-
// Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
|
|
20
|
-
extensions: ['mvt', 'pbf'],
|
|
21
|
-
mimeTypes: [
|
|
22
|
-
// https://www.iana.org/assignments/media-types/application/vnd.mapbox-vector-tile
|
|
23
|
-
'application/vnd.mapbox-vector-tile',
|
|
24
|
-
'application/x-protobuf'
|
|
25
|
-
// 'application/octet-stream'
|
|
26
|
-
],
|
|
27
18
|
worker: true,
|
|
28
|
-
category: 'geometry',
|
|
29
19
|
options: {
|
|
30
20
|
mvt: {
|
|
31
21
|
shape: 'geojson',
|
package/dist/mvt-source.d.ts
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import type { ImageType,
|
|
1
|
+
import type { ImageType, DataSourceOptions, ImageTileSource, VectorTileSource, GetTileParameters, GetTileDataParameters } from '@loaders.gl/loader-utils';
|
|
2
2
|
import { DataSource } from '@loaders.gl/loader-utils';
|
|
3
3
|
import { ImageLoaderOptions } from '@loaders.gl/images';
|
|
4
4
|
import { MVTLoaderOptions, TileJSON, TileJSONLoaderOptions } from '@loaders.gl/mvt';
|
|
5
|
-
/** Creates an MVTTileSource */
|
|
6
|
-
export declare const MVTSource: {
|
|
7
|
-
readonly name: "MVT";
|
|
8
|
-
readonly id: "mvt";
|
|
9
|
-
readonly module: "mvt";
|
|
10
|
-
readonly version: "0.0.0";
|
|
11
|
-
readonly extensions: ["mvt"];
|
|
12
|
-
readonly mimeTypes: ["application/octet-stream"];
|
|
13
|
-
readonly options: {
|
|
14
|
-
readonly mvt: {};
|
|
15
|
-
};
|
|
16
|
-
readonly type: "mvt";
|
|
17
|
-
readonly fromUrl: true;
|
|
18
|
-
readonly fromBlob: false;
|
|
19
|
-
readonly testURL: (url: string) => boolean;
|
|
20
|
-
readonly createDataSource: (url: string, props: MVTTileSourceProps) => MVTTileSource;
|
|
21
|
-
};
|
|
22
5
|
/** Properties for a Mapbox Vector Tile Source */
|
|
23
|
-
export type
|
|
6
|
+
export type MVTSourceOptions = DataSourceOptions & {
|
|
24
7
|
mvt?: {
|
|
25
8
|
/** if not supplied, loads tilejson.json, If null does not load metadata */
|
|
26
9
|
metadataUrl?: string | null;
|
|
@@ -32,6 +15,24 @@ export type MVTTileSourceProps = DataSourceProps & {
|
|
|
32
15
|
loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
|
|
33
16
|
};
|
|
34
17
|
};
|
|
18
|
+
/** Creates an MVTTileSource */
|
|
19
|
+
export declare const MVTSource: {
|
|
20
|
+
readonly version: "0.0.0";
|
|
21
|
+
readonly type: "mvt";
|
|
22
|
+
readonly fromUrl: true;
|
|
23
|
+
readonly fromBlob: false;
|
|
24
|
+
readonly defaultOptions: {
|
|
25
|
+
readonly mvt: {};
|
|
26
|
+
};
|
|
27
|
+
readonly testURL: (url: string) => boolean;
|
|
28
|
+
readonly createDataSource: (url: string, options: MVTSourceOptions) => MVTTileSource;
|
|
29
|
+
readonly name: "Mapbox Vector Tile";
|
|
30
|
+
readonly id: "mvt";
|
|
31
|
+
readonly module: "mvt";
|
|
32
|
+
readonly extensions: ["mvt", "pbf"];
|
|
33
|
+
readonly mimeTypes: ["application/vnd.mapbox-vector-tile", "application/x-protobuf"];
|
|
34
|
+
readonly category: "geometry";
|
|
35
|
+
};
|
|
35
36
|
/**
|
|
36
37
|
* MVT data source for Mapbox Vector Tiles v1.
|
|
37
38
|
*/
|
|
@@ -39,16 +40,13 @@ export type MVTTileSourceProps = DataSourceProps & {
|
|
|
39
40
|
* A PMTiles data source
|
|
40
41
|
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
41
42
|
*/
|
|
42
|
-
export declare class MVTTileSource extends DataSource implements ImageTileSource, VectorTileSource {
|
|
43
|
-
readonly props: MVTTileSourceProps;
|
|
44
|
-
readonly url: string;
|
|
43
|
+
export declare class MVTTileSource extends DataSource<string, MVTSourceOptions> implements ImageTileSource, VectorTileSource {
|
|
45
44
|
readonly metadataUrl: string | null;
|
|
46
|
-
data: string;
|
|
47
45
|
schema: 'tms' | 'xyz' | 'template';
|
|
48
46
|
metadata: Promise<TileJSON | null>;
|
|
49
47
|
extension: string;
|
|
50
48
|
mimeType: string | null;
|
|
51
|
-
constructor(url: string,
|
|
49
|
+
constructor(url: string, options: MVTSourceOptions);
|
|
52
50
|
getMetadata(): Promise<TileJSON | null>;
|
|
53
51
|
getTileMIMEType(): string | null;
|
|
54
52
|
getTile(parameters: GetTileParameters): Promise<ArrayBuffer | null>;
|
package/dist/mvt-source.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mvt-source.d.ts","sourceRoot":"","sources":["../src/mvt-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,SAAS,EACT,
|
|
1
|
+
{"version":3,"file":"mvt-source.d.ts","sourceRoot":"","sources":["../src/mvt-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAc,kBAAkB,EAAyB,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAEL,gBAAgB,EAEhB,QAAQ,EACR,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAGzB,iDAAiD;AACjD,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAAG;IACjD,GAAG,CAAC,EAAE;QAEJ,2EAA2E;QAC3E,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,oDAAoD;QACpD,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,mFAAmF;QACnF,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,+CAA+C;QAC/C,WAAW,CAAC,EAAE,qBAAqB,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;KAC7E,CAAC;CACH,CAAC;AAEF,+BAA+B;AAC/B,eAAO,MAAM,SAAS;;;;;;;;4BAaL,MAAM,KAAG,OAAO;qCACT,MAAM,WAAW,gBAAgB,KAAG,aAAa;;;;;;;CAG/B,CAAC;AAE3C;;GAEG;AACH;;;GAGG;AACH,qBAAa,aACX,SAAQ,UAAU,CAAC,MAAM,EAAE,gBAAgB,CAC3C,YAAW,eAAe,EAAE,gBAAgB;IAE5C,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC3C,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,UAAU,CAAS;IAC3C,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;gBAEnB,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB;IAc5C,WAAW,IAAI,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAgC7C,eAAe,IAAI,MAAM,GAAG,IAAI;IAI1B,OAAO,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAcnE,WAAW,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC;IAuB5D,YAAY,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;cAK5D,eAAe,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC;IAMvE,aAAa,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;cAK3D,gBAAgB,CAC9B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,iBAAiB,GAC5B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAc1B,cAAc,IAAI,MAAM,GAAG,IAAI;IAI/B,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;CAY3C;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAM5C;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,WAAW,EACrB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,EAAE,GAAE,MAAY,GACf,MAAM,CAiBR"}
|
package/dist/mvt-source.js
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { DataSource
|
|
4
|
+
import { DataSource } from '@loaders.gl/loader-utils';
|
|
5
5
|
import { ImageLoader, getBinaryImageMetadata } from '@loaders.gl/images';
|
|
6
6
|
import { MVTLoader, TileJSONLoader } from '@loaders.gl/mvt';
|
|
7
|
+
import { MVTFormat } from "./mvt-format.js";
|
|
7
8
|
/** Creates an MVTTileSource */
|
|
8
9
|
export const MVTSource = {
|
|
9
|
-
|
|
10
|
-
id: 'mvt',
|
|
11
|
-
module: 'mvt',
|
|
10
|
+
...MVTFormat,
|
|
12
11
|
version: '0.0.0',
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
type: 'mvt',
|
|
13
|
+
fromUrl: true,
|
|
14
|
+
fromBlob: false,
|
|
15
|
+
defaultOptions: {
|
|
16
16
|
mvt: {
|
|
17
17
|
// TODO - add options here
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
-
type: 'mvt',
|
|
21
|
-
fromUrl: true,
|
|
22
|
-
fromBlob: false,
|
|
23
20
|
testURL: (url) => true,
|
|
24
|
-
createDataSource(url,
|
|
25
|
-
return new MVTTileSource(url,
|
|
21
|
+
createDataSource(url, options) {
|
|
22
|
+
return new MVTTileSource(url, options);
|
|
26
23
|
}
|
|
27
24
|
};
|
|
28
25
|
/**
|
|
@@ -33,21 +30,15 @@ export const MVTSource = {
|
|
|
33
30
|
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
34
31
|
*/
|
|
35
32
|
export class MVTTileSource extends DataSource {
|
|
36
|
-
props;
|
|
37
|
-
url;
|
|
38
33
|
metadataUrl = null;
|
|
39
|
-
data;
|
|
40
34
|
schema = 'tms';
|
|
41
35
|
metadata;
|
|
42
36
|
extension;
|
|
43
37
|
mimeType = null;
|
|
44
|
-
constructor(url,
|
|
45
|
-
super(
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
this.metadataUrl = props.mvt?.metadataUrl || `${this.url}/tilejson.json`;
|
|
49
|
-
this.extension = props.mvt?.extension || '.png';
|
|
50
|
-
this.data = this.url;
|
|
38
|
+
constructor(url, options) {
|
|
39
|
+
super(url, options, MVTSource.defaultOptions);
|
|
40
|
+
this.metadataUrl = options.mvt?.metadataUrl || `${this.url}/tilejson.json`;
|
|
41
|
+
this.extension = options.mvt?.extension || '.png';
|
|
51
42
|
this.getTileData = this.getTileData.bind(this);
|
|
52
43
|
this.metadata = this.getMetadata();
|
|
53
44
|
if (isURLTemplate(this.url)) {
|
|
@@ -78,7 +69,7 @@ export class MVTTileSource extends DataSource {
|
|
|
78
69
|
const tileJSON = await response.text();
|
|
79
70
|
const metadata = TileJSONLoader.parseTextSync?.(tileJSON) || null;
|
|
80
71
|
// TODO add metadata attributions
|
|
81
|
-
// metadata.attributions = [...this.
|
|
72
|
+
// metadata.attributions = [...this.options.attributions, ...(metadata.attributions || [])];
|
|
82
73
|
// if (metadata?.mimeType) {
|
|
83
74
|
// this.mimeType = metadata?.tileMIMEType;
|
|
84
75
|
// }
|