@dra2020/baseclient 1.0.48 → 1.0.49
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/baseclient.js +67 -36
- package/dist/baseclient.js.map +1 -1
- package/lib/poly/polylabel.ts +66 -39
- package/package.json +1 -1
package/dist/baseclient.js
CHANGED
|
@@ -6874,16 +6874,68 @@ function polyDistance(poly, x, y) {
|
|
|
6874
6874
|
let pp = P.polyNormalize(poly);
|
|
6875
6875
|
if (pp == null)
|
|
6876
6876
|
return 0;
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6877
|
+
// First find if it is contained in one of the outer polygons, or outside all outer polygons
|
|
6878
|
+
let iContaining = -1;
|
|
6879
|
+
let maxOutside = -Infinity;
|
|
6880
|
+
let minInside = Infinity;
|
|
6881
|
+
let noholes = true;
|
|
6882
|
+
PP.polyPackEachRing(pp, (b, iPoly, iRing, iOffset, nPoints) => {
|
|
6883
|
+
// If we have determined we are inside this polygon, keep track of whether it has holes
|
|
6884
|
+
if (iContaining == iPoly && iRing > 0)
|
|
6885
|
+
noholes = false;
|
|
6886
|
+
// Don't process rings
|
|
6887
|
+
if (iRing > 0)
|
|
6888
|
+
return;
|
|
6889
|
+
// OK, get distance
|
|
6890
|
+
let forEachPointPair = (iter) => {
|
|
6891
|
+
PP.polyPackEachRing(pp, (b, iInteriorPoly, iRing, iOffset, nPoints) => {
|
|
6892
|
+
if (iRing || iInteriorPoly != iPoly)
|
|
6893
|
+
return;
|
|
6894
|
+
let iFirst = iOffset;
|
|
6895
|
+
let iLast = iOffset + nPoints * 2;
|
|
6896
|
+
let iSecond = iLast - 2;
|
|
6897
|
+
for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
|
|
6898
|
+
iter(b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
|
|
6899
|
+
});
|
|
6900
|
+
};
|
|
6901
|
+
let dist = pointToPolygonDist(x, y, forEachPointPair);
|
|
6902
|
+
// If inside, is it closest inside (deal with multipolygons that self-contain - think filled donut)
|
|
6903
|
+
if (dist > 0 && dist < minInside) {
|
|
6904
|
+
iContaining = iPoly;
|
|
6905
|
+
minInside = dist;
|
|
6906
|
+
noholes = true;
|
|
6907
|
+
}
|
|
6908
|
+
else if (dist < 0)
|
|
6909
|
+
maxOutside = Math.max(maxOutside, dist);
|
|
6910
|
+
});
|
|
6911
|
+
if (iContaining < 0)
|
|
6912
|
+
return maxOutside;
|
|
6913
|
+
if (noholes)
|
|
6914
|
+
return minInside;
|
|
6915
|
+
// OK, now need to worry about holes in the polygon it is contained in
|
|
6916
|
+
PP.polyPackEachRing(pp, (b, iPoly, iRing, iOffset, nPoints) => {
|
|
6917
|
+
// Only want to look at the holes for the containing polygon
|
|
6918
|
+
if (iPoly != iContaining || iRing == 0)
|
|
6919
|
+
return;
|
|
6920
|
+
// Compute distance to those holes
|
|
6921
|
+
let forEachPointPair = (iter) => {
|
|
6922
|
+
PP.polyPackEachRing(pp, (b, iInteriorPoly, iRing, iOffset, nPoints) => {
|
|
6923
|
+
if (iInteriorPoly != iContaining || iRing == 0)
|
|
6924
|
+
return;
|
|
6925
|
+
let iFirst = iOffset;
|
|
6926
|
+
let iLast = iOffset + nPoints * 2;
|
|
6927
|
+
let iSecond = iLast - 2;
|
|
6928
|
+
for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
|
|
6929
|
+
iter(b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
|
|
6930
|
+
});
|
|
6931
|
+
};
|
|
6932
|
+
// Negate distance since dealing with holes
|
|
6933
|
+
let dist = -pointToPolygonDist(x, y, forEachPointPair);
|
|
6934
|
+
// We take the min to either get a negative value (inside hole) or a smaller positive value
|
|
6935
|
+
// (outside hole but close to hole boundary).
|
|
6936
|
+
minInside = Math.min(minInside, dist);
|
|
6937
|
+
});
|
|
6938
|
+
return minInside;
|
|
6887
6939
|
}
|
|
6888
6940
|
exports.polyDistance = polyDistance;
|
|
6889
6941
|
//
|
|
@@ -6922,7 +6974,7 @@ function polyLabel(poly, precision, debug) {
|
|
|
6922
6974
|
let iLast = iOffset + nPoints * 2;
|
|
6923
6975
|
let iSecond = iLast - 2;
|
|
6924
6976
|
for (; iFirst < iLast; iSecond = iFirst, iFirst += 2)
|
|
6925
|
-
iter(
|
|
6977
|
+
iter(b[iFirst], b[iFirst + 1], b[iSecond], b[iSecond + 1]);
|
|
6926
6978
|
});
|
|
6927
6979
|
};
|
|
6928
6980
|
// find the bounding box of the outer ring
|
|
@@ -6996,34 +7048,13 @@ class Cell {
|
|
|
6996
7048
|
}
|
|
6997
7049
|
// signed distance from point to polygon outline (negative if point is outside)
|
|
6998
7050
|
function pointToPolygonDist(x, y, forEachPointPair) {
|
|
6999
|
-
let iPolyLast = -1;
|
|
7000
|
-
let iRingLast = -1;
|
|
7001
7051
|
let inside = false;
|
|
7002
|
-
let thisInside = false;
|
|
7003
|
-
let useInside = false;
|
|
7004
|
-
let isHole = false;
|
|
7005
7052
|
let minDistSq = Infinity;
|
|
7006
|
-
forEachPointPair((
|
|
7007
|
-
if (iPoly != iPolyLast || iRing != iRingLast) {
|
|
7008
|
-
if (useInside)
|
|
7009
|
-
inside = isHole ? !thisInside : thisInside;
|
|
7010
|
-
iPolyLast = iPoly;
|
|
7011
|
-
iRingLast = iRing;
|
|
7012
|
-
thisInside = false;
|
|
7013
|
-
useInside = false;
|
|
7014
|
-
isHole = false;
|
|
7015
|
-
}
|
|
7053
|
+
forEachPointPair((ax, ay, bx, by) => {
|
|
7016
7054
|
if ((ay > y !== by > y) && (x < (bx - ax) * (y - ay) / (by - ay) + ax))
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
if (thisDistSq < minDistSq) {
|
|
7020
|
-
minDistSq = thisDistSq;
|
|
7021
|
-
useInside = true;
|
|
7022
|
-
isHole = iRing != 0;
|
|
7023
|
-
}
|
|
7055
|
+
inside = !inside;
|
|
7056
|
+
minDistSq = Math.min(minDistSq, getSegDistSq(x, y, ax, ay, bx, by));
|
|
7024
7057
|
});
|
|
7025
|
-
if (useInside)
|
|
7026
|
-
inside = isHole ? !thisInside : thisInside;
|
|
7027
7058
|
return (inside ? 1 : -1) * Math.sqrt(minDistSq);
|
|
7028
7059
|
}
|
|
7029
7060
|
// get polygon centroid
|
|
@@ -7033,7 +7064,7 @@ function getCentroidCell(forEachPointPair) {
|
|
|
7033
7064
|
let y = 0;
|
|
7034
7065
|
let fx;
|
|
7035
7066
|
let fy;
|
|
7036
|
-
forEachPointPair((
|
|
7067
|
+
forEachPointPair((ax, ay, bx, by) => {
|
|
7037
7068
|
if (fx === undefined)
|
|
7038
7069
|
fx = ax, fy = ay;
|
|
7039
7070
|
let f = ax * by - bx * ay;
|