@loaders.gl/mvt 4.0.0-alpha.5 → 4.0.0-alpha.6
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.js +2 -2
- package/dist/dist.min.js +1748 -913
- 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.js +111 -77
- package/dist/helpers/mapbox-util-functions.d.ts +2 -2
- package/dist/helpers/mapbox-util-functions.js +78 -45
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -143
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
- 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 +4 -4
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
- package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
- package/dist/lib/parse-mvt.d.ts +6 -9
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +148 -98
- package/dist/lib/types.d.ts +48 -7
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +2 -2
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +43 -22
- package/dist/mvt-worker.js +903 -829
- package/dist/workers/mvt-worker.js +5 -4
- package/package.json +7 -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 +6 -1
- 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 +136 -93
- package/src/lib/types.ts +53 -7
- 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/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/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
|
}
|
|
@@ -1511,16 +1232,543 @@
|
|
|
1511
1232
|
if (p.nextZ)
|
|
1512
1233
|
p.nextZ.prevZ = p.prevZ;
|
|
1513
1234
|
}
|
|
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;
|
|
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
|
|
@@ -1652,440 +1900,232 @@
|
|
|
1652
1900
|
if (i > 0) {
|
|
1653
1901
|
const start = indices[indices.length - 1];
|
|
1654
1902
|
data.push(data[start], data[start + 1]);
|
|
1655
|
-
i += 2;
|
|
1656
|
-
}
|
|
1657
|
-
} else {
|
|
1658
|
-
throw new Error(`unknown command ${cmd}`);
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
return { data, indices };
|
|
1662
|
-
}
|
|
1663
|
-
_toBinaryCoordinates(transform) {
|
|
1664
|
-
const geom = this.loadGeometry();
|
|
1665
|
-
let geometry;
|
|
1666
|
-
transform(geom.data, this);
|
|
1667
|
-
const coordLength = 2;
|
|
1668
|
-
switch (this.type) {
|
|
1669
|
-
case 1:
|
|
1670
|
-
this._geometryInfo.pointFeaturesCount++;
|
|
1671
|
-
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
1672
|
-
geometry = { type: "Point", ...geom };
|
|
1673
|
-
break;
|
|
1674
|
-
case 2:
|
|
1675
|
-
this._geometryInfo.lineFeaturesCount++;
|
|
1676
|
-
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
1677
|
-
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
1678
|
-
geometry = { type: "LineString", ...geom };
|
|
1679
|
-
break;
|
|
1680
|
-
case 3:
|
|
1681
|
-
geometry = classifyRings2(geom);
|
|
1682
|
-
this._geometryInfo.polygonFeaturesCount++;
|
|
1683
|
-
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
1684
|
-
for (const indices of geometry.indices) {
|
|
1685
|
-
this._geometryInfo.polygonRingsCount += indices.length;
|
|
1686
|
-
}
|
|
1687
|
-
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
1688
|
-
break;
|
|
1689
|
-
default:
|
|
1690
|
-
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
1691
|
-
}
|
|
1692
|
-
const result = { type: "Feature", geometry, properties: this.properties };
|
|
1693
|
-
if (this.id !== null) {
|
|
1694
|
-
result.id = this.id;
|
|
1695
|
-
}
|
|
1696
|
-
return result;
|
|
1697
|
-
}
|
|
1698
|
-
toBinaryCoordinates(options) {
|
|
1699
|
-
if (typeof options === "function") {
|
|
1700
|
-
return this._toBinaryCoordinates(options);
|
|
1701
|
-
}
|
|
1702
|
-
return this._toBinaryCoordinates(project);
|
|
1703
|
-
}
|
|
1704
|
-
};
|
|
1705
|
-
|
|
1706
|
-
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
1707
|
-
var VectorTileLayer2 = class {
|
|
1708
|
-
constructor(pbf, end) {
|
|
1709
|
-
this.version = 1;
|
|
1710
|
-
this.name = "";
|
|
1711
|
-
this.extent = 4096;
|
|
1712
|
-
this.length = 0;
|
|
1713
|
-
this._pbf = pbf;
|
|
1714
|
-
this._keys = [];
|
|
1715
|
-
this._values = [];
|
|
1716
|
-
this._features = [];
|
|
1717
|
-
pbf.readFields(readLayer2, this, end);
|
|
1718
|
-
this.length = this._features.length;
|
|
1719
|
-
}
|
|
1720
|
-
feature(i2, geometryInfo) {
|
|
1721
|
-
if (i2 < 0 || i2 >= this._features.length) {
|
|
1722
|
-
throw new Error("feature index out of bounds");
|
|
1723
|
-
}
|
|
1724
|
-
this._pbf.pos = this._features[i2];
|
|
1725
|
-
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1726
|
-
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
1727
|
-
}
|
|
1728
|
-
};
|
|
1729
|
-
function readLayer2(tag, layer, pbf) {
|
|
1730
|
-
if (layer && pbf) {
|
|
1731
|
-
if (tag === 15)
|
|
1732
|
-
layer.version = pbf.readVarint();
|
|
1733
|
-
else if (tag === 1)
|
|
1734
|
-
layer.name = pbf.readString();
|
|
1735
|
-
else if (tag === 5)
|
|
1736
|
-
layer.extent = pbf.readVarint();
|
|
1737
|
-
else if (tag === 2)
|
|
1738
|
-
layer._features.push(pbf.pos);
|
|
1739
|
-
else if (tag === 3)
|
|
1740
|
-
layer._keys.push(pbf.readString());
|
|
1741
|
-
else if (tag === 4)
|
|
1742
|
-
layer._values.push(readValueMessage2(pbf));
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
function readValueMessage2(pbf) {
|
|
1746
|
-
let value = null;
|
|
1747
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
1748
|
-
while (pbf.pos < end) {
|
|
1749
|
-
const tag = pbf.readVarint() >> 3;
|
|
1750
|
-
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;
|
|
1751
|
-
}
|
|
1752
|
-
return value;
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
|
-
// src/lib/binary-vector-tile/vector-tile.ts
|
|
1756
|
-
var VectorTile2 = class {
|
|
1757
|
-
constructor(pbf, end) {
|
|
1758
|
-
this.layers = pbf.readFields(readTile2, {}, end);
|
|
1759
|
-
}
|
|
1760
|
-
};
|
|
1761
|
-
function readTile2(tag, layers, pbf) {
|
|
1762
|
-
if (tag === 3) {
|
|
1763
|
-
if (pbf) {
|
|
1764
|
-
const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
|
|
1765
|
-
if (layer.length && layers) {
|
|
1766
|
-
layers[layer.name] = layer;
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
|
-
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1773
|
-
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1774
|
-
const propArrayTypes = extractNumericPropTypes(features);
|
|
1775
|
-
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1776
|
-
return fillArrays(features, {
|
|
1777
|
-
propArrayTypes,
|
|
1778
|
-
...geometryInfo
|
|
1779
|
-
}, {
|
|
1780
|
-
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1781
|
-
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1782
|
-
});
|
|
1783
|
-
}
|
|
1784
|
-
function extractNumericPropTypes(features) {
|
|
1785
|
-
const propArrayTypes = {};
|
|
1786
|
-
for (const feature of features) {
|
|
1787
|
-
if (feature.properties) {
|
|
1788
|
-
for (const key in feature.properties) {
|
|
1789
|
-
const val = feature.properties[key];
|
|
1790
|
-
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
return propArrayTypes;
|
|
1795
|
-
}
|
|
1796
|
-
function fillArrays(features, geometryInfo, options) {
|
|
1797
|
-
const {
|
|
1798
|
-
pointPositionsCount,
|
|
1799
|
-
pointFeaturesCount,
|
|
1800
|
-
linePositionsCount,
|
|
1801
|
-
linePathsCount,
|
|
1802
|
-
lineFeaturesCount,
|
|
1803
|
-
polygonPositionsCount,
|
|
1804
|
-
polygonObjectsCount,
|
|
1805
|
-
polygonRingsCount,
|
|
1806
|
-
polygonFeaturesCount,
|
|
1807
|
-
propArrayTypes,
|
|
1808
|
-
coordLength
|
|
1809
|
-
} = geometryInfo;
|
|
1810
|
-
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
1811
|
-
const hasGlobalId = features[0] && "id" in features[0];
|
|
1812
|
-
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1813
|
-
const points = {
|
|
1814
|
-
type: "Point",
|
|
1815
|
-
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1816
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1817
|
-
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1818
|
-
numericProps: {},
|
|
1819
|
-
properties: [],
|
|
1820
|
-
fields: []
|
|
1821
|
-
};
|
|
1822
|
-
const lines = {
|
|
1823
|
-
type: "LineString",
|
|
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
|
-
type: "Polygon",
|
|
1834
|
-
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1835
|
-
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1836
|
-
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
1837
|
-
triangles: [],
|
|
1838
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1839
|
-
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1840
|
-
numericProps: {},
|
|
1841
|
-
properties: [],
|
|
1842
|
-
fields: []
|
|
1843
|
-
};
|
|
1844
|
-
for (const object of [points, lines, polygons]) {
|
|
1845
|
-
for (const propName of numericPropKeys) {
|
|
1846
|
-
const T = propArrayTypes[propName];
|
|
1847
|
-
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
1851
|
-
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
1852
|
-
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
1853
|
-
const indexMap = {
|
|
1854
|
-
pointPosition: 0,
|
|
1855
|
-
pointFeature: 0,
|
|
1856
|
-
linePosition: 0,
|
|
1857
|
-
linePath: 0,
|
|
1858
|
-
lineFeature: 0,
|
|
1859
|
-
polygonPosition: 0,
|
|
1860
|
-
polygonObject: 0,
|
|
1861
|
-
polygonRing: 0,
|
|
1862
|
-
polygonFeature: 0,
|
|
1863
|
-
feature: 0
|
|
1864
|
-
};
|
|
1865
|
-
for (const feature of features) {
|
|
1866
|
-
const geometry = feature.geometry;
|
|
1867
|
-
const properties = feature.properties || {};
|
|
1868
|
-
switch (geometry.type) {
|
|
1869
|
-
case "Point":
|
|
1870
|
-
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1871
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1872
|
-
if (hasGlobalId) {
|
|
1873
|
-
points.fields.push({ id: feature.id });
|
|
1874
|
-
}
|
|
1875
|
-
indexMap.pointFeature++;
|
|
1876
|
-
break;
|
|
1877
|
-
case "LineString":
|
|
1878
|
-
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1879
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1880
|
-
if (hasGlobalId) {
|
|
1881
|
-
lines.fields.push({ id: feature.id });
|
|
1903
|
+
i += 2;
|
|
1882
1904
|
}
|
|
1883
|
-
|
|
1905
|
+
} else {
|
|
1906
|
+
throw new Error(`unknown command ${cmd}`);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
return { data, indices };
|
|
1910
|
+
}
|
|
1911
|
+
_toBinaryCoordinates(transform) {
|
|
1912
|
+
const geom = this.loadGeometry();
|
|
1913
|
+
let geometry;
|
|
1914
|
+
transform(geom.data, this);
|
|
1915
|
+
const coordLength = 2;
|
|
1916
|
+
switch (this.type) {
|
|
1917
|
+
case 1:
|
|
1918
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
1919
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
1920
|
+
geometry = { type: "Point", ...geom };
|
|
1884
1921
|
break;
|
|
1885
|
-
case
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1922
|
+
case 2:
|
|
1923
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
1924
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
1925
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
1926
|
+
geometry = { type: "LineString", ...geom };
|
|
1927
|
+
break;
|
|
1928
|
+
case 3:
|
|
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;
|
|
1890
1934
|
}
|
|
1891
|
-
|
|
1935
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
1892
1936
|
break;
|
|
1893
1937
|
default:
|
|
1894
|
-
throw new Error(
|
|
1938
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
1895
1939
|
}
|
|
1896
|
-
|
|
1940
|
+
const result = { type: "Feature", geometry, properties: this.properties };
|
|
1941
|
+
if (this.id !== null) {
|
|
1942
|
+
result.id = this.id;
|
|
1943
|
+
}
|
|
1944
|
+
return result;
|
|
1897
1945
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
}
|
|
1908
|
-
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1909
|
-
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1910
|
-
const nPositions = geometry.data.length / coordLength;
|
|
1911
|
-
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1912
|
-
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1913
|
-
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1914
|
-
for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
|
|
1915
|
-
const start = geometry.indices[i2];
|
|
1916
|
-
const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
|
|
1917
|
-
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1918
|
-
indexMap.linePosition += (end - start) / coordLength;
|
|
1946
|
+
toBinaryCoordinates(options) {
|
|
1947
|
+
if (typeof options === "function") {
|
|
1948
|
+
return this._toBinaryCoordinates(options);
|
|
1949
|
+
}
|
|
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));
|
|
1919
1955
|
}
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1956
|
+
};
|
|
1957
|
+
|
|
1958
|
+
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
1959
|
+
var VectorTileLayer2 = class {
|
|
1960
|
+
constructor(pbf, end) {
|
|
1961
|
+
this.version = 1;
|
|
1962
|
+
this.name = "";
|
|
1963
|
+
this.extent = 4096;
|
|
1964
|
+
this.length = 0;
|
|
1965
|
+
this._pbf = pbf;
|
|
1966
|
+
this._keys = [];
|
|
1967
|
+
this._values = [];
|
|
1968
|
+
this._features = [];
|
|
1969
|
+
pbf.readFields(readLayer2, this, end);
|
|
1970
|
+
this.length = this._features.length;
|
|
1971
|
+
}
|
|
1972
|
+
feature(i2, geometryInfo) {
|
|
1973
|
+
if (i2 < 0 || i2 >= this._features.length) {
|
|
1974
|
+
throw new Error("feature index out of bounds");
|
|
1938
1975
|
}
|
|
1939
|
-
|
|
1940
|
-
|
|
1976
|
+
this._pbf.pos = this._features[i2];
|
|
1977
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1978
|
+
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
1941
1979
|
}
|
|
1942
|
-
}
|
|
1943
|
-
function
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1980
|
+
};
|
|
1981
|
+
function readLayer2(tag, layer, pbf) {
|
|
1982
|
+
if (layer && pbf) {
|
|
1983
|
+
if (tag === 15)
|
|
1984
|
+
layer.version = pbf.readVarint();
|
|
1985
|
+
else if (tag === 1)
|
|
1986
|
+
layer.name = pbf.readString();
|
|
1987
|
+
else if (tag === 5)
|
|
1988
|
+
layer.extent = pbf.readVarint();
|
|
1989
|
+
else if (tag === 2)
|
|
1990
|
+
layer._features.push(pbf.pos);
|
|
1991
|
+
else if (tag === 3)
|
|
1992
|
+
layer._keys.push(pbf.readString());
|
|
1993
|
+
else if (tag === 4)
|
|
1994
|
+
layer._values.push(readValueMessage2(pbf));
|
|
1956
1995
|
}
|
|
1957
1996
|
}
|
|
1958
|
-
function
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1997
|
+
function readValueMessage2(pbf) {
|
|
1998
|
+
let value = null;
|
|
1999
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
2000
|
+
while (pbf.pos < end) {
|
|
2001
|
+
const tag = pbf.readVarint() >> 3;
|
|
2002
|
+
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;
|
|
1962
2003
|
}
|
|
1963
|
-
return
|
|
1964
|
-
}
|
|
1965
|
-
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1966
|
-
return {
|
|
1967
|
-
points: {
|
|
1968
|
-
...points,
|
|
1969
|
-
positions: { value: points.positions, size: coordLength },
|
|
1970
|
-
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
1971
|
-
featureIds: { value: points.featureIds, size: 1 },
|
|
1972
|
-
numericProps: wrapProps(points.numericProps, 1)
|
|
1973
|
-
},
|
|
1974
|
-
lines: {
|
|
1975
|
-
...lines,
|
|
1976
|
-
positions: { value: lines.positions, size: coordLength },
|
|
1977
|
-
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1978
|
-
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
1979
|
-
featureIds: { value: lines.featureIds, size: 1 },
|
|
1980
|
-
numericProps: wrapProps(lines.numericProps, 1)
|
|
1981
|
-
},
|
|
1982
|
-
polygons: {
|
|
1983
|
-
...polygons,
|
|
1984
|
-
positions: { value: polygons.positions, size: coordLength },
|
|
1985
|
-
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
1986
|
-
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
1987
|
-
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
1988
|
-
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
1989
|
-
featureIds: { value: polygons.featureIds, size: 1 },
|
|
1990
|
-
numericProps: wrapProps(polygons.numericProps, 1)
|
|
1991
|
-
}
|
|
1992
|
-
};
|
|
2004
|
+
return value;
|
|
1993
2005
|
}
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
}
|
|
2006
|
+
|
|
2007
|
+
// src/lib/binary-vector-tile/vector-tile.ts
|
|
2008
|
+
var VectorTile2 = class {
|
|
2009
|
+
constructor(pbf, end) {
|
|
2010
|
+
this.layers = pbf.readFields(readTile2, {}, end);
|
|
2000
2011
|
}
|
|
2001
|
-
}
|
|
2002
|
-
function
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2012
|
+
};
|
|
2013
|
+
function readTile2(tag, layers, pbf) {
|
|
2014
|
+
if (tag === 3) {
|
|
2015
|
+
if (pbf) {
|
|
2016
|
+
const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
|
|
2017
|
+
if (layer.length && layers) {
|
|
2018
|
+
layers[layer.name] = layer;
|
|
2019
|
+
}
|
|
2007
2020
|
}
|
|
2008
2021
|
}
|
|
2009
|
-
return props;
|
|
2010
|
-
}
|
|
2011
|
-
function deduceArrayType(x2, constructor) {
|
|
2012
|
-
if (constructor === Array || !Number.isFinite(x2)) {
|
|
2013
|
-
return Array;
|
|
2014
|
-
}
|
|
2015
|
-
return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
|
|
2016
2022
|
}
|
|
2017
2023
|
|
|
2018
2024
|
// src/lib/parse-mvt.ts
|
|
2019
|
-
var import_pbf = __toModule(require_pbf());
|
|
2020
2025
|
function parseMVT(arrayBuffer, options) {
|
|
2021
|
-
|
|
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;
|
|
2037
|
+
}
|
|
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);
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
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;
|
|
2053
|
+
}
|
|
2054
|
+
function parseToFlatGeoJson(arrayBuffer, options) {
|
|
2022
2055
|
const features = [];
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
if (!vectorTileLayer) {
|
|
2045
|
-
return;
|
|
2046
|
-
}
|
|
2047
|
-
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2048
|
-
const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
|
|
2049
|
-
const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
|
|
2050
|
-
features.push(decodedFeature);
|
|
2051
|
-
}
|
|
2052
|
-
});
|
|
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
|
|
2067
|
+
};
|
|
2068
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
2069
|
+
return [features, geometryInfo];
|
|
2070
|
+
}
|
|
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;
|
|
2053
2077
|
}
|
|
2054
|
-
|
|
2055
|
-
const
|
|
2056
|
-
|
|
2057
|
-
|
|
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);
|
|
2058
2082
|
}
|
|
2083
|
+
});
|
|
2084
|
+
return [features, geometryInfo];
|
|
2085
|
+
}
|
|
2086
|
+
function parseToGeojson(arrayBuffer, options) {
|
|
2087
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
2088
|
+
return [];
|
|
2059
2089
|
}
|
|
2090
|
+
const features = [];
|
|
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);
|
|
2102
|
+
}
|
|
2103
|
+
});
|
|
2060
2104
|
return features;
|
|
2061
2105
|
}
|
|
2062
2106
|
function normalizeOptions(options) {
|
|
2063
|
-
if (options) {
|
|
2064
|
-
options
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2072
|
-
if (wgs84Coordinates && !hasTileIndex) {
|
|
2073
|
-
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.");
|
|
2074
|
-
}
|
|
2107
|
+
if (!options?.mvt) {
|
|
2108
|
+
throw new Error("mvt options required");
|
|
2109
|
+
}
|
|
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");
|
|
2075
2115
|
}
|
|
2076
|
-
return options;
|
|
2116
|
+
return options.mvt;
|
|
2077
2117
|
}
|
|
2078
|
-
function getDecodedFeature(feature, options) {
|
|
2118
|
+
function getDecodedFeature(feature, options, layerName) {
|
|
2079
2119
|
const decodedFeature = feature.toGeoJSON(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates);
|
|
2080
2120
|
if (options.layerProperty) {
|
|
2081
|
-
decodedFeature.properties[options.layerProperty] =
|
|
2121
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2082
2122
|
}
|
|
2083
2123
|
return decodedFeature;
|
|
2084
2124
|
}
|
|
2085
|
-
function getDecodedFeatureBinary(feature, options) {
|
|
2125
|
+
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
2086
2126
|
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
2087
2127
|
if (options.layerProperty && decodedFeature.properties) {
|
|
2088
|
-
decodedFeature.properties[options.layerProperty] =
|
|
2128
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2089
2129
|
}
|
|
2090
2130
|
return decodedFeature;
|
|
2091
2131
|
}
|
|
@@ -2105,7 +2145,16 @@
|
|
|
2105
2145
|
}
|
|
2106
2146
|
|
|
2107
2147
|
// src/mvt-loader.ts
|
|
2108
|
-
var VERSION = true ? "4.0.0-alpha.
|
|
2148
|
+
var VERSION = true ? "4.0.0-alpha.6" : "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
|
+
};
|
|
2109
2158
|
var MVTWorkerLoader = {
|
|
2110
2159
|
name: "Mapbox Vector Tile",
|
|
2111
2160
|
id: "mvt",
|
|
@@ -2118,14 +2167,7 @@
|
|
|
2118
2167
|
],
|
|
2119
2168
|
worker: true,
|
|
2120
2169
|
category: "geometry",
|
|
2121
|
-
options:
|
|
2122
|
-
mvt: {
|
|
2123
|
-
coordinates: "local",
|
|
2124
|
-
layerProperty: "layerName",
|
|
2125
|
-
layers: null,
|
|
2126
|
-
tileIndex: null
|
|
2127
|
-
}
|
|
2128
|
-
}
|
|
2170
|
+
options: DEFAULT_MVT_LOADER_OPTIONS
|
|
2129
2171
|
};
|
|
2130
2172
|
var MVTLoader = {
|
|
2131
2173
|
...MVTWorkerLoader,
|
|
@@ -2170,16 +2212,33 @@
|
|
|
2170
2212
|
}
|
|
2171
2213
|
|
|
2172
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
|
+
}
|
|
2173
2224
|
var onMessageWrapperMap = new Map();
|
|
2174
2225
|
var WorkerBody = class {
|
|
2226
|
+
static inWorkerThread() {
|
|
2227
|
+
return typeof self !== "undefined" || Boolean(getParentPort());
|
|
2228
|
+
}
|
|
2175
2229
|
static set onmessage(onMessage) {
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
}
|
|
2180
|
-
const { type, payload } = message.data;
|
|
2230
|
+
function handleMessage(message) {
|
|
2231
|
+
const parentPort3 = getParentPort();
|
|
2232
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
2181
2233
|
onMessage(type, payload);
|
|
2182
|
-
}
|
|
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
|
+
}
|
|
2183
2242
|
}
|
|
2184
2243
|
static addEventListener(onMessage) {
|
|
2185
2244
|
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
@@ -2188,22 +2247,36 @@
|
|
|
2188
2247
|
if (!isKnownMessage(message)) {
|
|
2189
2248
|
return;
|
|
2190
2249
|
}
|
|
2191
|
-
const
|
|
2250
|
+
const parentPort3 = getParentPort();
|
|
2251
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
2192
2252
|
onMessage(type, payload);
|
|
2193
2253
|
};
|
|
2194
2254
|
}
|
|
2195
|
-
|
|
2255
|
+
const parentPort2 = getParentPort();
|
|
2256
|
+
if (parentPort2) {
|
|
2257
|
+
console.error("not implemented");
|
|
2258
|
+
} else {
|
|
2259
|
+
globalThis.addEventListener("message", onMessageWrapper);
|
|
2260
|
+
}
|
|
2196
2261
|
}
|
|
2197
2262
|
static removeEventListener(onMessage) {
|
|
2198
2263
|
const onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
2199
2264
|
onMessageWrapperMap.delete(onMessage);
|
|
2200
|
-
|
|
2265
|
+
const parentPort2 = getParentPort();
|
|
2266
|
+
if (parentPort2) {
|
|
2267
|
+
console.error("not implemented");
|
|
2268
|
+
} else {
|
|
2269
|
+
globalThis.removeEventListener("message", onMessageWrapper);
|
|
2270
|
+
}
|
|
2201
2271
|
}
|
|
2202
2272
|
static postMessage(type, payload) {
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
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);
|
|
2207
2280
|
}
|
|
2208
2281
|
}
|
|
2209
2282
|
};
|
|
@@ -2215,19 +2288,20 @@
|
|
|
2215
2288
|
// ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
|
|
2216
2289
|
var requestId = 0;
|
|
2217
2290
|
function createLoaderWorker(loader) {
|
|
2218
|
-
if (
|
|
2291
|
+
if (!WorkerBody.inWorkerThread()) {
|
|
2219
2292
|
return;
|
|
2220
2293
|
}
|
|
2221
2294
|
WorkerBody.onmessage = async (type, payload) => {
|
|
2222
2295
|
switch (type) {
|
|
2223
2296
|
case "process":
|
|
2224
2297
|
try {
|
|
2225
|
-
const { input, options = {} } = payload;
|
|
2298
|
+
const { input, options = {}, context = {} } = payload;
|
|
2226
2299
|
const result = await parseData({
|
|
2227
2300
|
loader,
|
|
2228
2301
|
arrayBuffer: input,
|
|
2229
2302
|
options,
|
|
2230
2303
|
context: {
|
|
2304
|
+
...context,
|
|
2231
2305
|
parse: parseOnMainThread
|
|
2232
2306
|
}
|
|
2233
2307
|
});
|