@loaders.gl/mvt 4.3.0-alpha.2 → 4.3.0-alpha.4
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 +821 -680
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +795 -656
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/lib/get-schemas-from-tilejson.d.ts +4 -0
- package/dist/lib/get-schemas-from-tilejson.d.ts.map +1 -0
- package/dist/lib/get-schemas-from-tilejson.js +55 -0
- package/dist/lib/parse-tilejson.d.ts +9 -4
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.js +6 -6
- package/dist/lib/types.d.ts +39 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +1 -1
- package/dist/lib/utils/geometry-utils.js +1 -1
- package/dist/lib/vector-tiler/{clip.d.ts → features/clip-features.d.ts} +4 -4
- package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{clip.js → features/clip-features.js} +4 -4
- package/dist/lib/vector-tiler/{convert.d.ts → features/convert-feature.d.ts} +7 -7
- package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
- package/dist/lib/vector-tiler/{simplify.d.ts → features/simplify-path.d.ts} +2 -2
- package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{simplify.js → features/simplify-path.js} +3 -3
- package/dist/lib/vector-tiler/{wrap.d.ts → features/wrap-features.d.ts} +5 -5
- package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{wrap.js → features/wrap-features.js} +33 -26
- package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
- package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/proto-tile.js +138 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
- package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/transform-tile.js +41 -0
- package/dist/mvt-loader.d.ts +2 -0
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-source.d.ts +31 -14
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +26 -6
- package/dist/mvt-worker.js +4 -4
- package/dist/table-tile-source.d.ts +66 -36
- package/dist/table-tile-source.d.ts.map +1 -1
- package/dist/table-tile-source.js +167 -117
- package/dist/tilejson-loader.js +1 -1
- package/package.json +9 -6
- package/src/index.ts +13 -6
- package/src/lib/get-schemas-from-tilejson.ts +64 -0
- package/src/lib/parse-tilejson.ts +19 -12
- package/src/lib/types.ts +40 -2
- package/src/lib/utils/geometry-utils.ts +1 -1
- package/src/lib/vector-tiler/{clip.ts → features/clip-features.ts} +8 -8
- package/src/lib/vector-tiler/{convert.ts → features/convert-feature.ts} +91 -70
- package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
- package/src/lib/vector-tiler/{simplify.ts → features/simplify-path.ts} +8 -3
- package/src/lib/vector-tiler/{wrap.ts → features/wrap-features.ts} +44 -29
- package/src/lib/vector-tiler/proto-tile.ts +217 -0
- package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
- package/src/lib/vector-tiler/transform-tile.ts +57 -0
- package/src/mvt-loader.ts +2 -0
- package/src/mvt-source.ts +42 -18
- package/src/table-tile-source.ts +130 -85
- package/src/tilejson-loader.ts +2 -2
- package/dist/lib/vector-tiler/clip.d.ts.map +0 -1
- package/dist/lib/vector-tiler/convert.d.ts.map +0 -1
- package/dist/lib/vector-tiler/convert.js +0 -139
- package/dist/lib/vector-tiler/feature.d.ts +0 -3
- package/dist/lib/vector-tiler/feature.d.ts.map +0 -1
- package/dist/lib/vector-tiler/feature.js +0 -44
- package/dist/lib/vector-tiler/simplify.d.ts.map +0 -1
- package/dist/lib/vector-tiler/tile.d.ts +0 -38
- package/dist/lib/vector-tiler/tile.d.ts.map +0 -1
- package/dist/lib/vector-tiler/tile.js +0 -123
- package/dist/lib/vector-tiler/transform.d.ts +0 -7
- package/dist/lib/vector-tiler/transform.d.ts.map +0 -1
- package/dist/lib/vector-tiler/transform.js +0 -41
- package/dist/lib/vector-tiler/wrap.d.ts.map +0 -1
- package/src/lib/vector-tiler/feature.ts +0 -47
- package/src/lib/vector-tiler/tile.ts +0 -187
- package/src/lib/vector-tiler/transform.ts +0 -57
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export type { MVTLoaderOptions } from "./mvt-loader.js";
|
|
2
|
-
export { MVTLoader, MVTWorkerLoader } from "./mvt-loader.js";
|
|
3
|
-
export type { TileJSON } from "./lib/parse-tilejson.js";
|
|
4
|
-
export type { TileJSONLoaderOptions } from "./tilejson-loader.js";
|
|
5
1
|
export { TileJSONLoader } from "./tilejson-loader.js";
|
|
2
|
+
export type { TileJSONLoaderOptions } from "./tilejson-loader.js";
|
|
3
|
+
export type { TileJSON } from "./lib/parse-tilejson.js";
|
|
4
|
+
export { MVTLoader, MVTWorkerLoader } from "./mvt-loader.js";
|
|
5
|
+
export type { MVTLoaderOptions } from "./mvt-loader.js";
|
|
6
6
|
export { MVTSource } from "./mvt-source.js";
|
|
7
|
-
export type {
|
|
7
|
+
export type { MVTTileSource, MVTTileSourceProps } from "./mvt-source.js";
|
|
8
8
|
export { TableTileSource } from "./table-tile-source.js";
|
|
9
|
+
export type { DynamicVectorTileSource, DynamicVectorTileSourceProps } from "./table-tile-source.js";
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,cAAc,EAAC,6BAA0B;AACjD,YAAY,EAAC,qBAAqB,EAAC,6BAA0B;AAC7D,YAAY,EAAC,QAAQ,EAAC,gCAA6B;AAInD,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,wBAAqB;AACxD,YAAY,EAAC,gBAAgB,EAAC,wBAAqB;AAInD,OAAO,EAAC,SAAS,EAAC,wBAAqB;AACvC,YAAY,EAAC,aAAa,EAAE,kBAAkB,EAAC,wBAAqB;AAIpE,OAAO,EAAC,eAAe,EAAC,+BAA4B;AACpD,YAAY,EAAC,uBAAuB,EAAE,4BAA4B,EAAC,+BAA4B"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
4
|
+
// TileJSONLoader
|
|
5
5
|
export { TileJSONLoader } from "./tilejson-loader.js";
|
|
6
|
+
// MVTLoader
|
|
7
|
+
export { MVTLoader, MVTWorkerLoader } from "./mvt-loader.js";
|
|
8
|
+
// MVTSource
|
|
6
9
|
export { MVTSource } from "./mvt-source.js";
|
|
10
|
+
// TableTileSource (dynamically tiles a table)
|
|
7
11
|
export { TableTileSource } from "./table-tile-source.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-schemas-from-tilejson.d.ts","sourceRoot":"","sources":["../../src/lib/get-schemas-from-tilejson.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAiD,MAAM,oBAAoB,CAAC;AAC/F,OAAO,KAAK,EAAC,aAAa,EAAgB,4BAAyB;AAInE,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAevE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// LAYERS
|
|
5
|
+
export function getSchemaFromTileJSONLayer(layer) {
|
|
6
|
+
const fields = [];
|
|
7
|
+
if (layer.fields) {
|
|
8
|
+
for (const field of layer.fields) {
|
|
9
|
+
fields.push({
|
|
10
|
+
name: field.name,
|
|
11
|
+
type: getDataTypeFromTileJSONField(field),
|
|
12
|
+
metadata: getMetadataFromTileJSONField(field)
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
metadata: getMetadataFromTileJSONLayer(layer),
|
|
18
|
+
fields
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function getMetadataFromTileJSONLayer(layer) {
|
|
22
|
+
const metadata = {};
|
|
23
|
+
for (const [key, value] of Object.entries(layer)) {
|
|
24
|
+
if (key !== 'fields' && value) {
|
|
25
|
+
metadata[key] = JSON.stringify(value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return metadata;
|
|
29
|
+
}
|
|
30
|
+
// FIELDS
|
|
31
|
+
function getDataTypeFromTileJSONField(field) {
|
|
32
|
+
switch (field.type.toLowerCase()) {
|
|
33
|
+
case 'float32':
|
|
34
|
+
return 'float32';
|
|
35
|
+
case 'number':
|
|
36
|
+
case 'float64':
|
|
37
|
+
return 'float64';
|
|
38
|
+
case 'string':
|
|
39
|
+
case 'utf8':
|
|
40
|
+
return 'utf8';
|
|
41
|
+
case 'boolean':
|
|
42
|
+
return 'bool';
|
|
43
|
+
default:
|
|
44
|
+
return 'null';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function getMetadataFromTileJSONField(field) {
|
|
48
|
+
const metadata = {};
|
|
49
|
+
for (const [key, value] of Object.entries(field)) {
|
|
50
|
+
if (key !== 'name' && value) {
|
|
51
|
+
metadata[key] = JSON.stringify(value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return metadata;
|
|
55
|
+
}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
|
+
import { Schema } from '@loaders.gl/schema';
|
|
1
2
|
export type TileJSONOptions = {
|
|
2
3
|
/** max number of values. If not provided, include all values in the source tilestats */
|
|
3
4
|
maxValues?: number;
|
|
4
5
|
};
|
|
5
6
|
/** Parsed and typed TileJSON, merges Tilestats information if present */
|
|
6
7
|
export type TileJSON = {
|
|
8
|
+
/** Name of the tileset (for presentation in UI) */
|
|
7
9
|
name?: string;
|
|
10
|
+
/** A description of the contents or purpose of the tileset */
|
|
8
11
|
description?: string;
|
|
12
|
+
/** The version of the tileset */
|
|
9
13
|
version?: string;
|
|
10
14
|
tileFormat?: string;
|
|
11
15
|
tilesetType?: string;
|
|
16
|
+
/** Generating application. Tippecanoe adds this. */
|
|
17
|
+
generator?: string;
|
|
18
|
+
/** Generating application options. Tippecanoe adds this. */
|
|
19
|
+
generatorOptions?: string;
|
|
12
20
|
/** Tile indexing scheme */
|
|
13
21
|
scheme?: 'xyz' | 'tms';
|
|
14
22
|
/** Sharded URLs */
|
|
@@ -23,10 +31,6 @@ export type TileJSON = {
|
|
|
23
31
|
htmlAttribution?: string;
|
|
24
32
|
htmlLegend?: string;
|
|
25
33
|
layers?: TileJSONLayer[];
|
|
26
|
-
/** Generating application. Tippecanoe adds this. */
|
|
27
|
-
generator?: string;
|
|
28
|
-
/** Generating application options. Tippecanoe adds this. */
|
|
29
|
-
generatorOptions?: string;
|
|
30
34
|
/** Any nested JSON metadata */
|
|
31
35
|
metaJson?: any | null;
|
|
32
36
|
};
|
|
@@ -44,6 +48,7 @@ export type TileJSONLayer = {
|
|
|
44
48
|
minZoom?: number;
|
|
45
49
|
maxZoom?: number;
|
|
46
50
|
fields: TileJSONField[];
|
|
51
|
+
schema?: Schema;
|
|
47
52
|
};
|
|
48
53
|
export type TileJSONField = {
|
|
49
54
|
/** The name of this attribute */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-tilejson.d.ts","sourceRoot":"","sources":["../../src/lib/parse-tilejson.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,eAAe,GAAG;IAC5B,wFAAwF;IACxF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,yEAAyE;AACzE,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,2BAA2B;IAC3B,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,wHAAwH;IACxH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACzE,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;IAEzB
|
|
1
|
+
{"version":3,"file":"parse-tilejson.d.ts","sourceRoot":"","sources":["../../src/lib/parse-tilejson.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAC;AAG1C,MAAM,MAAM,eAAe,GAAG;IAC5B,wFAAwF;IACxF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,yEAAyE;AACzE,MAAM,MAAM,QAAQ,GAAG;IACrB,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,2BAA2B;IAC3B,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,wHAAwH;IACxH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACzE,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;IAEzB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,2FAA2F;IAC3F,IAAI,EAAE,MAAM,CAAC;IAEb,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IAIrB,mEAAmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uEAAuE;IAEvE,OAAO;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,aAAa,EAAE,CAAC;IAExB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IAIrB,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AA+CF;;;;;GAKG;AAEH,wBAAgB,aAAa,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,GAAG,IAAI,CAiE1F"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { getSchemaFromTileJSONLayer } from "./get-schemas-from-tilejson.js";
|
|
4
5
|
const isObject = (x) => x !== null && typeof x === 'object';
|
|
5
6
|
/**
|
|
6
7
|
* Parse TileJSON from metadata
|
|
@@ -125,15 +126,14 @@ function parseTilestatsForLayer(layer, options) {
|
|
|
125
126
|
function mergeLayers(layers, tilestatsLayers) {
|
|
126
127
|
return layers.map((layer) => {
|
|
127
128
|
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
delete layer2.fields;
|
|
132
|
-
return {
|
|
133
|
-
...layer2,
|
|
129
|
+
const fields = tilestatsLayer?.fields || layer.fields || [];
|
|
130
|
+
const mergedLayer = {
|
|
131
|
+
...layer,
|
|
134
132
|
...tilestatsLayer,
|
|
135
133
|
fields
|
|
136
134
|
};
|
|
135
|
+
mergedLayer.schema = getSchemaFromTileJSONLayer(mergedLayer);
|
|
136
|
+
return mergedLayer;
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
/**
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** For local coordinates, the tileIndex is not required */
|
|
2
|
+
type MVTLocalCoordinatesOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.
|
|
5
|
+
*/
|
|
6
|
+
coordinates: 'local';
|
|
7
|
+
tileIndex: null;
|
|
8
|
+
};
|
|
9
|
+
/** In WGS84 coordinates, the tileIndex is required */
|
|
10
|
+
type MVTWgs84CoordinatesOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* When set to `wgs84`, the parser will return a flat array of GeoJSON objects with coordinates in longitude, latitude decoded from the provided tile index.
|
|
13
|
+
*/
|
|
14
|
+
coordinates?: 'wgs84';
|
|
15
|
+
/**
|
|
16
|
+
* Mandatory with `wgs84` coordinates option. An object containing tile index values (`x`, `y`,
|
|
17
|
+
* `z`) to reproject features' coordinates into WGS84.
|
|
18
|
+
*/
|
|
19
|
+
tileIndex?: {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
z: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {
|
|
26
|
+
shape?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
27
|
+
/**
|
|
28
|
+
* When non-`null`, the layer name of each feature is added to
|
|
29
|
+
* `feature.properties[layerProperty]`. (A `feature.properties` object is created if the feature
|
|
30
|
+
* has no existing properties). If set to `null`, a layer name property will not be added.
|
|
31
|
+
*/
|
|
32
|
+
layerProperty?: string | number;
|
|
33
|
+
/**
|
|
34
|
+
* Optional list of layer names. If not `null`, only features belonging to the named layers will
|
|
35
|
+
* be included in the output. If `null`, features from all layers are returned.
|
|
36
|
+
*/
|
|
37
|
+
layers?: string[];
|
|
38
|
+
};
|
|
2
39
|
export type MVTMapboxGeometry = {
|
|
3
40
|
type?: string;
|
|
4
41
|
id?: number;
|
|
@@ -16,4 +53,5 @@ export type MVTMapboxCoordinates = {
|
|
|
16
53
|
};
|
|
17
54
|
id?: number;
|
|
18
55
|
};
|
|
56
|
+
export {};
|
|
19
57
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAIA,2DAA2D;AAC3D,KAAK,0BAA0B,GAAG;IAChC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC;AAEF,sDAAsD;AACtD,KAAK,0BAA0B,GAAG;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,SAAS,CAAC,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,0BAA0B,GAAG,0BAA0B,CAAC,GAAG;IACnF,KAAK,CAAC,EAAE,eAAe,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;IACtF;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEhC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,iBAAiB,CAAC;KAChC,CAAC;IACF,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC"}
|
package/dist/lib/types.js
CHANGED
|
@@ -43,7 +43,7 @@ export function convertToLocalCoordinates(coordinates, extent) {
|
|
|
43
43
|
* @param feature
|
|
44
44
|
*/
|
|
45
45
|
export function convertToLocalCoordinatesFlat(data, extent) {
|
|
46
|
-
for (let i = 0
|
|
46
|
+
for (let i = 0; i < data.length; ++i) {
|
|
47
47
|
data[i] /= extent;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProtoFeature } from "./proto-feature.js";
|
|
2
2
|
/**
|
|
3
3
|
* Clip features between two vertical or horizontal axis-parallel lines:
|
|
4
4
|
* | |
|
|
@@ -10,7 +10,7 @@ import type { TableTileFeature } from "./tile.js";
|
|
|
10
10
|
* @param axis: 0 for x, 1 for y
|
|
11
11
|
* @param minAll and maxAll: minimum and maximum coordinate value for all features
|
|
12
12
|
*/
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function clipFeatures(features: ProtoFeature[], scale: number, k1: number, k2: number, axis: any, minAll: number, maxAll: number, options: {
|
|
14
14
|
lineMetrics: boolean;
|
|
15
|
-
}):
|
|
16
|
-
//# sourceMappingURL=clip.d.ts.map
|
|
15
|
+
}): ProtoFeature[] | null;
|
|
16
|
+
//# sourceMappingURL=clip-features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clip-features.d.ts","sourceRoot":"","sources":["../../../../src/lib/vector-tiler/features/clip-features.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,YAAY,EAAC,2BAAwB;AAKlD;;;;;;;;;;GAUG;AAEH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,YAAY,EAAE,EACxB,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,KAAA,EACJ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAC,WAAW,EAAE,OAAO,CAAA;CAAC,GAC9B,YAAY,EAAE,GAAG,IAAI,CA4EvB"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
import {
|
|
5
|
+
import { createProtoFeature } from "./proto-feature.js";
|
|
6
6
|
/* eslint-disable no-continue */
|
|
7
7
|
/**
|
|
8
8
|
* Clip features between two vertical or horizontal axis-parallel lines:
|
|
@@ -16,7 +16,7 @@ import { createFeature } from "./feature.js";
|
|
|
16
16
|
* @param minAll and maxAll: minimum and maximum coordinate value for all features
|
|
17
17
|
*/
|
|
18
18
|
// eslint-disable-next-line max-params, complexity, max-statements
|
|
19
|
-
export function
|
|
19
|
+
export function clipFeatures(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
20
20
|
k1 /= scale;
|
|
21
21
|
k2 /= scale;
|
|
22
22
|
if (minAll >= k1 && maxAll < k2) {
|
|
@@ -66,7 +66,7 @@ export function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
|
66
66
|
if (newGeometry.length) {
|
|
67
67
|
if (options.lineMetrics && type === 'LineString') {
|
|
68
68
|
for (const line of newGeometry) {
|
|
69
|
-
clipped.push(
|
|
69
|
+
clipped.push(createProtoFeature(feature.id, type, line, feature.tags));
|
|
70
70
|
}
|
|
71
71
|
continue;
|
|
72
72
|
}
|
|
@@ -83,7 +83,7 @@ export function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
|
83
83
|
if (type === 'Point' || type === 'MultiPoint') {
|
|
84
84
|
type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
|
|
85
85
|
}
|
|
86
|
-
clipped.push(
|
|
86
|
+
clipped.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
return clipped.length ? clipped : null;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { Feature, FeatureCollection } from '@loaders.gl/schema';
|
|
2
|
-
import type {
|
|
3
|
-
/**
|
|
4
|
-
* converts a GeoJSON feature into an intermediate projected JSON vector format
|
|
5
|
-
* with simplification data
|
|
6
|
-
*/
|
|
7
|
-
export declare function convert(data: Feature | FeatureCollection, options: any): TableTileFeature[];
|
|
2
|
+
import type { ProtoFeature } from "./proto-feature.js";
|
|
8
3
|
export type ConvertFeatureOptions = {
|
|
9
4
|
/** max zoom to preserve detail on */
|
|
10
5
|
maxZoom?: number;
|
|
@@ -15,4 +10,9 @@ export type ConvertFeatureOptions = {
|
|
|
15
10
|
/** whether to calculate line metrics */
|
|
16
11
|
lineMetrics?: boolean;
|
|
17
12
|
};
|
|
18
|
-
|
|
13
|
+
/**
|
|
14
|
+
* converts a GeoJSON feature into an intermediate projected JSON vector format
|
|
15
|
+
* with simplification data
|
|
16
|
+
*/
|
|
17
|
+
export declare function convertFeaturesToProtoFeature(data: Feature | FeatureCollection, options: ConvertFeatureOptions): ProtoFeature[];
|
|
18
|
+
//# sourceMappingURL=convert-feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-feature.d.ts","sourceRoot":"","sources":["../../../../src/lib/vector-tiler/features/convert-feature.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAC,YAAY,EAAC,2BAAwB;AAKlD,MAAM,MAAM,qBAAqB,GAAG;IAClC,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GAAG,iBAAiB,EACjC,OAAO,EAAE,qBAAqB,GAC7B,YAAY,EAAE,CAkBhB"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
+
import { createProtoFeature } from "./proto-feature.js";
|
|
6
|
+
import { simplifyPath } from "./simplify-path.js";
|
|
7
|
+
/**
|
|
8
|
+
* converts a GeoJSON feature into an intermediate projected JSON vector format
|
|
9
|
+
* with simplification data
|
|
10
|
+
*/
|
|
11
|
+
export function convertFeaturesToProtoFeature(data, options) {
|
|
12
|
+
const protoFeatures = [];
|
|
13
|
+
switch (data.type) {
|
|
14
|
+
case 'FeatureCollection':
|
|
15
|
+
let i = 0;
|
|
16
|
+
for (const feature of data.features) {
|
|
17
|
+
protoFeatures.push(convertFeature(feature, options, i++));
|
|
18
|
+
}
|
|
19
|
+
break;
|
|
20
|
+
case 'Feature':
|
|
21
|
+
protoFeatures.push(convertFeature(data, options));
|
|
22
|
+
break;
|
|
23
|
+
default:
|
|
24
|
+
// single geometry or a geometry collection
|
|
25
|
+
protoFeatures.push(convertFeature({ geometry: data }, options));
|
|
26
|
+
}
|
|
27
|
+
return protoFeatures;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* converts a GeoJSON feature into an intermediate projected JSON vector format
|
|
31
|
+
* with simplification data
|
|
32
|
+
*/
|
|
33
|
+
function convertFeature(geojson, options, index) {
|
|
34
|
+
// GeoJSON geometries can be null, but no vector tile will include them.
|
|
35
|
+
if (!geojson.geometry) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const coords = geojson.geometry.coordinates;
|
|
39
|
+
const type = geojson.geometry.type;
|
|
40
|
+
const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
|
|
41
|
+
let geometry = [];
|
|
42
|
+
let id = geojson.id;
|
|
43
|
+
if (options.promoteId) {
|
|
44
|
+
id = geojson.properties[options.promoteId];
|
|
45
|
+
}
|
|
46
|
+
else if (options.generateId) {
|
|
47
|
+
id = index || 0;
|
|
48
|
+
}
|
|
49
|
+
switch (type) {
|
|
50
|
+
case 'Point':
|
|
51
|
+
convertPoint(coords, geometry);
|
|
52
|
+
break;
|
|
53
|
+
case 'MultiPoint':
|
|
54
|
+
for (const p of coords) {
|
|
55
|
+
convertPoint(p, geometry);
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 'LineString':
|
|
59
|
+
convertLine(coords, geometry, tolerance, false);
|
|
60
|
+
break;
|
|
61
|
+
case 'MultiLineString':
|
|
62
|
+
if (options.lineMetrics) {
|
|
63
|
+
// explode into linestrings to be able to track metrics
|
|
64
|
+
for (const line of coords) {
|
|
65
|
+
geometry = [];
|
|
66
|
+
convertLine(line, geometry, tolerance, false);
|
|
67
|
+
features.push(createProtoFeature(id, 'LineString', geometry, geojson.properties));
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
convertLines(coords, geometry, tolerance, false);
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
case 'Polygon':
|
|
74
|
+
convertLines(coords, geometry, tolerance, true);
|
|
75
|
+
break;
|
|
76
|
+
case 'MultiPolygon':
|
|
77
|
+
for (const polygon of coords) {
|
|
78
|
+
const newPolygon = [];
|
|
79
|
+
convertLines(polygon, newPolygon, tolerance, true);
|
|
80
|
+
geometry.push(newPolygon);
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case 'GeometryCollection':
|
|
84
|
+
for (const singleGeometry of geojson.geometry.geometries) {
|
|
85
|
+
convertFeature(features, {
|
|
86
|
+
id,
|
|
87
|
+
geometry: singleGeometry,
|
|
88
|
+
properties: geojson.properties
|
|
89
|
+
}, options, index);
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
throw new Error('Input data is not a valid GeoJSON object.');
|
|
94
|
+
}
|
|
95
|
+
return createProtoFeature(id, type, geometry, geojson.properties);
|
|
96
|
+
}
|
|
97
|
+
function convertPoint(coords, out) {
|
|
98
|
+
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
99
|
+
}
|
|
100
|
+
function convertLine(ring, out, tolerance, isPolygon) {
|
|
101
|
+
let x0, y0;
|
|
102
|
+
let size = 0;
|
|
103
|
+
for (let j = 0; j < ring.length; j++) {
|
|
104
|
+
const x = projectX(ring[j][0]);
|
|
105
|
+
const y = projectY(ring[j][1]);
|
|
106
|
+
out.push(x, y, 0);
|
|
107
|
+
if (j > 0) {
|
|
108
|
+
if (isPolygon) {
|
|
109
|
+
size += (x0 * y - x * y0) / 2; // area
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
x0 = x;
|
|
116
|
+
y0 = y;
|
|
117
|
+
}
|
|
118
|
+
const last = out.length - 3;
|
|
119
|
+
out[2] = 1;
|
|
120
|
+
simplifyPath(out, 0, last, tolerance);
|
|
121
|
+
out[last + 2] = 1;
|
|
122
|
+
out.size = Math.abs(size);
|
|
123
|
+
out.start = 0;
|
|
124
|
+
out.end = out.size;
|
|
125
|
+
}
|
|
126
|
+
function convertLines(rings, out, tolerance, isPolygon) {
|
|
127
|
+
for (let i = 0; i < rings.length; i++) {
|
|
128
|
+
const geom = [];
|
|
129
|
+
convertLine(rings[i], geom, tolerance, isPolygon);
|
|
130
|
+
out.push(geom);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function projectX(x) {
|
|
134
|
+
return x / 360 + 0.5;
|
|
135
|
+
}
|
|
136
|
+
function projectY(y) {
|
|
137
|
+
const sin = Math.sin((y * Math.PI) / 180);
|
|
138
|
+
const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
|
|
139
|
+
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
|
|
140
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type ProtoFeature = {
|
|
2
|
+
type: 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon';
|
|
3
|
+
simplifiedType: 1 | 2 | 3;
|
|
4
|
+
geometry: any[];
|
|
5
|
+
id?: string;
|
|
6
|
+
tags?: Record<string, unknown>;
|
|
7
|
+
/** spatial extents */
|
|
8
|
+
minX: number;
|
|
9
|
+
/** spatial extents */
|
|
10
|
+
maxX: number;
|
|
11
|
+
/** spatial extents */
|
|
12
|
+
minY: number;
|
|
13
|
+
/** spatial extents */
|
|
14
|
+
maxY: number;
|
|
15
|
+
};
|
|
16
|
+
export type GeoJSONTileGeometry = GeoJSONTilePointGeometry | GeoJSONTileLineGeometry | GeoJSONTilePolygonGeometry;
|
|
17
|
+
export type GeoJSONTilePointGeometry = {
|
|
18
|
+
simplifiedType: 1;
|
|
19
|
+
geometry: number[];
|
|
20
|
+
};
|
|
21
|
+
export type GeoJSONTileLineGeometry = {
|
|
22
|
+
simplifiedType: 1;
|
|
23
|
+
geometry: number[][];
|
|
24
|
+
};
|
|
25
|
+
export type GeoJSONTilePolygonGeometry = {
|
|
26
|
+
simplifiedType: 1;
|
|
27
|
+
geometry: number[][][];
|
|
28
|
+
};
|
|
29
|
+
export declare function createProtoFeature(id: any, type: 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon', geometry: any[], tags: any): ProtoFeature;
|
|
30
|
+
//# sourceMappingURL=proto-feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proto-feature.d.ts","sourceRoot":"","sources":["../../../../src/lib/vector-tiler/features/proto-feature.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,iBAAiB,GAAG,SAAS,GAAG,cAAc,CAAC;IAC7F,cAAc,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,QAAQ,EAAE,GAAG,EAAE,CAAC;IAGhB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE/B,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAC3B,wBAAwB,GACxB,uBAAuB,GACvB,0BAA0B,CAAC;AAE/B,MAAM,MAAM,wBAAwB,GAAG;IACrC,cAAc,EAAE,CAAC,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,cAAc,EAAE,CAAC,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,cAAc,EAAE,CAAC,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;CACxB,CAAC;AAEF,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,GAAG,EACP,IAAI,EAAE,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,iBAAiB,GAAG,SAAS,GAAG,cAAc,EAC5F,QAAQ,EAAE,GAAG,EAAE,EACf,IAAI,KAAA,GACH,YAAY,CA6Cd"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
+
export function createProtoFeature(id, type, geometry, tags) {
|
|
6
|
+
const feature = {
|
|
7
|
+
// eslint-disable-next-line
|
|
8
|
+
id: id == null ? null : id,
|
|
9
|
+
type,
|
|
10
|
+
simplifiedType: undefined, // TODO
|
|
11
|
+
geometry,
|
|
12
|
+
tags,
|
|
13
|
+
minX: Infinity,
|
|
14
|
+
minY: Infinity,
|
|
15
|
+
maxX: -Infinity,
|
|
16
|
+
maxY: -Infinity
|
|
17
|
+
};
|
|
18
|
+
// TODO break out into separate function
|
|
19
|
+
switch (type) {
|
|
20
|
+
case 'Point':
|
|
21
|
+
case 'MultiPoint':
|
|
22
|
+
case 'LineString':
|
|
23
|
+
calcLineBBox(feature, geometry);
|
|
24
|
+
break;
|
|
25
|
+
case 'MultiLineString':
|
|
26
|
+
for (const line of geometry) {
|
|
27
|
+
calcLineBBox(feature, line);
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
30
|
+
case 'Polygon':
|
|
31
|
+
// the outer ring (ie [0]) contains all inner rings
|
|
32
|
+
calcLineBBox(feature, geometry[0]);
|
|
33
|
+
break;
|
|
34
|
+
case 'MultiPolygon':
|
|
35
|
+
for (const polygon of geometry) {
|
|
36
|
+
// the outer ring (ie [0]) contains all inner rings
|
|
37
|
+
calcLineBBox(feature, polygon[0]);
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(String(type));
|
|
42
|
+
}
|
|
43
|
+
return feature;
|
|
44
|
+
}
|
|
45
|
+
function calcLineBBox(feature, geometry) {
|
|
46
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
47
|
+
feature.minX = Math.min(feature.minX, geometry[i]);
|
|
48
|
+
feature.minY = Math.min(feature.minY, geometry[i + 1]);
|
|
49
|
+
feature.maxX = Math.max(feature.maxX, geometry[i]);
|
|
50
|
+
feature.maxY = Math.max(feature.maxY, geometry[i + 1]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* @param last last coord to simplify
|
|
7
7
|
* @param sqTolerance tolerance (square distance)
|
|
8
8
|
*/
|
|
9
|
-
export declare function
|
|
10
|
-
//# sourceMappingURL=simplify.d.ts.map
|
|
9
|
+
export declare function simplifyPath(coords: number[], first: number, last: number, sqTolerance: number): void;
|
|
10
|
+
//# sourceMappingURL=simplify-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplify-path.d.ts","sourceRoot":"","sources":["../../../../src/lib/vector-tiler/features/simplify-path.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EAAE,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,IAAI,CAkCN"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @param last last coord to simplify
|
|
11
11
|
* @param sqTolerance tolerance (square distance)
|
|
12
12
|
*/
|
|
13
|
-
export function
|
|
13
|
+
export function simplifyPath(coords, first, last, sqTolerance) {
|
|
14
14
|
let maxSqDist = sqTolerance;
|
|
15
15
|
const mid = (last - first) >> 1;
|
|
16
16
|
let minPosToMid = last - first;
|
|
@@ -38,10 +38,10 @@ export function simplify(coords, first, last, sqTolerance) {
|
|
|
38
38
|
}
|
|
39
39
|
if (maxSqDist > sqTolerance) {
|
|
40
40
|
if (index - first > 3)
|
|
41
|
-
|
|
41
|
+
simplifyPath(coords, first, index, sqTolerance);
|
|
42
42
|
coords[index + 2] = maxSqDist;
|
|
43
43
|
if (last - index > 3)
|
|
44
|
-
|
|
44
|
+
simplifyPath(coords, index, last, sqTolerance);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
/** square distance from a point to a segment */
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProtoFeature } from "./proto-feature.js";
|
|
2
2
|
/**
|
|
3
3
|
* Options for wrap()
|
|
4
4
|
*/
|
|
5
|
-
export type
|
|
5
|
+
export type WrapFeaturesOptions = {
|
|
6
6
|
buffer: number /** number of pixels of buffer for the tile */;
|
|
7
7
|
extent: number /** extent of each tile */;
|
|
8
8
|
lineMetrics: boolean;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Wrap across antemeridian, by clipping into two tiles, shifting the overflowing x coordinates
|
|
12
|
-
* @param
|
|
12
|
+
* @param list of features to be wrapped
|
|
13
13
|
* @param options buffer and extent
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
export declare function
|
|
17
|
-
//# sourceMappingURL=wrap.d.ts.map
|
|
16
|
+
export declare function wrapFeatures(features: ProtoFeature[], options: WrapFeaturesOptions): ProtoFeature[];
|
|
17
|
+
//# sourceMappingURL=wrap-features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap-features.d.ts","sourceRoot":"","sources":["../../../../src/lib/vector-tiler/features/wrap-features.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,YAAY,EAAC,2BAAwB;AAIlD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC,8CAA8C,CAAC;IAC9D,MAAM,EAAE,MAAM,CAAC,0BAA0B,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,YAAY,EAAE,EACxB,OAAO,EAAE,mBAAmB,GAC3B,YAAY,EAAE,CAkBhB"}
|