gis-common 5.1.25 → 5.1.26
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/gis-common.es.js +87 -0
- package/dist/gis-common.umd.js +1 -1
- package/dist/index.d.ts +10 -7
- package/package.json +1 -1
package/dist/gis-common.es.js
CHANGED
|
@@ -1921,6 +1921,93 @@ const GeoJsonUtil = {
|
|
|
1921
1921
|
geometry: { type, coordinates },
|
|
1922
1922
|
properties: properties || {}
|
|
1923
1923
|
};
|
|
1924
|
+
},
|
|
1925
|
+
getFeatureBbox(feature) {
|
|
1926
|
+
const geometry = feature.geometry;
|
|
1927
|
+
if (!geometry || !geometry.coordinates) {
|
|
1928
|
+
return null;
|
|
1929
|
+
}
|
|
1930
|
+
const coords = geometry.coordinates;
|
|
1931
|
+
let minX = Infinity;
|
|
1932
|
+
let minY = Infinity;
|
|
1933
|
+
let maxX = -Infinity;
|
|
1934
|
+
let maxY = -Infinity;
|
|
1935
|
+
let hasCoordinates = false;
|
|
1936
|
+
function processCoordinates(coordsArray) {
|
|
1937
|
+
if (!Array.isArray(coordsArray)) return;
|
|
1938
|
+
if (typeof coordsArray[0] === "number") {
|
|
1939
|
+
const x = coordsArray[0];
|
|
1940
|
+
const y = coordsArray[1];
|
|
1941
|
+
if (typeof x === "number" && typeof y === "number") {
|
|
1942
|
+
minX = Math.min(minX, x);
|
|
1943
|
+
minY = Math.min(minY, y);
|
|
1944
|
+
maxX = Math.max(maxX, x);
|
|
1945
|
+
maxY = Math.max(maxY, y);
|
|
1946
|
+
hasCoordinates = true;
|
|
1947
|
+
}
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
for (let i = 0; i < coordsArray.length; i++) {
|
|
1951
|
+
processCoordinates(coordsArray[i]);
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
processCoordinates(coords);
|
|
1955
|
+
if (!hasCoordinates || minX === Infinity) {
|
|
1956
|
+
feature.bbox = void 0;
|
|
1957
|
+
return null;
|
|
1958
|
+
}
|
|
1959
|
+
feature.bbox = [minX, minY, maxX, maxY];
|
|
1960
|
+
return feature.bbox;
|
|
1961
|
+
},
|
|
1962
|
+
getFeatureCollectionBbox(featureCollection, recalculate = false) {
|
|
1963
|
+
if (!featureCollection || featureCollection.type !== "FeatureCollection" || !Array.isArray(featureCollection.features)) {
|
|
1964
|
+
throw new Error("无效的GeoJSON FeatureCollection数据");
|
|
1965
|
+
}
|
|
1966
|
+
if (featureCollection.bbox && !recalculate) {
|
|
1967
|
+
return featureCollection;
|
|
1968
|
+
}
|
|
1969
|
+
const features = featureCollection.features;
|
|
1970
|
+
if (features.length === 0) {
|
|
1971
|
+
featureCollection.bbox = void 0;
|
|
1972
|
+
return featureCollection;
|
|
1973
|
+
}
|
|
1974
|
+
let minX = Infinity;
|
|
1975
|
+
let minY = Infinity;
|
|
1976
|
+
let maxX = -Infinity;
|
|
1977
|
+
let maxY = -Infinity;
|
|
1978
|
+
let hasValidGeometry = false;
|
|
1979
|
+
for (let i = 0; i < features.length; i++) {
|
|
1980
|
+
const feature = features[i];
|
|
1981
|
+
const geometry = feature.geometry;
|
|
1982
|
+
if (!geometry || !geometry.coordinates || geometry.type === "GeometryCollection") {
|
|
1983
|
+
continue;
|
|
1984
|
+
}
|
|
1985
|
+
if (feature.bbox && !recalculate) {
|
|
1986
|
+
const [fx1, fy1, fx2, fy2] = feature.bbox;
|
|
1987
|
+
minX = Math.min(minX, fx1);
|
|
1988
|
+
minY = Math.min(minY, fy1);
|
|
1989
|
+
maxX = Math.max(maxX, fx2);
|
|
1990
|
+
maxY = Math.max(maxY, fy2);
|
|
1991
|
+
hasValidGeometry = true;
|
|
1992
|
+
continue;
|
|
1993
|
+
}
|
|
1994
|
+
const featureBbox = this.getFeatureBbox(feature);
|
|
1995
|
+
if (featureBbox) {
|
|
1996
|
+
const [fx1, fy1, fx2, fy2] = featureBbox;
|
|
1997
|
+
minX = Math.min(minX, fx1);
|
|
1998
|
+
minY = Math.min(minY, fy1);
|
|
1999
|
+
maxX = Math.max(maxX, fx2);
|
|
2000
|
+
maxY = Math.max(maxY, fy2);
|
|
2001
|
+
hasValidGeometry = true;
|
|
2002
|
+
feature.bbox = featureBbox;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
if (hasValidGeometry) {
|
|
2006
|
+
featureCollection.bbox = [minX, minY, maxX, maxY];
|
|
2007
|
+
} else {
|
|
2008
|
+
featureCollection.bbox = void 0;
|
|
2009
|
+
}
|
|
2010
|
+
return featureCollection.bbox;
|
|
1924
2011
|
}
|
|
1925
2012
|
};
|
|
1926
2013
|
const MathUtil = {
|