@loaders.gl/mvt 4.2.0-alpha.4 → 4.2.0-alpha.6
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 +312 -244
- package/dist/dist.min.js +14 -0
- package/dist/helpers/binary-util-functions.d.ts +1 -1
- package/dist/helpers/binary-util-functions.d.ts.map +1 -1
- package/dist/helpers/binary-util-functions.js +99 -61
- package/dist/helpers/mapbox-util-functions.d.ts +2 -2
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -1
- package/dist/helpers/mapbox-util-functions.js +67 -33
- package/dist/index.cjs +86 -68
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +144 -118
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -38
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +1 -1
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile.js +18 -12
- package/dist/lib/geojson-tiler/clip.d.ts +1 -1
- package/dist/lib/geojson-tiler/clip.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/clip.js +180 -142
- package/dist/lib/geojson-tiler/convert.d.ts +1 -1
- package/dist/lib/geojson-tiler/convert.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/convert.js +116 -100
- package/dist/lib/geojson-tiler/feature.d.ts +1 -1
- package/dist/lib/geojson-tiler/feature.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/feature.js +38 -29
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts +1 -1
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/geojson-tiler.js +198 -159
- package/dist/lib/geojson-tiler/simplify.js +60 -40
- package/dist/lib/geojson-tiler/tile.js +108 -88
- package/dist/lib/geojson-tiler/transform.d.ts +1 -1
- package/dist/lib/geojson-tiler/transform.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/transform.js +35 -26
- package/dist/lib/geojson-tiler/wrap.d.ts +1 -1
- package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/wrap.js +74 -53
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +164 -151
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -38
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.js +18 -12
- package/dist/lib/parse-mvt.d.ts +1 -1
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +142 -115
- package/dist/lib/parse-tilejson.js +234 -176
- package/dist/lib/types.js +0 -1
- package/dist/mvt-loader.d.ts +1 -1
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +42 -22
- package/dist/mvt-source.js +153 -139
- package/dist/mvt-worker.js +39 -2
- package/dist/tilejson-loader.d.ts +1 -1
- package/dist/tilejson-loader.d.ts.map +1 -1
- package/dist/tilejson-loader.js +32 -31
- package/dist/workers/mvt-worker.js +0 -1
- package/package.json +12 -8
- package/dist/helpers/binary-util-functions.js.map +0 -1
- package/dist/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/binary-vector-tile/LICENSE.txt +0 -31
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/geojson-tiler/LICENSE +0 -19
- package/dist/lib/geojson-tiler/clip.js.map +0 -1
- package/dist/lib/geojson-tiler/convert.js.map +0 -1
- package/dist/lib/geojson-tiler/feature.js.map +0 -1
- package/dist/lib/geojson-tiler/geojson-tiler.js.map +0 -1
- package/dist/lib/geojson-tiler/simplify.js.map +0 -1
- package/dist/lib/geojson-tiler/tile.js.map +0 -1
- package/dist/lib/geojson-tiler/transform.js.map +0 -1
- package/dist/lib/geojson-tiler/wrap.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/LICENSE.txt +0 -31
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/parse-mvt.js.map +0 -1
- package/dist/lib/parse-tilejson.js.map +0 -1
- package/dist/lib/types.js.map +0 -1
- package/dist/mvt-loader.js.map +0 -1
- package/dist/mvt-source.js.map +0 -1
- package/dist/tilejson-loader.js.map +0 -1
- package/dist/workers/mvt-worker.js.map +0 -1
package/dist/mvt-source.js
CHANGED
|
@@ -1,160 +1,174 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { DataSource, resolvePath } from '@loaders.gl/loader-utils';
|
|
2
5
|
import { ImageLoader, getBinaryImageMetadata } from '@loaders.gl/images';
|
|
3
6
|
import { MVTLoader, TileJSONLoader } from '@loaders.gl/mvt';
|
|
7
|
+
/**
|
|
8
|
+
* MVT data source for Mapbox Vector Tiles v1.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* A PMTiles data source
|
|
12
|
+
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
13
|
+
*/
|
|
4
14
|
export class MVTSource extends DataSource {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
props;
|
|
16
|
+
url;
|
|
17
|
+
metadataUrl = null;
|
|
18
|
+
data;
|
|
19
|
+
schema = 'tms';
|
|
20
|
+
metadata;
|
|
21
|
+
extension;
|
|
22
|
+
mimeType = null;
|
|
23
|
+
constructor(props) {
|
|
24
|
+
super(props);
|
|
25
|
+
this.props = props;
|
|
26
|
+
this.url = resolvePath(props.url);
|
|
27
|
+
this.metadataUrl =
|
|
28
|
+
props.metadataUrl === undefined ? `${this.url}/tilejson.json` : props.metadataUrl;
|
|
29
|
+
this.extension = props.extension || '.png';
|
|
30
|
+
this.data = this.url;
|
|
31
|
+
this.getTileData = this.getTileData.bind(this);
|
|
32
|
+
this.metadata = this.getMetadata();
|
|
33
|
+
if (isURLTemplate(this.url)) {
|
|
34
|
+
this.schema = 'template';
|
|
35
|
+
}
|
|
24
36
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
// @ts-ignore - Metadata type misalignment
|
|
38
|
+
async getMetadata() {
|
|
39
|
+
if (!this.metadataUrl) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
let response;
|
|
43
|
+
try {
|
|
44
|
+
// Annoyingly, on CORS errors, fetch doesn't use the response status/ok mechanism but instead throws
|
|
45
|
+
// CORS errors are common when requesting an unavailable sub resource such as a metadata file or an unavailable tile)
|
|
46
|
+
response = await this.fetch(this.metadataUrl);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.error(error.message);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
// eslint-disable-next-line no-console
|
|
55
|
+
console.error(response.statusText);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const tileJSON = await response.text();
|
|
59
|
+
const metadata = TileJSONLoader.parseTextSync?.(tileJSON) || null;
|
|
60
|
+
// TODO add metadata attributions
|
|
61
|
+
// metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];
|
|
62
|
+
// if (metadata?.mimeType) {
|
|
63
|
+
// this.mimeType = metadata?.tileMIMEType;
|
|
64
|
+
// }
|
|
65
|
+
return metadata;
|
|
30
66
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
response = await this.fetch(this.metadataUrl);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error(error.message);
|
|
36
|
-
return null;
|
|
67
|
+
getTileMIMEType() {
|
|
68
|
+
return this.mimeType;
|
|
37
69
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
70
|
+
async getTile(tileParams) {
|
|
71
|
+
const { x, y, zoom: z } = tileParams;
|
|
72
|
+
const tileUrl = this.getTileURL(x, y, z);
|
|
73
|
+
const response = await this.fetch(tileUrl);
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
78
|
+
return arrayBuffer;
|
|
41
79
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
80
|
+
// Tile Source interface implementation: deck.gl compatible API
|
|
81
|
+
// TODO - currently only handles image tiles, not vector tiles
|
|
82
|
+
async getTileData(tileParams) {
|
|
83
|
+
const { x, y, z } = tileParams.index;
|
|
84
|
+
// const metadata = await this.metadata;
|
|
85
|
+
// mimeType = metadata?.tileMIMEType || 'application/vnd.mapbox-vector-tile';
|
|
86
|
+
const arrayBuffer = await this.getTile({ x, y, zoom: z, layers: [] });
|
|
87
|
+
if (arrayBuffer === null) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const imageMetadata = getBinaryImageMetadata(arrayBuffer);
|
|
91
|
+
this.mimeType =
|
|
92
|
+
this.mimeType || imageMetadata?.mimeType || 'application/vnd.mapbox-vector-tile';
|
|
93
|
+
switch (this.mimeType) {
|
|
94
|
+
case 'application/vnd.mapbox-vector-tile':
|
|
95
|
+
return await this._parseVectorTile(arrayBuffer, { x, y, zoom: z, layers: [] });
|
|
96
|
+
default:
|
|
97
|
+
return await this._parseImageTile(arrayBuffer);
|
|
98
|
+
}
|
|
59
99
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const {
|
|
65
|
-
x,
|
|
66
|
-
y,
|
|
67
|
-
z
|
|
68
|
-
} = tileParams.index;
|
|
69
|
-
const arrayBuffer = await this.getTile({
|
|
70
|
-
x,
|
|
71
|
-
y,
|
|
72
|
-
zoom: z,
|
|
73
|
-
layers: []
|
|
74
|
-
});
|
|
75
|
-
if (arrayBuffer === null) {
|
|
76
|
-
return null;
|
|
100
|
+
// ImageTileSource interface implementation
|
|
101
|
+
async getImageTile(tileParams) {
|
|
102
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
103
|
+
return arrayBuffer ? this._parseImageTile(arrayBuffer) : null;
|
|
77
104
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
switch (this.mimeType) {
|
|
81
|
-
case 'application/vnd.mapbox-vector-tile':
|
|
82
|
-
return await this._parseVectorTile(arrayBuffer, {
|
|
83
|
-
x,
|
|
84
|
-
y,
|
|
85
|
-
zoom: z,
|
|
86
|
-
layers: []
|
|
87
|
-
});
|
|
88
|
-
default:
|
|
89
|
-
return await this._parseImageTile(arrayBuffer);
|
|
105
|
+
async _parseImageTile(arrayBuffer) {
|
|
106
|
+
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
90
107
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
getTileURL(x, y, z) {
|
|
124
|
-
switch (this.schema) {
|
|
125
|
-
case 'xyz':
|
|
126
|
-
return `${this.url}/${x}/${y}/${z}${this.extension}`;
|
|
127
|
-
case 'tms':
|
|
128
|
-
return `${this.url}/${z}/${x}/${y}${this.extension}`;
|
|
129
|
-
case 'template':
|
|
130
|
-
return getURLFromTemplate(this.url, x, y, z, '0');
|
|
131
|
-
default:
|
|
132
|
-
throw new Error(this.schema);
|
|
108
|
+
// VectorTileSource interface implementation
|
|
109
|
+
async getVectorTile(tileParams) {
|
|
110
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
111
|
+
return arrayBuffer ? this._parseVectorTile(arrayBuffer, tileParams) : null;
|
|
112
|
+
}
|
|
113
|
+
async _parseVectorTile(arrayBuffer, tileParams) {
|
|
114
|
+
const loadOptions = {
|
|
115
|
+
shape: 'geojson-table',
|
|
116
|
+
mvt: {
|
|
117
|
+
coordinates: 'wgs84',
|
|
118
|
+
tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.zoom },
|
|
119
|
+
...this.loadOptions?.mvt
|
|
120
|
+
},
|
|
121
|
+
...this.loadOptions
|
|
122
|
+
};
|
|
123
|
+
return await MVTLoader.parse(arrayBuffer, loadOptions);
|
|
124
|
+
}
|
|
125
|
+
getMetadataUrl() {
|
|
126
|
+
return this.metadataUrl;
|
|
127
|
+
}
|
|
128
|
+
getTileURL(x, y, z) {
|
|
129
|
+
switch (this.schema) {
|
|
130
|
+
case 'xyz':
|
|
131
|
+
return `${this.url}/${x}/${y}/${z}${this.extension}`;
|
|
132
|
+
case 'tms':
|
|
133
|
+
return `${this.url}/${z}/${x}/${y}${this.extension}`;
|
|
134
|
+
case 'template':
|
|
135
|
+
return getURLFromTemplate(this.url, x, y, z, '0');
|
|
136
|
+
default:
|
|
137
|
+
throw new Error(this.schema);
|
|
138
|
+
}
|
|
133
139
|
}
|
|
134
|
-
}
|
|
135
140
|
}
|
|
136
141
|
export function isURLTemplate(s) {
|
|
137
|
-
|
|
142
|
+
return /(?=.*{z})(?=.*{x})(?=.*({y}|{-y}))|(?=.*{x})(?=.*({y}|{-y})(?=.*{z}))/.test(s);
|
|
138
143
|
}
|
|
139
144
|
const xRegex = new RegExp('{x}', 'g');
|
|
140
145
|
const yRegex = new RegExp('{y}', 'g');
|
|
141
146
|
const zRegex = new RegExp('{z}', 'g');
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Get a URL from a URL template
|
|
149
|
+
* @note copied from deck.gl/modules/geo-layers/src/tileset-2d/utils.ts
|
|
150
|
+
* @param template - URL template
|
|
151
|
+
* @param x - tile x coordinate
|
|
152
|
+
* @param y - tile y coordinate
|
|
153
|
+
* @param z - tile z coordinate
|
|
154
|
+
* @param id - tile id
|
|
155
|
+
* @returns URL
|
|
156
|
+
*/
|
|
157
|
+
export function getURLFromTemplate(template, x, y, z, id = '0') {
|
|
158
|
+
if (Array.isArray(template)) {
|
|
159
|
+
const i = stringHash(id) % template.length;
|
|
160
|
+
template = template[i];
|
|
161
|
+
}
|
|
162
|
+
let url = template;
|
|
163
|
+
url = url.replace(xRegex, String(x));
|
|
164
|
+
url = url.replace(yRegex, String(y));
|
|
165
|
+
url = url.replace(zRegex, String(z));
|
|
166
|
+
// Back-compatible support for {-y}
|
|
167
|
+
if (Number.isInteger(y) && Number.isInteger(z)) {
|
|
168
|
+
url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
|
|
169
|
+
}
|
|
170
|
+
return url;
|
|
156
171
|
}
|
|
157
172
|
function stringHash(s) {
|
|
158
|
-
|
|
173
|
+
return Math.abs(s.split('').reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0));
|
|
159
174
|
}
|
|
160
|
-
//# sourceMappingURL=mvt-source.js.map
|
package/dist/mvt-worker.js
CHANGED
|
@@ -1673,6 +1673,14 @@
|
|
|
1673
1673
|
|
|
1674
1674
|
// src/lib/mapbox-vector-tile/vector-tile-feature.ts
|
|
1675
1675
|
var VectorTileFeature = class {
|
|
1676
|
+
properties;
|
|
1677
|
+
extent;
|
|
1678
|
+
type;
|
|
1679
|
+
id;
|
|
1680
|
+
_pbf;
|
|
1681
|
+
_geometry;
|
|
1682
|
+
_keys;
|
|
1683
|
+
_values;
|
|
1676
1684
|
static get types() {
|
|
1677
1685
|
return ["Unknown", "Point", "LineString", "Polygon"];
|
|
1678
1686
|
}
|
|
@@ -1832,6 +1840,14 @@
|
|
|
1832
1840
|
|
|
1833
1841
|
// src/lib/mapbox-vector-tile/vector-tile-layer.ts
|
|
1834
1842
|
var VectorTileLayer = class {
|
|
1843
|
+
version;
|
|
1844
|
+
name;
|
|
1845
|
+
extent;
|
|
1846
|
+
length;
|
|
1847
|
+
_pbf;
|
|
1848
|
+
_keys;
|
|
1849
|
+
_values;
|
|
1850
|
+
_features;
|
|
1835
1851
|
constructor(pbf, end) {
|
|
1836
1852
|
this.version = 1;
|
|
1837
1853
|
this.name = "";
|
|
@@ -1886,6 +1902,7 @@
|
|
|
1886
1902
|
|
|
1887
1903
|
// src/lib/mapbox-vector-tile/vector-tile.ts
|
|
1888
1904
|
var VectorTile = class {
|
|
1905
|
+
layers;
|
|
1889
1906
|
constructor(pbf, end) {
|
|
1890
1907
|
this.layers = pbf.readFields(readTile, {}, end);
|
|
1891
1908
|
}
|
|
@@ -1988,6 +2005,15 @@
|
|
|
1988
2005
|
var y;
|
|
1989
2006
|
var i;
|
|
1990
2007
|
var VectorTileFeature2 = class {
|
|
2008
|
+
properties;
|
|
2009
|
+
extent;
|
|
2010
|
+
type;
|
|
2011
|
+
id;
|
|
2012
|
+
_pbf;
|
|
2013
|
+
_geometry;
|
|
2014
|
+
_keys;
|
|
2015
|
+
_values;
|
|
2016
|
+
_geometryInfo;
|
|
1991
2017
|
// eslint-disable-next-line max-params
|
|
1992
2018
|
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
1993
2019
|
this.properties = {};
|
|
@@ -2094,6 +2120,14 @@
|
|
|
2094
2120
|
|
|
2095
2121
|
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
2096
2122
|
var VectorTileLayer2 = class {
|
|
2123
|
+
version;
|
|
2124
|
+
name;
|
|
2125
|
+
extent;
|
|
2126
|
+
length;
|
|
2127
|
+
_pbf;
|
|
2128
|
+
_keys;
|
|
2129
|
+
_values;
|
|
2130
|
+
_features;
|
|
2097
2131
|
constructor(pbf, end) {
|
|
2098
2132
|
this.version = 1;
|
|
2099
2133
|
this.name = "";
|
|
@@ -2157,6 +2191,7 @@
|
|
|
2157
2191
|
|
|
2158
2192
|
// src/lib/binary-vector-tile/vector-tile.ts
|
|
2159
2193
|
var VectorTile2 = class {
|
|
2194
|
+
layers;
|
|
2160
2195
|
constructor(pbf, end) {
|
|
2161
2196
|
this.layers = pbf.readFields(readTile2, {}, end);
|
|
2162
2197
|
}
|
|
@@ -2303,7 +2338,7 @@
|
|
|
2303
2338
|
}
|
|
2304
2339
|
|
|
2305
2340
|
// src/mvt-loader.ts
|
|
2306
|
-
var VERSION = true ? "4.2.0-alpha.
|
|
2341
|
+
var VERSION = true ? "4.2.0-alpha.5" : "latest";
|
|
2307
2342
|
var MVTWorkerLoader = {
|
|
2308
2343
|
name: "Mapbox Vector Tile",
|
|
2309
2344
|
id: "mvt",
|
|
@@ -2395,7 +2430,9 @@
|
|
|
2395
2430
|
}
|
|
2396
2431
|
getParentPort().then((parentPort2) => {
|
|
2397
2432
|
if (parentPort2) {
|
|
2398
|
-
parentPort2.on("message",
|
|
2433
|
+
parentPort2.on("message", (message) => {
|
|
2434
|
+
handleMessage(message);
|
|
2435
|
+
});
|
|
2399
2436
|
parentPort2.on("exit", () => console.debug("Node worker closing"));
|
|
2400
2437
|
} else {
|
|
2401
2438
|
globalThis.onmessage = handleMessage;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
-
import type { TileJSON } from
|
|
2
|
+
import type { TileJSON } from "./lib/parse-tilejson.js";
|
|
3
3
|
export type TileJSONLoaderOptions = LoaderOptions & {
|
|
4
4
|
/** Options for the TileJSONLoader */
|
|
5
5
|
tilejson?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tilejson-loader.d.ts","sourceRoot":"","sources":["../src/tilejson-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAC,QAAQ,EAAC,
|
|
1
|
+
{"version":3,"file":"tilejson-loader.d.ts","sourceRoot":"","sources":["../src/tilejson-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAC,QAAQ,EAAC,gCAA6B;AAOnD,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAAG;IAClD,qCAAqC;IACrC,QAAQ,CAAC,EAAE;QACT,kCAAkC;QAClC,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAAE,qBAAqB,CAyBnF,CAAC"}
|
package/dist/tilejson-loader.js
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { parseTileJSON } from "./lib/parse-tilejson.js";
|
|
2
|
-
|
|
5
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
+
const VERSION = typeof "4.2.0-alpha.5" !== 'undefined' ? "4.2.0-alpha.5" : 'latest';
|
|
8
|
+
/**
|
|
9
|
+
* Loader for TileJSON metadata
|
|
10
|
+
*/
|
|
3
11
|
export const TileJSONLoader = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
name: 'TileJSON',
|
|
13
|
+
id: 'tilejson',
|
|
14
|
+
module: 'pmtiles',
|
|
15
|
+
version: VERSION,
|
|
16
|
+
worker: true,
|
|
17
|
+
extensions: ['json'],
|
|
18
|
+
mimeTypes: ['application/json'],
|
|
19
|
+
text: true,
|
|
20
|
+
options: {
|
|
21
|
+
tilejson: {
|
|
22
|
+
maxValues: undefined
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
parse: async (arrayBuffer, options) => {
|
|
26
|
+
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
27
|
+
const json = JSON.parse(jsonString);
|
|
28
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
29
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
30
|
+
},
|
|
31
|
+
parseTextSync: (text, options) => {
|
|
32
|
+
const json = JSON.parse(text);
|
|
33
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
34
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
15
35
|
}
|
|
16
|
-
},
|
|
17
|
-
parse: async (arrayBuffer, options) => {
|
|
18
|
-
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
19
|
-
const json = JSON.parse(jsonString);
|
|
20
|
-
const tilejsonOptions = {
|
|
21
|
-
...TileJSONLoader.options.tilejson,
|
|
22
|
-
...(options === null || options === void 0 ? void 0 : options.tilejson)
|
|
23
|
-
};
|
|
24
|
-
return parseTileJSON(json, tilejsonOptions);
|
|
25
|
-
},
|
|
26
|
-
parseTextSync: (text, options) => {
|
|
27
|
-
const json = JSON.parse(text);
|
|
28
|
-
const tilejsonOptions = {
|
|
29
|
-
...TileJSONLoader.options.tilejson,
|
|
30
|
-
...(options === null || options === void 0 ? void 0 : options.tilejson)
|
|
31
|
-
};
|
|
32
|
-
return parseTileJSON(json, tilejsonOptions);
|
|
33
|
-
}
|
|
34
36
|
};
|
|
35
|
-
//# sourceMappingURL=tilejson-loader.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/mvt",
|
|
3
3
|
"description": "Loader for Mapbox Vector Tiles",
|
|
4
|
-
"version": "4.2.0-alpha.
|
|
4
|
+
"version": "4.2.0-alpha.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -35,20 +35,24 @@
|
|
|
35
35
|
"README.md"
|
|
36
36
|
],
|
|
37
37
|
"scripts": {
|
|
38
|
-
"pre-build": "npm run build-worker && npm run build-worker --env.dev && npm run build-bundle && npm run build-bundle
|
|
39
|
-
"build-bundle": "ocular-bundle ./
|
|
38
|
+
"pre-build": "npm run build-worker && npm run build-worker --env.dev && npm run build-bundle && npm run build-bundle-dev",
|
|
39
|
+
"build-bundle": "ocular-bundle ./bundle.ts --output=dist/dist.min.js",
|
|
40
|
+
"build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js",
|
|
40
41
|
"build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
|
-
"@loaders.gl/gis": "4.2.0-alpha.
|
|
44
|
-
"@loaders.gl/images": "4.2.0-alpha.
|
|
45
|
-
"@loaders.gl/loader-utils": "4.2.0-alpha.
|
|
46
|
-
"@loaders.gl/schema": "4.2.0-alpha.
|
|
44
|
+
"@loaders.gl/gis": "4.2.0-alpha.6",
|
|
45
|
+
"@loaders.gl/images": "4.2.0-alpha.6",
|
|
46
|
+
"@loaders.gl/loader-utils": "4.2.0-alpha.6",
|
|
47
|
+
"@loaders.gl/schema": "4.2.0-alpha.6",
|
|
47
48
|
"@math.gl/polygon": "^4.0.0",
|
|
48
49
|
"pbf": "^3.2.1"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@types/pbf": "^3.0.2"
|
|
52
53
|
},
|
|
53
|
-
"
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@loaders.gl/core": "^4.0.0"
|
|
56
|
+
},
|
|
57
|
+
"gitHead": "37bd8ca71763529f18727ee4bf29dd176aa914ca"
|
|
54
58
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"binary-util-functions.js","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"],"sources":["../../src/helpers/binary-util-functions.ts"],"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"],"mappings":"AACA,SAAQA,oBAAoB,QAAO,kBAAkB;AAcrD,OAAO,SAASC,aAAaA,CAACC,IAAyB,EAAe;EACpE,MAAMC,GAAG,GAAGD,IAAI,CAACE,OAAO,CAACC,MAAM;EAC/B,MAAMC,IAAI,GAAG,SAAS;EAEtB,IAAIH,GAAG,IAAI,CAAC,EAAE;IACZ,OAAO;MACLG,IAAI;MACJC,IAAI,EAAEL,IAAI,CAACK,IAAI;MACfC,KAAK,EAAE,CAAC,CAACR,oBAAoB,CAACE,IAAI,CAACK,IAAI,CAAC,CAAC,CAAC;MAC1CH,OAAO,EAAE,CAACF,IAAI,CAACE,OAAO;IACxB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AAG,EAAE;IAClB,IAAIF,GAAG,KAAK,CAAC,EAAEC,OAAO,CAACE,EAAE,GAAGD,GAAG,CAACE,UAAU,CAAC,CAAC,CAAC,KACxC,IAAIJ,GAAG,KAAK,CAAC,EAAEK,OAAO,CAACH,GAAG,EAAED,OAAO,CAAC,CAAC,KACrC,IAAID,GAAG,KAAK,CAAC,EAAEC,OAAO,CAAChC,IAAI,GAAGiC,GAAG,CAACE,UAAU,CAAC,CAAC,CAAC,KAC/C,IAAIJ,GAAG,KAAK,CAAC,EAAEC,OAAO,CAACK,SAAS,GAAGJ,GAAG,CAACK,GAAG;EACjD;AACF;AAMA,OAAO,SAASF,OAAOA,CAACH,GAAa,EAAED,OAA0B,EAAQ;EACvE,MAAMO,GAAG,GAAGN,GAAG,CAACE,UAAU,CAAC,CAAC,GAAGF,GAAG,CAACK,GAAG;EAEtC,OAAOL,GAAG,CAACK,GAAG,GAAGC,GAAG,EAAE;IACpB,MAAMC,GAAG,GAAGR,OAAO,CAACS,KAAK,CAACR,GAAG,CAACE,UAAU,CAAC,CAAC,CAAC;IAC3C,MAAMO,KAAK,GAAGV,OAAO,CAACW,OAAO,CAACV,GAAG,CAACE,UAAU,CAAC,CAAC,CAAC;IAC/CH,OAAO,CAACY,UAAU,CAACJ,GAAG,CAAC,GAAGE,KAAK;EACjC;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mapbox-util-functions.js","names":["classifyRings","rings","len","length","polygons","polygon","ccw","i","area","signedArea","undefined","push","ring","sum","j","p1","p2","readFeature","tag","feature","pbf","id","readVarint","readTag","type","_geometry","pos","end","key","_keys","value","_values","properties"],"sources":["../../src/helpers/mapbox-util-functions.ts"],"sourcesContent":["import Protobuf from 'pbf';\nimport {MVTMapboxGeometry} from '../lib/types';\nimport VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';\n\n/**\n * Classifies an array of rings into polygons with outer rings and holes\n * @param rings\n * @returns polygons\n */\nexport function classifyRings(rings: MVTMapboxGeometry) {\n const len = rings.length;\n\n if (len <= 1) return [rings];\n\n const polygons: number[][][] = [];\n let polygon: number[][] | undefined;\n let ccw: boolean | undefined;\n\n for (let i = 0; i < len; i++) {\n const area = signedArea(rings[i]);\n if (area === 0) continue; // eslint-disable-line no-continue\n\n if (ccw === undefined) ccw = area < 0;\n\n if (ccw === area < 0) {\n if (polygon) polygons.push(polygon);\n polygon = [rings[i]];\n } else if (polygon) polygon.push(rings[i]);\n }\n if (polygon) polygons.push(polygon);\n\n return polygons;\n}\n\n/**\n *\n * @param ring\n * @returns sum\n */\nexport function signedArea(ring: number[][]) {\n let sum = 0;\n for (let i = 0, j = ring.length - 1, p1: number[], p2: number[]; i < ring.length; j = i++) {\n p1 = ring[i];\n p2 = ring[j];\n sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);\n }\n return sum;\n}\n\n/**\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 *\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"],"mappings":"AASA,OAAO,SAASA,aAAaA,CAACC,KAAwB,EAAE;EACtD,MAAMC,GAAG,GAAGD,KAAK,CAACE,MAAM;EAExB,IAAID,GAAG,IAAI,CAAC,EAAE,OAAO,CAACD,KAAK,CAAC;EAE5B,MAAMG,QAAsB,GAAG,EAAE;EACjC,IAAIC,OAA+B;EACnC,IAAIC,GAAwB;EAE5B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CA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,IAAIF,GAAG,KAAK,CAAC,EAAEC,OAAO,CAACE,EAAE,GAAGD,GAAG,CAACE,UAAU,CAAC,CAAC,CAAC,KACxC,IAAIJ,GAAG,KAAK,CAAC,EAAEK,OAAO,CAACH,GAAG,EAAED,OAAO,CAAC,CAAC,KACrC,IAAID,GAAG,KAAK,CAAC,EAAEC,OAAO,CAACK,IAAI,GAAGJ,GAAG,CAACE,UAAU,CAAC,CAAC,CAAC,KAC/C,IAAIJ,GAAG,KAAK,CAAC,EAAEC,OAAO,CAACM,SAAS,GAAGL,GAAG,CAACM,GAAG;EACjD;AACF;AAOA,OAAO,SAASH,OAAOA,CAACH,GAAa,EAAED,OAA0B,EAAQ;EACvE,MAAMQ,GAAG,GAAGP,GAAG,CAACE,UAAU,CAAC,CAAC,GAAGF,GAAG,CAACM,GAAG;EAEtC,OAAON,GAAG,CAACM,GAAG,GAAGC,GAAG,EAAE;IACpB,MAAMC,GAAG,GAAGT,OAAO,CAACU,KAAK,CAACT,GAAG,CAACE,UAAU,CAAC,CAAC,CAAC;IAC3C,MAAMQ,KAAK,GAAGX,OAAO,CAACY,OAAO,CAACX,GAAG,CAACE,UAAU,CAAC,CAAC,CAAC;IAC/CH,OAAO,CAACa,UAAU,CAACJ,GAAG,CAAC,GAAGE,KAAK;EACjC;AACF"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["MVTLoader","MVTWorkerLoader","TileJSONLoader","MVTSource","GeoJSONTiler"],"sources":["../src/index.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nexport type {MVTLoaderOptions} from './lib/types';\nexport {MVTLoader, MVTWorkerLoader} from './mvt-loader';\n\nexport type {TileJSON} from './lib/parse-tilejson';\nexport type {TileJSONLoaderOptions} from './tilejson-loader';\nexport {TileJSONLoader} from './tilejson-loader';\n\nexport {MVTSource} from './mvt-source';\n\n// GeoJSONTiler\n\nexport type {GeoJSONTilerOptions} from './lib/geojson-tiler/geojson-tiler';\nexport {GeoJSONTiler} from './lib/geojson-tiler/geojson-tiler';\n"],"mappings":"SAKQA,SAAS,EAAEC,eAAe;AAAA,SAI1BC,cAAc;AAAA,SAEdC,SAAS;AAAA,SAKTC,YAAY"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Copyright (c) 2014, Mapbox
|
|
6
|
-
|
|
7
|
-
All rights reserved.
|
|
8
|
-
|
|
9
|
-
Redistribution and use in source and binary forms, with or without modification,
|
|
10
|
-
are permitted provided that the following conditions are met:
|
|
11
|
-
|
|
12
|
-
* Redistributions of source code must retain the above copyright notice,
|
|
13
|
-
this list of conditions and the following disclaimer.
|
|
14
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
|
15
|
-
this list of conditions and the following disclaimer in the documentation
|
|
16
|
-
and/or other materials provided with the distribution.
|
|
17
|
-
* Neither the name of Mapbox nor the names of its contributors
|
|
18
|
-
may be used to endorse or promote products derived from this software
|
|
19
|
-
without specific prior written permission.
|
|
20
|
-
|
|
21
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
22
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
23
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
24
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
25
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
26
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
28
|
-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
29
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
30
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
31
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile-feature.js","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","z","size","Math","pow","x0","y0"],"sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"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 const {x, y, z} = options;\n const size = this.extent * Math.pow(2, z);\n const x0 = this.extent * x;\n const y0 = this.extent * y;\n\n return this._toBinaryCoordinates((data: number[]) => project(data, x0, y0, size));\n }\n}\n"],"mappings":"SAIQA,aAAa,EAAEC,OAAO,EAAEC,WAAW;AAG3C,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