@loaders.gl/mvt 3.1.0-alpha.4 → 4.0.0-alpha.1
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/{esm/bundle.js → bundle.js} +0 -0
- package/dist/bundle.js.map +1 -0
- package/dist/{esm/helpers → helpers}/binary-util-functions.js +0 -0
- package/dist/helpers/binary-util-functions.js.map +1 -0
- package/dist/{esm/helpers → helpers}/mapbox-util-functions.js +0 -0
- package/dist/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/{esm/index.js → index.js} +0 -0
- package/dist/index.js.map +1 -0
- package/dist/{es5/lib → lib}/binary-vector-tile/LICENSE.txt +0 -0
- package/dist/{esm/lib → lib}/binary-vector-tile/features-to-binary.js +0 -0
- package/dist/lib/binary-vector-tile/features-to-binary.js.map +1 -0
- package/dist/{esm/lib → lib}/binary-vector-tile/vector-tile-feature.js +2 -2
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/{esm/lib → lib}/binary-vector-tile/vector-tile-layer.js +0 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/{esm/lib → lib}/binary-vector-tile/vector-tile.js +0 -0
- package/dist/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/{es5/lib → lib}/mapbox-vector-tile/LICENSE.txt +0 -0
- package/dist/{esm/lib → lib}/mapbox-vector-tile/vector-tile-feature.js +3 -3
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/{esm/lib → lib}/mapbox-vector-tile/vector-tile-layer.js +0 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/{esm/lib → lib}/mapbox-vector-tile/vector-tile.js +0 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/{esm/lib → lib}/parse-mvt.js +0 -0
- package/dist/lib/parse-mvt.js.map +1 -0
- package/dist/{esm/lib → lib}/types.js +0 -0
- package/dist/{es5/lib → lib}/types.js.map +0 -0
- package/dist/{esm/mvt-loader.js → mvt-loader.js} +1 -1
- package/dist/mvt-loader.js.map +1 -0
- package/dist/mvt-worker.js +2286 -3
- package/dist/{esm/workers → workers}/mvt-worker.js +0 -0
- package/dist/workers/mvt-worker.js.map +1 -0
- package/package.json +8 -8
- package/dist/dist.min.js +0 -4
- package/dist/dist.min.js.map +0 -1
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/helpers/binary-util-functions.js +0 -95
- package/dist/es5/helpers/binary-util-functions.js.map +0 -1
- package/dist/es5/helpers/mapbox-util-functions.js +0 -62
- package/dist/es5/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/es5/index.js +0 -20
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js +0 -385
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +0 -189
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +0 -77
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +0 -35
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +0 -217
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +0 -77
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +0 -35
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/es5/lib/parse-mvt.js +0 -131
- package/dist/es5/lib/parse-mvt.js.map +0 -1
- package/dist/es5/lib/types.js +0 -2
- package/dist/es5/mvt-loader.js +0 -71
- package/dist/es5/mvt-loader.js.map +0 -1
- package/dist/es5/workers/mvt-worker.js +0 -8
- package/dist/es5/workers/mvt-worker.js.map +0 -1
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/helpers/binary-util-functions.js.map +0 -1
- package/dist/esm/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/LICENSE.txt +0 -31
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +0 -31
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/esm/lib/parse-mvt.js.map +0 -1
- package/dist/esm/lib/types.js.map +0 -1
- package/dist/esm/mvt-loader.js.map +0 -1
- package/dist/esm/workers/mvt-worker.js.map +0 -1
- package/dist/mvt-worker.js.map +0 -1
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.classifyRings = classifyRings;
|
|
7
|
-
exports.project = project;
|
|
8
|
-
exports.readFeature = readFeature;
|
|
9
|
-
exports.readTag = readTag;
|
|
10
|
-
|
|
11
|
-
var _polygon = require("@math.gl/polygon");
|
|
12
|
-
|
|
13
|
-
function classifyRings(geom) {
|
|
14
|
-
var len = geom.lines.length;
|
|
15
|
-
|
|
16
|
-
if (len <= 1) {
|
|
17
|
-
return {
|
|
18
|
-
data: geom.data,
|
|
19
|
-
areas: [[(0, _polygon.getPolygonSignedArea)(geom.data)]],
|
|
20
|
-
lines: [geom.lines]
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var areas = [];
|
|
25
|
-
var polygons = [];
|
|
26
|
-
var ringAreas = [];
|
|
27
|
-
var polygon = [];
|
|
28
|
-
var ccw;
|
|
29
|
-
var offset = 0;
|
|
30
|
-
|
|
31
|
-
for (var endIndex, i = 0, startIndex; i < len; i++) {
|
|
32
|
-
startIndex = geom.lines[i] - offset;
|
|
33
|
-
endIndex = geom.lines[i + 1] - offset || geom.data.length;
|
|
34
|
-
var shape = geom.data.slice(startIndex, endIndex);
|
|
35
|
-
var area = (0, _polygon.getPolygonSignedArea)(shape);
|
|
36
|
-
|
|
37
|
-
if (area === 0) {
|
|
38
|
-
var before = geom.data.slice(0, startIndex);
|
|
39
|
-
var after = geom.data.slice(endIndex);
|
|
40
|
-
geom.data = before.concat(after);
|
|
41
|
-
offset += endIndex - startIndex;
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (ccw === undefined) ccw = area < 0;
|
|
46
|
-
|
|
47
|
-
if (ccw === area < 0) {
|
|
48
|
-
if (polygon.length) {
|
|
49
|
-
areas.push(ringAreas);
|
|
50
|
-
polygons.push(polygon);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
polygon = [startIndex];
|
|
54
|
-
ringAreas = [area];
|
|
55
|
-
} else {
|
|
56
|
-
ringAreas.push(area);
|
|
57
|
-
polygon.push(startIndex);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (ringAreas) areas.push(ringAreas);
|
|
62
|
-
if (polygon.length) polygons.push(polygon);
|
|
63
|
-
return {
|
|
64
|
-
areas: areas,
|
|
65
|
-
lines: polygons,
|
|
66
|
-
data: geom.data
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function project(data, x0, y0, size) {
|
|
71
|
-
for (var j = 0, jl = data.length; j < jl; j += 2) {
|
|
72
|
-
data[j] = (data[j] + x0) * 360 / size - 180;
|
|
73
|
-
var y2 = 180 - (data[j + 1] + y0) * 360 / size;
|
|
74
|
-
data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function readFeature(tag, feature, pbf) {
|
|
79
|
-
if (feature && pbf) {
|
|
80
|
-
if (tag === 1) feature.id = pbf.readVarint();else if (tag === 2) readTag(pbf, feature);else if (tag === 3) feature.type = pbf.readVarint();else if (tag === 4) feature._geometry = pbf.pos;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function readTag(pbf, feature) {
|
|
85
|
-
var end = pbf.readVarint() + pbf.pos;
|
|
86
|
-
|
|
87
|
-
while (pbf.pos < end) {
|
|
88
|
-
var key = feature._keys[pbf.readVarint()];
|
|
89
|
-
|
|
90
|
-
var value = feature._values[pbf.readVarint()];
|
|
91
|
-
|
|
92
|
-
feature.properties[key] = value;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=binary-util-functions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/helpers/binary-util-functions.ts"],"names":["classifyRings","geom","len","lines","length","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","type","_geometry","pos","end","key","_keys","value","_values","properties"],"mappings":";;;;;;;;;;AACA;;AAcO,SAASA,aAAT,CAAuBC,IAAvB,EAAgD;AACrD,MAAMC,GAAG,GAAGD,IAAI,CAACE,KAAL,CAAWC,MAAvB;;AAEA,MAAIF,GAAG,IAAI,CAAX,EAAc;AACZ,WAAO;AACLG,MAAAA,IAAI,EAAEJ,IAAI,CAACI,IADN;A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AZ,GAAkBD,IAAI,CAACE,IAAL,CAAUF,IAAI,CAACG,GAAL,CAAUJ,EAAE,GAAGC,IAAI,CAACC,EAAX,GAAiB,GAA1B,CAAV,CAAlB,GAA8D,EAA5E;AACD;AACF;;AASM,SAASG,WAAT,CAAqBC,GAArB,EAAkCC,OAAlC,EAA+DC,GAA/D,EAAqF;AAC1F,MAAID,OAAO,IAAIC,GAAf,EAAoB;AAClB,QAAIF,GAAG,KAAK,CAAZ,EAAeC,OAAO,CAACE,EAAR,GAAaD,GAAG,CAACE,UAAJ,EAAb,CAAf,KACK,IAAIJ,GAAG,KAAK,CAAZ,EAAeK,OAAO,CAACH,GAAD,EAAMD,OAAN,CAAP,CAAf,KACA,IAAID,GAAG,KAAK,CAAZ,EAAeC,OAAO,CAACK,IAAR,GAAeJ,GAAG,CAACE,UAAJ,EAAf,CAAf,KACA,IAAIJ,GAAG,KAAK,CAAZ,EAAeC,OAAO,CAACM,SAAR,GAAoBL,GAAG,CAACM,GAAxB;AACrB;AACF;;AAMM,SAASH,OAAT,CAAiBH,GAAjB,EAAgCD,OAAhC,EAAkE;AACvE,MAAMQ,GAAG,GAAGP,GAAG,CAACE,UAAJ,KAAmBF,GAAG,CAACM,GAAnC;;AAEA,SAAON,GAAG,CAACM,GAAJ,GAAUC,GAAjB,EAAsB;AACpB,QAAMC,GAAG,GAAGT,OAAO,CAACU,KAAR,CAAcT,GAAG,CAACE,UAAJ,EAAd,CAAZ;;AACA,QAAMQ,KAAK,GAAGX,OAAO,CAACY,OAAR,CAAgBX,GAAG,CAACE,UAAJ,EAAhB,CAAd;;AACAH,IAAAA,OAAO,CAACa,UAAR,CAAmBJ,GAAnB,IAA0BE,KAA1B;AACD;AACF","sourcesContent":["import Protobuf from 'pbf';\nimport {getPolygonSignedArea} from '@math.gl/polygon';\nimport {MvtBinaryGeometry} from '../lib/types';\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: MvtBinaryGeometry) {\n const len = geom.lines.length;\n\n if (len <= 1) {\n return {\n data: geom.data,\n areas: [[getPolygonSignedArea(geom.data)]],\n lines: [geom.lines]\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.lines[i] - offset;\n\n endIndex = geom.lines[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 {areas, lines: 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"],"file":"binary-util-functions.js"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.classifyRings = classifyRings;
|
|
7
|
-
exports.signedArea = signedArea;
|
|
8
|
-
exports.readFeature = readFeature;
|
|
9
|
-
exports.readTag = readTag;
|
|
10
|
-
|
|
11
|
-
function classifyRings(rings) {
|
|
12
|
-
var len = rings.length;
|
|
13
|
-
if (len <= 1) return [rings];
|
|
14
|
-
var polygons = [];
|
|
15
|
-
var polygon;
|
|
16
|
-
var ccw;
|
|
17
|
-
|
|
18
|
-
for (var i = 0; i < len; i++) {
|
|
19
|
-
var area = signedArea(rings[i]);
|
|
20
|
-
if (area === 0) continue;
|
|
21
|
-
if (ccw === undefined) ccw = area < 0;
|
|
22
|
-
|
|
23
|
-
if (ccw === area < 0) {
|
|
24
|
-
if (polygon) polygons.push(polygon);
|
|
25
|
-
polygon = [rings[i]];
|
|
26
|
-
} else if (polygon) polygon.push(rings[i]);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (polygon) polygons.push(polygon);
|
|
30
|
-
return polygons;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function signedArea(ring) {
|
|
34
|
-
var sum = 0;
|
|
35
|
-
|
|
36
|
-
for (var i = 0, j = ring.length - 1, p1, p2; i < ring.length; j = i++) {
|
|
37
|
-
p1 = ring[i];
|
|
38
|
-
p2 = ring[j];
|
|
39
|
-
sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return sum;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function readFeature(tag, feature, pbf) {
|
|
46
|
-
if (feature && pbf) {
|
|
47
|
-
if (tag === 1) feature.id = pbf.readVarint();else if (tag === 2) readTag(pbf, feature);else if (tag === 3) feature.type = pbf.readVarint();else if (tag === 4) feature._geometry = pbf.pos;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function readTag(pbf, feature) {
|
|
52
|
-
var end = pbf.readVarint() + pbf.pos;
|
|
53
|
-
|
|
54
|
-
while (pbf.pos < end) {
|
|
55
|
-
var key = feature._keys[pbf.readVarint()];
|
|
56
|
-
|
|
57
|
-
var value = feature._values[pbf.readVarint()];
|
|
58
|
-
|
|
59
|
-
feature.properties[key] = value;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=mapbox-util-functions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/helpers/mapbox-util-functions.ts"],"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"],"mappings":";;;;;;;;;;AASO,SAASA,aAAT,CAAuBC,KAAvB,EAAiD;AACtD,MAAMC,GAAG,GAAGD,KAAK,CAACE,MAAlB;AAEA,MAAID,GAAG,IAAI,CAAX,EAAc,OAAO,CAACD,KAAD,CAAP;AAEd,MAAMG,QAAsB,GAAG,EAA/B;AACA,MAAIC,OAAJ;AACA,MAAIC,GAAJ;;AAEA,OAAK,IA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AlC,EAA+DC,GAA/D,EAAqF;AAC1F,MAAID,OAAO,IAAIC,GAAf,EAAoB;AAClB,QAAIF,GAAG,KAAK,CAAZ,EAAeC,OAAO,CAACE,EAAR,GAAaD,GAAG,CAACE,UAAJ,EAAb,CAAf,KACK,IAAIJ,GAAG,KAAK,CAAZ,EAAeK,OAAO,CAACH,GAAD,EAAMD,OAAN,CAAP,CAAf,KACA,IAAID,GAAG,KAAK,CAAZ,EAAeC,OAAO,CAACK,IAAR,GAAeJ,GAAG,CAACE,UAAJ,EAAf,CAAf,KACA,IAAIJ,GAAG,KAAK,CAAZ,EAAeC,OAAO,CAACM,SAAR,GAAoBL,GAAG,CAACM,GAAxB;AACrB;AACF;;AAOM,SAASH,OAAT,CAAiBH,GAAjB,EAAgCD,OAAhC,EAAkE;AACvE,MAAMQ,GAAG,GAAGP,GAAG,CAACE,UAAJ,KAAmBF,GAAG,CAACM,GAAnC;;AAEA,SAAON,GAAG,CAACM,GAAJ,GAAUC,GAAjB,EAAsB;AACpB,QAAMC,GAAG,GAAGT,OAAO,CAACU,KAAR,CAAcT,GAAG,CAACE,UAAJ,EAAd,CAAZ;;AACA,QAAMQ,KAAK,GAAGX,OAAO,CAACY,OAAR,CAAgBX,GAAG,CAACE,UAAJ,EAAhB,CAAd;;AACAH,IAAAA,OAAO,CAACa,UAAR,CAAmBJ,GAAnB,IAA0BE,KAA1B;AACD;AACF","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"],"file":"mapbox-util-functions.js"}
|
package/dist/es5/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "MVTLoader", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _mvtLoader.MVTLoader;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "MVTWorkerLoader", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _mvtLoader.MVTWorkerLoader;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
var _mvtLoader = require("./mvt-loader");
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
package/dist/es5/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA","sourcesContent":["export {MVTLoader, MVTWorkerLoader} from './mvt-loader';\n"],"file":"index.js"}
|
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.featuresToBinary = featuresToBinary;
|
|
9
|
-
exports.TEST_EXPORTS = void 0;
|
|
10
|
-
|
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
|
|
13
|
-
var _polygon = require("@math.gl/polygon");
|
|
14
|
-
|
|
15
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
-
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
18
|
-
|
|
19
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
20
|
-
|
|
21
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
22
|
-
|
|
23
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
24
|
-
|
|
25
|
-
function featuresToBinary(features, firstPassData, options) {
|
|
26
|
-
return fillArrays(features, firstPassData, {
|
|
27
|
-
numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),
|
|
28
|
-
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var TEST_EXPORTS = {
|
|
33
|
-
extractNumericPropKeys: extractNumericPropKeys,
|
|
34
|
-
fillArrays: fillArrays
|
|
35
|
-
};
|
|
36
|
-
exports.TEST_EXPORTS = TEST_EXPORTS;
|
|
37
|
-
|
|
38
|
-
function extractNumericPropKeys(features) {
|
|
39
|
-
var numericPropKeys = {};
|
|
40
|
-
|
|
41
|
-
var _iterator = _createForOfIteratorHelper(features),
|
|
42
|
-
_step;
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
46
|
-
var feature = _step.value;
|
|
47
|
-
|
|
48
|
-
if (feature.properties) {
|
|
49
|
-
for (var key in feature.properties) {
|
|
50
|
-
var numericSoFar = numericPropKeys[key];
|
|
51
|
-
|
|
52
|
-
if (numericSoFar || numericSoFar === undefined) {
|
|
53
|
-
var val = feature.properties[key];
|
|
54
|
-
numericPropKeys[key] = isNumeric(val);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
} catch (err) {
|
|
60
|
-
_iterator.e(err);
|
|
61
|
-
} finally {
|
|
62
|
-
_iterator.f();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return Object.keys(numericPropKeys).filter(function (k) {
|
|
66
|
-
return numericPropKeys[k];
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function fillArrays(features, firstPassData, options) {
|
|
71
|
-
var pointPositionsCount = firstPassData.pointPositionsCount,
|
|
72
|
-
pointFeaturesCount = firstPassData.pointFeaturesCount,
|
|
73
|
-
linePositionsCount = firstPassData.linePositionsCount,
|
|
74
|
-
linePathsCount = firstPassData.linePathsCount,
|
|
75
|
-
lineFeaturesCount = firstPassData.lineFeaturesCount,
|
|
76
|
-
polygonPositionsCount = firstPassData.polygonPositionsCount,
|
|
77
|
-
polygonObjectsCount = firstPassData.polygonObjectsCount,
|
|
78
|
-
polygonRingsCount = firstPassData.polygonRingsCount,
|
|
79
|
-
polygonFeaturesCount = firstPassData.polygonFeaturesCount;
|
|
80
|
-
var numericPropKeys = options.numericPropKeys,
|
|
81
|
-
_options$PositionData = options.PositionDataType,
|
|
82
|
-
PositionDataType = _options$PositionData === void 0 ? Float32Array : _options$PositionData;
|
|
83
|
-
var hasGlobalId = features[0] && 'id' in features[0];
|
|
84
|
-
var coordLength = 2;
|
|
85
|
-
var GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
86
|
-
var points = {
|
|
87
|
-
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
88
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
89
|
-
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
90
|
-
numericProps: {},
|
|
91
|
-
properties: [],
|
|
92
|
-
fields: []
|
|
93
|
-
};
|
|
94
|
-
var lines = {
|
|
95
|
-
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
96
|
-
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
97
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
98
|
-
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
99
|
-
numericProps: {},
|
|
100
|
-
properties: [],
|
|
101
|
-
fields: []
|
|
102
|
-
};
|
|
103
|
-
var polygons = {
|
|
104
|
-
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
105
|
-
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
106
|
-
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
107
|
-
triangles: [],
|
|
108
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
109
|
-
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
110
|
-
numericProps: {},
|
|
111
|
-
properties: [],
|
|
112
|
-
fields: []
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
for (var _i = 0, _arr = [points, lines, polygons]; _i < _arr.length; _i++) {
|
|
116
|
-
var object = _arr[_i];
|
|
117
|
-
|
|
118
|
-
var _iterator2 = _createForOfIteratorHelper(numericPropKeys),
|
|
119
|
-
_step2;
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
123
|
-
var propName = _step2.value;
|
|
124
|
-
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
|
|
125
|
-
}
|
|
126
|
-
} catch (err) {
|
|
127
|
-
_iterator2.e(err);
|
|
128
|
-
} finally {
|
|
129
|
-
_iterator2.f();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
134
|
-
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
135
|
-
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
136
|
-
var indexMap = {
|
|
137
|
-
pointPosition: 0,
|
|
138
|
-
pointFeature: 0,
|
|
139
|
-
linePosition: 0,
|
|
140
|
-
linePath: 0,
|
|
141
|
-
lineFeature: 0,
|
|
142
|
-
polygonPosition: 0,
|
|
143
|
-
polygonObject: 0,
|
|
144
|
-
polygonRing: 0,
|
|
145
|
-
polygonFeature: 0,
|
|
146
|
-
feature: 0
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
var _iterator3 = _createForOfIteratorHelper(features),
|
|
150
|
-
_step3;
|
|
151
|
-
|
|
152
|
-
try {
|
|
153
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
154
|
-
var feature = _step3.value;
|
|
155
|
-
var geometry = feature.geometry;
|
|
156
|
-
var properties = feature.properties || {};
|
|
157
|
-
|
|
158
|
-
switch (geometry.type) {
|
|
159
|
-
case 'Point':
|
|
160
|
-
case 'MultiPoint':
|
|
161
|
-
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
162
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
163
|
-
|
|
164
|
-
if (hasGlobalId) {
|
|
165
|
-
points.fields.push({
|
|
166
|
-
id: feature.id
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
indexMap.pointFeature++;
|
|
171
|
-
break;
|
|
172
|
-
|
|
173
|
-
case 'LineString':
|
|
174
|
-
case 'MultiLineString':
|
|
175
|
-
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
176
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
177
|
-
|
|
178
|
-
if (hasGlobalId) {
|
|
179
|
-
lines.fields.push({
|
|
180
|
-
id: feature.id
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
indexMap.lineFeature++;
|
|
185
|
-
break;
|
|
186
|
-
|
|
187
|
-
case 'Polygon':
|
|
188
|
-
case 'MultiPolygon':
|
|
189
|
-
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
190
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
191
|
-
|
|
192
|
-
if (hasGlobalId) {
|
|
193
|
-
polygons.fields.push({
|
|
194
|
-
id: feature.id
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
indexMap.polygonFeature++;
|
|
199
|
-
break;
|
|
200
|
-
|
|
201
|
-
default:
|
|
202
|
-
throw new Error('Invalid geometry type');
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
indexMap.feature++;
|
|
206
|
-
}
|
|
207
|
-
} catch (err) {
|
|
208
|
-
_iterator3.e(err);
|
|
209
|
-
} finally {
|
|
210
|
-
_iterator3.f();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
217
|
-
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
218
|
-
var nPositions = geometry.data.length / coordLength;
|
|
219
|
-
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
220
|
-
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
221
|
-
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
222
|
-
indexMap.pointPosition += nPositions;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
226
|
-
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
227
|
-
var nPositions = geometry.data.length / coordLength;
|
|
228
|
-
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
229
|
-
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
230
|
-
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
231
|
-
|
|
232
|
-
for (var i = 0, il = geometry.lines.length; i < il; ++i) {
|
|
233
|
-
var start = geometry.lines[i];
|
|
234
|
-
var end = i === il - 1 ? geometry.data.length : geometry.lines[i + 1];
|
|
235
|
-
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
236
|
-
indexMap.linePosition += (end - start) / coordLength;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
241
|
-
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
242
|
-
var nPositions = geometry.data.length / coordLength;
|
|
243
|
-
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
244
|
-
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
245
|
-
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
246
|
-
|
|
247
|
-
for (var l = 0, ll = geometry.lines.length; l < ll; ++l) {
|
|
248
|
-
var startPosition = indexMap.polygonPosition;
|
|
249
|
-
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
250
|
-
var areas = geometry.areas[l];
|
|
251
|
-
var lines = geometry.lines[l];
|
|
252
|
-
var nextLines = geometry.lines[l + 1];
|
|
253
|
-
|
|
254
|
-
for (var i = 0, il = lines.length; i < il; ++i) {
|
|
255
|
-
var start = lines[i];
|
|
256
|
-
var end = i === il - 1 ? nextLines === undefined ? geometry.data.length : nextLines[0] : lines[i + 1];
|
|
257
|
-
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
258
|
-
indexMap.polygonPosition += (end - start) / coordLength;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
var endPosition = indexMap.polygonPosition;
|
|
262
|
-
triangulatePolygon(polygons, areas, lines, {
|
|
263
|
-
startPosition: startPosition,
|
|
264
|
-
endPosition: endPosition,
|
|
265
|
-
coordLength: coordLength
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function triangulatePolygon(polygons, areas, lines, _ref) {
|
|
271
|
-
var startPosition = _ref.startPosition,
|
|
272
|
-
endPosition = _ref.endPosition,
|
|
273
|
-
coordLength = _ref.coordLength;
|
|
274
|
-
var start = startPosition * coordLength;
|
|
275
|
-
var end = endPosition * coordLength;
|
|
276
|
-
var polygonPositions = polygons.positions.subarray(start, end);
|
|
277
|
-
var offset = lines[0];
|
|
278
|
-
var holes = lines.slice(1).map(function (n) {
|
|
279
|
-
return (n - offset) / coordLength;
|
|
280
|
-
});
|
|
281
|
-
var indices = (0, _polygon.earcut)(polygonPositions, holes, coordLength, areas);
|
|
282
|
-
|
|
283
|
-
for (var t = 0, tl = indices.length; t < tl; ++t) {
|
|
284
|
-
polygons.triangles.push(startPosition + indices[t]);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
289
|
-
var returnObj = {
|
|
290
|
-
points: _objectSpread(_objectSpread({}, points), {}, {
|
|
291
|
-
positions: {
|
|
292
|
-
value: points.positions,
|
|
293
|
-
size: coordLength
|
|
294
|
-
},
|
|
295
|
-
globalFeatureIds: {
|
|
296
|
-
value: points.globalFeatureIds,
|
|
297
|
-
size: 1
|
|
298
|
-
},
|
|
299
|
-
featureIds: {
|
|
300
|
-
value: points.featureIds,
|
|
301
|
-
size: 1
|
|
302
|
-
}
|
|
303
|
-
}),
|
|
304
|
-
lines: _objectSpread(_objectSpread({}, lines), {}, {
|
|
305
|
-
pathIndices: {
|
|
306
|
-
value: lines.pathIndices,
|
|
307
|
-
size: 1
|
|
308
|
-
},
|
|
309
|
-
positions: {
|
|
310
|
-
value: lines.positions,
|
|
311
|
-
size: coordLength
|
|
312
|
-
},
|
|
313
|
-
globalFeatureIds: {
|
|
314
|
-
value: lines.globalFeatureIds,
|
|
315
|
-
size: 1
|
|
316
|
-
},
|
|
317
|
-
featureIds: {
|
|
318
|
-
value: lines.featureIds,
|
|
319
|
-
size: 1
|
|
320
|
-
}
|
|
321
|
-
}),
|
|
322
|
-
polygons: _objectSpread(_objectSpread({}, polygons), {}, {
|
|
323
|
-
polygonIndices: {
|
|
324
|
-
value: polygons.polygonIndices,
|
|
325
|
-
size: 1
|
|
326
|
-
},
|
|
327
|
-
primitivePolygonIndices: {
|
|
328
|
-
value: polygons.primitivePolygonIndices,
|
|
329
|
-
size: 1
|
|
330
|
-
},
|
|
331
|
-
positions: {
|
|
332
|
-
value: polygons.positions,
|
|
333
|
-
size: coordLength
|
|
334
|
-
},
|
|
335
|
-
triangles: {
|
|
336
|
-
value: new Uint32Array(polygons.triangles),
|
|
337
|
-
size: 1
|
|
338
|
-
},
|
|
339
|
-
globalFeatureIds: {
|
|
340
|
-
value: polygons.globalFeatureIds,
|
|
341
|
-
size: 1
|
|
342
|
-
},
|
|
343
|
-
featureIds: {
|
|
344
|
-
value: polygons.featureIds,
|
|
345
|
-
size: 1
|
|
346
|
-
}
|
|
347
|
-
})
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
for (var geomType in returnObj) {
|
|
351
|
-
for (var numericProp in returnObj[geomType].numericProps) {
|
|
352
|
-
returnObj[geomType].numericProps[numericProp] = {
|
|
353
|
-
value: returnObj[geomType].numericProps[numericProp],
|
|
354
|
-
size: 1
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
return returnObj;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function fillNumericProperties(object, properties, index, length) {
|
|
363
|
-
for (var numericPropName in object.numericProps) {
|
|
364
|
-
if (numericPropName in properties) {
|
|
365
|
-
object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function keepStringProperties(properties, numericKeys) {
|
|
371
|
-
var props = {};
|
|
372
|
-
|
|
373
|
-
for (var key in properties) {
|
|
374
|
-
if (!numericKeys.includes(key)) {
|
|
375
|
-
props[key] = properties[key];
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
return props;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function isNumeric(x) {
|
|
383
|
-
return Number.isFinite(x);
|
|
384
|
-
}
|
|
385
|
-
//# sourceMappingURL=features-to-binary.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":["featuresToBinary","features","firstPassData","options","fillArrays","numericPropKeys","extractNumericPropKeys","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","numericSoFar","undefined","val","isNumeric","Object","keys","filter","k","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","hasGlobalId","coordLength","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","type","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","start","end","l","ll","startPosition","areas","nextLines","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","indices","t","tl","returnObj","value","size","geomType","numericProp","index","numericPropName","numericKeys","props","includes","x","Number","isFinite"],"mappings":";;;;;;;;;;;;AACA;;;;;;;;;;;;AAwBO,SAASA,gBAAT,CACLC,QADK,EAELC,aAFK,EAGLC,OAHK,EAIL;AACA,SAAOC,UAAU,CAACH,QAAD,EAAWC,aAAX,EAA0B;AACzCG,IAAAA,eAAe,EAAEF,OAAO,GAAGA,OAAO,CAACE,eAAX,GAA6BC,sBAAsB,CAACL,QAAD,CADlC;AAEzCM,IAAAA,gBAAgB,EAAEJ,OAAO,GAAGA,OAAO,CAACI,gBAAX,GAA8BC;AAFd,GAA1B,CAAjB;AAID;;AAEM,IAAMC,YAAY,GAAG;AAC1BH,EAAAA,sBAAsB,EAAtBA,sBAD0B;AAE1BF,EAAAA,UAAU,EAAVA;AAF0B,CAArB;;;AAWP,SAASE,sBAAT,CAAgCL,QAAhC,EAA4E;AAC1E,MAAMI,eAAe,GAAG,EAAxB;;AAD0E,6CAEpDJ,QAFoD;AAAA;;AAAA;AAE1E,wDAAgC;AAAA,UAArBS,OAAqB;;AAC9B,UAAIA,OAAO,CAACC,UAAZ,EAAwB;AACtB,aAAK,IAAMC,GAAX,IAAkBF,OAAO,CAACC,UAA1B,EAAsC;AAIpC,cAAME,YAAY,GAAGR,eAAe,CAACO,G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B,SAAOC,MAAM,CAACC,QAAP,CAAgBF,CAAhB,CAAP;AACD","sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport {\n MvtBinaryCoordinates,\n MvtBinaryGeometry,\n MvtBinaryOptions,\n MvtFirstPassedData,\n MvtLines,\n MvtPoints,\n MvtPolygons\n} from '../types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns filled arrays\n */\nexport function featuresToBinary(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options?: MvtBinaryOptions\n) {\n return fillArrays(features, firstPassData, {\n numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),\n PositionDataType: options ? options.PositionDataType : Float32Array\n });\n}\n\nexport const TEST_EXPORTS = {\n extractNumericPropKeys,\n fillArrays\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric keys\n */\nfunction extractNumericPropKeys(features: MvtBinaryCoordinates[]): string[] {\n const numericPropKeys = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, false is stored to prevent rechecking in the future\n const numericSoFar = numericPropKeys[key];\n if (numericSoFar || numericSoFar === undefined) {\n const val = feature.properties[key];\n numericPropKeys[key] = isNumeric(val);\n }\n }\n }\n }\n\n return Object.keys(numericPropKeys).filter((k) => numericPropKeys[k]);\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options: MvtBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n } = firstPassData;\n const {numericPropKeys, PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const coordLength = 2;\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: MvtPoints = {\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: MvtLines = {\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: MvtPolygons = {\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n case 'MultiPoint':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n case 'MultiLineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n case 'MultiPolygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: MvtBinaryGeometry,\n points: MvtPoints,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: MvtBinaryGeometry,\n lines: MvtLines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.lines.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.lines[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.lines[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: MvtBinaryGeometry,\n polygons: MvtPolygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.lines is a 2D array\n for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas![l];\n const lines = geometry.lines[l];\n const nextLines = geometry.lines[l + 1];\n\n for (let i = 0, il = lines.length; i < il; ++i) {\n const start = lines[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextLines === undefined\n ? geometry.data.length // end of data (no next lines)\n : nextLines[0] // start of first line in nextLines\n : lines[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, lines, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param lines\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: MvtPolygons,\n areas: number,\n lines: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = lines[0];\n const holes = lines.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const indices = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = indices.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + indices[t]);\n }\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: MvtPoints,\n lines: MvtLines,\n polygons: MvtPolygons,\n coordLength: number\n) {\n const returnObj = {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1}\n },\n lines: {\n ...lines,\n pathIndices: {value: lines.pathIndices, size: 1},\n positions: {value: lines.positions, size: coordLength},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1}\n },\n polygons: {\n ...polygons,\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n positions: {value: polygons.positions, size: coordLength},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1}\n }\n };\n\n for (const geomType in returnObj) {\n for (const numericProp in returnObj[geomType].numericProps) {\n returnObj[geomType].numericProps[numericProp] = {\n value: returnObj[geomType].numericProps[numericProp],\n size: 1\n };\n }\n }\n return returnObj;\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: MvtPoints,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\nfunction isNumeric(x: unknown) {\n return Number.isFinite(x);\n}\n"],"file":"features-to-binary.js"}
|