maplibre-gl 2.0.1 → 2.0.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/CHANGELOG.md +7 -0
- package/build/generate-struct-arrays.ts +3 -3
- package/build/post-ts-build.js +10 -0
- package/dist/maplibre-gl.d.ts +259 -187
- package/dist/maplibre-gl.js +3 -3
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +2 -3
- package/src/data/array_types.ts +20 -20
- package/src/data/bucket/fill_bucket.test.ts +1 -1
- package/src/data/bucket/line_bucket.test.ts +1 -1
- package/src/data/feature_index.ts +2 -2
- package/src/index.ts +0 -1
- package/src/source/source.ts +2 -2
- package/src/source/source_cache.test.ts +2 -2
- package/src/source/worker_tile.test.ts +2 -1
- package/src/style/style.ts +1 -1
- package/src/style/style_layer.ts +12 -15
- package/src/types/packages-types/vector-tile/index.d.ts +27 -0
- package/src/util/transferable_grid_index.test.ts +56 -0
- package/src/util/transferable_grid_index.ts +216 -0
- package/src/util/web_worker_transfer.ts +1 -17
- package/src/types/non-typed-modules.d.ts +0 -47
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maplibre-gl",
|
|
3
3
|
"description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.2",
|
|
5
5
|
"main": "dist/maplibre-gl.js",
|
|
6
6
|
"style": "dist/maplibre-gl.css",
|
|
7
7
|
"license": "BSD-3-Clause",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"@mapbox/unitbezier": "^0.0.1",
|
|
23
23
|
"@mapbox/vector-tile": "^1.3.1",
|
|
24
24
|
"@mapbox/whoots-js": "^3.1.0",
|
|
25
|
+
"@types/pbf": "^3.0.2",
|
|
25
26
|
"csscolorparser": "~1.0.3",
|
|
26
27
|
"earcut": "^2.2.2",
|
|
27
28
|
"geojson-vt": "^3.2.1",
|
|
28
29
|
"gl-matrix": "^3.2.1",
|
|
29
|
-
"grid-index": "^1.1.0",
|
|
30
30
|
"murmurhash-js": "^1.0.0",
|
|
31
31
|
"pbf": "^3.2.1",
|
|
32
32
|
"potpack": "^1.0.1",
|
|
@@ -69,7 +69,6 @@
|
|
|
69
69
|
"@types/node-notifier": "^8.0.0",
|
|
70
70
|
"@types/npm-packlist": "^1.1.1",
|
|
71
71
|
"@types/offscreencanvas": "^2019.6.3",
|
|
72
|
-
"@types/pbf": "^3.0.2",
|
|
73
72
|
"@types/pixelmatch": "^5.2.2",
|
|
74
73
|
"@types/pngjs": "^6.0.1",
|
|
75
74
|
"@types/puppeteer": "^5.4.4",
|
package/src/data/array_types.ts
CHANGED
|
@@ -1031,6 +1031,25 @@ export class FeatureIndexArray extends StructArrayLayout1ul2ui8 {
|
|
|
1031
1031
|
|
|
1032
1032
|
register('FeatureIndexArray', FeatureIndexArray);
|
|
1033
1033
|
|
|
1034
|
+
export class PosArray extends StructArrayLayout2i4 {}
|
|
1035
|
+
export class RasterBoundsArray extends StructArrayLayout4i8 {}
|
|
1036
|
+
export class CircleLayoutArray extends StructArrayLayout2i4 {}
|
|
1037
|
+
export class FillLayoutArray extends StructArrayLayout2i4 {}
|
|
1038
|
+
export class FillExtrusionLayoutArray extends StructArrayLayout2i4i12 {}
|
|
1039
|
+
export class HeatmapLayoutArray extends StructArrayLayout2i4 {}
|
|
1040
|
+
export class LineLayoutArray extends StructArrayLayout2i4ub8 {}
|
|
1041
|
+
export class LineExtLayoutArray extends StructArrayLayout2f8 {}
|
|
1042
|
+
export class PatternLayoutArray extends StructArrayLayout10ui20 {}
|
|
1043
|
+
export class SymbolLayoutArray extends StructArrayLayout4i4ui4i24 {}
|
|
1044
|
+
export class SymbolDynamicLayoutArray extends StructArrayLayout3f12 {}
|
|
1045
|
+
export class SymbolOpacityArray extends StructArrayLayout1ul4 {}
|
|
1046
|
+
export class CollisionBoxLayoutArray extends StructArrayLayout2i2i2i12 {}
|
|
1047
|
+
export class CollisionCircleLayoutArray extends StructArrayLayout2f1f2i16 {}
|
|
1048
|
+
export class CollisionVertexArray extends StructArrayLayout2ub2f12 {}
|
|
1049
|
+
export class QuadTriangleArray extends StructArrayLayout3ui6 {}
|
|
1050
|
+
export class TriangleIndexArray extends StructArrayLayout3ui6 {}
|
|
1051
|
+
export class LineIndexArray extends StructArrayLayout2ui4 {}
|
|
1052
|
+
export class LineStripIndexArray extends StructArrayLayout1ui2 {}
|
|
1034
1053
|
export {
|
|
1035
1054
|
StructArrayLayout2i4,
|
|
1036
1055
|
StructArrayLayout4i8,
|
|
@@ -1053,24 +1072,5 @@ export {
|
|
|
1053
1072
|
StructArrayLayout1ul2ui8,
|
|
1054
1073
|
StructArrayLayout2ui4,
|
|
1055
1074
|
StructArrayLayout1ui2,
|
|
1056
|
-
StructArrayLayout4f16
|
|
1057
|
-
StructArrayLayout2i4 as PosArray,
|
|
1058
|
-
StructArrayLayout4i8 as RasterBoundsArray,
|
|
1059
|
-
StructArrayLayout2i4 as CircleLayoutArray,
|
|
1060
|
-
StructArrayLayout2i4 as FillLayoutArray,
|
|
1061
|
-
StructArrayLayout2i4i12 as FillExtrusionLayoutArray,
|
|
1062
|
-
StructArrayLayout2i4 as HeatmapLayoutArray,
|
|
1063
|
-
StructArrayLayout2i4ub8 as LineLayoutArray,
|
|
1064
|
-
StructArrayLayout2f8 as LineExtLayoutArray,
|
|
1065
|
-
StructArrayLayout10ui20 as PatternLayoutArray,
|
|
1066
|
-
StructArrayLayout4i4ui4i24 as SymbolLayoutArray,
|
|
1067
|
-
StructArrayLayout3f12 as SymbolDynamicLayoutArray,
|
|
1068
|
-
StructArrayLayout1ul4 as SymbolOpacityArray,
|
|
1069
|
-
StructArrayLayout2i2i2i12 as CollisionBoxLayoutArray,
|
|
1070
|
-
StructArrayLayout2f1f2i16 as CollisionCircleLayoutArray,
|
|
1071
|
-
StructArrayLayout2ub2f12 as CollisionVertexArray,
|
|
1072
|
-
StructArrayLayout3ui6 as QuadTriangleArray,
|
|
1073
|
-
StructArrayLayout3ui6 as TriangleIndexArray,
|
|
1074
|
-
StructArrayLayout2ui4 as LineIndexArray,
|
|
1075
|
-
StructArrayLayout1ui2 as LineStripIndexArray
|
|
1075
|
+
StructArrayLayout4f16
|
|
1076
1076
|
};
|
|
@@ -42,7 +42,7 @@ test('FillBucket', () => {
|
|
|
42
42
|
new Point(10, 20)
|
|
43
43
|
]], undefined, undefined, undefined);
|
|
44
44
|
|
|
45
|
-
bucket.addFeature(feature, feature.loadGeometry(), undefined, undefined, undefined);
|
|
45
|
+
bucket.addFeature(feature as any, feature.loadGeometry(), undefined, undefined, undefined);
|
|
46
46
|
}).not.toThrow();
|
|
47
47
|
});
|
|
48
48
|
|
|
@@ -96,7 +96,7 @@ describe('LineBucket', () => {
|
|
|
96
96
|
new Point(0, 0)
|
|
97
97
|
], polygon, undefined, undefined, undefined, undefined);
|
|
98
98
|
|
|
99
|
-
bucket.addFeature(feature, feature.loadGeometry(), undefined, undefined, undefined);
|
|
99
|
+
bucket.addFeature(feature as any, feature.loadGeometry(), undefined, undefined, undefined);
|
|
100
100
|
}).not.toThrow();
|
|
101
101
|
});
|
|
102
102
|
|
|
@@ -3,7 +3,7 @@ import loadGeometry from './load_geometry';
|
|
|
3
3
|
import toEvaluationFeature from './evaluation_feature';
|
|
4
4
|
import EXTENT from './extent';
|
|
5
5
|
import featureFilter from '../style-spec/feature_filter';
|
|
6
|
-
import TransferableGridIndex from '
|
|
6
|
+
import TransferableGridIndex from '../util/transferable_grid_index';
|
|
7
7
|
import DictionaryCoder from '../util/dictionary_coder';
|
|
8
8
|
import vt from '@mapbox/vector-tile';
|
|
9
9
|
import Protobuf from 'pbf';
|
|
@@ -296,7 +296,7 @@ class FeatureIndex {
|
|
|
296
296
|
let id: string | number = feature.id;
|
|
297
297
|
if (this.promoteId) {
|
|
298
298
|
const propName = typeof this.promoteId === 'string' ? this.promoteId : this.promoteId[sourceLayerId];
|
|
299
|
-
id = feature.properties[propName];
|
|
299
|
+
id = feature.properties[propName] as string | number;
|
|
300
300
|
if (typeof id === 'boolean') id = Number(id);
|
|
301
301
|
}
|
|
302
302
|
return id;
|
package/src/index.ts
CHANGED
package/src/source/source.ts
CHANGED
|
@@ -117,11 +117,11 @@ export const create = function(id: string, specification: SourceSpecification, d
|
|
|
117
117
|
return source;
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
export const
|
|
120
|
+
export const getSourceType = function (name: string) {
|
|
121
121
|
return sourceTypes[name];
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
-
export const
|
|
124
|
+
export const setSourceType = function (name: string, type: {
|
|
125
125
|
new (...args: any): Source;
|
|
126
126
|
}) {
|
|
127
127
|
sourceTypes[name] = type;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import SourceCache from './source_cache';
|
|
2
|
-
import {
|
|
2
|
+
import {setSourceType} from './source';
|
|
3
3
|
import Tile from './tile';
|
|
4
4
|
import {OverscaledTileID} from './tile_id';
|
|
5
5
|
import Transform from '../geo/transform';
|
|
@@ -63,7 +63,7 @@ function createSource(id: string, sourceOptions: any, _dispatcher: any, eventedP
|
|
|
63
63
|
return source;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
setSourceType('mock-source-type', createSource as any);
|
|
67
67
|
|
|
68
68
|
function createSourceCache(options?, used?) {
|
|
69
69
|
const sc = new SourceCache('id', extend({
|
|
@@ -4,6 +4,7 @@ import {OverscaledTileID} from '../source/tile_id';
|
|
|
4
4
|
import StyleLayerIndex from '../style/style_layer_index';
|
|
5
5
|
import {WorkerTileParameters} from './worker_source';
|
|
6
6
|
import Actor from '../util/actor';
|
|
7
|
+
import {VectorTile} from '@mapbox/vector-tile';
|
|
7
8
|
|
|
8
9
|
function createWorkerTile() {
|
|
9
10
|
return new WorkerTile({
|
|
@@ -87,7 +88,7 @@ describe('worker tile', () => {
|
|
|
87
88
|
version: 1
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
};
|
|
91
|
+
} as any as VectorTile;
|
|
91
92
|
|
|
92
93
|
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
93
94
|
|
package/src/style/style.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {getJSON, getReferrer, makeRequest, ResourceType} from '../util/ajax';
|
|
|
13
13
|
import browser from '../util/browser';
|
|
14
14
|
import Dispatcher from '../util/dispatcher';
|
|
15
15
|
import {validateStyle, emitValidationErrors as _emitValidationErrors} from './validate_style';
|
|
16
|
-
import {
|
|
16
|
+
import {getSourceType, setSourceType, Source} from '../source/source';
|
|
17
17
|
import type {SourceClass} from '../source/source';
|
|
18
18
|
import {queryRenderedFeatures, queryRenderedSymbols, querySourceFeatures} from '../source/query_features';
|
|
19
19
|
import SourceCache from '../source/source_cache';
|
package/src/style/style_layer.ts
CHANGED
|
@@ -32,21 +32,6 @@ import type {VectorTileFeature} from '@mapbox/vector-tile';
|
|
|
32
32
|
|
|
33
33
|
const TRANSITION_SUFFIX = '-transition';
|
|
34
34
|
|
|
35
|
-
// this interface is used to allow optional overload for this methods in the derived classes.
|
|
36
|
-
interface StyleLayer {
|
|
37
|
-
queryRadius?(bucket: Bucket): number;
|
|
38
|
-
queryIntersectsFeature?(
|
|
39
|
-
queryGeometry: Array<Point>,
|
|
40
|
-
feature: VectorTileFeature,
|
|
41
|
-
featureState: FeatureState,
|
|
42
|
-
geometry: Array<Array<Point>>,
|
|
43
|
-
zoom: number,
|
|
44
|
-
transform: Transform,
|
|
45
|
-
pixelsToTileUnits: number,
|
|
46
|
-
pixelPosMatrix: mat4
|
|
47
|
-
): boolean | number;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
35
|
abstract class StyleLayer extends Evented {
|
|
51
36
|
id: string;
|
|
52
37
|
metadata: unknown;
|
|
@@ -71,6 +56,18 @@ abstract class StyleLayer extends Evented {
|
|
|
71
56
|
readonly onAdd: ((map: Map) => void);
|
|
72
57
|
readonly onRemove: ((map: Map) => void);
|
|
73
58
|
|
|
59
|
+
queryRadius?(bucket: Bucket): number;
|
|
60
|
+
queryIntersectsFeature?(
|
|
61
|
+
queryGeometry: Array<Point>,
|
|
62
|
+
feature: VectorTileFeature,
|
|
63
|
+
featureState: FeatureState,
|
|
64
|
+
geometry: Array<Array<Point>>,
|
|
65
|
+
zoom: number,
|
|
66
|
+
transform: Transform,
|
|
67
|
+
pixelsToTileUnits: number,
|
|
68
|
+
pixelPosMatrix: mat4
|
|
69
|
+
): boolean | number;
|
|
70
|
+
|
|
74
71
|
constructor(layer: LayerSpecification | CustomLayerInterface, properties: Readonly<{
|
|
75
72
|
layout?: Properties<any>;
|
|
76
73
|
paint?: Properties<any>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare module '@mapbox/vector-tile' {
|
|
2
|
+
import '@mapbox/vector-tile';
|
|
3
|
+
import type Pbf from 'pbf';
|
|
4
|
+
|
|
5
|
+
export class VectorTileLayer {
|
|
6
|
+
version?: number;
|
|
7
|
+
name: string;
|
|
8
|
+
extent: number;
|
|
9
|
+
length: number;
|
|
10
|
+
feature(i: number): VectorTileFeature;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class VectorTile {
|
|
14
|
+
constructor(pbf: Pbf);
|
|
15
|
+
layers: {[_: string]: VectorTileLayer};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class VectorTileFeature {
|
|
19
|
+
static types: ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
20
|
+
extent: number;
|
|
21
|
+
type: 1 | 2 | 3;
|
|
22
|
+
id: number;
|
|
23
|
+
properties: {[_: string]: string | number | boolean};
|
|
24
|
+
loadGeometry(): Array<Array<Point>>;
|
|
25
|
+
toGeoJSON(x: number, y: number, z: number): GeoJSON.Feature;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import TransferableGridIndex from './transferable_grid_index';
|
|
2
|
+
|
|
3
|
+
describe('TransferableGridIndex', () => {
|
|
4
|
+
|
|
5
|
+
test('indexes features', () => {
|
|
6
|
+
const grid = new TransferableGridIndex(100, 4, 1);
|
|
7
|
+
grid.insert(0, 4, 10, 6, 30);
|
|
8
|
+
grid.insert(1, 4, 10, 30, 12);
|
|
9
|
+
grid.insert(2, -10, 30, -5, 35);
|
|
10
|
+
|
|
11
|
+
expect(grid.query(4, 10, 5, 11).sort()).toEqual([0, 1]);
|
|
12
|
+
expect(grid.query(24, 10, 25, 11).sort()).toEqual([1]);
|
|
13
|
+
expect(grid.query(40, 40, 100, 100)).toEqual([]);
|
|
14
|
+
expect(grid.query(-6, 0, -7, 100)).toEqual([2]);
|
|
15
|
+
expect(grid.query(-Infinity, -Infinity, Infinity, Infinity).sort()).toEqual([0, 1, 2]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('returns multiple copies of a key if multiple boxes were inserted with the same key', () => {
|
|
19
|
+
const grid = new TransferableGridIndex(100, 4, 0);
|
|
20
|
+
const key = 123;
|
|
21
|
+
grid.insert(key, 3, 3, 4, 4);
|
|
22
|
+
grid.insert(key, 13, 13, 14, 14);
|
|
23
|
+
grid.insert(key, 23, 23, 24, 24);
|
|
24
|
+
expect(grid.query(0, 0, 30, 30)).toEqual([key, key, key]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('serializing to an arraybuffer', () => {
|
|
28
|
+
const originalGrid = new TransferableGridIndex(100, 4, 1);
|
|
29
|
+
originalGrid.insert(0, 4, 10, 6, 30);
|
|
30
|
+
originalGrid.insert(1, 4, 10, 30, 12);
|
|
31
|
+
originalGrid.insert(2, -10, 30, -5, 35);
|
|
32
|
+
|
|
33
|
+
const arrayBuffer = originalGrid.toArrayBuffer();
|
|
34
|
+
const grid = new TransferableGridIndex(arrayBuffer);
|
|
35
|
+
|
|
36
|
+
expect(grid.query(4, 10, 5, 11).sort()).toEqual([0, 1]);
|
|
37
|
+
expect(grid.query(24, 10, 25, 11).sort()).toEqual([1]);
|
|
38
|
+
expect(grid.query(40, 40, 100, 100)).toEqual([]);
|
|
39
|
+
expect(grid.query(-6, 0, -7, 100)).toEqual([2]);
|
|
40
|
+
expect(grid.query(-Infinity, -Infinity, Infinity, Infinity).sort()).toEqual([0, 1, 2]);
|
|
41
|
+
|
|
42
|
+
expect(() => grid.insert(3, 0, 0, 0, 0)).toThrow();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('serialize round trip', () => {
|
|
46
|
+
const grid = new TransferableGridIndex(100, 4, 0);
|
|
47
|
+
const key = 123;
|
|
48
|
+
grid.insert(key, 3, 3, 4, 4);
|
|
49
|
+
grid.insert(key, 13, 13, 14, 14);
|
|
50
|
+
grid.insert(key, 23, 23, 24, 24);
|
|
51
|
+
const serializedGrid = TransferableGridIndex.serialize(grid);
|
|
52
|
+
const deserializedGrid = TransferableGridIndex.deserialize(serializedGrid);
|
|
53
|
+
expect(deserializedGrid.query(0, 0, 30, 30)).toEqual([key, key, key]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This file was copied from https://github.com/mapbox/grid-index and was
|
|
3
|
+
migrated from JavaScript to TypeScript.
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2016, Mapbox
|
|
6
|
+
|
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
8
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
|
9
|
+
and this permission notice appear in all copies.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
13
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
15
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
16
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
17
|
+
THIS SOFTWARE.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const NUM_PARAMS = 3;
|
|
21
|
+
|
|
22
|
+
export type SerializedGrid = {
|
|
23
|
+
buffer: ArrayBuffer;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
class TransferableGridIndex {
|
|
27
|
+
cells: number[][];
|
|
28
|
+
arrayBuffer: ArrayBuffer;
|
|
29
|
+
d: number;
|
|
30
|
+
keys: number[];
|
|
31
|
+
bboxes: number[];
|
|
32
|
+
n: number;
|
|
33
|
+
extent: number;
|
|
34
|
+
padding: number;
|
|
35
|
+
scale: any;
|
|
36
|
+
uid: number;
|
|
37
|
+
min: number;
|
|
38
|
+
max: number;
|
|
39
|
+
|
|
40
|
+
constructor(extent: number | ArrayBuffer, n?: number, padding?: number) {
|
|
41
|
+
const cells = this.cells = [];
|
|
42
|
+
|
|
43
|
+
if (extent instanceof ArrayBuffer) {
|
|
44
|
+
this.arrayBuffer = extent;
|
|
45
|
+
const array = new Int32Array(this.arrayBuffer);
|
|
46
|
+
extent = array[0];
|
|
47
|
+
n = array[1];
|
|
48
|
+
padding = array[2];
|
|
49
|
+
|
|
50
|
+
this.d = n + 2 * padding;
|
|
51
|
+
for (let k = 0; k < this.d * this.d; k++) {
|
|
52
|
+
const start = array[NUM_PARAMS + k];
|
|
53
|
+
const end = array[NUM_PARAMS + k + 1];
|
|
54
|
+
cells.push(start === end ? null : array.subarray(start, end));
|
|
55
|
+
}
|
|
56
|
+
const keysOffset = array[NUM_PARAMS + cells.length];
|
|
57
|
+
const bboxesOffset = array[NUM_PARAMS + cells.length + 1];
|
|
58
|
+
this.keys = array.subarray(keysOffset, bboxesOffset) as any as number[];
|
|
59
|
+
this.bboxes = array.subarray(bboxesOffset) as any as number[];
|
|
60
|
+
|
|
61
|
+
this.insert = this._insertReadonly;
|
|
62
|
+
|
|
63
|
+
} else {
|
|
64
|
+
this.d = n + 2 * padding;
|
|
65
|
+
for (let i = 0; i < this.d * this.d; i++) {
|
|
66
|
+
cells.push([]);
|
|
67
|
+
}
|
|
68
|
+
this.keys = [];
|
|
69
|
+
this.bboxes = [];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.n = n;
|
|
73
|
+
this.extent = extent;
|
|
74
|
+
this.padding = padding;
|
|
75
|
+
this.scale = n / extent;
|
|
76
|
+
this.uid = 0;
|
|
77
|
+
|
|
78
|
+
const p = (padding / n) * extent;
|
|
79
|
+
this.min = -p;
|
|
80
|
+
this.max = extent + p;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
insert(key: number, x1: number, y1: number, x2: number, y2: number) {
|
|
84
|
+
this._forEachCell(x1, y1, x2, y2, this._insertCell, this.uid++, undefined, undefined);
|
|
85
|
+
this.keys.push(key);
|
|
86
|
+
this.bboxes.push(x1);
|
|
87
|
+
this.bboxes.push(y1);
|
|
88
|
+
this.bboxes.push(x2);
|
|
89
|
+
this.bboxes.push(y2);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_insertReadonly() {
|
|
93
|
+
throw new Error('Cannot insert into a GridIndex created from an ArrayBuffer.');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
_insertCell(x1: number, y1: number, x2: number, y2: number, cellIndex: number, uid: number) {
|
|
97
|
+
this.cells[cellIndex].push(uid);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
query(x1: number, y1: number, x2: number, y2: number, intersectionTest?: Function): number[] {
|
|
101
|
+
const min = this.min;
|
|
102
|
+
const max = this.max;
|
|
103
|
+
if (x1 <= min && y1 <= min && max <= x2 && max <= y2 && !intersectionTest) {
|
|
104
|
+
// We use `Array#slice` because `this.keys` may be a `Int32Array` and
|
|
105
|
+
// some browsers (Safari and IE) do not support `TypedArray#slice`
|
|
106
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice#Browser_compatibility
|
|
107
|
+
return Array.prototype.slice.call(this.keys);
|
|
108
|
+
|
|
109
|
+
} else {
|
|
110
|
+
const result = [];
|
|
111
|
+
const seenUids = {};
|
|
112
|
+
this._forEachCell(x1, y1, x2, y2, this._queryCell, result, seenUids, intersectionTest);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
_queryCell(x1: number, y1: number, x2: number, y2:number, cellIndex:number, result, seenUids, intersectionTest: Function) {
|
|
118
|
+
const cell = this.cells[cellIndex];
|
|
119
|
+
if (cell !== null) {
|
|
120
|
+
const keys = this.keys;
|
|
121
|
+
const bboxes = this.bboxes;
|
|
122
|
+
for (let u = 0; u < cell.length; u++) {
|
|
123
|
+
const uid = cell[u];
|
|
124
|
+
if (seenUids[uid] === undefined) {
|
|
125
|
+
const offset = uid * 4;
|
|
126
|
+
if (intersectionTest ?
|
|
127
|
+
intersectionTest(bboxes[offset + 0], bboxes[offset + 1], bboxes[offset + 2], bboxes[offset + 3]) :
|
|
128
|
+
((x1 <= bboxes[offset + 2]) &&
|
|
129
|
+
(y1 <= bboxes[offset + 3]) &&
|
|
130
|
+
(x2 >= bboxes[offset + 0]) &&
|
|
131
|
+
(y2 >= bboxes[offset + 1]))) {
|
|
132
|
+
seenUids[uid] = true;
|
|
133
|
+
result.push(keys[uid]);
|
|
134
|
+
} else {
|
|
135
|
+
seenUids[uid] = false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
_forEachCell(x1: number, y1: number, x2:number, y2:number, fn: Function, arg1, arg2, intersectionTest) {
|
|
143
|
+
const cx1 = this._convertToCellCoord(x1);
|
|
144
|
+
const cy1 = this._convertToCellCoord(y1);
|
|
145
|
+
const cx2 = this._convertToCellCoord(x2);
|
|
146
|
+
const cy2 = this._convertToCellCoord(y2);
|
|
147
|
+
for (let x = cx1; x <= cx2; x++) {
|
|
148
|
+
for (let y = cy1; y <= cy2; y++) {
|
|
149
|
+
const cellIndex = this.d * y + x;
|
|
150
|
+
if (intersectionTest && !intersectionTest(
|
|
151
|
+
this._convertFromCellCoord(x),
|
|
152
|
+
this._convertFromCellCoord(y),
|
|
153
|
+
this._convertFromCellCoord(x + 1),
|
|
154
|
+
this._convertFromCellCoord(y + 1))) continue;
|
|
155
|
+
if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2, intersectionTest)) return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
_convertFromCellCoord (x) {
|
|
161
|
+
return (x - this.padding) / this.scale;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
_convertToCellCoord(x) {
|
|
165
|
+
return Math.max(0, Math.min(this.d - 1, Math.floor(x * this.scale) + this.padding));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
toArrayBuffer(): ArrayBuffer {
|
|
169
|
+
if (this.arrayBuffer) return this.arrayBuffer;
|
|
170
|
+
|
|
171
|
+
const cells = this.cells;
|
|
172
|
+
|
|
173
|
+
const metadataLength = NUM_PARAMS + this.cells.length + 1 + 1;
|
|
174
|
+
let totalCellLength = 0;
|
|
175
|
+
for (let i = 0; i < this.cells.length; i++) {
|
|
176
|
+
totalCellLength += this.cells[i].length;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const array = new Int32Array(metadataLength + totalCellLength + this.keys.length + this.bboxes.length);
|
|
180
|
+
array[0] = this.extent;
|
|
181
|
+
array[1] = this.n;
|
|
182
|
+
array[2] = this.padding;
|
|
183
|
+
|
|
184
|
+
let offset = metadataLength;
|
|
185
|
+
for (let k = 0; k < cells.length; k++) {
|
|
186
|
+
const cell = cells[k];
|
|
187
|
+
array[NUM_PARAMS + k] = offset;
|
|
188
|
+
array.set(cell, offset);
|
|
189
|
+
offset += cell.length;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
array[NUM_PARAMS + cells.length] = offset;
|
|
193
|
+
array.set(this.keys, offset);
|
|
194
|
+
offset += this.keys.length;
|
|
195
|
+
|
|
196
|
+
array[NUM_PARAMS + cells.length + 1] = offset;
|
|
197
|
+
array.set(this.bboxes, offset);
|
|
198
|
+
offset += this.bboxes.length;
|
|
199
|
+
|
|
200
|
+
return array.buffer;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
public static serialize(grid: TransferableGridIndex, transferables?: Array<Transferable>): SerializedGrid {
|
|
204
|
+
const buffer = grid.toArrayBuffer();
|
|
205
|
+
if (transferables) {
|
|
206
|
+
transferables.push(buffer);
|
|
207
|
+
}
|
|
208
|
+
return {buffer};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
public static deserialize(serialized: SerializedGrid): TransferableGridIndex {
|
|
212
|
+
return new TransferableGridIndex(serialized.buffer);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export default TransferableGridIndex;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
2
|
|
|
3
|
-
import TransferableGridIndex from '
|
|
3
|
+
import TransferableGridIndex from './transferable_grid_index';
|
|
4
4
|
import Color from '../style-spec/util/color';
|
|
5
5
|
import {StylePropertyFunction, StyleExpression, ZoomDependentExpression, ZoomConstantExpression} from '../style-spec/expression';
|
|
6
6
|
import CompoundExpression from '../style-spec/expression/compound_expression';
|
|
@@ -63,22 +63,6 @@ export function register<T extends any>(
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
register('Object', Object);
|
|
66
|
-
|
|
67
|
-
type SerializedGrid = {
|
|
68
|
-
buffer: ArrayBuffer;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
TransferableGridIndex.serialize = function serialize(grid: TransferableGridIndex, transferables?: Array<Transferable>): SerializedGrid {
|
|
72
|
-
const buffer = grid.toArrayBuffer();
|
|
73
|
-
if (transferables) {
|
|
74
|
-
transferables.push(buffer);
|
|
75
|
-
}
|
|
76
|
-
return {buffer};
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
TransferableGridIndex.deserialize = function deserialize(serialized: SerializedGrid): TransferableGridIndex {
|
|
80
|
-
return new TransferableGridIndex(serialized.buffer);
|
|
81
|
-
};
|
|
82
66
|
register('TransferableGridIndex', TransferableGridIndex);
|
|
83
67
|
|
|
84
68
|
register('Color', Color);
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type Pbf from 'pbf';
|
|
2
|
-
import type Point from '../util/point';
|
|
3
|
-
|
|
4
|
-
declare module 'grid-index' {
|
|
5
|
-
class TransferableGridIndex {
|
|
6
|
-
constructor(extent: number, n: number, padding: number);
|
|
7
|
-
constructor(arrayBuffer: ArrayBuffer);
|
|
8
|
-
insert(key: number, x1: number, y1: number, x2: number, y2: number);
|
|
9
|
-
query(key: number, x1: number, y1: number, x2: number, y2: number, intersectionTest?: Function): number[];
|
|
10
|
-
toArrayBuffer(): ArrayBuffer;
|
|
11
|
-
}
|
|
12
|
-
export default TransferableGridIndex;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare module '@mapbox/vector-tile' {
|
|
16
|
-
import '@mapbox/vector-tile';
|
|
17
|
-
|
|
18
|
-
interface VectorTileLayer {
|
|
19
|
-
version?: number;
|
|
20
|
-
name: string;
|
|
21
|
-
extent: number;
|
|
22
|
-
length: number;
|
|
23
|
-
feature(i: number): VectorTileFeature;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class VectorTile {
|
|
27
|
-
constructor(pbf: Pbf);
|
|
28
|
-
layers: {[_: string]: VectorTileLayer};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
class VectorTileFeature {
|
|
32
|
-
static types: ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
33
|
-
extent: number;
|
|
34
|
-
type: 1 | 2 | 3;
|
|
35
|
-
id: number;
|
|
36
|
-
properties: {[_: string]: string | number | boolean};
|
|
37
|
-
loadGeometry(): Array<Array<Point>>;
|
|
38
|
-
toGeoJSON(x: number, y: number, z: number): GeoJSON.Feature;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let __exports: {
|
|
42
|
-
VectorTile: typeof VectorTile;
|
|
43
|
-
VectorTileFeature: typeof VectorTileFeature;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export = __exports
|
|
47
|
-
}
|