@deck.gl/carto 8.8.0-alpha.4 → 8.8.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +181 -190
- package/dist/es5/layers/carto-tile-layer.js +17 -12
- package/dist/es5/layers/carto-tile-layer.js.map +1 -1
- package/dist/es5/layers/h3-tile-layer.js +1 -1
- package/dist/es5/layers/h3-tile-layer.js.map +1 -1
- package/dist/es5/layers/quadkey-tile-layer.js +1 -1
- package/dist/es5/layers/quadkey-tile-layer.js.map +1 -1
- package/dist/es5/layers/schema/carto-tile.js +261 -188
- package/dist/es5/layers/schema/carto-tile.js.map +1 -1
- package/dist/esm/layers/carto-tile-layer.js +20 -16
- package/dist/esm/layers/carto-tile-layer.js.map +1 -1
- package/dist/esm/layers/h3-tile-layer.js +1 -1
- package/dist/esm/layers/h3-tile-layer.js.map +1 -1
- package/dist/esm/layers/quadkey-tile-layer.js +1 -1
- package/dist/esm/layers/quadkey-tile-layer.js.map +1 -1
- package/dist/esm/layers/schema/carto-tile.js +174 -189
- package/dist/esm/layers/schema/carto-tile.js.map +1 -1
- package/dist.min.js +2 -2
- package/package.json +5 -3
- package/src/layers/{carto-tile-layer.js → carto-tile-layer.ts} +64 -27
- package/src/layers/h3-tile-layer.js +1 -1
- package/src/layers/quadkey-tile-layer.js +1 -1
- package/src/layers/schema/carto-tile.ts +221 -0
- package/src/layers/schema/carto-tile.js +0 -195
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@deck.gl/carto",
|
|
3
3
|
"description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "8.8.0-alpha.
|
|
5
|
+
"version": "8.8.0-alpha.5",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
25
|
"src",
|
|
26
|
+
"typed",
|
|
26
27
|
"dist.min.js"
|
|
27
28
|
],
|
|
28
29
|
"sideEffects": false,
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
"@loaders.gl/loader-utils": "^3.2.0-alpha.4",
|
|
36
37
|
"@loaders.gl/mvt": "^3.2.0-alpha.4",
|
|
37
38
|
"@loaders.gl/tiles": "^3.2.0-alpha.4",
|
|
38
|
-
"@luma.gl/constants": "^8.5.
|
|
39
|
+
"@luma.gl/constants": "^8.5.13",
|
|
39
40
|
"@math.gl/web-mercator": "3.6.0-alpha.5",
|
|
40
41
|
"cartocolor": "^4.0.2",
|
|
41
42
|
"d3-array": "^2.8.0",
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"pbf": "^3.2.1"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
50
|
+
"@loaders.gl/schema": "^3.2.0-alpha.4",
|
|
49
51
|
"@types/d3-array": "^3.0.2",
|
|
50
52
|
"@types/d3-color": "^1.4.2",
|
|
51
53
|
"@types/d3-scale": "^3.0.0"
|
|
@@ -58,5 +60,5 @@
|
|
|
58
60
|
"@deck.gl/layers": "^8.0.0",
|
|
59
61
|
"@loaders.gl/core": "^3.0.0"
|
|
60
62
|
},
|
|
61
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "a5e210f62321ab78b7cacbcd0614e0ffcdf6bca7"
|
|
62
64
|
}
|
|
@@ -1,29 +1,39 @@
|
|
|
1
1
|
/* global TextDecoder */
|
|
2
2
|
import Protobuf from 'pbf';
|
|
3
|
-
import {log} from '@deck.gl/core';
|
|
3
|
+
import {Layer, LayersList, log} from '@deck.gl/core';
|
|
4
4
|
import {ClipExtension} from '@deck.gl/extensions';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
MVTLayer,
|
|
7
|
+
MVTLayerProps,
|
|
8
|
+
TileLayer,
|
|
9
|
+
_getURLFromTemplate,
|
|
10
|
+
_Tile2DHeader,
|
|
11
|
+
_TileLoadProps as TileLoadProps
|
|
12
|
+
} from '@deck.gl/geo-layers';
|
|
6
13
|
import {GeoJsonLayer} from '@deck.gl/layers';
|
|
7
14
|
import {geojsonToBinary} from '@loaders.gl/gis';
|
|
8
|
-
import {Tile} from './schema/carto-tile';
|
|
9
|
-
import {TILE_FORMATS} from '../api/maps-api-common';
|
|
15
|
+
import {Properties, Tile, TileReader} from './schema/carto-tile';
|
|
16
|
+
import {TileFormat, TILE_FORMATS} from '../api/maps-api-common';
|
|
17
|
+
import {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
18
|
+
import type {BinaryFeatures} from '@loaders.gl/schema';
|
|
19
|
+
import type {Feature} from 'geojson';
|
|
10
20
|
|
|
11
|
-
function parseJSON(arrayBuffer) {
|
|
21
|
+
function parseJSON(arrayBuffer: ArrayBuffer): any {
|
|
12
22
|
return JSON.parse(new TextDecoder().decode(arrayBuffer));
|
|
13
23
|
}
|
|
14
24
|
|
|
15
|
-
function parsePbf(buffer) {
|
|
25
|
+
function parsePbf(buffer: ArrayBuffer): Tile {
|
|
16
26
|
const pbf = new Protobuf(buffer);
|
|
17
|
-
const tile =
|
|
27
|
+
const tile = TileReader.read(pbf);
|
|
18
28
|
return tile;
|
|
19
29
|
}
|
|
20
30
|
|
|
21
|
-
function unpackProperties(properties) {
|
|
31
|
+
function unpackProperties(properties: Properties[]) {
|
|
22
32
|
if (!properties || !properties.length) {
|
|
23
33
|
return [];
|
|
24
34
|
}
|
|
25
35
|
return properties.map(item => {
|
|
26
|
-
const currentRecord = {};
|
|
36
|
+
const currentRecord: Record<string, unknown> = {};
|
|
27
37
|
item.data.forEach(({key, value}) => {
|
|
28
38
|
currentRecord[key] = value;
|
|
29
39
|
});
|
|
@@ -31,7 +41,7 @@ function unpackProperties(properties) {
|
|
|
31
41
|
});
|
|
32
42
|
}
|
|
33
43
|
|
|
34
|
-
function parseCartoTile(arrayBuffer, options) {
|
|
44
|
+
function parseCartoTile(arrayBuffer: ArrayBuffer, options?: LoaderOptions): BinaryFeatures | null {
|
|
35
45
|
if (!arrayBuffer) return null;
|
|
36
46
|
const formatTiles = options && options.cartoTile && options.cartoTile.formatTiles;
|
|
37
47
|
if (formatTiles === TILE_FORMATS.GEOJSON) return geojsonToBinary(parseJSON(arrayBuffer).features);
|
|
@@ -45,13 +55,15 @@ function parseCartoTile(arrayBuffer, options) {
|
|
|
45
55
|
polygons: {...polygons, properties: unpackProperties(polygons.properties)}
|
|
46
56
|
};
|
|
47
57
|
|
|
48
|
-
|
|
58
|
+
// Note: there is slight, difference in `numericProps` type, however geojson/mvtlayer can cope with this
|
|
59
|
+
return data as unknown as BinaryFeatures;
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
const defaultTileFormat = TILE_FORMATS.BINARY;
|
|
52
63
|
|
|
53
|
-
const CartoTileLoader = {
|
|
64
|
+
const CartoTileLoader: LoaderWithParser = {
|
|
54
65
|
name: 'CARTO Tile',
|
|
66
|
+
version: '1',
|
|
55
67
|
id: 'cartoTile',
|
|
56
68
|
module: 'carto',
|
|
57
69
|
extensions: ['pbf'],
|
|
@@ -73,8 +85,29 @@ const defaultProps = {
|
|
|
73
85
|
loaders: [CartoTileLoader]
|
|
74
86
|
};
|
|
75
87
|
|
|
76
|
-
|
|
77
|
-
|
|
88
|
+
/** All properties supported by CartoTileLayer. */
|
|
89
|
+
export type CartoTileLayerProps<DataT extends Feature = Feature> = _CartoTileLayerProps &
|
|
90
|
+
MVTLayerProps<DataT>;
|
|
91
|
+
|
|
92
|
+
/** Properties added by CartoTileLayer. */
|
|
93
|
+
type _CartoTileLayerProps = {
|
|
94
|
+
/** Use to override the default tile data format.
|
|
95
|
+
*
|
|
96
|
+
* Possible values are: `TILE_FORMATS.BINARY`, `TILE_FORMATS.GEOJSON` and `TILE_FORMATS.MVT`.
|
|
97
|
+
*
|
|
98
|
+
* Only supported when `apiVersion` is `API_VERSIONS.V3` and `format` is `FORMATS.TILEJSON`.
|
|
99
|
+
* */
|
|
100
|
+
formatTiles?: TileFormat;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export default class CartoTileLayer<
|
|
104
|
+
DataT extends Feature = Feature,
|
|
105
|
+
ExtraProps = {}
|
|
106
|
+
> extends MVTLayer<DataT, Required<_CartoTileLayerProps> & ExtraProps> {
|
|
107
|
+
static layerName = 'CartoTileLayer';
|
|
108
|
+
static defaultProps = defaultProps;
|
|
109
|
+
|
|
110
|
+
getTileData(tile: TileLoadProps) {
|
|
78
111
|
const url = _getURLFromTemplate(this.state.data, tile);
|
|
79
112
|
if (!url) {
|
|
80
113
|
return Promise.reject('Invalid URL');
|
|
@@ -100,25 +133,29 @@ export default class CartoTileLayer extends MVTLayer {
|
|
|
100
133
|
return fetch(url, {propName: 'data', layer: this, loadOptions, signal});
|
|
101
134
|
}
|
|
102
135
|
|
|
103
|
-
renderSubLayers(
|
|
136
|
+
renderSubLayers(
|
|
137
|
+
props: TileLayer['props'] & {
|
|
138
|
+
id: string;
|
|
139
|
+
data: any;
|
|
140
|
+
_offset: number;
|
|
141
|
+
tile: _Tile2DHeader;
|
|
142
|
+
}
|
|
143
|
+
): GeoJsonLayer | null {
|
|
104
144
|
if (props.data === null) {
|
|
105
145
|
return null;
|
|
106
146
|
}
|
|
107
147
|
|
|
108
|
-
props.
|
|
148
|
+
const tileBbox = props.tile.bbox as any;
|
|
149
|
+
const {west, south, east, north} = tileBbox;
|
|
109
150
|
|
|
110
|
-
const {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
151
|
+
const subLayerProps = {
|
|
152
|
+
...props,
|
|
153
|
+
autoHighlight: false,
|
|
154
|
+
extensions: [new ClipExtension(), ...(props.extensions || [])],
|
|
155
|
+
clipBounds: [west, south, east, north]
|
|
156
|
+
};
|
|
115
157
|
|
|
116
|
-
const subLayer = new GeoJsonLayer(
|
|
117
|
-
...props
|
|
118
|
-
});
|
|
158
|
+
const subLayer = new GeoJsonLayer(subLayerProps);
|
|
119
159
|
return subLayer;
|
|
120
160
|
}
|
|
121
161
|
}
|
|
122
|
-
|
|
123
|
-
CartoTileLayer.layerName = 'CartoTileLayer';
|
|
124
|
-
CartoTileLayer.defaultProps = defaultProps;
|
|
@@ -37,7 +37,7 @@ export default class H3TileLayer extends CompositeLayer {
|
|
|
37
37
|
const maxZoom = parseInt(tileJSON.maxresolution);
|
|
38
38
|
return [
|
|
39
39
|
new SpatialIndexTileLayer(this.props, {
|
|
40
|
-
id:
|
|
40
|
+
id: `h3-tile-layer-${this.props.id}`,
|
|
41
41
|
data,
|
|
42
42
|
getHexagon: d => d.id,
|
|
43
43
|
TilesetClass: H3Tileset2D,
|
|
@@ -32,7 +32,7 @@ export default class QuadkeyTileLayer extends CompositeLayer {
|
|
|
32
32
|
const maxZoom = parseInt(tileJSON.maxresolution);
|
|
33
33
|
return [
|
|
34
34
|
new SpatialIndexTileLayer(this.props, {
|
|
35
|
-
id:
|
|
35
|
+
id: `quadkey-tile-layer-${this.props.id}`,
|
|
36
36
|
data,
|
|
37
37
|
getQuadkey: d => d.id,
|
|
38
38
|
TilesetClass: QuadkeyTileset2D,
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// KeyValueObject ========================================
|
|
2
|
+
interface KeyValueObject {
|
|
3
|
+
key: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
class KeyValueObjectReader {
|
|
8
|
+
static read(pbf, end?: number): KeyValueObject {
|
|
9
|
+
return pbf.readFields(KeyValueObjectReader._readField, {key: '', value: ''}, end);
|
|
10
|
+
}
|
|
11
|
+
static _readField(this: void, tag: number, obj: KeyValueObject, pbf) {
|
|
12
|
+
if (tag === 1) obj.key = pbf.readString();
|
|
13
|
+
else if (tag === 2) obj.value = pbf.readString();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Properties ========================================
|
|
18
|
+
|
|
19
|
+
export interface Properties {
|
|
20
|
+
data: KeyValueObject[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class PropertiesReader {
|
|
24
|
+
static read(pbf, end?: number) {
|
|
25
|
+
return pbf.readFields(PropertiesReader._readField, {data: []}, end);
|
|
26
|
+
}
|
|
27
|
+
static _readField(this: void, tag: number, obj: Properties, pbf) {
|
|
28
|
+
if (tag === 1) obj.data.push(KeyValueObjectReader.read(pbf, pbf.readVarint() + pbf.pos));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Doubles ========================================
|
|
33
|
+
|
|
34
|
+
interface Doubles {
|
|
35
|
+
value: Float32Array;
|
|
36
|
+
size: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class DoublesReader {
|
|
40
|
+
static read(pbf, end?: number): Doubles {
|
|
41
|
+
// TODO perhaps we can do better and directly map from the source
|
|
42
|
+
// ArrayBuffer using ArrayBuffer.slice()
|
|
43
|
+
const {value, size} = pbf.readFields(DoublesReader._readField, {value: [], size: 0}, end);
|
|
44
|
+
return {value: new Float32Array(value), size};
|
|
45
|
+
}
|
|
46
|
+
static _readField(this: void, tag: number, obj, pbf) {
|
|
47
|
+
if (tag === 1) pbf.readPackedDouble(obj.value);
|
|
48
|
+
else if (tag === 2) obj.size = pbf.readVarint(true);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Ints ========================================
|
|
53
|
+
|
|
54
|
+
interface Ints {
|
|
55
|
+
value: Uint32Array;
|
|
56
|
+
size: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class IntsReader {
|
|
60
|
+
static read(pbf, end?: number): Ints {
|
|
61
|
+
const {value, size} = pbf.readFields(IntsReader._readField, {value: [], size: 0}, end);
|
|
62
|
+
return {value: new Uint32Array(value), size};
|
|
63
|
+
}
|
|
64
|
+
static _readField(this: void, tag: number, obj, pbf) {
|
|
65
|
+
if (tag === 1) pbf.readPackedVarint(obj.value);
|
|
66
|
+
else if (tag === 2) obj.size = pbf.readVarint(true);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// NumericProp ========================================
|
|
71
|
+
|
|
72
|
+
interface NumericProp {
|
|
73
|
+
value: number[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class NumericPropReader {
|
|
77
|
+
static read(pbf, end?: number): NumericProp {
|
|
78
|
+
return pbf.readFields(NumericPropReader._readField, {value: []}, end);
|
|
79
|
+
}
|
|
80
|
+
static _readField(this: void, tag: number, obj: NumericProp, pbf) {
|
|
81
|
+
if (tag === 1) pbf.readPackedDouble(obj.value);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// NumericPropKeyValue ========================================
|
|
86
|
+
interface NumbericPropKeyValue {
|
|
87
|
+
key: string;
|
|
88
|
+
value: NumericProp;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
class NumericPropKeyValueReader {
|
|
92
|
+
static read(pbf, end?: number): NumbericPropKeyValue {
|
|
93
|
+
return pbf.readFields(NumericPropKeyValueReader._readField, {key: '', value: null}, end);
|
|
94
|
+
}
|
|
95
|
+
static _readField(this: void, tag: number, obj: NumbericPropKeyValue, pbf) {
|
|
96
|
+
if (tag === 1) obj.key = pbf.readString();
|
|
97
|
+
else if (tag === 2) obj.value = NumericPropReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Points ========================================
|
|
102
|
+
|
|
103
|
+
interface Points {
|
|
104
|
+
positions: Doubles;
|
|
105
|
+
globalFeatureIds: Ints;
|
|
106
|
+
featureIds: Ints;
|
|
107
|
+
properties: Properties[];
|
|
108
|
+
numericProps: Record<string, NumericProp>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
class PointsReader {
|
|
112
|
+
static read(pbf, end?: number): Points {
|
|
113
|
+
return pbf.readFields(
|
|
114
|
+
PointsReader._readField,
|
|
115
|
+
{positions: null, globalFeatureIds: null, featureIds: null, properties: [], numericProps: {}},
|
|
116
|
+
end
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
static _readField(this: void, tag: number, obj: Points, pbf) {
|
|
120
|
+
if (tag === 1) obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
121
|
+
else if (tag === 2) obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
122
|
+
else if (tag === 3) obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
123
|
+
else if (tag === 4) obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
|
|
124
|
+
else if (tag === 5) {
|
|
125
|
+
const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
126
|
+
obj.numericProps[entry.key] = entry.value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
interface Lines extends Points {
|
|
132
|
+
pathIndices: Ints;
|
|
133
|
+
}
|
|
134
|
+
// Lines ========================================
|
|
135
|
+
|
|
136
|
+
class LinesReader {
|
|
137
|
+
static read(pbf, end?: number): Lines {
|
|
138
|
+
return pbf.readFields(
|
|
139
|
+
LinesReader._readField,
|
|
140
|
+
{
|
|
141
|
+
positions: null,
|
|
142
|
+
pathIndices: null,
|
|
143
|
+
globalFeatureIds: null,
|
|
144
|
+
featureIds: null,
|
|
145
|
+
properties: [],
|
|
146
|
+
numericProps: {}
|
|
147
|
+
},
|
|
148
|
+
end
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
static _readField(this: void, tag: number, obj: Lines, pbf) {
|
|
152
|
+
if (tag === 1) obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
153
|
+
else if (tag === 2) obj.pathIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
154
|
+
else if (tag === 3) obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
155
|
+
else if (tag === 4) obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
156
|
+
else if (tag === 5) obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
|
|
157
|
+
else if (tag === 6) {
|
|
158
|
+
const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
159
|
+
obj.numericProps[entry.key] = entry.value;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Polygons ========================================
|
|
164
|
+
|
|
165
|
+
interface Polygons extends Points {
|
|
166
|
+
polygonIndices: Ints;
|
|
167
|
+
primitivePolygonIndices: Ints;
|
|
168
|
+
triangles: Ints;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
class PolygonsReader {
|
|
172
|
+
static read(pbf, end?: number): Polygons {
|
|
173
|
+
return pbf.readFields(
|
|
174
|
+
PolygonsReader._readField,
|
|
175
|
+
{
|
|
176
|
+
positions: null,
|
|
177
|
+
polygonIndices: null,
|
|
178
|
+
globalFeatureIds: null,
|
|
179
|
+
featureIds: null,
|
|
180
|
+
primitivePolygonIndices: null,
|
|
181
|
+
triangles: null,
|
|
182
|
+
properties: [],
|
|
183
|
+
numericProps: {}
|
|
184
|
+
},
|
|
185
|
+
end
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
static _readField(this: void, tag: number, obj: Polygons, pbf) {
|
|
189
|
+
if (tag === 1) obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
190
|
+
else if (tag === 2) obj.polygonIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
191
|
+
else if (tag === 3) obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
192
|
+
else if (tag === 4) obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
193
|
+
else if (tag === 5)
|
|
194
|
+
obj.primitivePolygonIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
195
|
+
else if (tag === 6) obj.triangles = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
196
|
+
else if (tag === 7) obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
|
|
197
|
+
else if (tag === 8) {
|
|
198
|
+
const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
199
|
+
obj.numericProps[entry.key] = entry.value;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Tile ========================================
|
|
205
|
+
|
|
206
|
+
export interface Tile {
|
|
207
|
+
points: Points;
|
|
208
|
+
lines: Lines;
|
|
209
|
+
polygons: Polygons;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export class TileReader {
|
|
213
|
+
static read(pbf, end?: number): Tile {
|
|
214
|
+
return pbf.readFields(TileReader._readField, {points: null, lines: null, polygons: null}, end);
|
|
215
|
+
}
|
|
216
|
+
static _readField(this: void, tag: number, obj: Tile, pbf) {
|
|
217
|
+
if (tag === 1) obj.points = PointsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
218
|
+
else if (tag === 2) obj.lines = LinesReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
219
|
+
else if (tag === 3) obj.polygons = PolygonsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
// KeyValueObject ========================================
|
|
2
|
-
|
|
3
|
-
const KeyValueObject = {};
|
|
4
|
-
|
|
5
|
-
KeyValueObject.read = function (pbf, end) {
|
|
6
|
-
return pbf.readFields(KeyValueObject._readField, {key: '', value: ''}, end);
|
|
7
|
-
};
|
|
8
|
-
KeyValueObject._readField = function (tag, obj, pbf) {
|
|
9
|
-
if (tag === 1) obj.key = pbf.readString();
|
|
10
|
-
else if (tag === 2) obj.value = pbf.readString();
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// Properties ========================================
|
|
14
|
-
|
|
15
|
-
const Properties = {};
|
|
16
|
-
|
|
17
|
-
Properties.read = function (pbf, end) {
|
|
18
|
-
return pbf.readFields(Properties._readField, {data: []}, end);
|
|
19
|
-
};
|
|
20
|
-
Properties._readField = function (tag, obj, pbf) {
|
|
21
|
-
if (tag === 1) obj.data.push(KeyValueObject.read(pbf, pbf.readVarint() + pbf.pos));
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// Doubles ========================================
|
|
25
|
-
|
|
26
|
-
const Doubles = {};
|
|
27
|
-
|
|
28
|
-
Doubles.read = function (pbf, end) {
|
|
29
|
-
// TODO perhaps we can do better and directly map from the source
|
|
30
|
-
// ArrayBuffer using ArrayBuffer.slice()
|
|
31
|
-
const {value, size} = pbf.readFields(Doubles._readField, {value: [], size: 0}, end);
|
|
32
|
-
return {value: new Float32Array(value), size};
|
|
33
|
-
};
|
|
34
|
-
Doubles._readField = function (tag, obj, pbf) {
|
|
35
|
-
if (tag === 1) pbf.readPackedDouble(obj.value);
|
|
36
|
-
else if (tag === 2) obj.size = pbf.readVarint(true);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// Ints ========================================
|
|
40
|
-
|
|
41
|
-
const Ints = {};
|
|
42
|
-
|
|
43
|
-
Ints.read = function (pbf, end) {
|
|
44
|
-
const {value, size} = pbf.readFields(Ints._readField, {value: [], size: 0}, end);
|
|
45
|
-
return {value: new Uint32Array(value), size};
|
|
46
|
-
};
|
|
47
|
-
Ints._readField = function (tag, obj, pbf) {
|
|
48
|
-
if (tag === 1) pbf.readPackedVarint(obj.value);
|
|
49
|
-
else if (tag === 2) obj.size = pbf.readVarint(true);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// NumericProp ========================================
|
|
53
|
-
|
|
54
|
-
const NumericProp = {};
|
|
55
|
-
|
|
56
|
-
NumericProp.read = function (pbf, end) {
|
|
57
|
-
return pbf.readFields(NumericProp._readField, {value: []}, end);
|
|
58
|
-
};
|
|
59
|
-
NumericProp._readField = function (tag, obj, pbf) {
|
|
60
|
-
if (tag === 1) pbf.readPackedDouble(obj.value);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// NumericPropKeyValue ========================================
|
|
64
|
-
|
|
65
|
-
const NumericPropKeyValue = {};
|
|
66
|
-
|
|
67
|
-
NumericPropKeyValue.read = function (pbf, end) {
|
|
68
|
-
return pbf.readFields(NumericPropKeyValue._readField, {key: '', value: null}, end);
|
|
69
|
-
};
|
|
70
|
-
NumericPropKeyValue._readField = function (tag, obj, pbf) {
|
|
71
|
-
if (tag === 1) obj.key = pbf.readString();
|
|
72
|
-
else if (tag === 2) obj.value = NumericProp.read(pbf, pbf.readVarint() + pbf.pos);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// NumericProp._FieldEntry1 ========================================
|
|
76
|
-
|
|
77
|
-
NumericProp._FieldEntry1 = {};
|
|
78
|
-
|
|
79
|
-
NumericProp._FieldEntry1.read = function (pbf, end) {
|
|
80
|
-
return pbf.readFields(NumericProp._FieldEntry1._readField, {key: '', value: 0}, end);
|
|
81
|
-
};
|
|
82
|
-
NumericProp._FieldEntry1._readField = function (tag, obj, pbf) {
|
|
83
|
-
if (tag === 1) obj.key = pbf.readString();
|
|
84
|
-
else if (tag === 2) obj.value = pbf.readDouble();
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// StringProp ========================================
|
|
88
|
-
|
|
89
|
-
const StringProp = {};
|
|
90
|
-
|
|
91
|
-
StringProp.read = function (pbf, end) {
|
|
92
|
-
return pbf.readFields(StringProp._readField, {value: []}, end);
|
|
93
|
-
};
|
|
94
|
-
StringProp._readField = function (tag, obj, pbf) {
|
|
95
|
-
if (tag === 1) obj.value.push(pbf.readString());
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// Points ========================================
|
|
99
|
-
|
|
100
|
-
const Points = {};
|
|
101
|
-
|
|
102
|
-
Points.read = function (pbf, end) {
|
|
103
|
-
return pbf.readFields(
|
|
104
|
-
Points._readField,
|
|
105
|
-
{positions: null, globalFeatureIds: null, featureIds: null, properties: [], numericProps: {}},
|
|
106
|
-
end
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
Points._readField = function (tag, obj, pbf) {
|
|
110
|
-
if (tag === 1) obj.positions = Doubles.read(pbf, pbf.readVarint() + pbf.pos);
|
|
111
|
-
else if (tag === 2) obj.globalFeatureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
112
|
-
else if (tag === 3) obj.featureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
113
|
-
else if (tag === 4) obj.properties.push(Properties.read(pbf, pbf.readVarint() + pbf.pos));
|
|
114
|
-
else if (tag === 5) {
|
|
115
|
-
const entry = NumericPropKeyValue.read(pbf, pbf.readVarint() + pbf.pos);
|
|
116
|
-
obj.numericProps[entry.key] = entry.value;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// Lines ========================================
|
|
121
|
-
|
|
122
|
-
const Lines = {};
|
|
123
|
-
|
|
124
|
-
Lines.read = function (pbf, end) {
|
|
125
|
-
return pbf.readFields(
|
|
126
|
-
Lines._readField,
|
|
127
|
-
{
|
|
128
|
-
positions: null,
|
|
129
|
-
pathIndices: null,
|
|
130
|
-
globalFeatureIds: null,
|
|
131
|
-
featureIds: null,
|
|
132
|
-
properties: [],
|
|
133
|
-
numericProps: {}
|
|
134
|
-
},
|
|
135
|
-
end
|
|
136
|
-
);
|
|
137
|
-
};
|
|
138
|
-
Lines._readField = function (tag, obj, pbf) {
|
|
139
|
-
if (tag === 1) obj.positions = Doubles.read(pbf, pbf.readVarint() + pbf.pos);
|
|
140
|
-
else if (tag === 2) obj.pathIndices = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
141
|
-
else if (tag === 3) obj.globalFeatureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
142
|
-
else if (tag === 4) obj.featureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
143
|
-
else if (tag === 5) obj.properties.push(Properties.read(pbf, pbf.readVarint() + pbf.pos));
|
|
144
|
-
else if (tag === 6) {
|
|
145
|
-
const entry = NumericPropKeyValue.read(pbf, pbf.readVarint() + pbf.pos);
|
|
146
|
-
obj.numericProps[entry.key] = entry.value;
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// Polygons ========================================
|
|
151
|
-
|
|
152
|
-
const Polygons = {};
|
|
153
|
-
|
|
154
|
-
Polygons.read = function (pbf, end) {
|
|
155
|
-
return pbf.readFields(
|
|
156
|
-
Polygons._readField,
|
|
157
|
-
{
|
|
158
|
-
positions: null,
|
|
159
|
-
polygonIndices: null,
|
|
160
|
-
globalFeatureIds: null,
|
|
161
|
-
featureIds: null,
|
|
162
|
-
primitivePolygonIndices: null,
|
|
163
|
-
triangles: null,
|
|
164
|
-
properties: [],
|
|
165
|
-
numericProps: {}
|
|
166
|
-
},
|
|
167
|
-
end
|
|
168
|
-
);
|
|
169
|
-
};
|
|
170
|
-
Polygons._readField = function (tag, obj, pbf) {
|
|
171
|
-
if (tag === 1) obj.positions = Doubles.read(pbf, pbf.readVarint() + pbf.pos);
|
|
172
|
-
else if (tag === 2) obj.polygonIndices = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
173
|
-
else if (tag === 3) obj.globalFeatureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
174
|
-
else if (tag === 4) obj.featureIds = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
175
|
-
else if (tag === 5) obj.primitivePolygonIndices = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
176
|
-
else if (tag === 6) obj.triangles = Ints.read(pbf, pbf.readVarint() + pbf.pos);
|
|
177
|
-
else if (tag === 7) obj.properties.push(Properties.read(pbf, pbf.readVarint() + pbf.pos));
|
|
178
|
-
else if (tag === 8) {
|
|
179
|
-
const entry = NumericPropKeyValue.read(pbf, pbf.readVarint() + pbf.pos);
|
|
180
|
-
obj.numericProps[entry.key] = entry.value;
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
// Tile ========================================
|
|
185
|
-
|
|
186
|
-
export const Tile = {};
|
|
187
|
-
|
|
188
|
-
Tile.read = function (pbf, end) {
|
|
189
|
-
return pbf.readFields(Tile._readField, {points: null, lines: null, polygons: null}, end);
|
|
190
|
-
};
|
|
191
|
-
Tile._readField = function (tag, obj, pbf) {
|
|
192
|
-
if (tag === 1) obj.points = Points.read(pbf, pbf.readVarint() + pbf.pos);
|
|
193
|
-
else if (tag === 2) obj.lines = Lines.read(pbf, pbf.readVarint() + pbf.pos);
|
|
194
|
-
else if (tag === 3) obj.polygons = Polygons.read(pbf, pbf.readVarint() + pbf.pos);
|
|
195
|
-
};
|