@loaders.gl/mvt 3.2.0-alpha.1 → 3.2.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.min.js +978 -941
- package/dist/es5/helpers/mapbox-util-functions.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/es5/lib/parse-mvt.js +117 -66
- package/dist/es5/lib/parse-mvt.js.map +1 -1
- package/dist/es5/mvt-loader.js +11 -9
- package/dist/es5/mvt-loader.js.map +1 -1
- package/dist/esm/helpers/mapbox-util-functions.js.map +1 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/esm/lib/parse-mvt.js +113 -60
- package/dist/esm/lib/parse-mvt.js.map +1 -1
- package/dist/esm/mvt-loader.js +11 -9
- package/dist/esm/mvt-loader.js.map +1 -1
- package/dist/helpers/mapbox-util-functions.d.ts +2 -2
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +4 -4
- 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 +97 -73
- package/dist/lib/types.d.ts +48 -7
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +10 -8
- package/dist/mvt-worker.js +970 -930
- package/package.json +5 -5
- package/src/helpers/mapbox-util-functions.ts +2 -2
- 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/mvt-worker.js
CHANGED
|
@@ -757,530 +757,252 @@
|
|
|
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(data, holeIndices, dim, areas) {
|
|
777
|
+
dim = dim || 2;
|
|
778
|
+
const hasHoles = holeIndices && holeIndices.length;
|
|
779
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
|
780
|
+
let outerNode = linkedList(data, 0, outerLen, dim, true, areas && areas[0]);
|
|
781
|
+
const triangles = [];
|
|
782
|
+
if (!outerNode || outerNode.next === outerNode.prev)
|
|
783
|
+
return triangles;
|
|
784
|
+
let invSize;
|
|
785
|
+
let maxX;
|
|
786
|
+
let maxY;
|
|
787
|
+
let minX;
|
|
788
|
+
let minY;
|
|
789
|
+
let x2;
|
|
790
|
+
let y2;
|
|
791
|
+
if (hasHoles)
|
|
792
|
+
outerNode = eliminateHoles(data, holeIndices, outerNode, dim, areas);
|
|
793
|
+
if (data.length > 80 * dim) {
|
|
794
|
+
minX = maxX = data[0];
|
|
795
|
+
minY = maxY = data[1];
|
|
796
|
+
for (let i2 = dim; i2 < outerLen; i2 += dim) {
|
|
797
|
+
x2 = data[i2];
|
|
798
|
+
y2 = data[i2 + 1];
|
|
799
|
+
if (x2 < minX)
|
|
800
|
+
minX = x2;
|
|
801
|
+
if (y2 < minY)
|
|
802
|
+
minY = y2;
|
|
803
|
+
if (x2 > maxX)
|
|
804
|
+
maxX = x2;
|
|
805
|
+
if (y2 > maxY)
|
|
806
|
+
maxY = y2;
|
|
807
|
+
}
|
|
808
|
+
invSize = Math.max(maxX - minX, maxY - minY);
|
|
809
|
+
invSize = invSize !== 0 ? 1 / invSize : 0;
|
|
804
810
|
}
|
|
811
|
+
earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
|
|
812
|
+
return triangles;
|
|
805
813
|
}
|
|
806
|
-
function
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
814
|
+
function linkedList(data, start, end, dim, clockwise, area2) {
|
|
815
|
+
let i2;
|
|
816
|
+
let last;
|
|
817
|
+
if (area2 === void 0) {
|
|
818
|
+
area2 = getPolygonSignedArea(data, {
|
|
819
|
+
start,
|
|
820
|
+
end,
|
|
821
|
+
size: dim
|
|
822
|
+
});
|
|
812
823
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
824
|
+
if (clockwise === area2 < 0) {
|
|
825
|
+
for (i2 = start; i2 < end; i2 += dim)
|
|
826
|
+
last = insertNode(i2, data[i2], data[i2 + 1], last);
|
|
827
|
+
} else {
|
|
828
|
+
for (i2 = end - dim; i2 >= start; i2 -= dim)
|
|
829
|
+
last = insertNode(i2, data[i2], data[i2 + 1], last);
|
|
819
830
|
}
|
|
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);
|
|
831
|
+
if (last && equals(last, last.next)) {
|
|
832
|
+
removeNode(last);
|
|
833
|
+
last = last.next;
|
|
830
834
|
}
|
|
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
|
-
}
|
|
835
|
+
return last;
|
|
836
|
+
}
|
|
837
|
+
function filterPoints(start, end) {
|
|
838
|
+
if (!start)
|
|
839
|
+
return start;
|
|
840
|
+
if (!end)
|
|
841
|
+
end = start;
|
|
842
|
+
let p = start;
|
|
843
|
+
let again;
|
|
844
|
+
do {
|
|
845
|
+
again = false;
|
|
846
|
+
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
847
|
+
removeNode(p);
|
|
848
|
+
p = end = p.prev;
|
|
849
|
+
if (p === p.next)
|
|
850
|
+
break;
|
|
851
|
+
again = true;
|
|
852
|
+
} else {
|
|
853
|
+
p = p.next;
|
|
865
854
|
}
|
|
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}`);
|
|
855
|
+
} while (again || p !== end);
|
|
856
|
+
return end;
|
|
857
|
+
}
|
|
858
|
+
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
859
|
+
if (!ear)
|
|
860
|
+
return;
|
|
861
|
+
if (!pass && invSize)
|
|
862
|
+
indexCurve(ear, minX, minY, invSize);
|
|
863
|
+
let stop = ear;
|
|
864
|
+
let prev;
|
|
865
|
+
let next;
|
|
866
|
+
while (ear.prev !== ear.next) {
|
|
867
|
+
prev = ear.prev;
|
|
868
|
+
next = ear.next;
|
|
869
|
+
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
870
|
+
triangles.push(prev.i / dim);
|
|
871
|
+
triangles.push(ear.i / dim);
|
|
872
|
+
triangles.push(next.i / dim);
|
|
873
|
+
removeNode(ear);
|
|
874
|
+
ear = next.next;
|
|
875
|
+
stop = next.next;
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
ear = next;
|
|
879
|
+
if (ear === stop) {
|
|
880
|
+
if (!pass) {
|
|
881
|
+
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
882
|
+
} else if (pass === 1) {
|
|
883
|
+
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
884
|
+
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
885
|
+
} else if (pass === 2) {
|
|
886
|
+
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
902
887
|
}
|
|
888
|
+
break;
|
|
903
889
|
}
|
|
904
|
-
return [x1, y1, x22, y22];
|
|
905
890
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
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);
|
|
891
|
+
}
|
|
892
|
+
function isEar(ear) {
|
|
893
|
+
const a = ear.prev;
|
|
894
|
+
const b = ear;
|
|
895
|
+
const c = ear.next;
|
|
896
|
+
if (area(a, b, c) >= 0)
|
|
897
|
+
return false;
|
|
898
|
+
let p = ear.next.next;
|
|
899
|
+
while (p !== ear.prev) {
|
|
900
|
+
if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
901
|
+
return false;
|
|
902
|
+
p = p.next;
|
|
969
903
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
904
|
+
return true;
|
|
905
|
+
}
|
|
906
|
+
function isEarHashed(ear, minX, minY, invSize) {
|
|
907
|
+
const a = ear.prev;
|
|
908
|
+
const b = ear;
|
|
909
|
+
const c = ear.next;
|
|
910
|
+
if (area(a, b, c) >= 0)
|
|
911
|
+
return false;
|
|
912
|
+
const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
|
|
913
|
+
const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
|
|
914
|
+
const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
|
|
915
|
+
const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
|
|
916
|
+
const minZ = zOrder(minTX, minTY, minX, minY, invSize);
|
|
917
|
+
const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
|
|
918
|
+
let p = ear.prevZ;
|
|
919
|
+
let n = ear.nextZ;
|
|
920
|
+
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
921
|
+
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
922
|
+
return false;
|
|
923
|
+
p = p.prevZ;
|
|
924
|
+
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
925
|
+
return false;
|
|
926
|
+
n = n.nextZ;
|
|
985
927
|
}
|
|
986
|
-
|
|
987
|
-
if (
|
|
988
|
-
|
|
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);
|
|
928
|
+
while (p && p.z >= minZ) {
|
|
929
|
+
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
930
|
+
return false;
|
|
931
|
+
p = p.prevZ;
|
|
993
932
|
}
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
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));
|
|
933
|
+
while (n && n.z <= maxZ) {
|
|
934
|
+
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
935
|
+
return false;
|
|
936
|
+
n = n.nextZ;
|
|
1009
937
|
}
|
|
938
|
+
return true;
|
|
1010
939
|
}
|
|
1011
|
-
function
|
|
1012
|
-
let
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
const
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
940
|
+
function cureLocalIntersections(start, triangles, dim) {
|
|
941
|
+
let p = start;
|
|
942
|
+
do {
|
|
943
|
+
const a = p.prev;
|
|
944
|
+
const b = p.next.next;
|
|
945
|
+
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
946
|
+
triangles.push(a.i / dim);
|
|
947
|
+
triangles.push(p.i / dim);
|
|
948
|
+
triangles.push(b.i / dim);
|
|
949
|
+
removeNode(p);
|
|
950
|
+
removeNode(p.next);
|
|
951
|
+
p = start = b;
|
|
952
|
+
}
|
|
953
|
+
p = p.next;
|
|
954
|
+
} while (p !== start);
|
|
955
|
+
return filterPoints(p);
|
|
1019
956
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
layers[layer.name] = layer;
|
|
957
|
+
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
958
|
+
let a = start;
|
|
959
|
+
do {
|
|
960
|
+
let b = a.next.next;
|
|
961
|
+
while (b !== a.prev) {
|
|
962
|
+
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
963
|
+
let c = splitPolygon(a, b);
|
|
964
|
+
a = filterPoints(a, a.next);
|
|
965
|
+
c = filterPoints(c, c.next);
|
|
966
|
+
earcutLinked(a, triangles, dim, minX, minY, invSize);
|
|
967
|
+
earcutLinked(c, triangles, dim, minX, minY, invSize);
|
|
968
|
+
return;
|
|
1033
969
|
}
|
|
970
|
+
b = b.next;
|
|
1034
971
|
}
|
|
972
|
+
a = a.next;
|
|
973
|
+
} while (a !== start);
|
|
974
|
+
}
|
|
975
|
+
function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
|
|
976
|
+
const queue = [];
|
|
977
|
+
let i2;
|
|
978
|
+
let len;
|
|
979
|
+
let start;
|
|
980
|
+
let end;
|
|
981
|
+
let list;
|
|
982
|
+
for (i2 = 0, len = holeIndices.length; i2 < len; i2++) {
|
|
983
|
+
start = holeIndices[i2] * dim;
|
|
984
|
+
end = i2 < len - 1 ? holeIndices[i2 + 1] * dim : data.length;
|
|
985
|
+
list = linkedList(data, start, end, dim, false, areas && areas[i2 + 1]);
|
|
986
|
+
if (list === list.next)
|
|
987
|
+
list.steiner = true;
|
|
988
|
+
queue.push(getLeftmost(list));
|
|
989
|
+
}
|
|
990
|
+
queue.sort(compareX);
|
|
991
|
+
for (i2 = 0; i2 < queue.length; i2++) {
|
|
992
|
+
eliminateHole(queue[i2], outerNode);
|
|
993
|
+
outerNode = filterPoints(outerNode, outerNode.next);
|
|
1035
994
|
}
|
|
995
|
+
return outerNode;
|
|
1036
996
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
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;
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
function isEar(ear) {
|
|
1171
|
-
const a = ear.prev;
|
|
1172
|
-
const b = ear;
|
|
1173
|
-
const c = ear.next;
|
|
1174
|
-
if (area(a, b, c) >= 0)
|
|
1175
|
-
return false;
|
|
1176
|
-
let p = ear.next.next;
|
|
1177
|
-
while (p !== ear.prev) {
|
|
1178
|
-
if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
1179
|
-
return false;
|
|
1180
|
-
p = p.next;
|
|
1181
|
-
}
|
|
1182
|
-
return true;
|
|
1183
|
-
}
|
|
1184
|
-
function isEarHashed(ear, minX, minY, invSize) {
|
|
1185
|
-
const a = ear.prev;
|
|
1186
|
-
const b = ear;
|
|
1187
|
-
const c = ear.next;
|
|
1188
|
-
if (area(a, b, c) >= 0)
|
|
1189
|
-
return false;
|
|
1190
|
-
const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
|
|
1191
|
-
const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
|
|
1192
|
-
const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
|
|
1193
|
-
const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
|
|
1194
|
-
const minZ = zOrder(minTX, minTY, minX, minY, invSize);
|
|
1195
|
-
const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
|
|
1196
|
-
let p = ear.prevZ;
|
|
1197
|
-
let n = ear.nextZ;
|
|
1198
|
-
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
1199
|
-
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
1200
|
-
return false;
|
|
1201
|
-
p = p.prevZ;
|
|
1202
|
-
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
1203
|
-
return false;
|
|
1204
|
-
n = n.nextZ;
|
|
1205
|
-
}
|
|
1206
|
-
while (p && p.z >= minZ) {
|
|
1207
|
-
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
1208
|
-
return false;
|
|
1209
|
-
p = p.prevZ;
|
|
1210
|
-
}
|
|
1211
|
-
while (n && n.z <= maxZ) {
|
|
1212
|
-
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
1213
|
-
return false;
|
|
1214
|
-
n = n.nextZ;
|
|
1215
|
-
}
|
|
1216
|
-
return true;
|
|
1217
|
-
}
|
|
1218
|
-
function cureLocalIntersections(start, triangles, dim) {
|
|
1219
|
-
let p = start;
|
|
1220
|
-
do {
|
|
1221
|
-
const a = p.prev;
|
|
1222
|
-
const b = p.next.next;
|
|
1223
|
-
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
1224
|
-
triangles.push(a.i / dim);
|
|
1225
|
-
triangles.push(p.i / dim);
|
|
1226
|
-
triangles.push(b.i / dim);
|
|
1227
|
-
removeNode(p);
|
|
1228
|
-
removeNode(p.next);
|
|
1229
|
-
p = start = b;
|
|
1230
|
-
}
|
|
1231
|
-
p = p.next;
|
|
1232
|
-
} while (p !== start);
|
|
1233
|
-
return filterPoints(p);
|
|
1234
|
-
}
|
|
1235
|
-
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
1236
|
-
let a = start;
|
|
1237
|
-
do {
|
|
1238
|
-
let b = a.next.next;
|
|
1239
|
-
while (b !== a.prev) {
|
|
1240
|
-
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
1241
|
-
let c = splitPolygon(a, b);
|
|
1242
|
-
a = filterPoints(a, a.next);
|
|
1243
|
-
c = filterPoints(c, c.next);
|
|
1244
|
-
earcutLinked(a, triangles, dim, minX, minY, invSize);
|
|
1245
|
-
earcutLinked(c, triangles, dim, minX, minY, invSize);
|
|
1246
|
-
return;
|
|
1247
|
-
}
|
|
1248
|
-
b = b.next;
|
|
1249
|
-
}
|
|
1250
|
-
a = a.next;
|
|
1251
|
-
} while (a !== start);
|
|
1252
|
-
}
|
|
1253
|
-
function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
|
|
1254
|
-
const queue = [];
|
|
1255
|
-
let i2;
|
|
1256
|
-
let len;
|
|
1257
|
-
let start;
|
|
1258
|
-
let end;
|
|
1259
|
-
let list;
|
|
1260
|
-
for (i2 = 0, len = holeIndices.length; i2 < len; i2++) {
|
|
1261
|
-
start = holeIndices[i2] * dim;
|
|
1262
|
-
end = i2 < len - 1 ? holeIndices[i2 + 1] * dim : data.length;
|
|
1263
|
-
list = linkedList(data, start, end, dim, false, areas && areas[i2 + 1]);
|
|
1264
|
-
if (list === list.next)
|
|
1265
|
-
list.steiner = true;
|
|
1266
|
-
queue.push(getLeftmost(list));
|
|
1267
|
-
}
|
|
1268
|
-
queue.sort(compareX);
|
|
1269
|
-
for (i2 = 0; i2 < queue.length; i2++) {
|
|
1270
|
-
eliminateHole(queue[i2], outerNode);
|
|
1271
|
-
outerNode = filterPoints(outerNode, outerNode.next);
|
|
1272
|
-
}
|
|
1273
|
-
return outerNode;
|
|
1274
|
-
}
|
|
1275
|
-
function compareX(a, b) {
|
|
1276
|
-
return a.x - b.x;
|
|
1277
|
-
}
|
|
1278
|
-
function eliminateHole(hole, outerNode) {
|
|
1279
|
-
outerNode = findHoleBridge(hole, outerNode);
|
|
1280
|
-
if (outerNode) {
|
|
1281
|
-
const b = splitPolygon(outerNode, hole);
|
|
1282
|
-
filterPoints(outerNode, outerNode.next);
|
|
1283
|
-
filterPoints(b, b.next);
|
|
997
|
+
function compareX(a, b) {
|
|
998
|
+
return a.x - b.x;
|
|
999
|
+
}
|
|
1000
|
+
function eliminateHole(hole, outerNode) {
|
|
1001
|
+
outerNode = findHoleBridge(hole, outerNode);
|
|
1002
|
+
if (outerNode) {
|
|
1003
|
+
const b = splitPolygon(outerNode, hole);
|
|
1004
|
+
filterPoints(outerNode, outerNode.next);
|
|
1005
|
+
filterPoints(b, b.next);
|
|
1284
1006
|
}
|
|
1285
1007
|
}
|
|
1286
1008
|
function findHoleBridge(hole, outerNode) {
|
|
@@ -1511,16 +1233,543 @@
|
|
|
1511
1233
|
if (p.nextZ)
|
|
1512
1234
|
p.nextZ.prevZ = p.prevZ;
|
|
1513
1235
|
}
|
|
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;
|
|
1236
|
+
function Node(i2, x2, y2) {
|
|
1237
|
+
this.i = i2;
|
|
1238
|
+
this.x = x2;
|
|
1239
|
+
this.y = y2;
|
|
1240
|
+
this.prev = null;
|
|
1241
|
+
this.next = null;
|
|
1242
|
+
this.z = null;
|
|
1243
|
+
this.prevZ = null;
|
|
1244
|
+
this.nextZ = null;
|
|
1245
|
+
this.steiner = false;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1249
|
+
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1250
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
1251
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1252
|
+
return fillArrays(features, {
|
|
1253
|
+
propArrayTypes,
|
|
1254
|
+
...geometryInfo
|
|
1255
|
+
}, {
|
|
1256
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1257
|
+
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
function extractNumericPropTypes(features) {
|
|
1261
|
+
const propArrayTypes = {};
|
|
1262
|
+
for (const feature of features) {
|
|
1263
|
+
if (feature.properties) {
|
|
1264
|
+
for (const key in feature.properties) {
|
|
1265
|
+
const val = feature.properties[key];
|
|
1266
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
return propArrayTypes;
|
|
1271
|
+
}
|
|
1272
|
+
function fillArrays(features, geometryInfo, options) {
|
|
1273
|
+
const {
|
|
1274
|
+
pointPositionsCount,
|
|
1275
|
+
pointFeaturesCount,
|
|
1276
|
+
linePositionsCount,
|
|
1277
|
+
linePathsCount,
|
|
1278
|
+
lineFeaturesCount,
|
|
1279
|
+
polygonPositionsCount,
|
|
1280
|
+
polygonObjectsCount,
|
|
1281
|
+
polygonRingsCount,
|
|
1282
|
+
polygonFeaturesCount,
|
|
1283
|
+
propArrayTypes,
|
|
1284
|
+
coordLength
|
|
1285
|
+
} = geometryInfo;
|
|
1286
|
+
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
1287
|
+
const hasGlobalId = features[0] && "id" in features[0];
|
|
1288
|
+
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1289
|
+
const points = {
|
|
1290
|
+
type: "Point",
|
|
1291
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1292
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1293
|
+
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1294
|
+
numericProps: {},
|
|
1295
|
+
properties: [],
|
|
1296
|
+
fields: []
|
|
1297
|
+
};
|
|
1298
|
+
const lines = {
|
|
1299
|
+
type: "LineString",
|
|
1300
|
+
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
1301
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
1302
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
1303
|
+
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
1304
|
+
numericProps: {},
|
|
1305
|
+
properties: [],
|
|
1306
|
+
fields: []
|
|
1307
|
+
};
|
|
1308
|
+
const polygons = {
|
|
1309
|
+
type: "Polygon",
|
|
1310
|
+
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1311
|
+
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1312
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
1313
|
+
triangles: [],
|
|
1314
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1315
|
+
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1316
|
+
numericProps: {},
|
|
1317
|
+
properties: [],
|
|
1318
|
+
fields: []
|
|
1319
|
+
};
|
|
1320
|
+
for (const object of [points, lines, polygons]) {
|
|
1321
|
+
for (const propName of numericPropKeys) {
|
|
1322
|
+
const T = propArrayTypes[propName];
|
|
1323
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
1327
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
1328
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
1329
|
+
const indexMap = {
|
|
1330
|
+
pointPosition: 0,
|
|
1331
|
+
pointFeature: 0,
|
|
1332
|
+
linePosition: 0,
|
|
1333
|
+
linePath: 0,
|
|
1334
|
+
lineFeature: 0,
|
|
1335
|
+
polygonPosition: 0,
|
|
1336
|
+
polygonObject: 0,
|
|
1337
|
+
polygonRing: 0,
|
|
1338
|
+
polygonFeature: 0,
|
|
1339
|
+
feature: 0
|
|
1340
|
+
};
|
|
1341
|
+
for (const feature of features) {
|
|
1342
|
+
const geometry = feature.geometry;
|
|
1343
|
+
const properties = feature.properties || {};
|
|
1344
|
+
switch (geometry.type) {
|
|
1345
|
+
case "Point":
|
|
1346
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1347
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1348
|
+
if (hasGlobalId) {
|
|
1349
|
+
points.fields.push({ id: feature.id });
|
|
1350
|
+
}
|
|
1351
|
+
indexMap.pointFeature++;
|
|
1352
|
+
break;
|
|
1353
|
+
case "LineString":
|
|
1354
|
+
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1355
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1356
|
+
if (hasGlobalId) {
|
|
1357
|
+
lines.fields.push({ id: feature.id });
|
|
1358
|
+
}
|
|
1359
|
+
indexMap.lineFeature++;
|
|
1360
|
+
break;
|
|
1361
|
+
case "Polygon":
|
|
1362
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1363
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1364
|
+
if (hasGlobalId) {
|
|
1365
|
+
polygons.fields.push({ id: feature.id });
|
|
1366
|
+
}
|
|
1367
|
+
indexMap.polygonFeature++;
|
|
1368
|
+
break;
|
|
1369
|
+
default:
|
|
1370
|
+
throw new Error("Invalid geometry type");
|
|
1371
|
+
}
|
|
1372
|
+
indexMap.feature++;
|
|
1373
|
+
}
|
|
1374
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
1375
|
+
}
|
|
1376
|
+
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
1377
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
1378
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1379
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
1380
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1381
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1382
|
+
indexMap.pointPosition += nPositions;
|
|
1383
|
+
}
|
|
1384
|
+
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1385
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1386
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1387
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1388
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1389
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1390
|
+
for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
|
|
1391
|
+
const start = geometry.indices[i2];
|
|
1392
|
+
const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
|
|
1393
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1394
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
1398
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
1399
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1400
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
1401
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1402
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1403
|
+
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
1404
|
+
const startPosition = indexMap.polygonPosition;
|
|
1405
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
1406
|
+
const areas = geometry.areas[l];
|
|
1407
|
+
const indices = geometry.indices[l];
|
|
1408
|
+
const nextIndices = geometry.indices[l + 1];
|
|
1409
|
+
for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
|
|
1410
|
+
const start = indices[i2];
|
|
1411
|
+
const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
|
|
1412
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
1413
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
1414
|
+
}
|
|
1415
|
+
const endPosition = indexMap.polygonPosition;
|
|
1416
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
function triangulatePolygon(polygons, areas, indices, {
|
|
1420
|
+
startPosition,
|
|
1421
|
+
endPosition,
|
|
1422
|
+
coordLength
|
|
1423
|
+
}) {
|
|
1424
|
+
const start = startPosition * coordLength;
|
|
1425
|
+
const end = endPosition * coordLength;
|
|
1426
|
+
const polygonPositions = polygons.positions.subarray(start, end);
|
|
1427
|
+
const offset = indices[0];
|
|
1428
|
+
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
1429
|
+
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
1430
|
+
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
1431
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
function wrapProps(obj, size) {
|
|
1435
|
+
const returnObj = {};
|
|
1436
|
+
for (const key in obj) {
|
|
1437
|
+
returnObj[key] = { value: obj[key], size };
|
|
1438
|
+
}
|
|
1439
|
+
return returnObj;
|
|
1440
|
+
}
|
|
1441
|
+
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1442
|
+
return {
|
|
1443
|
+
points: {
|
|
1444
|
+
...points,
|
|
1445
|
+
positions: { value: points.positions, size: coordLength },
|
|
1446
|
+
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
1447
|
+
featureIds: { value: points.featureIds, size: 1 },
|
|
1448
|
+
numericProps: wrapProps(points.numericProps, 1)
|
|
1449
|
+
},
|
|
1450
|
+
lines: {
|
|
1451
|
+
...lines,
|
|
1452
|
+
positions: { value: lines.positions, size: coordLength },
|
|
1453
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1454
|
+
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
1455
|
+
featureIds: { value: lines.featureIds, size: 1 },
|
|
1456
|
+
numericProps: wrapProps(lines.numericProps, 1)
|
|
1457
|
+
},
|
|
1458
|
+
polygons: {
|
|
1459
|
+
...polygons,
|
|
1460
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
1461
|
+
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
1462
|
+
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
1463
|
+
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
1464
|
+
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
1465
|
+
featureIds: { value: polygons.featureIds, size: 1 },
|
|
1466
|
+
numericProps: wrapProps(polygons.numericProps, 1)
|
|
1467
|
+
}
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
function fillNumericProperties(object, properties, index, length2) {
|
|
1471
|
+
for (const numericPropName in object.numericProps) {
|
|
1472
|
+
if (numericPropName in properties) {
|
|
1473
|
+
const value = properties[numericPropName];
|
|
1474
|
+
object.numericProps[numericPropName].fill(value, index, index + length2);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
function keepStringProperties(properties, numericKeys) {
|
|
1479
|
+
const props = {};
|
|
1480
|
+
for (const key in properties) {
|
|
1481
|
+
if (!numericKeys.includes(key)) {
|
|
1482
|
+
props[key] = properties[key];
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
return props;
|
|
1486
|
+
}
|
|
1487
|
+
function deduceArrayType(x2, constructor) {
|
|
1488
|
+
if (constructor === Array || !Number.isFinite(x2)) {
|
|
1489
|
+
return Array;
|
|
1490
|
+
}
|
|
1491
|
+
return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
// src/lib/parse-mvt.ts
|
|
1495
|
+
var import_pbf = __toModule(require_pbf());
|
|
1496
|
+
|
|
1497
|
+
// src/helpers/mapbox-util-functions.ts
|
|
1498
|
+
function classifyRings(rings) {
|
|
1499
|
+
const len = rings.length;
|
|
1500
|
+
if (len <= 1)
|
|
1501
|
+
return [rings];
|
|
1502
|
+
const polygons = [];
|
|
1503
|
+
let polygon;
|
|
1504
|
+
let ccw;
|
|
1505
|
+
for (let i2 = 0; i2 < len; i2++) {
|
|
1506
|
+
const area2 = signedArea(rings[i2]);
|
|
1507
|
+
if (area2 === 0)
|
|
1508
|
+
continue;
|
|
1509
|
+
if (ccw === void 0)
|
|
1510
|
+
ccw = area2 < 0;
|
|
1511
|
+
if (ccw === area2 < 0) {
|
|
1512
|
+
if (polygon)
|
|
1513
|
+
polygons.push(polygon);
|
|
1514
|
+
polygon = [rings[i2]];
|
|
1515
|
+
} else if (polygon)
|
|
1516
|
+
polygon.push(rings[i2]);
|
|
1517
|
+
}
|
|
1518
|
+
if (polygon)
|
|
1519
|
+
polygons.push(polygon);
|
|
1520
|
+
return polygons;
|
|
1521
|
+
}
|
|
1522
|
+
function signedArea(ring) {
|
|
1523
|
+
let sum = 0;
|
|
1524
|
+
for (let i2 = 0, j = ring.length - 1, p1, p2; i2 < ring.length; j = i2++) {
|
|
1525
|
+
p1 = ring[i2];
|
|
1526
|
+
p2 = ring[j];
|
|
1527
|
+
sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
|
|
1528
|
+
}
|
|
1529
|
+
return sum;
|
|
1530
|
+
}
|
|
1531
|
+
function readFeature(tag, feature, pbf) {
|
|
1532
|
+
if (feature && pbf) {
|
|
1533
|
+
if (tag === 1)
|
|
1534
|
+
feature.id = pbf.readVarint();
|
|
1535
|
+
else if (tag === 2)
|
|
1536
|
+
readTag(pbf, feature);
|
|
1537
|
+
else if (tag === 3)
|
|
1538
|
+
feature.type = pbf.readVarint();
|
|
1539
|
+
else if (tag === 4)
|
|
1540
|
+
feature._geometry = pbf.pos;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
function readTag(pbf, feature) {
|
|
1544
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1545
|
+
while (pbf.pos < end) {
|
|
1546
|
+
const key = feature._keys[pbf.readVarint()];
|
|
1547
|
+
const value = feature._values[pbf.readVarint()];
|
|
1548
|
+
feature.properties[key] = value;
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
// src/lib/mapbox-vector-tile/vector-tile-feature.ts
|
|
1553
|
+
var VectorTileFeature = class {
|
|
1554
|
+
static get types() {
|
|
1555
|
+
return ["Unknown", "Point", "LineString", "Polygon"];
|
|
1556
|
+
}
|
|
1557
|
+
constructor(pbf, end, extent, keys, values) {
|
|
1558
|
+
this.properties = {};
|
|
1559
|
+
this.extent = extent;
|
|
1560
|
+
this.type = 0;
|
|
1561
|
+
this.id = null;
|
|
1562
|
+
this._pbf = pbf;
|
|
1563
|
+
this._geometry = -1;
|
|
1564
|
+
this._keys = keys;
|
|
1565
|
+
this._values = values;
|
|
1566
|
+
pbf.readFields(readFeature, this, end);
|
|
1567
|
+
}
|
|
1568
|
+
loadGeometry() {
|
|
1569
|
+
const pbf = this._pbf;
|
|
1570
|
+
pbf.pos = this._geometry;
|
|
1571
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1572
|
+
let cmd2 = 1;
|
|
1573
|
+
let length2 = 0;
|
|
1574
|
+
let x2 = 0;
|
|
1575
|
+
let y2 = 0;
|
|
1576
|
+
const lines = [];
|
|
1577
|
+
let line;
|
|
1578
|
+
while (pbf.pos < end) {
|
|
1579
|
+
if (length2 <= 0) {
|
|
1580
|
+
const cmdLen2 = pbf.readVarint();
|
|
1581
|
+
cmd2 = cmdLen2 & 7;
|
|
1582
|
+
length2 = cmdLen2 >> 3;
|
|
1583
|
+
}
|
|
1584
|
+
length2--;
|
|
1585
|
+
if (cmd2 === 1 || cmd2 === 2) {
|
|
1586
|
+
x2 += pbf.readSVarint();
|
|
1587
|
+
y2 += pbf.readSVarint();
|
|
1588
|
+
if (cmd2 === 1) {
|
|
1589
|
+
if (line)
|
|
1590
|
+
lines.push(line);
|
|
1591
|
+
line = [];
|
|
1592
|
+
}
|
|
1593
|
+
if (line)
|
|
1594
|
+
line.push([x2, y2]);
|
|
1595
|
+
} else if (cmd2 === 7) {
|
|
1596
|
+
if (line) {
|
|
1597
|
+
line.push(line[0].slice());
|
|
1598
|
+
}
|
|
1599
|
+
} else {
|
|
1600
|
+
throw new Error(`unknown command ${cmd2}`);
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
if (line)
|
|
1604
|
+
lines.push(line);
|
|
1605
|
+
return lines;
|
|
1606
|
+
}
|
|
1607
|
+
bbox() {
|
|
1608
|
+
const pbf = this._pbf;
|
|
1609
|
+
pbf.pos = this._geometry;
|
|
1610
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1611
|
+
let cmd2 = 1;
|
|
1612
|
+
let length2 = 0;
|
|
1613
|
+
let x2 = 0;
|
|
1614
|
+
let y2 = 0;
|
|
1615
|
+
let x1 = Infinity;
|
|
1616
|
+
let x22 = -Infinity;
|
|
1617
|
+
let y1 = Infinity;
|
|
1618
|
+
let y22 = -Infinity;
|
|
1619
|
+
while (pbf.pos < end) {
|
|
1620
|
+
if (length2 <= 0) {
|
|
1621
|
+
const cmdLen2 = pbf.readVarint();
|
|
1622
|
+
cmd2 = cmdLen2 & 7;
|
|
1623
|
+
length2 = cmdLen2 >> 3;
|
|
1624
|
+
}
|
|
1625
|
+
length2--;
|
|
1626
|
+
if (cmd2 === 1 || cmd2 === 2) {
|
|
1627
|
+
x2 += pbf.readSVarint();
|
|
1628
|
+
y2 += pbf.readSVarint();
|
|
1629
|
+
if (x2 < x1)
|
|
1630
|
+
x1 = x2;
|
|
1631
|
+
if (x2 > x22)
|
|
1632
|
+
x22 = x2;
|
|
1633
|
+
if (y2 < y1)
|
|
1634
|
+
y1 = y2;
|
|
1635
|
+
if (y2 > y22)
|
|
1636
|
+
y22 = y2;
|
|
1637
|
+
} else if (cmd2 !== 7) {
|
|
1638
|
+
throw new Error(`unknown command ${cmd2}`);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
return [x1, y1, x22, y22];
|
|
1642
|
+
}
|
|
1643
|
+
_toGeoJSON(transform) {
|
|
1644
|
+
let coords = this.loadGeometry();
|
|
1645
|
+
let type = VectorTileFeature.types[this.type];
|
|
1646
|
+
let i2;
|
|
1647
|
+
let j;
|
|
1648
|
+
switch (this.type) {
|
|
1649
|
+
case 1:
|
|
1650
|
+
const points = [];
|
|
1651
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1652
|
+
points[i2] = coords[i2][0];
|
|
1653
|
+
}
|
|
1654
|
+
coords = points;
|
|
1655
|
+
transform(coords, this);
|
|
1656
|
+
break;
|
|
1657
|
+
case 2:
|
|
1658
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1659
|
+
transform(coords[i2], this);
|
|
1660
|
+
}
|
|
1661
|
+
break;
|
|
1662
|
+
case 3:
|
|
1663
|
+
coords = classifyRings(coords);
|
|
1664
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1665
|
+
for (j = 0; j < coords[i2].length; j++) {
|
|
1666
|
+
transform(coords[i2][j], this);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
break;
|
|
1670
|
+
}
|
|
1671
|
+
if (coords.length === 1) {
|
|
1672
|
+
coords = coords[0];
|
|
1673
|
+
} else {
|
|
1674
|
+
type = `Multi${type}`;
|
|
1675
|
+
}
|
|
1676
|
+
const result = {
|
|
1677
|
+
type: "Feature",
|
|
1678
|
+
geometry: {
|
|
1679
|
+
type,
|
|
1680
|
+
coordinates: coords
|
|
1681
|
+
},
|
|
1682
|
+
properties: this.properties
|
|
1683
|
+
};
|
|
1684
|
+
if (this.id !== null) {
|
|
1685
|
+
result.id = this.id;
|
|
1686
|
+
}
|
|
1687
|
+
return result;
|
|
1688
|
+
}
|
|
1689
|
+
toGeoJSON(options) {
|
|
1690
|
+
if (typeof options === "function") {
|
|
1691
|
+
return this._toGeoJSON(options);
|
|
1692
|
+
}
|
|
1693
|
+
const { x: x2, y: y2, z } = options;
|
|
1694
|
+
const size = this.extent * Math.pow(2, z);
|
|
1695
|
+
const x0 = this.extent * x2;
|
|
1696
|
+
const y0 = this.extent * y2;
|
|
1697
|
+
function project2(line) {
|
|
1698
|
+
for (let j = 0; j < line.length; j++) {
|
|
1699
|
+
const p = line[j];
|
|
1700
|
+
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
1701
|
+
const y22 = 180 - (p[1] + y0) * 360 / size;
|
|
1702
|
+
p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
return this._toGeoJSON(project2);
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
// src/lib/mapbox-vector-tile/vector-tile-layer.ts
|
|
1710
|
+
var VectorTileLayer = class {
|
|
1711
|
+
constructor(pbf, end) {
|
|
1712
|
+
this.version = 1;
|
|
1713
|
+
this.name = "";
|
|
1714
|
+
this.extent = 4096;
|
|
1715
|
+
this.length = 0;
|
|
1716
|
+
this._pbf = pbf;
|
|
1717
|
+
this._keys = [];
|
|
1718
|
+
this._values = [];
|
|
1719
|
+
this._features = [];
|
|
1720
|
+
pbf.readFields(readLayer, this, end);
|
|
1721
|
+
this.length = this._features.length;
|
|
1722
|
+
}
|
|
1723
|
+
feature(i2) {
|
|
1724
|
+
if (i2 < 0 || i2 >= this._features.length) {
|
|
1725
|
+
throw new Error("feature index out of bounds");
|
|
1726
|
+
}
|
|
1727
|
+
this._pbf.pos = this._features[i2];
|
|
1728
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1729
|
+
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
function readLayer(tag, layer, pbf) {
|
|
1733
|
+
if (layer && pbf) {
|
|
1734
|
+
if (tag === 15)
|
|
1735
|
+
layer.version = pbf.readVarint();
|
|
1736
|
+
else if (tag === 1)
|
|
1737
|
+
layer.name = pbf.readString();
|
|
1738
|
+
else if (tag === 5)
|
|
1739
|
+
layer.extent = pbf.readVarint();
|
|
1740
|
+
else if (tag === 2)
|
|
1741
|
+
layer._features.push(pbf.pos);
|
|
1742
|
+
else if (tag === 3)
|
|
1743
|
+
layer._keys.push(pbf.readString());
|
|
1744
|
+
else if (tag === 4)
|
|
1745
|
+
layer._values.push(readValueMessage(pbf));
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
function readValueMessage(pbf) {
|
|
1749
|
+
let value = null;
|
|
1750
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1751
|
+
while (pbf.pos < end) {
|
|
1752
|
+
const tag = pbf.readVarint() >> 3;
|
|
1753
|
+
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;
|
|
1754
|
+
}
|
|
1755
|
+
return value;
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
// src/lib/mapbox-vector-tile/vector-tile.ts
|
|
1759
|
+
var VectorTile = class {
|
|
1760
|
+
constructor(pbf, end) {
|
|
1761
|
+
this.layers = pbf.readFields(readTile, {}, end);
|
|
1762
|
+
}
|
|
1763
|
+
};
|
|
1764
|
+
function readTile(tag, layers, pbf) {
|
|
1765
|
+
if (tag === 3) {
|
|
1766
|
+
if (pbf) {
|
|
1767
|
+
const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
|
|
1768
|
+
if (layer.length && layers) {
|
|
1769
|
+
layers[layer.name] = layer;
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1524
1773
|
}
|
|
1525
1774
|
|
|
1526
1775
|
// src/helpers/binary-util-functions.ts
|
|
@@ -1646,450 +1895,238 @@
|
|
|
1646
1895
|
if (cmd === 1) {
|
|
1647
1896
|
indices.push(i);
|
|
1648
1897
|
}
|
|
1649
|
-
data.push(x, y);
|
|
1650
|
-
i += 2;
|
|
1651
|
-
} else if (cmd === 7) {
|
|
1652
|
-
if (i > 0) {
|
|
1653
|
-
const start = indices[indices.length - 1];
|
|
1654
|
-
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
|
-
const { x: x2, y: y2, z } = options;
|
|
1703
|
-
const size = this.extent * Math.pow(2, z);
|
|
1704
|
-
const x0 = this.extent * x2;
|
|
1705
|
-
const y0 = this.extent * y2;
|
|
1706
|
-
return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
|
|
1707
|
-
}
|
|
1708
|
-
};
|
|
1709
|
-
|
|
1710
|
-
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
1711
|
-
var VectorTileLayer2 = class {
|
|
1712
|
-
constructor(pbf, end) {
|
|
1713
|
-
this.version = 1;
|
|
1714
|
-
this.name = "";
|
|
1715
|
-
this.extent = 4096;
|
|
1716
|
-
this.length = 0;
|
|
1717
|
-
this._pbf = pbf;
|
|
1718
|
-
this._keys = [];
|
|
1719
|
-
this._values = [];
|
|
1720
|
-
this._features = [];
|
|
1721
|
-
pbf.readFields(readLayer2, this, end);
|
|
1722
|
-
this.length = this._features.length;
|
|
1723
|
-
}
|
|
1724
|
-
feature(i2, geometryInfo) {
|
|
1725
|
-
if (i2 < 0 || i2 >= this._features.length) {
|
|
1726
|
-
throw new Error("feature index out of bounds");
|
|
1727
|
-
}
|
|
1728
|
-
this._pbf.pos = this._features[i2];
|
|
1729
|
-
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1730
|
-
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
1731
|
-
}
|
|
1732
|
-
};
|
|
1733
|
-
function readLayer2(tag, layer, pbf) {
|
|
1734
|
-
if (layer && pbf) {
|
|
1735
|
-
if (tag === 15)
|
|
1736
|
-
layer.version = pbf.readVarint();
|
|
1737
|
-
else if (tag === 1)
|
|
1738
|
-
layer.name = pbf.readString();
|
|
1739
|
-
else if (tag === 5)
|
|
1740
|
-
layer.extent = pbf.readVarint();
|
|
1741
|
-
else if (tag === 2)
|
|
1742
|
-
layer._features.push(pbf.pos);
|
|
1743
|
-
else if (tag === 3)
|
|
1744
|
-
layer._keys.push(pbf.readString());
|
|
1745
|
-
else if (tag === 4)
|
|
1746
|
-
layer._values.push(readValueMessage2(pbf));
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
function readValueMessage2(pbf) {
|
|
1750
|
-
let value = null;
|
|
1751
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
1752
|
-
while (pbf.pos < end) {
|
|
1753
|
-
const tag = pbf.readVarint() >> 3;
|
|
1754
|
-
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;
|
|
1755
|
-
}
|
|
1756
|
-
return value;
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
|
-
// src/lib/binary-vector-tile/vector-tile.ts
|
|
1760
|
-
var VectorTile2 = class {
|
|
1761
|
-
constructor(pbf, end) {
|
|
1762
|
-
this.layers = pbf.readFields(readTile2, {}, end);
|
|
1763
|
-
}
|
|
1764
|
-
};
|
|
1765
|
-
function readTile2(tag, layers, pbf) {
|
|
1766
|
-
if (tag === 3) {
|
|
1767
|
-
if (pbf) {
|
|
1768
|
-
const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
|
|
1769
|
-
if (layer.length && layers) {
|
|
1770
|
-
layers[layer.name] = layer;
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
|
-
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1777
|
-
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1778
|
-
const propArrayTypes = extractNumericPropTypes(features);
|
|
1779
|
-
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1780
|
-
return fillArrays(features, {
|
|
1781
|
-
propArrayTypes,
|
|
1782
|
-
...geometryInfo
|
|
1783
|
-
}, {
|
|
1784
|
-
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1785
|
-
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1786
|
-
});
|
|
1787
|
-
}
|
|
1788
|
-
function extractNumericPropTypes(features) {
|
|
1789
|
-
const propArrayTypes = {};
|
|
1790
|
-
for (const feature of features) {
|
|
1791
|
-
if (feature.properties) {
|
|
1792
|
-
for (const key in feature.properties) {
|
|
1793
|
-
const val = feature.properties[key];
|
|
1794
|
-
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
return propArrayTypes;
|
|
1799
|
-
}
|
|
1800
|
-
function fillArrays(features, geometryInfo, options) {
|
|
1801
|
-
const {
|
|
1802
|
-
pointPositionsCount,
|
|
1803
|
-
pointFeaturesCount,
|
|
1804
|
-
linePositionsCount,
|
|
1805
|
-
linePathsCount,
|
|
1806
|
-
lineFeaturesCount,
|
|
1807
|
-
polygonPositionsCount,
|
|
1808
|
-
polygonObjectsCount,
|
|
1809
|
-
polygonRingsCount,
|
|
1810
|
-
polygonFeaturesCount,
|
|
1811
|
-
propArrayTypes,
|
|
1812
|
-
coordLength
|
|
1813
|
-
} = geometryInfo;
|
|
1814
|
-
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
1815
|
-
const hasGlobalId = features[0] && "id" in features[0];
|
|
1816
|
-
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1817
|
-
const points = {
|
|
1818
|
-
type: "Point",
|
|
1819
|
-
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1820
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1821
|
-
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1822
|
-
numericProps: {},
|
|
1823
|
-
properties: [],
|
|
1824
|
-
fields: []
|
|
1825
|
-
};
|
|
1826
|
-
const lines = {
|
|
1827
|
-
type: "LineString",
|
|
1828
|
-
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
1829
|
-
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
1830
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
1831
|
-
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
1832
|
-
numericProps: {},
|
|
1833
|
-
properties: [],
|
|
1834
|
-
fields: []
|
|
1835
|
-
};
|
|
1836
|
-
const polygons = {
|
|
1837
|
-
type: "Polygon",
|
|
1838
|
-
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1839
|
-
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1840
|
-
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
1841
|
-
triangles: [],
|
|
1842
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1843
|
-
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1844
|
-
numericProps: {},
|
|
1845
|
-
properties: [],
|
|
1846
|
-
fields: []
|
|
1847
|
-
};
|
|
1848
|
-
for (const object of [points, lines, polygons]) {
|
|
1849
|
-
for (const propName of numericPropKeys) {
|
|
1850
|
-
const T = propArrayTypes[propName];
|
|
1851
|
-
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
1855
|
-
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
1856
|
-
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
1857
|
-
const indexMap = {
|
|
1858
|
-
pointPosition: 0,
|
|
1859
|
-
pointFeature: 0,
|
|
1860
|
-
linePosition: 0,
|
|
1861
|
-
linePath: 0,
|
|
1862
|
-
lineFeature: 0,
|
|
1863
|
-
polygonPosition: 0,
|
|
1864
|
-
polygonObject: 0,
|
|
1865
|
-
polygonRing: 0,
|
|
1866
|
-
polygonFeature: 0,
|
|
1867
|
-
feature: 0
|
|
1868
|
-
};
|
|
1869
|
-
for (const feature of features) {
|
|
1870
|
-
const geometry = feature.geometry;
|
|
1871
|
-
const properties = feature.properties || {};
|
|
1872
|
-
switch (geometry.type) {
|
|
1873
|
-
case "Point":
|
|
1874
|
-
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1875
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1876
|
-
if (hasGlobalId) {
|
|
1877
|
-
points.fields.push({ id: feature.id });
|
|
1878
|
-
}
|
|
1879
|
-
indexMap.pointFeature++;
|
|
1880
|
-
break;
|
|
1881
|
-
case "LineString":
|
|
1882
|
-
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1883
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1884
|
-
if (hasGlobalId) {
|
|
1885
|
-
lines.fields.push({ id: feature.id });
|
|
1898
|
+
data.push(x, y);
|
|
1899
|
+
i += 2;
|
|
1900
|
+
} else if (cmd === 7) {
|
|
1901
|
+
if (i > 0) {
|
|
1902
|
+
const start = indices[indices.length - 1];
|
|
1903
|
+
data.push(data[start], data[start + 1]);
|
|
1904
|
+
i += 2;
|
|
1886
1905
|
}
|
|
1887
|
-
|
|
1906
|
+
} else {
|
|
1907
|
+
throw new Error(`unknown command ${cmd}`);
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
return { data, indices };
|
|
1911
|
+
}
|
|
1912
|
+
_toBinaryCoordinates(transform) {
|
|
1913
|
+
const geom = this.loadGeometry();
|
|
1914
|
+
let geometry;
|
|
1915
|
+
transform(geom.data, this);
|
|
1916
|
+
const coordLength = 2;
|
|
1917
|
+
switch (this.type) {
|
|
1918
|
+
case 1:
|
|
1919
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
1920
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
1921
|
+
geometry = { type: "Point", ...geom };
|
|
1888
1922
|
break;
|
|
1889
|
-
case
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1923
|
+
case 2:
|
|
1924
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
1925
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
1926
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
1927
|
+
geometry = { type: "LineString", ...geom };
|
|
1928
|
+
break;
|
|
1929
|
+
case 3:
|
|
1930
|
+
geometry = classifyRings2(geom);
|
|
1931
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
1932
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
1933
|
+
for (const indices of geometry.indices) {
|
|
1934
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
1894
1935
|
}
|
|
1895
|
-
|
|
1936
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
1896
1937
|
break;
|
|
1897
1938
|
default:
|
|
1898
|
-
throw new Error(
|
|
1939
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
1899
1940
|
}
|
|
1900
|
-
|
|
1941
|
+
const result = { type: "Feature", geometry, properties: this.properties };
|
|
1942
|
+
if (this.id !== null) {
|
|
1943
|
+
result.id = this.id;
|
|
1944
|
+
}
|
|
1945
|
+
return result;
|
|
1901
1946
|
}
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
}
|
|
1912
|
-
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1913
|
-
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1914
|
-
const nPositions = geometry.data.length / coordLength;
|
|
1915
|
-
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1916
|
-
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1917
|
-
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1918
|
-
for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
|
|
1919
|
-
const start = geometry.indices[i2];
|
|
1920
|
-
const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
|
|
1921
|
-
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1922
|
-
indexMap.linePosition += (end - start) / coordLength;
|
|
1947
|
+
toBinaryCoordinates(options) {
|
|
1948
|
+
if (typeof options === "function") {
|
|
1949
|
+
return this._toBinaryCoordinates(options);
|
|
1950
|
+
}
|
|
1951
|
+
const { x: x2, y: y2, z } = options;
|
|
1952
|
+
const size = this.extent * Math.pow(2, z);
|
|
1953
|
+
const x0 = this.extent * x2;
|
|
1954
|
+
const y0 = this.extent * y2;
|
|
1955
|
+
return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
|
|
1923
1956
|
}
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1957
|
+
};
|
|
1958
|
+
|
|
1959
|
+
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
1960
|
+
var VectorTileLayer2 = class {
|
|
1961
|
+
constructor(pbf, end) {
|
|
1962
|
+
this.version = 1;
|
|
1963
|
+
this.name = "";
|
|
1964
|
+
this.extent = 4096;
|
|
1965
|
+
this.length = 0;
|
|
1966
|
+
this._pbf = pbf;
|
|
1967
|
+
this._keys = [];
|
|
1968
|
+
this._values = [];
|
|
1969
|
+
this._features = [];
|
|
1970
|
+
pbf.readFields(readLayer2, this, end);
|
|
1971
|
+
this.length = this._features.length;
|
|
1972
|
+
}
|
|
1973
|
+
feature(i2, geometryInfo) {
|
|
1974
|
+
if (i2 < 0 || i2 >= this._features.length) {
|
|
1975
|
+
throw new Error("feature index out of bounds");
|
|
1942
1976
|
}
|
|
1943
|
-
|
|
1944
|
-
|
|
1977
|
+
this._pbf.pos = this._features[i2];
|
|
1978
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1979
|
+
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
1945
1980
|
}
|
|
1946
|
-
}
|
|
1947
|
-
function
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1981
|
+
};
|
|
1982
|
+
function readLayer2(tag, layer, pbf) {
|
|
1983
|
+
if (layer && pbf) {
|
|
1984
|
+
if (tag === 15)
|
|
1985
|
+
layer.version = pbf.readVarint();
|
|
1986
|
+
else if (tag === 1)
|
|
1987
|
+
layer.name = pbf.readString();
|
|
1988
|
+
else if (tag === 5)
|
|
1989
|
+
layer.extent = pbf.readVarint();
|
|
1990
|
+
else if (tag === 2)
|
|
1991
|
+
layer._features.push(pbf.pos);
|
|
1992
|
+
else if (tag === 3)
|
|
1993
|
+
layer._keys.push(pbf.readString());
|
|
1994
|
+
else if (tag === 4)
|
|
1995
|
+
layer._values.push(readValueMessage2(pbf));
|
|
1960
1996
|
}
|
|
1961
1997
|
}
|
|
1962
|
-
function
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1998
|
+
function readValueMessage2(pbf) {
|
|
1999
|
+
let value = null;
|
|
2000
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
2001
|
+
while (pbf.pos < end) {
|
|
2002
|
+
const tag = pbf.readVarint() >> 3;
|
|
2003
|
+
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;
|
|
1966
2004
|
}
|
|
1967
|
-
return
|
|
1968
|
-
}
|
|
1969
|
-
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1970
|
-
return {
|
|
1971
|
-
points: {
|
|
1972
|
-
...points,
|
|
1973
|
-
positions: { value: points.positions, size: coordLength },
|
|
1974
|
-
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
1975
|
-
featureIds: { value: points.featureIds, size: 1 },
|
|
1976
|
-
numericProps: wrapProps(points.numericProps, 1)
|
|
1977
|
-
},
|
|
1978
|
-
lines: {
|
|
1979
|
-
...lines,
|
|
1980
|
-
positions: { value: lines.positions, size: coordLength },
|
|
1981
|
-
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1982
|
-
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
1983
|
-
featureIds: { value: lines.featureIds, size: 1 },
|
|
1984
|
-
numericProps: wrapProps(lines.numericProps, 1)
|
|
1985
|
-
},
|
|
1986
|
-
polygons: {
|
|
1987
|
-
...polygons,
|
|
1988
|
-
positions: { value: polygons.positions, size: coordLength },
|
|
1989
|
-
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
1990
|
-
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
1991
|
-
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
1992
|
-
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
1993
|
-
featureIds: { value: polygons.featureIds, size: 1 },
|
|
1994
|
-
numericProps: wrapProps(polygons.numericProps, 1)
|
|
1995
|
-
}
|
|
1996
|
-
};
|
|
2005
|
+
return value;
|
|
1997
2006
|
}
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
}
|
|
2007
|
+
|
|
2008
|
+
// src/lib/binary-vector-tile/vector-tile.ts
|
|
2009
|
+
var VectorTile2 = class {
|
|
2010
|
+
constructor(pbf, end) {
|
|
2011
|
+
this.layers = pbf.readFields(readTile2, {}, end);
|
|
2004
2012
|
}
|
|
2005
|
-
}
|
|
2006
|
-
function
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2013
|
+
};
|
|
2014
|
+
function readTile2(tag, layers, pbf) {
|
|
2015
|
+
if (tag === 3) {
|
|
2016
|
+
if (pbf) {
|
|
2017
|
+
const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
|
|
2018
|
+
if (layer.length && layers) {
|
|
2019
|
+
layers[layer.name] = layer;
|
|
2020
|
+
}
|
|
2011
2021
|
}
|
|
2012
2022
|
}
|
|
2013
|
-
return props;
|
|
2014
|
-
}
|
|
2015
|
-
function deduceArrayType(x2, constructor) {
|
|
2016
|
-
if (constructor === Array || !Number.isFinite(x2)) {
|
|
2017
|
-
return Array;
|
|
2018
|
-
}
|
|
2019
|
-
return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
|
|
2020
2023
|
}
|
|
2021
2024
|
|
|
2022
2025
|
// src/lib/parse-mvt.ts
|
|
2023
|
-
var import_pbf = __toModule(require_pbf());
|
|
2024
2026
|
function parseMVT(arrayBuffer, options) {
|
|
2025
|
-
|
|
2027
|
+
const mvtOptions = normalizeOptions(options);
|
|
2028
|
+
const shape = options?.gis?.format || options?.mvt?.shape;
|
|
2029
|
+
switch (shape) {
|
|
2030
|
+
case "columnar-table":
|
|
2031
|
+
return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
|
|
2032
|
+
case "geojson-row-table": {
|
|
2033
|
+
const table = {
|
|
2034
|
+
shape: "geojson-row-table",
|
|
2035
|
+
data: parseToGeojson(arrayBuffer, mvtOptions)
|
|
2036
|
+
};
|
|
2037
|
+
return table;
|
|
2038
|
+
}
|
|
2039
|
+
case "geojson":
|
|
2040
|
+
return parseToGeojson(arrayBuffer, mvtOptions);
|
|
2041
|
+
case "binary-geometry":
|
|
2042
|
+
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2043
|
+
case "binary":
|
|
2044
|
+
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2045
|
+
default:
|
|
2046
|
+
throw new Error(shape);
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
function parseToBinary(arrayBuffer, options) {
|
|
2050
|
+
const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);
|
|
2051
|
+
const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, geometryInfo);
|
|
2052
|
+
binaryData.byteLength = arrayBuffer.byteLength;
|
|
2053
|
+
return binaryData;
|
|
2054
|
+
}
|
|
2055
|
+
function parseToFlatGeoJson(arrayBuffer, options) {
|
|
2026
2056
|
const features = [];
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
if (!vectorTileLayer) {
|
|
2049
|
-
return;
|
|
2050
|
-
}
|
|
2051
|
-
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2052
|
-
const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
|
|
2053
|
-
const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
|
|
2054
|
-
features.push(decodedFeature);
|
|
2055
|
-
}
|
|
2056
|
-
});
|
|
2057
|
+
const geometryInfo = {
|
|
2058
|
+
coordLength: 2,
|
|
2059
|
+
pointPositionsCount: 0,
|
|
2060
|
+
pointFeaturesCount: 0,
|
|
2061
|
+
linePositionsCount: 0,
|
|
2062
|
+
linePathsCount: 0,
|
|
2063
|
+
lineFeaturesCount: 0,
|
|
2064
|
+
polygonPositionsCount: 0,
|
|
2065
|
+
polygonObjectsCount: 0,
|
|
2066
|
+
polygonRingsCount: 0,
|
|
2067
|
+
polygonFeaturesCount: 0
|
|
2068
|
+
};
|
|
2069
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
2070
|
+
return [features, geometryInfo];
|
|
2071
|
+
}
|
|
2072
|
+
const tile = new VectorTile2(new import_pbf.default(arrayBuffer));
|
|
2073
|
+
const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
2074
|
+
selectedLayers.forEach((layerName) => {
|
|
2075
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
2076
|
+
if (!vectorTileLayer) {
|
|
2077
|
+
return;
|
|
2057
2078
|
}
|
|
2058
|
-
|
|
2059
|
-
const
|
|
2060
|
-
|
|
2061
|
-
|
|
2079
|
+
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2080
|
+
const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
|
|
2081
|
+
const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
|
|
2082
|
+
features.push(decodedFeature);
|
|
2062
2083
|
}
|
|
2084
|
+
});
|
|
2085
|
+
return [features, geometryInfo];
|
|
2086
|
+
}
|
|
2087
|
+
function parseToGeojson(arrayBuffer, options) {
|
|
2088
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
2089
|
+
return [];
|
|
2063
2090
|
}
|
|
2091
|
+
const features = [];
|
|
2092
|
+
const tile = new VectorTile(new import_pbf.default(arrayBuffer));
|
|
2093
|
+
const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
2094
|
+
selectedLayers.forEach((layerName) => {
|
|
2095
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
2096
|
+
if (!vectorTileLayer) {
|
|
2097
|
+
return;
|
|
2098
|
+
}
|
|
2099
|
+
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2100
|
+
const vectorTileFeature = vectorTileLayer.feature(i2);
|
|
2101
|
+
const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
|
|
2102
|
+
features.push(decodedFeature);
|
|
2103
|
+
}
|
|
2104
|
+
});
|
|
2064
2105
|
return features;
|
|
2065
2106
|
}
|
|
2066
2107
|
function normalizeOptions(options) {
|
|
2067
|
-
if (options) {
|
|
2068
|
-
options
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2076
|
-
if (wgs84Coordinates && !hasTileIndex) {
|
|
2077
|
-
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.");
|
|
2078
|
-
}
|
|
2108
|
+
if (!options?.mvt) {
|
|
2109
|
+
throw new Error("mvt options required");
|
|
2110
|
+
}
|
|
2111
|
+
const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
|
|
2112
|
+
const { tileIndex } = options.mvt;
|
|
2113
|
+
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2114
|
+
if (wgs84Coordinates && !hasTileIndex) {
|
|
2115
|
+
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
|
|
2079
2116
|
}
|
|
2080
|
-
return options;
|
|
2117
|
+
return options.mvt;
|
|
2081
2118
|
}
|
|
2082
|
-
function getDecodedFeature(feature, options) {
|
|
2119
|
+
function getDecodedFeature(feature, options, layerName) {
|
|
2083
2120
|
const decodedFeature = feature.toGeoJSON(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates);
|
|
2084
2121
|
if (options.layerProperty) {
|
|
2085
|
-
decodedFeature.properties[options.layerProperty] =
|
|
2122
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2086
2123
|
}
|
|
2087
2124
|
return decodedFeature;
|
|
2088
2125
|
}
|
|
2089
|
-
function getDecodedFeatureBinary(feature, options) {
|
|
2126
|
+
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
2090
2127
|
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
2091
2128
|
if (options.layerProperty && decodedFeature.properties) {
|
|
2092
|
-
decodedFeature.properties[options.layerProperty] =
|
|
2129
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2093
2130
|
}
|
|
2094
2131
|
return decodedFeature;
|
|
2095
2132
|
}
|
|
@@ -2109,7 +2146,16 @@
|
|
|
2109
2146
|
}
|
|
2110
2147
|
|
|
2111
2148
|
// src/mvt-loader.ts
|
|
2112
|
-
var VERSION = true ? "3.2.0-alpha.
|
|
2149
|
+
var VERSION = true ? "3.2.0-alpha.4" : "latest";
|
|
2150
|
+
var DEFAULT_MVT_LOADER_OPTIONS = {
|
|
2151
|
+
mvt: {
|
|
2152
|
+
shape: "geojson",
|
|
2153
|
+
coordinates: "local",
|
|
2154
|
+
layerProperty: "layerName",
|
|
2155
|
+
layers: void 0,
|
|
2156
|
+
tileIndex: null
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
2113
2159
|
var MVTWorkerLoader = {
|
|
2114
2160
|
name: "Mapbox Vector Tile",
|
|
2115
2161
|
id: "mvt",
|
|
@@ -2122,14 +2168,7 @@
|
|
|
2122
2168
|
],
|
|
2123
2169
|
worker: true,
|
|
2124
2170
|
category: "geometry",
|
|
2125
|
-
options:
|
|
2126
|
-
mvt: {
|
|
2127
|
-
coordinates: "local",
|
|
2128
|
-
layerProperty: "layerName",
|
|
2129
|
-
layers: null,
|
|
2130
|
-
tileIndex: null
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2171
|
+
options: DEFAULT_MVT_LOADER_OPTIONS
|
|
2133
2172
|
};
|
|
2134
2173
|
var MVTLoader = {
|
|
2135
2174
|
...MVTWorkerLoader,
|
|
@@ -2257,12 +2296,13 @@
|
|
|
2257
2296
|
switch (type) {
|
|
2258
2297
|
case "process":
|
|
2259
2298
|
try {
|
|
2260
|
-
const { input, options = {} } = payload;
|
|
2299
|
+
const { input, options = {}, context = {} } = payload;
|
|
2261
2300
|
const result = await parseData({
|
|
2262
2301
|
loader,
|
|
2263
2302
|
arrayBuffer: input,
|
|
2264
2303
|
options,
|
|
2265
2304
|
context: {
|
|
2305
|
+
...context,
|
|
2266
2306
|
parse: parseOnMainThread
|
|
2267
2307
|
}
|
|
2268
2308
|
});
|