@trackunit/geo-json-utils 1.14.22 → 1.14.26-alpha-27ad777c16e.0

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/index.cjs.js CHANGED
@@ -1519,6 +1519,33 @@ const tuGeoJsonRectangularBoxPolygonSchema = zod.z
1519
1519
  }
1520
1520
  });
1521
1521
 
1522
+ const DEG_TO_RAD = Math.PI / 180;
1523
+ /**
1524
+ * Compute the pixel length of a line segment at a given zoom level,
1525
+ * accounting for Web Mercator latitude distortion.
1526
+ *
1527
+ * Web Mercator tile math: worldSize = tileSize * 2^zoom pixels for 360 degrees of longitude.
1528
+ * Latitude pixels scale by sec(lat).
1529
+ *
1530
+ * Relocated from `@trackunit/react-map` (per ADR-0018 follow-up) since this is pure
1531
+ * Mercator math with no React or DS semantics — appropriate for a vanilla geo utility lib.
1532
+ *
1533
+ * @param x0 - Start longitude (degrees)
1534
+ * @param y0 - Start latitude (degrees)
1535
+ * @param x1 - End longitude (degrees)
1536
+ * @param y1 - End latitude (degrees)
1537
+ * @param zoom - Map zoom level
1538
+ * @param midLatDeg - Mid-point latitude for distortion correction (degrees)
1539
+ * @param tileSize - Tile size in pixels (default 256)
1540
+ */
1541
+ const edgePixelLength = (x0, y0, x1, y1, zoom, midLatDeg, tileSize = 256) => {
1542
+ const pxPerDeg = (tileSize * Math.pow(2, zoom)) / 360;
1543
+ const secLat = 1 / Math.cos(midLatDeg * DEG_TO_RAD);
1544
+ const dxPx = (x1 - x0) * pxPerDeg;
1545
+ const dyPx = (y1 - y0) * pxPerDeg * secLat;
1546
+ return Math.sqrt(dxPx * dxPx + dyPx * dyPx);
1547
+ };
1548
+
1522
1549
  exports.EARTH_RADIUS = EARTH_RADIUS;
1523
1550
  exports.EMPTY_FEATURE_COLLECTION = EMPTY_FEATURE_COLLECTION;
1524
1551
  exports.boundingBoxCrossesMeridian = boundingBoxCrossesMeridian;
@@ -1526,6 +1553,7 @@ exports.checkCrossesMeridian = checkCrossesMeridian;
1526
1553
  exports.computeGeometryCentroid = computeGeometryCentroid;
1527
1554
  exports.coordinatesToStandardFormat = coordinatesToStandardFormat;
1528
1555
  exports.denormalizeLongitude = denormalizeLongitude;
1556
+ exports.edgePixelLength = edgePixelLength;
1529
1557
  exports.extractEdges = extractEdges;
1530
1558
  exports.extractFirstPointCoordinate = extractFirstPointCoordinate;
1531
1559
  exports.extractPositionsFromGeometry = extractPositionsFromGeometry;
package/index.esm.js CHANGED
@@ -1517,4 +1517,31 @@ const tuGeoJsonRectangularBoxPolygonSchema = z
1517
1517
  }
1518
1518
  });
1519
1519
 
