@loaders.gl/mvt 4.0.0-alpha.1 → 4.0.0-alpha.11
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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +3124 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/helpers/binary-util-functions.js +82 -0
- package/dist/es5/helpers/binary-util-functions.js.map +1 -0
- package/dist/es5/helpers/mapbox-util-functions.js +50 -0
- package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/es5/index.js +26 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +168 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +62 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +28 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
- package/dist/es5/lib/geojson-tiler/clip.js +237 -0
- package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/convert.js +161 -0
- package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/feature.js +62 -0
- package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js +186 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/simplify.js +52 -0
- package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/tile.js +121 -0
- package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/transform.js +50 -0
- package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/wrap.js +122 -0
- package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +184 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +62 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +28 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/es5/lib/parse-mvt.js +143 -0
- package/dist/es5/lib/parse-mvt.js.map +1 -0
- package/dist/es5/lib/types.js +2 -0
- package/dist/es5/lib/types.js.map +1 -0
- package/dist/es5/mvt-loader.js +58 -0
- package/dist/es5/mvt-loader.js.map +1 -0
- package/dist/es5/workers/mvt-worker.js +6 -0
- package/dist/es5/workers/mvt-worker.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/helpers/binary-util-functions.js +73 -0
- package/dist/esm/helpers/binary-util-functions.js.map +1 -0
- package/dist/esm/helpers/mapbox-util-functions.js +41 -0
- package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +136 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +47 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile.js +19 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
- package/dist/esm/lib/geojson-tiler/clip.js +173 -0
- package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/convert.js +116 -0
- package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/feature.js +35 -0
- package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js +171 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/simplify.js +46 -0
- package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/tile.js +103 -0
- package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/transform.js +32 -0
- package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/wrap.js +67 -0
- package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +163 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +47 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +19 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/esm/lib/parse-mvt.js +138 -0
- package/dist/esm/lib/parse-mvt.js.map +1 -0
- package/dist/esm/lib/types.js +2 -0
- package/dist/esm/lib/types.js.map +1 -0
- package/dist/esm/mvt-loader.js +29 -0
- package/dist/esm/mvt-loader.js.map +1 -0
- package/dist/esm/workers/mvt-worker.js +4 -0
- package/dist/esm/workers/mvt-worker.js.map +1 -0
- package/dist/helpers/binary-util-functions.d.ts +35 -0
- package/dist/helpers/binary-util-functions.d.ts.map +1 -0
- package/dist/helpers/binary-util-functions.js +111 -74
- package/dist/helpers/mapbox-util-functions.d.ts +29 -0
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
- package/dist/helpers/mapbox-util-functions.js +78 -45
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -2
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +41 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -142
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
- package/dist/lib/geojson-tiler/clip.d.ts +16 -0
- package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/clip.js +209 -0
- package/dist/lib/geojson-tiler/convert.d.ts +10 -0
- package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/convert.js +134 -0
- package/dist/lib/geojson-tiler/feature.d.ts +3 -0
- package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/feature.js +46 -0
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
- package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
- package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/simplify.js +68 -0
- package/dist/lib/geojson-tiler/tile.d.ts +38 -0
- package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/tile.js +125 -0
- package/dist/lib/geojson-tiler/transform.d.ts +7 -0
- package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/transform.js +43 -0
- package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
- package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/wrap.js +86 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +27 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
- package/dist/lib/parse-mvt.d.ts +14 -0
- package/dist/lib/parse-mvt.d.ts.map +1 -0
- package/dist/lib/parse-mvt.js +149 -98
- package/dist/lib/types.d.ts +69 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -2
- package/dist/mvt-loader.d.ts +10 -0
- package/dist/mvt-loader.d.ts.map +1 -0
- package/dist/mvt-loader.js +43 -22
- package/dist/mvt-worker.js +845 -766
- package/dist/workers/mvt-worker.d.ts +2 -0
- package/dist/workers/mvt-worker.d.ts.map +1 -0
- package/dist/workers/mvt-worker.js +5 -4
- package/package.json +10 -9
- package/src/helpers/binary-util-functions.ts +9 -7
- package/src/helpers/mapbox-util-functions.ts +2 -2
- package/src/index.ts +7 -0
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +42 -45
- package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
- package/src/lib/geojson-tiler/LICENSE +19 -0
- package/src/lib/geojson-tiler/clip.ts +248 -0
- package/src/lib/geojson-tiler/convert.ts +158 -0
- package/src/lib/geojson-tiler/feature.ts +45 -0
- package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
- package/src/lib/geojson-tiler/simplify.ts +77 -0
- package/src/lib/geojson-tiler/tile.ts +185 -0
- package/src/lib/geojson-tiler/transform.ts +55 -0
- package/src/lib/geojson-tiler/wrap.ts +108 -0
- package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +4 -4
- package/src/lib/parse-mvt.ts +138 -93
- package/src/lib/types.ts +49 -72
- package/src/mvt-loader.ts +13 -9
- package/dist/bundle.js.map +0 -1
- package/dist/helpers/binary-util-functions.js.map +0 -1
- package/dist/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/binary-vector-tile/features-to-binary.js +0 -327
- package/dist/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/parse-mvt.js.map +0 -1
- package/dist/lib/types.js.map +0 -1
- package/dist/mvt-loader.js.map +0 -1
- package/dist/workers/mvt-worker.js.map +0 -1
- package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
- /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
- /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
package/dist/mvt-worker.js
CHANGED
|
@@ -757,413 +757,134 @@
|
|
|
757
757
|
}
|
|
758
758
|
});
|
|
759
759
|
|
|
760
|
-
//
|
|
761
|
-
function
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
let
|
|
768
|
-
for (let i2 =
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
continue;
|
|
772
|
-
if (ccw === void 0)
|
|
773
|
-
ccw = area2 < 0;
|
|
774
|
-
if (ccw === area2 < 0) {
|
|
775
|
-
if (polygon)
|
|
776
|
-
polygons.push(polygon);
|
|
777
|
-
polygon = [rings[i2]];
|
|
778
|
-
} else if (polygon)
|
|
779
|
-
polygon.push(rings[i2]);
|
|
780
|
-
}
|
|
781
|
-
if (polygon)
|
|
782
|
-
polygons.push(polygon);
|
|
783
|
-
return polygons;
|
|
784
|
-
}
|
|
785
|
-
function signedArea(ring) {
|
|
786
|
-
let sum = 0;
|
|
787
|
-
for (let i2 = 0, j = ring.length - 1, p1, p2; i2 < ring.length; j = i2++) {
|
|
788
|
-
p1 = ring[i2];
|
|
789
|
-
p2 = ring[j];
|
|
790
|
-
sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
|
|
760
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
|
|
761
|
+
function getPolygonSignedArea(points, options = {}) {
|
|
762
|
+
const {
|
|
763
|
+
start = 0,
|
|
764
|
+
end = points.length
|
|
765
|
+
} = options;
|
|
766
|
+
const dim = options.size || 2;
|
|
767
|
+
let area2 = 0;
|
|
768
|
+
for (let i2 = start, j = end - dim; i2 < end; i2 += dim) {
|
|
769
|
+
area2 += (points[i2] - points[j]) * (points[i2 + 1] + points[j + 1]);
|
|
770
|
+
j = i2;
|
|
791
771
|
}
|
|
792
|
-
return
|
|
772
|
+
return area2 / 2;
|
|
793
773
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
774
|
+
|
|
775
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
|
|
776
|
+
function earcut(positions, holeIndices, dim = 2, areas) {
|
|
777
|
+
const hasHoles = holeIndices && holeIndices.length;
|
|
778
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
|
|
779
|
+
let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0]);
|
|
780
|
+
const triangles = [];
|
|
781
|
+
if (!outerNode || outerNode.next === outerNode.prev)
|
|
782
|
+
return triangles;
|
|
783
|
+
let invSize;
|
|
784
|
+
let maxX;
|
|
785
|
+
let maxY;
|
|
786
|
+
let minX;
|
|
787
|
+
let minY;
|
|
788
|
+
let x2;
|
|
789
|
+
let y2;
|
|
790
|
+
if (hasHoles)
|
|
791
|
+
outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
|
|
792
|
+
if (positions.length > 80 * dim) {
|
|
793
|
+
minX = maxX = positions[0];
|
|
794
|
+
minY = maxY = positions[1];
|
|
795
|
+
for (let i2 = dim; i2 < outerLen; i2 += dim) {
|
|
796
|
+
x2 = positions[i2];
|
|
797
|
+
y2 = positions[i2 + 1];
|
|
798
|
+
if (x2 < minX)
|
|
799
|
+
minX = x2;
|
|
800
|
+
if (y2 < minY)
|
|
801
|
+
minY = y2;
|
|
802
|
+
if (x2 > maxX)
|
|
803
|
+
maxX = x2;
|
|
804
|
+
if (y2 > maxY)
|
|
805
|
+
maxY = y2;
|
|
806
|
+
}
|
|
807
|
+
invSize = Math.max(maxX - minX, maxY - minY);
|
|
808
|
+
invSize = invSize !== 0 ? 1 / invSize : 0;
|
|
804
809
|
}
|
|
810
|
+
earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
|
|
811
|
+
return triangles;
|
|
805
812
|
}
|
|
806
|
-
function
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
813
|
+
function linkedList(data, start, end, dim, clockwise, area2) {
|
|
814
|
+
let i2;
|
|
815
|
+
let last;
|
|
816
|
+
if (area2 === void 0) {
|
|
817
|
+
area2 = getPolygonSignedArea(data, {
|
|
818
|
+
start,
|
|
819
|
+
end,
|
|
820
|
+
size: dim
|
|
821
|
+
});
|
|
812
822
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
823
|
+
if (clockwise === area2 < 0) {
|
|
824
|
+
for (i2 = start; i2 < end; i2 += dim)
|
|
825
|
+
last = insertNode(i2, data[i2], data[i2 + 1], last);
|
|
826
|
+
} else {
|
|
827
|
+
for (i2 = end - dim; i2 >= start; i2 -= dim)
|
|
828
|
+
last = insertNode(i2, data[i2], data[i2 + 1], last);
|
|
819
829
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
this.type = 0;
|
|
824
|
-
this.id = null;
|
|
825
|
-
this._pbf = pbf;
|
|
826
|
-
this._geometry = -1;
|
|
827
|
-
this._keys = keys;
|
|
828
|
-
this._values = values;
|
|
829
|
-
pbf.readFields(readFeature, this, end);
|
|
830
|
+
if (last && equals(last, last.next)) {
|
|
831
|
+
removeNode(last);
|
|
832
|
+
last = last.next;
|
|
830
833
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
y2 += pbf.readSVarint();
|
|
851
|
-
if (cmd2 === 1) {
|
|
852
|
-
if (line)
|
|
853
|
-
lines.push(line);
|
|
854
|
-
line = [];
|
|
855
|
-
}
|
|
856
|
-
if (line)
|
|
857
|
-
line.push([x2, y2]);
|
|
858
|
-
} else if (cmd2 === 7) {
|
|
859
|
-
if (line) {
|
|
860
|
-
line.push(line[0].slice());
|
|
861
|
-
}
|
|
862
|
-
} else {
|
|
863
|
-
throw new Error(`unknown command ${cmd2}`);
|
|
864
|
-
}
|
|
834
|
+
return last;
|
|
835
|
+
}
|
|
836
|
+
function filterPoints(start, end) {
|
|
837
|
+
if (!start)
|
|
838
|
+
return start;
|
|
839
|
+
if (!end)
|
|
840
|
+
end = start;
|
|
841
|
+
let p = start;
|
|
842
|
+
let again;
|
|
843
|
+
do {
|
|
844
|
+
again = false;
|
|
845
|
+
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
846
|
+
removeNode(p);
|
|
847
|
+
p = end = p.prev;
|
|
848
|
+
if (p === p.next)
|
|
849
|
+
break;
|
|
850
|
+
again = true;
|
|
851
|
+
} else {
|
|
852
|
+
p = p.next;
|
|
865
853
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
if (y2 > y22)
|
|
899
|
-
y22 = y2;
|
|
900
|
-
} else if (cmd2 !== 7) {
|
|
901
|
-
throw new Error(`unknown command ${cmd2}`);
|
|
854
|
+
} while (again || p !== end);
|
|
855
|
+
return end;
|
|
856
|
+
}
|
|
857
|
+
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
858
|
+
if (!ear)
|
|
859
|
+
return;
|
|
860
|
+
if (!pass && invSize)
|
|
861
|
+
indexCurve(ear, minX, minY, invSize);
|
|
862
|
+
let stop = ear;
|
|
863
|
+
let prev;
|
|
864
|
+
let next;
|
|
865
|
+
while (ear.prev !== ear.next) {
|
|
866
|
+
prev = ear.prev;
|
|
867
|
+
next = ear.next;
|
|
868
|
+
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
869
|
+
triangles.push(prev.i / dim);
|
|
870
|
+
triangles.push(ear.i / dim);
|
|
871
|
+
triangles.push(next.i / dim);
|
|
872
|
+
removeNode(ear);
|
|
873
|
+
ear = next.next;
|
|
874
|
+
stop = next.next;
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
ear = next;
|
|
878
|
+
if (ear === stop) {
|
|
879
|
+
if (!pass) {
|
|
880
|
+
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
881
|
+
} else if (pass === 1) {
|
|
882
|
+
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
883
|
+
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
884
|
+
} else if (pass === 2) {
|
|
885
|
+
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
902
886
|
}
|
|
903
|
-
|
|
904
|
-
return [x1, y1, x22, y22];
|
|
905
|
-
}
|
|
906
|
-
_toGeoJSON(transform) {
|
|
907
|
-
let coords = this.loadGeometry();
|
|
908
|
-
let type = VectorTileFeature.types[this.type];
|
|
909
|
-
let i2;
|
|
910
|
-
let j;
|
|
911
|
-
switch (this.type) {
|
|
912
|
-
case 1:
|
|
913
|
-
const points = [];
|
|
914
|
-
for (i2 = 0; i2 < coords.length; i2++) {
|
|
915
|
-
points[i2] = coords[i2][0];
|
|
916
|
-
}
|
|
917
|
-
coords = points;
|
|
918
|
-
transform(coords, this);
|
|
919
|
-
break;
|
|
920
|
-
case 2:
|
|
921
|
-
for (i2 = 0; i2 < coords.length; i2++) {
|
|
922
|
-
transform(coords[i2], this);
|
|
923
|
-
}
|
|
924
|
-
break;
|
|
925
|
-
case 3:
|
|
926
|
-
coords = classifyRings(coords);
|
|
927
|
-
for (i2 = 0; i2 < coords.length; i2++) {
|
|
928
|
-
for (j = 0; j < coords[i2].length; j++) {
|
|
929
|
-
transform(coords[i2][j], this);
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
break;
|
|
933
|
-
}
|
|
934
|
-
if (coords.length === 1) {
|
|
935
|
-
coords = coords[0];
|
|
936
|
-
} else {
|
|
937
|
-
type = `Multi${type}`;
|
|
938
|
-
}
|
|
939
|
-
const result = {
|
|
940
|
-
type: "Feature",
|
|
941
|
-
geometry: {
|
|
942
|
-
type,
|
|
943
|
-
coordinates: coords
|
|
944
|
-
},
|
|
945
|
-
properties: this.properties
|
|
946
|
-
};
|
|
947
|
-
if (this.id !== null) {
|
|
948
|
-
result.id = this.id;
|
|
949
|
-
}
|
|
950
|
-
return result;
|
|
951
|
-
}
|
|
952
|
-
toGeoJSON(options) {
|
|
953
|
-
if (typeof options === "function") {
|
|
954
|
-
return this._toGeoJSON(options);
|
|
955
|
-
}
|
|
956
|
-
const { x: x2, y: y2, z } = options;
|
|
957
|
-
const size = this.extent * Math.pow(2, z);
|
|
958
|
-
const x0 = this.extent * x2;
|
|
959
|
-
const y0 = this.extent * y2;
|
|
960
|
-
function project2(line) {
|
|
961
|
-
for (let j = 0; j < line.length; j++) {
|
|
962
|
-
const p = line[j];
|
|
963
|
-
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
964
|
-
const y22 = 180 - (p[1] + y0) * 360 / size;
|
|
965
|
-
p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
return this._toGeoJSON(project2);
|
|
969
|
-
}
|
|
970
|
-
};
|
|
971
|
-
|
|
972
|
-
// src/lib/mapbox-vector-tile/vector-tile-layer.ts
|
|
973
|
-
var VectorTileLayer = class {
|
|
974
|
-
constructor(pbf, end) {
|
|
975
|
-
this.version = 1;
|
|
976
|
-
this.name = "";
|
|
977
|
-
this.extent = 4096;
|
|
978
|
-
this.length = 0;
|
|
979
|
-
this._pbf = pbf;
|
|
980
|
-
this._keys = [];
|
|
981
|
-
this._values = [];
|
|
982
|
-
this._features = [];
|
|
983
|
-
pbf.readFields(readLayer, this, end);
|
|
984
|
-
this.length = this._features.length;
|
|
985
|
-
}
|
|
986
|
-
feature(i2) {
|
|
987
|
-
if (i2 < 0 || i2 >= this._features.length) {
|
|
988
|
-
throw new Error("feature index out of bounds");
|
|
989
|
-
}
|
|
990
|
-
this._pbf.pos = this._features[i2];
|
|
991
|
-
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
992
|
-
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
|
|
993
|
-
}
|
|
994
|
-
};
|
|
995
|
-
function readLayer(tag, layer, pbf) {
|
|
996
|
-
if (layer && pbf) {
|
|
997
|
-
if (tag === 15)
|
|
998
|
-
layer.version = pbf.readVarint();
|
|
999
|
-
else if (tag === 1)
|
|
1000
|
-
layer.name = pbf.readString();
|
|
1001
|
-
else if (tag === 5)
|
|
1002
|
-
layer.extent = pbf.readVarint();
|
|
1003
|
-
else if (tag === 2)
|
|
1004
|
-
layer._features.push(pbf.pos);
|
|
1005
|
-
else if (tag === 3)
|
|
1006
|
-
layer._keys.push(pbf.readString());
|
|
1007
|
-
else if (tag === 4)
|
|
1008
|
-
layer._values.push(readValueMessage(pbf));
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
function readValueMessage(pbf) {
|
|
1012
|
-
let value = null;
|
|
1013
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
1014
|
-
while (pbf.pos < end) {
|
|
1015
|
-
const tag = pbf.readVarint() >> 3;
|
|
1016
|
-
value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
|
|
1017
|
-
}
|
|
1018
|
-
return value;
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
// src/lib/mapbox-vector-tile/vector-tile.ts
|
|
1022
|
-
var VectorTile = class {
|
|
1023
|
-
constructor(pbf, end) {
|
|
1024
|
-
this.layers = pbf.readFields(readTile, {}, end);
|
|
1025
|
-
}
|
|
1026
|
-
};
|
|
1027
|
-
function readTile(tag, layers, pbf) {
|
|
1028
|
-
if (tag === 3) {
|
|
1029
|
-
if (pbf) {
|
|
1030
|
-
const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
|
|
1031
|
-
if (layer.length && layers) {
|
|
1032
|
-
layers[layer.name] = layer;
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
// ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
|
|
1039
|
-
function getPolygonSignedArea(points, options = {}) {
|
|
1040
|
-
const {
|
|
1041
|
-
start = 0,
|
|
1042
|
-
end = points.length
|
|
1043
|
-
} = options;
|
|
1044
|
-
const dim = options.size || 2;
|
|
1045
|
-
let area2 = 0;
|
|
1046
|
-
for (let i2 = start, j = end - dim; i2 < end; i2 += dim) {
|
|
1047
|
-
area2 += (points[i2] - points[j]) * (points[i2 + 1] + points[j + 1]);
|
|
1048
|
-
j = i2;
|
|
1049
|
-
}
|
|
1050
|
-
return area2 / 2;
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
// ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
|
|
1054
|
-
function earcut(data, holeIndices, dim, areas) {
|
|
1055
|
-
dim = dim || 2;
|
|
1056
|
-
const hasHoles = holeIndices && holeIndices.length;
|
|
1057
|
-
const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
|
1058
|
-
let outerNode = linkedList(data, 0, outerLen, dim, true, areas && areas[0]);
|
|
1059
|
-
const triangles = [];
|
|
1060
|
-
if (!outerNode || outerNode.next === outerNode.prev)
|
|
1061
|
-
return triangles;
|
|
1062
|
-
let invSize;
|
|
1063
|
-
let maxX;
|
|
1064
|
-
let maxY;
|
|
1065
|
-
let minX;
|
|
1066
|
-
let minY;
|
|
1067
|
-
let x2;
|
|
1068
|
-
let y2;
|
|
1069
|
-
if (hasHoles)
|
|
1070
|
-
outerNode = eliminateHoles(data, holeIndices, outerNode, dim, areas);
|
|
1071
|
-
if (data.length > 80 * dim) {
|
|
1072
|
-
minX = maxX = data[0];
|
|
1073
|
-
minY = maxY = data[1];
|
|
1074
|
-
for (let i2 = dim; i2 < outerLen; i2 += dim) {
|
|
1075
|
-
x2 = data[i2];
|
|
1076
|
-
y2 = data[i2 + 1];
|
|
1077
|
-
if (x2 < minX)
|
|
1078
|
-
minX = x2;
|
|
1079
|
-
if (y2 < minY)
|
|
1080
|
-
minY = y2;
|
|
1081
|
-
if (x2 > maxX)
|
|
1082
|
-
maxX = x2;
|
|
1083
|
-
if (y2 > maxY)
|
|
1084
|
-
maxY = y2;
|
|
1085
|
-
}
|
|
1086
|
-
invSize = Math.max(maxX - minX, maxY - minY);
|
|
1087
|
-
invSize = invSize !== 0 ? 1 / invSize : 0;
|
|
1088
|
-
}
|
|
1089
|
-
earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
|
|
1090
|
-
return triangles;
|
|
1091
|
-
}
|
|
1092
|
-
function linkedList(data, start, end, dim, clockwise, area2) {
|
|
1093
|
-
let i2;
|
|
1094
|
-
let last;
|
|
1095
|
-
if (area2 === void 0) {
|
|
1096
|
-
area2 = getPolygonSignedArea(data, {
|
|
1097
|
-
start,
|
|
1098
|
-
end,
|
|
1099
|
-
size: dim
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
if (clockwise === area2 < 0) {
|
|
1103
|
-
for (i2 = start; i2 < end; i2 += dim)
|
|
1104
|
-
last = insertNode(i2, data[i2], data[i2 + 1], last);
|
|
1105
|
-
} else {
|
|
1106
|
-
for (i2 = end - dim; i2 >= start; i2 -= dim)
|
|
1107
|
-
last = insertNode(i2, data[i2], data[i2 + 1], last);
|
|
1108
|
-
}
|
|
1109
|
-
if (last && equals(last, last.next)) {
|
|
1110
|
-
removeNode(last);
|
|
1111
|
-
last = last.next;
|
|
1112
|
-
}
|
|
1113
|
-
return last;
|
|
1114
|
-
}
|
|
1115
|
-
function filterPoints(start, end) {
|
|
1116
|
-
if (!start)
|
|
1117
|
-
return start;
|
|
1118
|
-
if (!end)
|
|
1119
|
-
end = start;
|
|
1120
|
-
let p = start;
|
|
1121
|
-
let again;
|
|
1122
|
-
do {
|
|
1123
|
-
again = false;
|
|
1124
|
-
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
1125
|
-
removeNode(p);
|
|
1126
|
-
p = end = p.prev;
|
|
1127
|
-
if (p === p.next)
|
|
1128
|
-
break;
|
|
1129
|
-
again = true;
|
|
1130
|
-
} else {
|
|
1131
|
-
p = p.next;
|
|
1132
|
-
}
|
|
1133
|
-
} while (again || p !== end);
|
|
1134
|
-
return end;
|
|
1135
|
-
}
|
|
1136
|
-
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
1137
|
-
if (!ear)
|
|
1138
|
-
return;
|
|
1139
|
-
if (!pass && invSize)
|
|
1140
|
-
indexCurve(ear, minX, minY, invSize);
|
|
1141
|
-
let stop = ear;
|
|
1142
|
-
let prev;
|
|
1143
|
-
let next;
|
|
1144
|
-
while (ear.prev !== ear.next) {
|
|
1145
|
-
prev = ear.prev;
|
|
1146
|
-
next = ear.next;
|
|
1147
|
-
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
1148
|
-
triangles.push(prev.i / dim);
|
|
1149
|
-
triangles.push(ear.i / dim);
|
|
1150
|
-
triangles.push(next.i / dim);
|
|
1151
|
-
removeNode(ear);
|
|
1152
|
-
ear = next.next;
|
|
1153
|
-
stop = next.next;
|
|
1154
|
-
continue;
|
|
1155
|
-
}
|
|
1156
|
-
ear = next;
|
|
1157
|
-
if (ear === stop) {
|
|
1158
|
-
if (!pass) {
|
|
1159
|
-
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
1160
|
-
} else if (pass === 1) {
|
|
1161
|
-
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
1162
|
-
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
1163
|
-
} else if (pass === 2) {
|
|
1164
|
-
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
1165
|
-
}
|
|
1166
|
-
break;
|
|
887
|
+
break;
|
|
1167
888
|
}
|
|
1168
889
|
}
|
|
1169
890
|
}
|
|
@@ -1501,36 +1222,565 @@
|
|
|
1501
1222
|
last.next.prev = p;
|
|
1502
1223
|
last.next = p;
|
|
1503
1224
|
}
|
|
1504
|
-
return p;
|
|
1505
|
-
}
|
|
1506
|
-
function removeNode(p) {
|
|
1507
|
-
p.next.prev = p.prev;
|
|
1508
|
-
p.prev.next = p.next;
|
|
1509
|
-
if (p.prevZ)
|
|
1510
|
-
p.prevZ.nextZ = p.nextZ;
|
|
1511
|
-
if (p.nextZ)
|
|
1512
|
-
p.nextZ.prevZ = p.prevZ;
|
|
1513
|
-
}
|
|
1514
|
-
function Node(i2, x2, y2) {
|
|
1515
|
-
this.i = i2;
|
|
1516
|
-
this.x = x2;
|
|
1517
|
-
this.y = y2;
|
|
1518
|
-
this.prev = null;
|
|
1519
|
-
this.next = null;
|
|
1520
|
-
this.z = null;
|
|
1521
|
-
this.prevZ = null;
|
|
1522
|
-
this.nextZ = null;
|
|
1523
|
-
this.steiner = false;
|
|
1225
|
+
return p;
|
|
1226
|
+
}
|
|
1227
|
+
function removeNode(p) {
|
|
1228
|
+
p.next.prev = p.prev;
|
|
1229
|
+
p.prev.next = p.next;
|
|
1230
|
+
if (p.prevZ)
|
|
1231
|
+
p.prevZ.nextZ = p.nextZ;
|
|
1232
|
+
if (p.nextZ)
|
|
1233
|
+
p.nextZ.prevZ = p.prevZ;
|
|
1234
|
+
}
|
|
1235
|
+
function Node(i2, x2, y2) {
|
|
1236
|
+
this.i = i2;
|
|
1237
|
+
this.x = x2;
|
|
1238
|
+
this.y = y2;
|
|
1239
|
+
this.prev = null;
|
|
1240
|
+
this.next = null;
|
|
1241
|
+
this.z = null;
|
|
1242
|
+
this.prevZ = null;
|
|
1243
|
+
this.nextZ = null;
|
|
1244
|
+
this.steiner = false;
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1248
|
+
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1249
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
1250
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1251
|
+
return fillArrays(features, {
|
|
1252
|
+
propArrayTypes,
|
|
1253
|
+
...geometryInfo
|
|
1254
|
+
}, {
|
|
1255
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1256
|
+
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
function extractNumericPropTypes(features) {
|
|
1260
|
+
const propArrayTypes = {};
|
|
1261
|
+
for (const feature of features) {
|
|
1262
|
+
if (feature.properties) {
|
|
1263
|
+
for (const key in feature.properties) {
|
|
1264
|
+
const val = feature.properties[key];
|
|
1265
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
return propArrayTypes;
|
|
1270
|
+
}
|
|
1271
|
+
function fillArrays(features, geometryInfo, options) {
|
|
1272
|
+
const {
|
|
1273
|
+
pointPositionsCount,
|
|
1274
|
+
pointFeaturesCount,
|
|
1275
|
+
linePositionsCount,
|
|
1276
|
+
linePathsCount,
|
|
1277
|
+
lineFeaturesCount,
|
|
1278
|
+
polygonPositionsCount,
|
|
1279
|
+
polygonObjectsCount,
|
|
1280
|
+
polygonRingsCount,
|
|
1281
|
+
polygonFeaturesCount,
|
|
1282
|
+
propArrayTypes,
|
|
1283
|
+
coordLength
|
|
1284
|
+
} = geometryInfo;
|
|
1285
|
+
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
1286
|
+
const hasGlobalId = features[0] && "id" in features[0];
|
|
1287
|
+
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1288
|
+
const points = {
|
|
1289
|
+
type: "Point",
|
|
1290
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1291
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1292
|
+
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1293
|
+
numericProps: {},
|
|
1294
|
+
properties: [],
|
|
1295
|
+
fields: []
|
|
1296
|
+
};
|
|
1297
|
+
const lines = {
|
|
1298
|
+
type: "LineString",
|
|
1299
|
+
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
1300
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
1301
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
1302
|
+
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
1303
|
+
numericProps: {},
|
|
1304
|
+
properties: [],
|
|
1305
|
+
fields: []
|
|
1306
|
+
};
|
|
1307
|
+
const polygons = {
|
|
1308
|
+
type: "Polygon",
|
|
1309
|
+
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1310
|
+
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1311
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
1312
|
+
triangles: [],
|
|
1313
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1314
|
+
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1315
|
+
numericProps: {},
|
|
1316
|
+
properties: [],
|
|
1317
|
+
fields: []
|
|
1318
|
+
};
|
|
1319
|
+
for (const object of [points, lines, polygons]) {
|
|
1320
|
+
for (const propName of numericPropKeys) {
|
|
1321
|
+
const T = propArrayTypes[propName];
|
|
1322
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
1326
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
1327
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
1328
|
+
const indexMap = {
|
|
1329
|
+
pointPosition: 0,
|
|
1330
|
+
pointFeature: 0,
|
|
1331
|
+
linePosition: 0,
|
|
1332
|
+
linePath: 0,
|
|
1333
|
+
lineFeature: 0,
|
|
1334
|
+
polygonPosition: 0,
|
|
1335
|
+
polygonObject: 0,
|
|
1336
|
+
polygonRing: 0,
|
|
1337
|
+
polygonFeature: 0,
|
|
1338
|
+
feature: 0
|
|
1339
|
+
};
|
|
1340
|
+
for (const feature of features) {
|
|
1341
|
+
const geometry = feature.geometry;
|
|
1342
|
+
const properties = feature.properties || {};
|
|
1343
|
+
switch (geometry.type) {
|
|
1344
|
+
case "Point":
|
|
1345
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1346
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1347
|
+
if (hasGlobalId) {
|
|
1348
|
+
points.fields.push({ id: feature.id });
|
|
1349
|
+
}
|
|
1350
|
+
indexMap.pointFeature++;
|
|
1351
|
+
break;
|
|
1352
|
+
case "LineString":
|
|
1353
|
+
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1354
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1355
|
+
if (hasGlobalId) {
|
|
1356
|
+
lines.fields.push({ id: feature.id });
|
|
1357
|
+
}
|
|
1358
|
+
indexMap.lineFeature++;
|
|
1359
|
+
break;
|
|
1360
|
+
case "Polygon":
|
|
1361
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1362
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1363
|
+
if (hasGlobalId) {
|
|
1364
|
+
polygons.fields.push({ id: feature.id });
|
|
1365
|
+
}
|
|
1366
|
+
indexMap.polygonFeature++;
|
|
1367
|
+
break;
|
|
1368
|
+
default:
|
|
1369
|
+
throw new Error("Invalid geometry type");
|
|
1370
|
+
}
|
|
1371
|
+
indexMap.feature++;
|
|
1372
|
+
}
|
|
1373
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
1374
|
+
}
|
|
1375
|
+
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
1376
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
1377
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1378
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
1379
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1380
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1381
|
+
indexMap.pointPosition += nPositions;
|
|
1382
|
+
}
|
|
1383
|
+
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1384
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1385
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1386
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1387
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1388
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1389
|
+
for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
|
|
1390
|
+
const start = geometry.indices[i2];
|
|
1391
|
+
const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
|
|
1392
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1393
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
1397
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
1398
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1399
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
1400
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1401
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1402
|
+
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
1403
|
+
const startPosition = indexMap.polygonPosition;
|
|
1404
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
1405
|
+
const areas = geometry.areas[l];
|
|
1406
|
+
const indices = geometry.indices[l];
|
|
1407
|
+
const nextIndices = geometry.indices[l + 1];
|
|
1408
|
+
for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
|
|
1409
|
+
const start = indices[i2];
|
|
1410
|
+
const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
|
|
1411
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
1412
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
1413
|
+
}
|
|
1414
|
+
const endPosition = indexMap.polygonPosition;
|
|
1415
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
function triangulatePolygon(polygons, areas, indices, {
|
|
1419
|
+
startPosition,
|
|
1420
|
+
endPosition,
|
|
1421
|
+
coordLength
|
|
1422
|
+
}) {
|
|
1423
|
+
const start = startPosition * coordLength;
|
|
1424
|
+
const end = endPosition * coordLength;
|
|
1425
|
+
const polygonPositions = polygons.positions.subarray(start, end);
|
|
1426
|
+
const offset = indices[0];
|
|
1427
|
+
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
1428
|
+
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
1429
|
+
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
1430
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
function wrapProps(obj, size) {
|
|
1434
|
+
const returnObj = {};
|
|
1435
|
+
for (const key in obj) {
|
|
1436
|
+
returnObj[key] = { value: obj[key], size };
|
|
1437
|
+
}
|
|
1438
|
+
return returnObj;
|
|
1439
|
+
}
|
|
1440
|
+
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1441
|
+
return {
|
|
1442
|
+
points: {
|
|
1443
|
+
...points,
|
|
1444
|
+
positions: { value: points.positions, size: coordLength },
|
|
1445
|
+
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
1446
|
+
featureIds: { value: points.featureIds, size: 1 },
|
|
1447
|
+
numericProps: wrapProps(points.numericProps, 1)
|
|
1448
|
+
},
|
|
1449
|
+
lines: {
|
|
1450
|
+
...lines,
|
|
1451
|
+
positions: { value: lines.positions, size: coordLength },
|
|
1452
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1453
|
+
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
1454
|
+
featureIds: { value: lines.featureIds, size: 1 },
|
|
1455
|
+
numericProps: wrapProps(lines.numericProps, 1)
|
|
1456
|
+
},
|
|
1457
|
+
polygons: {
|
|
1458
|
+
...polygons,
|
|
1459
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
1460
|
+
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
1461
|
+
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
1462
|
+
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
1463
|
+
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
1464
|
+
featureIds: { value: polygons.featureIds, size: 1 },
|
|
1465
|
+
numericProps: wrapProps(polygons.numericProps, 1)
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
function fillNumericProperties(object, properties, index, length2) {
|
|
1470
|
+
for (const numericPropName in object.numericProps) {
|
|
1471
|
+
if (numericPropName in properties) {
|
|
1472
|
+
const value = properties[numericPropName];
|
|
1473
|
+
object.numericProps[numericPropName].fill(value, index, index + length2);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
function keepStringProperties(properties, numericKeys) {
|
|
1478
|
+
const props = {};
|
|
1479
|
+
for (const key in properties) {
|
|
1480
|
+
if (!numericKeys.includes(key)) {
|
|
1481
|
+
props[key] = properties[key];
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
return props;
|
|
1485
|
+
}
|
|
1486
|
+
function deduceArrayType(x2, constructor) {
|
|
1487
|
+
if (constructor === Array || !Number.isFinite(x2)) {
|
|
1488
|
+
return Array;
|
|
1489
|
+
}
|
|
1490
|
+
return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
// src/lib/parse-mvt.ts
|
|
1494
|
+
var import_pbf = __toModule(require_pbf());
|
|
1495
|
+
|
|
1496
|
+
// src/helpers/mapbox-util-functions.ts
|
|
1497
|
+
function classifyRings(rings) {
|
|
1498
|
+
const len = rings.length;
|
|
1499
|
+
if (len <= 1)
|
|
1500
|
+
return [rings];
|
|
1501
|
+
const polygons = [];
|
|
1502
|
+
let polygon;
|
|
1503
|
+
let ccw;
|
|
1504
|
+
for (let i2 = 0; i2 < len; i2++) {
|
|
1505
|
+
const area2 = signedArea(rings[i2]);
|
|
1506
|
+
if (area2 === 0)
|
|
1507
|
+
continue;
|
|
1508
|
+
if (ccw === void 0)
|
|
1509
|
+
ccw = area2 < 0;
|
|
1510
|
+
if (ccw === area2 < 0) {
|
|
1511
|
+
if (polygon)
|
|
1512
|
+
polygons.push(polygon);
|
|
1513
|
+
polygon = [rings[i2]];
|
|
1514
|
+
} else if (polygon)
|
|
1515
|
+
polygon.push(rings[i2]);
|
|
1516
|
+
}
|
|
1517
|
+
if (polygon)
|
|
1518
|
+
polygons.push(polygon);
|
|
1519
|
+
return polygons;
|
|
1520
|
+
}
|
|
1521
|
+
function signedArea(ring) {
|
|
1522
|
+
let sum = 0;
|
|
1523
|
+
for (let i2 = 0, j = ring.length - 1, p1, p2; i2 < ring.length; j = i2++) {
|
|
1524
|
+
p1 = ring[i2];
|
|
1525
|
+
p2 = ring[j];
|
|
1526
|
+
sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
|
|
1527
|
+
}
|
|
1528
|
+
return sum;
|
|
1529
|
+
}
|
|
1530
|
+
function readFeature(tag, feature, pbf) {
|
|
1531
|
+
if (feature && pbf) {
|
|
1532
|
+
if (tag === 1)
|
|
1533
|
+
feature.id = pbf.readVarint();
|
|
1534
|
+
else if (tag === 2)
|
|
1535
|
+
readTag(pbf, feature);
|
|
1536
|
+
else if (tag === 3)
|
|
1537
|
+
feature.type = pbf.readVarint();
|
|
1538
|
+
else if (tag === 4)
|
|
1539
|
+
feature._geometry = pbf.pos;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
function readTag(pbf, feature) {
|
|
1543
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1544
|
+
while (pbf.pos < end) {
|
|
1545
|
+
const key = feature._keys[pbf.readVarint()];
|
|
1546
|
+
const value = feature._values[pbf.readVarint()];
|
|
1547
|
+
feature.properties[key] = value;
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
// src/lib/mapbox-vector-tile/vector-tile-feature.ts
|
|
1552
|
+
var VectorTileFeature = class {
|
|
1553
|
+
static get types() {
|
|
1554
|
+
return ["Unknown", "Point", "LineString", "Polygon"];
|
|
1555
|
+
}
|
|
1556
|
+
constructor(pbf, end, extent, keys, values) {
|
|
1557
|
+
this.properties = {};
|
|
1558
|
+
this.extent = extent;
|
|
1559
|
+
this.type = 0;
|
|
1560
|
+
this.id = null;
|
|
1561
|
+
this._pbf = pbf;
|
|
1562
|
+
this._geometry = -1;
|
|
1563
|
+
this._keys = keys;
|
|
1564
|
+
this._values = values;
|
|
1565
|
+
pbf.readFields(readFeature, this, end);
|
|
1566
|
+
}
|
|
1567
|
+
loadGeometry() {
|
|
1568
|
+
const pbf = this._pbf;
|
|
1569
|
+
pbf.pos = this._geometry;
|
|
1570
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1571
|
+
let cmd2 = 1;
|
|
1572
|
+
let length2 = 0;
|
|
1573
|
+
let x2 = 0;
|
|
1574
|
+
let y2 = 0;
|
|
1575
|
+
const lines = [];
|
|
1576
|
+
let line;
|
|
1577
|
+
while (pbf.pos < end) {
|
|
1578
|
+
if (length2 <= 0) {
|
|
1579
|
+
const cmdLen2 = pbf.readVarint();
|
|
1580
|
+
cmd2 = cmdLen2 & 7;
|
|
1581
|
+
length2 = cmdLen2 >> 3;
|
|
1582
|
+
}
|
|
1583
|
+
length2--;
|
|
1584
|
+
if (cmd2 === 1 || cmd2 === 2) {
|
|
1585
|
+
x2 += pbf.readSVarint();
|
|
1586
|
+
y2 += pbf.readSVarint();
|
|
1587
|
+
if (cmd2 === 1) {
|
|
1588
|
+
if (line)
|
|
1589
|
+
lines.push(line);
|
|
1590
|
+
line = [];
|
|
1591
|
+
}
|
|
1592
|
+
if (line)
|
|
1593
|
+
line.push([x2, y2]);
|
|
1594
|
+
} else if (cmd2 === 7) {
|
|
1595
|
+
if (line) {
|
|
1596
|
+
line.push(line[0].slice());
|
|
1597
|
+
}
|
|
1598
|
+
} else {
|
|
1599
|
+
throw new Error(`unknown command ${cmd2}`);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
if (line)
|
|
1603
|
+
lines.push(line);
|
|
1604
|
+
return lines;
|
|
1605
|
+
}
|
|
1606
|
+
bbox() {
|
|
1607
|
+
const pbf = this._pbf;
|
|
1608
|
+
pbf.pos = this._geometry;
|
|
1609
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1610
|
+
let cmd2 = 1;
|
|
1611
|
+
let length2 = 0;
|
|
1612
|
+
let x2 = 0;
|
|
1613
|
+
let y2 = 0;
|
|
1614
|
+
let x1 = Infinity;
|
|
1615
|
+
let x22 = -Infinity;
|
|
1616
|
+
let y1 = Infinity;
|
|
1617
|
+
let y22 = -Infinity;
|
|
1618
|
+
while (pbf.pos < end) {
|
|
1619
|
+
if (length2 <= 0) {
|
|
1620
|
+
const cmdLen2 = pbf.readVarint();
|
|
1621
|
+
cmd2 = cmdLen2 & 7;
|
|
1622
|
+
length2 = cmdLen2 >> 3;
|
|
1623
|
+
}
|
|
1624
|
+
length2--;
|
|
1625
|
+
if (cmd2 === 1 || cmd2 === 2) {
|
|
1626
|
+
x2 += pbf.readSVarint();
|
|
1627
|
+
y2 += pbf.readSVarint();
|
|
1628
|
+
if (x2 < x1)
|
|
1629
|
+
x1 = x2;
|
|
1630
|
+
if (x2 > x22)
|
|
1631
|
+
x22 = x2;
|
|
1632
|
+
if (y2 < y1)
|
|
1633
|
+
y1 = y2;
|
|
1634
|
+
if (y2 > y22)
|
|
1635
|
+
y22 = y2;
|
|
1636
|
+
} else if (cmd2 !== 7) {
|
|
1637
|
+
throw new Error(`unknown command ${cmd2}`);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
return [x1, y1, x22, y22];
|
|
1641
|
+
}
|
|
1642
|
+
_toGeoJSON(transform) {
|
|
1643
|
+
let coords = this.loadGeometry();
|
|
1644
|
+
let type = VectorTileFeature.types[this.type];
|
|
1645
|
+
let i2;
|
|
1646
|
+
let j;
|
|
1647
|
+
switch (this.type) {
|
|
1648
|
+
case 1:
|
|
1649
|
+
const points = [];
|
|
1650
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1651
|
+
points[i2] = coords[i2][0];
|
|
1652
|
+
}
|
|
1653
|
+
coords = points;
|
|
1654
|
+
transform(coords, this);
|
|
1655
|
+
break;
|
|
1656
|
+
case 2:
|
|
1657
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1658
|
+
transform(coords[i2], this);
|
|
1659
|
+
}
|
|
1660
|
+
break;
|
|
1661
|
+
case 3:
|
|
1662
|
+
coords = classifyRings(coords);
|
|
1663
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1664
|
+
for (j = 0; j < coords[i2].length; j++) {
|
|
1665
|
+
transform(coords[i2][j], this);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
break;
|
|
1669
|
+
}
|
|
1670
|
+
if (coords.length === 1) {
|
|
1671
|
+
coords = coords[0];
|
|
1672
|
+
} else {
|
|
1673
|
+
type = `Multi${type}`;
|
|
1674
|
+
}
|
|
1675
|
+
const result = {
|
|
1676
|
+
type: "Feature",
|
|
1677
|
+
geometry: {
|
|
1678
|
+
type,
|
|
1679
|
+
coordinates: coords
|
|
1680
|
+
},
|
|
1681
|
+
properties: this.properties
|
|
1682
|
+
};
|
|
1683
|
+
if (this.id !== null) {
|
|
1684
|
+
result.id = this.id;
|
|
1685
|
+
}
|
|
1686
|
+
return result;
|
|
1687
|
+
}
|
|
1688
|
+
toGeoJSON(options) {
|
|
1689
|
+
if (typeof options === "function") {
|
|
1690
|
+
return this._toGeoJSON(options);
|
|
1691
|
+
}
|
|
1692
|
+
const { x: x2, y: y2, z } = options;
|
|
1693
|
+
const size = this.extent * Math.pow(2, z);
|
|
1694
|
+
const x0 = this.extent * x2;
|
|
1695
|
+
const y0 = this.extent * y2;
|
|
1696
|
+
function project2(line) {
|
|
1697
|
+
for (let j = 0; j < line.length; j++) {
|
|
1698
|
+
const p = line[j];
|
|
1699
|
+
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
1700
|
+
const y22 = 180 - (p[1] + y0) * 360 / size;
|
|
1701
|
+
p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
return this._toGeoJSON(project2);
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1707
|
+
|
|
1708
|
+
// src/lib/mapbox-vector-tile/vector-tile-layer.ts
|
|
1709
|
+
var VectorTileLayer = class {
|
|
1710
|
+
constructor(pbf, end) {
|
|
1711
|
+
this.version = 1;
|
|
1712
|
+
this.name = "";
|
|
1713
|
+
this.extent = 4096;
|
|
1714
|
+
this.length = 0;
|
|
1715
|
+
this._pbf = pbf;
|
|
1716
|
+
this._keys = [];
|
|
1717
|
+
this._values = [];
|
|
1718
|
+
this._features = [];
|
|
1719
|
+
pbf.readFields(readLayer, this, end);
|
|
1720
|
+
this.length = this._features.length;
|
|
1721
|
+
}
|
|
1722
|
+
feature(i2) {
|
|
1723
|
+
if (i2 < 0 || i2 >= this._features.length) {
|
|
1724
|
+
throw new Error("feature index out of bounds");
|
|
1725
|
+
}
|
|
1726
|
+
this._pbf.pos = this._features[i2];
|
|
1727
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1728
|
+
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
function readLayer(tag, layer, pbf) {
|
|
1732
|
+
if (layer && pbf) {
|
|
1733
|
+
if (tag === 15)
|
|
1734
|
+
layer.version = pbf.readVarint();
|
|
1735
|
+
else if (tag === 1)
|
|
1736
|
+
layer.name = pbf.readString();
|
|
1737
|
+
else if (tag === 5)
|
|
1738
|
+
layer.extent = pbf.readVarint();
|
|
1739
|
+
else if (tag === 2)
|
|
1740
|
+
layer._features.push(pbf.pos);
|
|
1741
|
+
else if (tag === 3)
|
|
1742
|
+
layer._keys.push(pbf.readString());
|
|
1743
|
+
else if (tag === 4)
|
|
1744
|
+
layer._values.push(readValueMessage(pbf));
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
function readValueMessage(pbf) {
|
|
1748
|
+
let value = null;
|
|
1749
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1750
|
+
while (pbf.pos < end) {
|
|
1751
|
+
const tag = pbf.readVarint() >> 3;
|
|
1752
|
+
value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
|
|
1753
|
+
}
|
|
1754
|
+
return value;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
// src/lib/mapbox-vector-tile/vector-tile.ts
|
|
1758
|
+
var VectorTile = class {
|
|
1759
|
+
constructor(pbf, end) {
|
|
1760
|
+
this.layers = pbf.readFields(readTile, {}, end);
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
function readTile(tag, layers, pbf) {
|
|
1764
|
+
if (tag === 3) {
|
|
1765
|
+
if (pbf) {
|
|
1766
|
+
const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
|
|
1767
|
+
if (layer.length && layers) {
|
|
1768
|
+
layers[layer.name] = layer;
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1524
1772
|
}
|
|
1525
1773
|
|
|
1526
1774
|
// src/helpers/binary-util-functions.ts
|
|
1527
1775
|
function classifyRings2(geom) {
|
|
1528
|
-
const len = geom.
|
|
1776
|
+
const len = geom.indices.length;
|
|
1777
|
+
const type = "Polygon";
|
|
1529
1778
|
if (len <= 1) {
|
|
1530
1779
|
return {
|
|
1780
|
+
type,
|
|
1531
1781
|
data: geom.data,
|
|
1532
1782
|
areas: [[getPolygonSignedArea(geom.data)]],
|
|
1533
|
-
|
|
1783
|
+
indices: [geom.indices]
|
|
1534
1784
|
};
|
|
1535
1785
|
}
|
|
1536
1786
|
const areas = [];
|
|
@@ -1540,8 +1790,8 @@
|
|
|
1540
1790
|
let ccw;
|
|
1541
1791
|
let offset = 0;
|
|
1542
1792
|
for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
|
|
1543
|
-
startIndex = geom.
|
|
1544
|
-
endIndex = geom.
|
|
1793
|
+
startIndex = geom.indices[i2] - offset;
|
|
1794
|
+
endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
|
|
1545
1795
|
const shape = geom.data.slice(startIndex, endIndex);
|
|
1546
1796
|
const area2 = getPolygonSignedArea(shape);
|
|
1547
1797
|
if (area2 === 0) {
|
|
@@ -1569,7 +1819,7 @@
|
|
|
1569
1819
|
areas.push(ringAreas);
|
|
1570
1820
|
if (polygon.length)
|
|
1571
1821
|
polygons.push(polygon);
|
|
1572
|
-
return { areas,
|
|
1822
|
+
return { type, areas, indices: polygons, data: geom.data };
|
|
1573
1823
|
}
|
|
1574
1824
|
function project(data, x0, y0, size) {
|
|
1575
1825
|
for (let j = 0, jl = data.length; j < jl; j += 2) {
|
|
@@ -1608,10 +1858,7 @@
|
|
|
1608
1858
|
var y;
|
|
1609
1859
|
var i;
|
|
1610
1860
|
var VectorTileFeature2 = class {
|
|
1611
|
-
|
|
1612
|
-
return ["Unknown", "Point", "LineString", "Polygon"];
|
|
1613
|
-
}
|
|
1614
|
-
constructor(pbf, end, extent, keys, values, firstPassData) {
|
|
1861
|
+
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
1615
1862
|
this.properties = {};
|
|
1616
1863
|
this.extent = extent;
|
|
1617
1864
|
this.type = 0;
|
|
@@ -1620,7 +1867,7 @@
|
|
|
1620
1867
|
this._geometry = -1;
|
|
1621
1868
|
this._keys = keys;
|
|
1622
1869
|
this._values = values;
|
|
1623
|
-
this.
|
|
1870
|
+
this._geometryInfo = geometryInfo;
|
|
1624
1871
|
pbf.readFields(readFeature2, this, end);
|
|
1625
1872
|
}
|
|
1626
1873
|
loadGeometry() {
|
|
@@ -1632,7 +1879,7 @@
|
|
|
1632
1879
|
x = 0;
|
|
1633
1880
|
y = 0;
|
|
1634
1881
|
i = 0;
|
|
1635
|
-
const
|
|
1882
|
+
const indices = [];
|
|
1636
1883
|
const data = [];
|
|
1637
1884
|
while (pbf.pos < endPos) {
|
|
1638
1885
|
if (length <= 0) {
|
|
@@ -1645,13 +1892,13 @@
|
|
|
1645
1892
|
x += pbf.readSVarint();
|
|
1646
1893
|
y += pbf.readSVarint();
|
|
1647
1894
|
if (cmd === 1) {
|
|
1648
|
-
|
|
1895
|
+
indices.push(i);
|
|
1649
1896
|
}
|
|
1650
1897
|
data.push(x, y);
|
|
1651
1898
|
i += 2;
|
|
1652
1899
|
} else if (cmd === 7) {
|
|
1653
1900
|
if (i > 0) {
|
|
1654
|
-
const start =
|
|
1901
|
+
const start = indices[indices.length - 1];
|
|
1655
1902
|
data.push(data[start], data[start + 1]);
|
|
1656
1903
|
i += 2;
|
|
1657
1904
|
}
|
|
@@ -1659,42 +1906,38 @@
|
|
|
1659
1906
|
throw new Error(`unknown command ${cmd}`);
|
|
1660
1907
|
}
|
|
1661
1908
|
}
|
|
1662
|
-
return { data,
|
|
1909
|
+
return { data, indices };
|
|
1663
1910
|
}
|
|
1664
1911
|
_toBinaryCoordinates(transform) {
|
|
1665
|
-
|
|
1912
|
+
const geom = this.loadGeometry();
|
|
1913
|
+
let geometry;
|
|
1666
1914
|
transform(geom.data, this);
|
|
1667
1915
|
const coordLength = 2;
|
|
1668
1916
|
switch (this.type) {
|
|
1669
1917
|
case 1:
|
|
1670
|
-
this.
|
|
1671
|
-
this.
|
|
1918
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
1919
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
1920
|
+
geometry = { type: "Point", ...geom };
|
|
1672
1921
|
break;
|
|
1673
1922
|
case 2:
|
|
1674
|
-
this.
|
|
1675
|
-
this.
|
|
1676
|
-
this.
|
|
1923
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
1924
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
1925
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
1926
|
+
geometry = { type: "LineString", ...geom };
|
|
1677
1927
|
break;
|
|
1678
1928
|
case 3:
|
|
1679
|
-
|
|
1680
|
-
this.
|
|
1681
|
-
this.
|
|
1682
|
-
for (const
|
|
1683
|
-
this.
|
|
1929
|
+
geometry = classifyRings2(geom);
|
|
1930
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
1931
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
1932
|
+
for (const indices of geometry.indices) {
|
|
1933
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
1684
1934
|
}
|
|
1685
|
-
this.
|
|
1686
|
-
geom = classified;
|
|
1935
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
1687
1936
|
break;
|
|
1937
|
+
default:
|
|
1938
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
1688
1939
|
}
|
|
1689
|
-
|
|
1690
|
-
if (geom.lines.length > 1) {
|
|
1691
|
-
geom.type = `Multi${geom.type}`;
|
|
1692
|
-
}
|
|
1693
|
-
const result = {
|
|
1694
|
-
type: "Feature",
|
|
1695
|
-
geometry: geom,
|
|
1696
|
-
properties: this.properties
|
|
1697
|
-
};
|
|
1940
|
+
const result = { type: "Feature", geometry, properties: this.properties };
|
|
1698
1941
|
if (this.id !== null) {
|
|
1699
1942
|
result.id = this.id;
|
|
1700
1943
|
}
|
|
@@ -1704,7 +1947,11 @@
|
|
|
1704
1947
|
if (typeof options === "function") {
|
|
1705
1948
|
return this._toBinaryCoordinates(options);
|
|
1706
1949
|
}
|
|
1707
|
-
|
|
1950
|
+
const { x: x2, y: y2, z } = options;
|
|
1951
|
+
const size = this.extent * Math.pow(2, z);
|
|
1952
|
+
const x0 = this.extent * x2;
|
|
1953
|
+
const y0 = this.extent * y2;
|
|
1954
|
+
return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
|
|
1708
1955
|
}
|
|
1709
1956
|
};
|
|
1710
1957
|
|
|
@@ -1722,13 +1969,13 @@
|
|
|
1722
1969
|
pbf.readFields(readLayer2, this, end);
|
|
1723
1970
|
this.length = this._features.length;
|
|
1724
1971
|
}
|
|
1725
|
-
feature(i2,
|
|
1972
|
+
feature(i2, geometryInfo) {
|
|
1726
1973
|
if (i2 < 0 || i2 >= this._features.length) {
|
|
1727
1974
|
throw new Error("feature index out of bounds");
|
|
1728
1975
|
}
|
|
1729
1976
|
this._pbf.pos = this._features[i2];
|
|
1730
1977
|
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1731
|
-
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values,
|
|
1978
|
+
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
1732
1979
|
}
|
|
1733
1980
|
};
|
|
1734
1981
|
function readLayer2(tag, layer, pbf) {
|
|
@@ -1774,313 +2021,111 @@
|
|
|
1774
2021
|
}
|
|
1775
2022
|
}
|
|
1776
2023
|
|
|
1777
|
-
// src/lib/
|
|
1778
|
-
function
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
if (numericSoFar || numericSoFar === void 0) {
|
|
1791
|
-
const val = feature.properties[key];
|
|
1792
|
-
numericPropKeys[key] = isNumeric(val);
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
return Object.keys(numericPropKeys).filter((k) => numericPropKeys[k]);
|
|
1798
|
-
}
|
|
1799
|
-
function fillArrays(features, firstPassData, options) {
|
|
1800
|
-
const {
|
|
1801
|
-
pointPositionsCount,
|
|
1802
|
-
pointFeaturesCount,
|
|
1803
|
-
linePositionsCount,
|
|
1804
|
-
linePathsCount,
|
|
1805
|
-
lineFeaturesCount,
|
|
1806
|
-
polygonPositionsCount,
|
|
1807
|
-
polygonObjectsCount,
|
|
1808
|
-
polygonRingsCount,
|
|
1809
|
-
polygonFeaturesCount
|
|
1810
|
-
} = firstPassData;
|
|
1811
|
-
const { numericPropKeys, PositionDataType = Float32Array } = options;
|
|
1812
|
-
const hasGlobalId = features[0] && "id" in features[0];
|
|
1813
|
-
const coordLength = 2;
|
|
1814
|
-
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1815
|
-
const points = {
|
|
1816
|
-
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1817
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1818
|
-
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1819
|
-
numericProps: {},
|
|
1820
|
-
properties: [],
|
|
1821
|
-
fields: []
|
|
1822
|
-
};
|
|
1823
|
-
const lines = {
|
|
1824
|
-
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
1825
|
-
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
1826
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
1827
|
-
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
1828
|
-
numericProps: {},
|
|
1829
|
-
properties: [],
|
|
1830
|
-
fields: []
|
|
1831
|
-
};
|
|
1832
|
-
const polygons = {
|
|
1833
|
-
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1834
|
-
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1835
|
-
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
1836
|
-
triangles: [],
|
|
1837
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1838
|
-
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1839
|
-
numericProps: {},
|
|
1840
|
-
properties: [],
|
|
1841
|
-
fields: []
|
|
1842
|
-
};
|
|
1843
|
-
for (const object of [points, lines, polygons]) {
|
|
1844
|
-
for (const propName of numericPropKeys) {
|
|
1845
|
-
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
1849
|
-
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
1850
|
-
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
1851
|
-
const indexMap = {
|
|
1852
|
-
pointPosition: 0,
|
|
1853
|
-
pointFeature: 0,
|
|
1854
|
-
linePosition: 0,
|
|
1855
|
-
linePath: 0,
|
|
1856
|
-
lineFeature: 0,
|
|
1857
|
-
polygonPosition: 0,
|
|
1858
|
-
polygonObject: 0,
|
|
1859
|
-
polygonRing: 0,
|
|
1860
|
-
polygonFeature: 0,
|
|
1861
|
-
feature: 0
|
|
1862
|
-
};
|
|
1863
|
-
for (const feature of features) {
|
|
1864
|
-
const geometry = feature.geometry;
|
|
1865
|
-
const properties = feature.properties || {};
|
|
1866
|
-
switch (geometry.type) {
|
|
1867
|
-
case "Point":
|
|
1868
|
-
case "MultiPoint":
|
|
1869
|
-
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1870
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1871
|
-
if (hasGlobalId) {
|
|
1872
|
-
points.fields.push({ id: feature.id });
|
|
1873
|
-
}
|
|
1874
|
-
indexMap.pointFeature++;
|
|
1875
|
-
break;
|
|
1876
|
-
case "LineString":
|
|
1877
|
-
case "MultiLineString":
|
|
1878
|
-
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1879
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1880
|
-
if (hasGlobalId) {
|
|
1881
|
-
lines.fields.push({ id: feature.id });
|
|
1882
|
-
}
|
|
1883
|
-
indexMap.lineFeature++;
|
|
1884
|
-
break;
|
|
1885
|
-
case "Polygon":
|
|
1886
|
-
case "MultiPolygon":
|
|
1887
|
-
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1888
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1889
|
-
if (hasGlobalId) {
|
|
1890
|
-
polygons.fields.push({ id: feature.id });
|
|
1891
|
-
}
|
|
1892
|
-
indexMap.polygonFeature++;
|
|
1893
|
-
break;
|
|
1894
|
-
default:
|
|
1895
|
-
throw new Error("Invalid geometry type");
|
|
1896
|
-
}
|
|
1897
|
-
indexMap.feature++;
|
|
1898
|
-
}
|
|
1899
|
-
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
1900
|
-
}
|
|
1901
|
-
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
1902
|
-
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
1903
|
-
const nPositions = geometry.data.length / coordLength;
|
|
1904
|
-
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
1905
|
-
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1906
|
-
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1907
|
-
indexMap.pointPosition += nPositions;
|
|
1908
|
-
}
|
|
1909
|
-
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1910
|
-
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1911
|
-
const nPositions = geometry.data.length / coordLength;
|
|
1912
|
-
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1913
|
-
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1914
|
-
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1915
|
-
for (let i2 = 0, il = geometry.lines.length; i2 < il; ++i2) {
|
|
1916
|
-
const start = geometry.lines[i2];
|
|
1917
|
-
const end = i2 === il - 1 ? geometry.data.length : geometry.lines[i2 + 1];
|
|
1918
|
-
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1919
|
-
indexMap.linePosition += (end - start) / coordLength;
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
1923
|
-
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
1924
|
-
const nPositions = geometry.data.length / coordLength;
|
|
1925
|
-
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
1926
|
-
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1927
|
-
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1928
|
-
for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {
|
|
1929
|
-
const startPosition = indexMap.polygonPosition;
|
|
1930
|
-
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
1931
|
-
const areas = geometry.areas[l];
|
|
1932
|
-
const lines = geometry.lines[l];
|
|
1933
|
-
const nextLines = geometry.lines[l + 1];
|
|
1934
|
-
for (let i2 = 0, il = lines.length; i2 < il; ++i2) {
|
|
1935
|
-
const start = lines[i2];
|
|
1936
|
-
const end = i2 === il - 1 ? nextLines === void 0 ? geometry.data.length : nextLines[0] : lines[i2 + 1];
|
|
1937
|
-
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
1938
|
-
indexMap.polygonPosition += (end - start) / coordLength;
|
|
2024
|
+
// src/lib/parse-mvt.ts
|
|
2025
|
+
function parseMVT(arrayBuffer, options) {
|
|
2026
|
+
const mvtOptions = normalizeOptions(options);
|
|
2027
|
+
const shape = options?.gis?.format || options?.mvt?.shape;
|
|
2028
|
+
switch (shape) {
|
|
2029
|
+
case "columnar-table":
|
|
2030
|
+
return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
|
|
2031
|
+
case "geojson-row-table": {
|
|
2032
|
+
const table = {
|
|
2033
|
+
shape: "geojson-row-table",
|
|
2034
|
+
data: parseToGeojson(arrayBuffer, mvtOptions)
|
|
2035
|
+
};
|
|
2036
|
+
return table;
|
|
1939
2037
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
2038
|
+
case "geojson":
|
|
2039
|
+
return parseToGeojson(arrayBuffer, mvtOptions);
|
|
2040
|
+
case "binary-geometry":
|
|
2041
|
+
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2042
|
+
case "binary":
|
|
2043
|
+
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2044
|
+
default:
|
|
2045
|
+
throw new Error(shape);
|
|
1942
2046
|
}
|
|
1943
2047
|
}
|
|
1944
|
-
function
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
const start = startPosition * coordLength;
|
|
1950
|
-
const end = endPosition * coordLength;
|
|
1951
|
-
const polygonPositions = polygons.positions.subarray(start, end);
|
|
1952
|
-
const offset = lines[0];
|
|
1953
|
-
const holes = lines.slice(1).map((n) => (n - offset) / coordLength);
|
|
1954
|
-
const indices = earcut(polygonPositions, holes, coordLength, areas);
|
|
1955
|
-
for (let t = 0, tl = indices.length; t < tl; ++t) {
|
|
1956
|
-
polygons.triangles.push(startPosition + indices[t]);
|
|
1957
|
-
}
|
|
2048
|
+
function parseToBinary(arrayBuffer, options) {
|
|
2049
|
+
const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);
|
|
2050
|
+
const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, geometryInfo);
|
|
2051
|
+
binaryData.byteLength = arrayBuffer.byteLength;
|
|
2052
|
+
return binaryData;
|
|
1958
2053
|
}
|
|
1959
|
-
function
|
|
1960
|
-
const
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
featureIds: { value: lines.featureIds, size: 1 }
|
|
1973
|
-
},
|
|
1974
|
-
polygons: {
|
|
1975
|
-
...polygons,
|
|
1976
|
-
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
1977
|
-
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
1978
|
-
positions: { value: polygons.positions, size: coordLength },
|
|
1979
|
-
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
1980
|
-
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
1981
|
-
featureIds: { value: polygons.featureIds, size: 1 }
|
|
1982
|
-
}
|
|
2054
|
+
function parseToFlatGeoJson(arrayBuffer, options) {
|
|
2055
|
+
const features = [];
|
|
2056
|
+
const geometryInfo = {
|
|
2057
|
+
coordLength: 2,
|
|
2058
|
+
pointPositionsCount: 0,
|
|
2059
|
+
pointFeaturesCount: 0,
|
|
2060
|
+
linePositionsCount: 0,
|
|
2061
|
+
linePathsCount: 0,
|
|
2062
|
+
lineFeaturesCount: 0,
|
|
2063
|
+
polygonPositionsCount: 0,
|
|
2064
|
+
polygonObjectsCount: 0,
|
|
2065
|
+
polygonRingsCount: 0,
|
|
2066
|
+
polygonFeaturesCount: 0
|
|
1983
2067
|
};
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
returnObj[geomType].numericProps[numericProp] = {
|
|
1987
|
-
value: returnObj[geomType].numericProps[numericProp],
|
|
1988
|
-
size: 1
|
|
1989
|
-
};
|
|
1990
|
-
}
|
|
2068
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
2069
|
+
return [features, geometryInfo];
|
|
1991
2070
|
}
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
if (
|
|
1997
|
-
|
|
2071
|
+
const tile = new VectorTile2(new import_pbf.default(arrayBuffer));
|
|
2072
|
+
const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
2073
|
+
selectedLayers.forEach((layerName) => {
|
|
2074
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
2075
|
+
if (!vectorTileLayer) {
|
|
2076
|
+
return;
|
|
1998
2077
|
}
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
for (const key in properties) {
|
|
2004
|
-
if (!numericKeys.includes(key)) {
|
|
2005
|
-
props[key] = properties[key];
|
|
2078
|
+
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2079
|
+
const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
|
|
2080
|
+
const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
|
|
2081
|
+
features.push(decodedFeature);
|
|
2006
2082
|
}
|
|
2007
|
-
}
|
|
2008
|
-
return
|
|
2009
|
-
}
|
|
2010
|
-
function isNumeric(x2) {
|
|
2011
|
-
return Number.isFinite(x2);
|
|
2083
|
+
});
|
|
2084
|
+
return [features, geometryInfo];
|
|
2012
2085
|
}
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
options = normalizeOptions(options);
|
|
2086
|
+
function parseToGeojson(arrayBuffer, options) {
|
|
2087
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
2088
|
+
return [];
|
|
2089
|
+
}
|
|
2018
2090
|
const features = [];
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
polygonFeaturesCount: 0
|
|
2031
|
-
};
|
|
2032
|
-
if (arrayBuffer.byteLength > 0) {
|
|
2033
|
-
const tile = binary ? new VectorTile2(new import_pbf.default(arrayBuffer)) : new VectorTile(new import_pbf.default(arrayBuffer));
|
|
2034
|
-
const loaderOptions = options.mvt;
|
|
2035
|
-
const selectedLayers = Array.isArray(loaderOptions.layers) ? loaderOptions.layers : Object.keys(tile.layers);
|
|
2036
|
-
selectedLayers.forEach((layerName) => {
|
|
2037
|
-
const vectorTileLayer = tile.layers[layerName];
|
|
2038
|
-
const featureOptions = { ...loaderOptions, layerName };
|
|
2039
|
-
if (!vectorTileLayer) {
|
|
2040
|
-
return;
|
|
2041
|
-
}
|
|
2042
|
-
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2043
|
-
const vectorTileFeature = vectorTileLayer.feature(i2, firstPassData);
|
|
2044
|
-
const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
|
|
2045
|
-
features.push(decodedFeature);
|
|
2046
|
-
}
|
|
2047
|
-
});
|
|
2048
|
-
}
|
|
2049
|
-
if (binary) {
|
|
2050
|
-
const data = featuresToBinary(features, firstPassData);
|
|
2051
|
-
data.byteLength = arrayBuffer.byteLength;
|
|
2052
|
-
return data;
|
|
2091
|
+
const tile = new VectorTile(new import_pbf.default(arrayBuffer));
|
|
2092
|
+
const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
2093
|
+
selectedLayers.forEach((layerName) => {
|
|
2094
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
2095
|
+
if (!vectorTileLayer) {
|
|
2096
|
+
return;
|
|
2097
|
+
}
|
|
2098
|
+
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2099
|
+
const vectorTileFeature = vectorTileLayer.feature(i2);
|
|
2100
|
+
const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
|
|
2101
|
+
features.push(decodedFeature);
|
|
2053
2102
|
}
|
|
2054
|
-
}
|
|
2103
|
+
});
|
|
2055
2104
|
return features;
|
|
2056
2105
|
}
|
|
2057
2106
|
function normalizeOptions(options) {
|
|
2058
|
-
if (options) {
|
|
2059
|
-
options
|
|
2060
|
-
...options,
|
|
2061
|
-
mvt: options.mvt || {},
|
|
2062
|
-
gis: options.gis || {}
|
|
2063
|
-
};
|
|
2064
|
-
const wgs84Coordinates = options.coordinates === "wgs84";
|
|
2065
|
-
const { tileIndex } = options;
|
|
2066
|
-
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2067
|
-
if (wgs84Coordinates && !hasTileIndex) {
|
|
2068
|
-
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.");
|
|
2069
|
-
}
|
|
2107
|
+
if (!options?.mvt) {
|
|
2108
|
+
throw new Error("mvt options required");
|
|
2070
2109
|
}
|
|
2071
|
-
|
|
2110
|
+
const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
|
|
2111
|
+
const { tileIndex } = options.mvt;
|
|
2112
|
+
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2113
|
+
if (wgs84Coordinates && !hasTileIndex) {
|
|
2114
|
+
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
|
|
2115
|
+
}
|
|
2116
|
+
return options.mvt;
|
|
2072
2117
|
}
|
|
2073
|
-
function getDecodedFeature(feature, options) {
|
|
2118
|
+
function getDecodedFeature(feature, options, layerName) {
|
|
2074
2119
|
const decodedFeature = feature.toGeoJSON(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates);
|
|
2075
2120
|
if (options.layerProperty) {
|
|
2076
|
-
decodedFeature.properties[options.layerProperty] =
|
|
2121
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2077
2122
|
}
|
|
2078
2123
|
return decodedFeature;
|
|
2079
2124
|
}
|
|
2080
|
-
function getDecodedFeatureBinary(feature, options) {
|
|
2125
|
+
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
2081
2126
|
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
2082
|
-
if (options.layerProperty) {
|
|
2083
|
-
decodedFeature.properties[options.layerProperty] =
|
|
2127
|
+
if (options.layerProperty && decodedFeature.properties) {
|
|
2128
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2084
2129
|
}
|
|
2085
2130
|
return decodedFeature;
|
|
2086
2131
|
}
|
|
@@ -2100,7 +2145,16 @@
|
|
|
2100
2145
|
}
|
|
2101
2146
|
|
|
2102
2147
|
// src/mvt-loader.ts
|
|
2103
|
-
var VERSION =
|
|
2148
|
+
var VERSION = true ? "4.0.0-alpha.11" : "latest";
|
|
2149
|
+
var DEFAULT_MVT_LOADER_OPTIONS = {
|
|
2150
|
+
mvt: {
|
|
2151
|
+
shape: "geojson",
|
|
2152
|
+
coordinates: "local",
|
|
2153
|
+
layerProperty: "layerName",
|
|
2154
|
+
layers: void 0,
|
|
2155
|
+
tileIndex: null
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2104
2158
|
var MVTWorkerLoader = {
|
|
2105
2159
|
name: "Mapbox Vector Tile",
|
|
2106
2160
|
id: "mvt",
|
|
@@ -2113,14 +2167,7 @@
|
|
|
2113
2167
|
],
|
|
2114
2168
|
worker: true,
|
|
2115
2169
|
category: "geometry",
|
|
2116
|
-
options:
|
|
2117
|
-
mvt: {
|
|
2118
|
-
coordinates: "local",
|
|
2119
|
-
layerProperty: "layerName",
|
|
2120
|
-
layers: null,
|
|
2121
|
-
tileIndex: null
|
|
2122
|
-
}
|
|
2123
|
-
}
|
|
2170
|
+
options: DEFAULT_MVT_LOADER_OPTIONS
|
|
2124
2171
|
};
|
|
2125
2172
|
var MVTLoader = {
|
|
2126
2173
|
...MVTWorkerLoader,
|
|
@@ -2165,16 +2212,33 @@
|
|
|
2165
2212
|
}
|
|
2166
2213
|
|
|
2167
2214
|
// ../worker-utils/src/lib/worker-farm/worker-body.ts
|
|
2215
|
+
function getParentPort() {
|
|
2216
|
+
let parentPort;
|
|
2217
|
+
try {
|
|
2218
|
+
eval("globalThis.parentPort = require('worker_threads').parentPort");
|
|
2219
|
+
parentPort = globalThis.parentPort;
|
|
2220
|
+
} catch {
|
|
2221
|
+
}
|
|
2222
|
+
return parentPort;
|
|
2223
|
+
}
|
|
2168
2224
|
var onMessageWrapperMap = new Map();
|
|
2169
2225
|
var WorkerBody = class {
|
|
2226
|
+
static inWorkerThread() {
|
|
2227
|
+
return typeof self !== "undefined" || Boolean(getParentPort());
|
|
2228
|
+
}
|
|
2170
2229
|
static set onmessage(onMessage) {
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
}
|
|
2175
|
-
const { type, payload } = message.data;
|
|
2230
|
+
function handleMessage(message) {
|
|
2231
|
+
const parentPort3 = getParentPort();
|
|
2232
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
2176
2233
|
onMessage(type, payload);
|
|
2177
|
-
}
|
|
2234
|
+
}
|
|
2235
|
+
const parentPort2 = getParentPort();
|
|
2236
|
+
if (parentPort2) {
|
|
2237
|
+
parentPort2.on("message", handleMessage);
|
|
2238
|
+
parentPort2.on("exit", () => console.debug("Node worker closing"));
|
|
2239
|
+
} else {
|
|
2240
|
+
globalThis.onmessage = handleMessage;
|
|
2241
|
+
}
|
|
2178
2242
|
}
|
|
2179
2243
|
static addEventListener(onMessage) {
|
|
2180
2244
|
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
@@ -2183,22 +2247,36 @@
|
|
|
2183
2247
|
if (!isKnownMessage(message)) {
|
|
2184
2248
|
return;
|
|
2185
2249
|
}
|
|
2186
|
-
const
|
|
2250
|
+
const parentPort3 = getParentPort();
|
|
2251
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
2187
2252
|
onMessage(type, payload);
|
|
2188
2253
|
};
|
|
2189
2254
|
}
|
|
2190
|
-
|
|
2255
|
+
const parentPort2 = getParentPort();
|
|
2256
|
+
if (parentPort2) {
|
|
2257
|
+
console.error("not implemented");
|
|
2258
|
+
} else {
|
|
2259
|
+
globalThis.addEventListener("message", onMessageWrapper);
|
|
2260
|
+
}
|
|
2191
2261
|
}
|
|
2192
2262
|
static removeEventListener(onMessage) {
|
|
2193
2263
|
const onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
2194
2264
|
onMessageWrapperMap.delete(onMessage);
|
|
2195
|
-
|
|
2265
|
+
const parentPort2 = getParentPort();
|
|
2266
|
+
if (parentPort2) {
|
|
2267
|
+
console.error("not implemented");
|
|
2268
|
+
} else {
|
|
2269
|
+
globalThis.removeEventListener("message", onMessageWrapper);
|
|
2270
|
+
}
|
|
2196
2271
|
}
|
|
2197
2272
|
static postMessage(type, payload) {
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2273
|
+
const data = { source: "loaders.gl", type, payload };
|
|
2274
|
+
const transferList = getTransferList(payload);
|
|
2275
|
+
const parentPort2 = getParentPort();
|
|
2276
|
+
if (parentPort2) {
|
|
2277
|
+
parentPort2.postMessage(data, transferList);
|
|
2278
|
+
} else {
|
|
2279
|
+
globalThis.postMessage(data, transferList);
|
|
2202
2280
|
}
|
|
2203
2281
|
}
|
|
2204
2282
|
};
|
|
@@ -2210,19 +2288,20 @@
|
|
|
2210
2288
|
// ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
|
|
2211
2289
|
var requestId = 0;
|
|
2212
2290
|
function createLoaderWorker(loader) {
|
|
2213
|
-
if (
|
|
2291
|
+
if (!WorkerBody.inWorkerThread()) {
|
|
2214
2292
|
return;
|
|
2215
2293
|
}
|
|
2216
2294
|
WorkerBody.onmessage = async (type, payload) => {
|
|
2217
2295
|
switch (type) {
|
|
2218
2296
|
case "process":
|
|
2219
2297
|
try {
|
|
2220
|
-
const { input, options = {} } = payload;
|
|
2298
|
+
const { input, options = {}, context = {} } = payload;
|
|
2221
2299
|
const result = await parseData({
|
|
2222
2300
|
loader,
|
|
2223
2301
|
arrayBuffer: input,
|
|
2224
2302
|
options,
|
|
2225
2303
|
context: {
|
|
2304
|
+
...context,
|
|
2226
2305
|
parse: parseOnMainThread
|
|
2227
2306
|
}
|
|
2228
2307
|
});
|