1520
- export { EARTH_RADIUS, EMPTY_FEATURE_COLLECTION, boundingBoxCrossesMeridian, checkCrossesMeridian, computeGeometryCentroid, coordinatesToStandardFormat, denormalizeLongitude, extractEdges, extractFirstPointCoordinate, extractPositionsFromGeometry, geoJsonBboxSchema, geoJsonFeatureCollectionSchema, geoJsonFeatureSchema, geoJsonGeometryCollectionSchema, geoJsonGeometrySchema, geoJsonLineStringSchema, geoJsonLinearRingSchema, geoJsonMultiLineStringSchema, geoJsonMultiPointSchema, geoJsonMultiPolygonSchema, geoJsonPointSchema, geoJsonPolygonSchema, geoJsonPosition2dSchema, geoJsonPositionSchema, getBboxFromGeoJsonPolygon, getBoundingBoxFromGeoJsonBbox, getBoundingBoxFromGeoJsonPolygon, getExtremeGeoJsonPointFromPolygon, getGeoJsonPolygonFromBoundingBox, getGeoJsonPolygonIntersection, getMinMaxLongitudes, getMultipleCoordinatesFromGeoJsonObject, getPointCoordinateFromGeoJsonObject, getPointCoordinateFromGeoJsonPoint, getPolygonFromBbox, getPolygonFromPointAndRadius, isBboxInsideFeatureCollection, isFullyContainedInGeoJsonPolygon, isGeoJsonPointInPolygon, isGeoJsonPositionInLinearRing, isPositionInsideRing, normalizeLongitudes, splitPolygonAtAntimeridian, splitPolygonWithHolesAtAntimeridian, toFeatureCollection, toPosition2d, tuGeoJsonPointRadiusSchema, tuGeoJsonPolygonNoHolesSchema, tuGeoJsonRectangularBoxPolygonSchema, validateBbox, validateBboxWithFallback, validateFeatureCollection, validatePosition };
1520
+ const DEG_TO_RAD = Math.PI / 180;
1521
+ /**
1522
+ * Compute the pixel length of a line segment at a given zoom level,
1523
+ * accounting for Web Mercator latitude distortion.
1524
+ *
1525
+ * Web Mercator tile math: worldSize = tileSize * 2^zoom pixels for 360 degrees of longitude.
1526
+ * Latitude pixels scale by sec(lat).
1527
+ *
1528
+ * Relocated from `@trackunit/react-map` (per ADR-0018 follow-up) since this is pure
1529
+ * Mercator math with no React or DS semantics — appropriate for a vanilla geo utility lib.
1530
+ *
1531
+ * @param x0 - Start longitude (degrees)
1532
+ * @param y0 - Start latitude (degrees)
1533
+ * @param x1 - End longitude (degrees)
1534
+ * @param y1 - End latitude (degrees)
1535
+ * @param zoom - Map zoom level
1536
+ * @param midLatDeg - Mid-point latitude for distortion correction (degrees)
1537
+ * @param tileSize - Tile size in pixels (default 256)
1538
+ */
1539
+ const edgePixelLength = (x0, y0, x1, y1, zoom, midLatDeg, tileSize = 256) => {
1540
+ const pxPerDeg = (tileSize * Math.pow(2, zoom)) / 360;
1541
+ const secLat = 1 / Math.cos(midLatDeg * DEG_TO_RAD);
1542
+ const dxPx = (x1 - x0) * pxPerDeg;
1543
+ const dyPx = (y1 - y0) * pxPerDeg * secLat;
1544
+ return Math.sqrt(dxPx * dxPx + dyPx * dyPx);
1545
+ };
1546
+
1547
+ export { EARTH_RADIUS, EMPTY_FEATURE_COLLECTION, boundingBoxCrossesMeridian, checkCrossesMeridian, computeGeometryCentroid, coordinatesToStandardFormat, denormalizeLongitude, edgePixelLength, extractEdges, extractFirstPointCoordinate, extractPositionsFromGeometry, geoJsonBboxSchema, geoJsonFeatureCollectionSchema, geoJsonFeatureSchema, geoJsonGeometryCollectionSchema, geoJsonGeometrySchema, geoJsonLineStringSchema, geoJsonLinearRingSchema, geoJsonMultiLineStringSchema, geoJsonMultiPointSchema, geoJsonMultiPolygonSchema, geoJsonPointSchema, geoJsonPolygonSchema, geoJsonPosition2dSchema, geoJsonPositionSchema, getBboxFromGeoJsonPolygon, getBoundingBoxFromGeoJsonBbox, getBoundingBoxFromGeoJsonPolygon, getExtremeGeoJsonPointFromPolygon, getGeoJsonPolygonFromBoundingBox, getGeoJsonPolygonIntersection, getMinMaxLongitudes, getMultipleCoordinatesFromGeoJsonObject, getPointCoordinateFromGeoJsonObject, getPointCoordinateFromGeoJsonPoint, getPolygonFromBbox, getPolygonFromPointAndRadius, isBboxInsideFeatureCollection, isFullyContainedInGeoJsonPolygon, isGeoJsonPointInPolygon, isGeoJsonPositionInLinearRing, isPositionInsideRing, normalizeLongitudes, splitPolygonAtAntimeridian, splitPolygonWithHolesAtAntimeridian, toFeatureCollection, toPosition2d, tuGeoJsonPointRadiusSchema, tuGeoJsonPolygonNoHolesSchema, tuGeoJsonRectangularBoxPolygonSchema, validateBbox, validateBboxWithFallback, validateFeatureCollection, validatePosition };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/geo-json-utils",
3
- "version": "1.14.22",
3
+ "version": "1.14.26-alpha-27ad777c16e.0",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Compute the pixel length of a line segment at a given zoom level,
3
+ * accounting for Web Mercator latitude distortion.
4
+ *
5
+ * Web Mercator tile math: worldSize = tileSize * 2^zoom pixels for 360 degrees of longitude.
6
+ * Latitude pixels scale by sec(lat).
7
+ *
8
+ * Relocated from `@trackunit/react-map` (per ADR-0018 follow-up) since this is pure
9
+ * Mercator math with no React or DS semantics — appropriate for a vanilla geo utility lib.
10
+ *
11
+ * @param x0 - Start longitude (degrees)
12
+ * @param y0 - Start latitude (degrees)
13
+ * @param x1 - End longitude (degrees)
14
+ * @param y1 - End latitude (degrees)
15
+ * @param zoom - Map zoom level
16
+ * @param midLatDeg - Mid-point latitude for distortion correction (degrees)
17
+ * @param tileSize - Tile size in pixels (default 256)
18
+ */
19
+ export declare const edgePixelLength: (x0: number, y0: number, x1: number, y1: number, zoom: number, midLatDeg: number, tileSize?: number) => number;
package/src/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from "./MeridianUtils";
6
6
  export * from "./TuGeoJsonBridgeUtils";
7
7
  export * from "./TuGeoJsonConversions";
8
8
  export * from "./TuGeoJsonSchemas";
9
+ export * from "./WebMercatorUtils";