@math.gl/geospatial 5.0.0-beta.8 → 5.0.0-rc.1
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/README.md +3 -3
- package/dist/crs/crs-descriptor-types.d.ts +2 -1
- package/dist/crs/crs-descriptor-types.d.ts.map +1 -1
- package/dist/crs/index.cjs +54 -0
- package/dist/crs/index.cjs.map +2 -2
- package/dist/crs/index.d.ts +1 -0
- package/dist/crs/index.d.ts.map +1 -1
- package/dist/crs/index.js +1 -0
- package/dist/crs/index.js.map +1 -1
- package/dist/crs/spatial-reference-metadata.d.ts +20 -0
- package/dist/crs/spatial-reference-metadata.d.ts.map +1 -0
- package/dist/crs/spatial-reference-metadata.js +86 -0
- package/dist/crs/spatial-reference-metadata.js.map +1 -0
- package/dist/ellipsoid-helpers/ellipsoid-transform.d.ts +1 -1
- package/dist/ellipsoid-helpers/ellipsoid-transform.d.ts.map +1 -1
- package/dist/ellipsoid-helpers/ellipsoid-transform.js +2 -2
- package/dist/ellipsoid-helpers/ellipsoid-transform.js.map +1 -1
- package/dist/ellipsoid-helpers/scale-to-geodetic-surface.js +1 -1
- package/dist/ellipsoid-helpers/scale-to-geodetic-surface.js.map +1 -1
- package/dist/ellipsoid-helpers/tangent-plane-numerics.d.ts +1 -1
- package/dist/ellipsoid-helpers/tangent-plane-numerics.d.ts.map +1 -1
- package/dist/ellipsoid-tangent-plane.d.ts +2 -2
- package/dist/ellipsoid-tangent-plane.d.ts.map +1 -1
- package/dist/ellipsoid-tangent-plane.js +1 -1
- package/dist/ellipsoid-tangent-plane.js.map +1 -1
- package/dist/ellipsoid-transforms.d.ts +2 -2
- package/dist/ellipsoid-transforms.d.ts.map +1 -1
- package/dist/ellipsoid-transforms.js +1 -1
- package/dist/ellipsoid-transforms.js.map +1 -1
- package/dist/ellipsoid.d.ts +2 -2
- package/dist/ellipsoid.d.ts.map +1 -1
- package/dist/ellipsoid.js +2 -2
- package/dist/ellipsoid.js.map +1 -1
- package/dist/expressions.d.ts +1 -1
- package/dist/expressions.d.ts.map +1 -1
- package/dist/expressions.js +1 -1
- package/dist/expressions.js.map +1 -1
- package/dist/geodesic-buffer.d.ts +1 -1
- package/dist/geodesic-buffer.d.ts.map +1 -1
- package/dist/geodesic-path.d.ts +1 -1
- package/dist/geodesic-path.d.ts.map +1 -1
- package/dist/geometry-constructors.d.ts +6 -0
- package/dist/geometry-constructors.d.ts.map +1 -0
- package/dist/geometry-constructors.js +37 -0
- package/dist/geometry-constructors.js.map +1 -0
- package/dist/geometry-inspection.d.ts +8 -0
- package/dist/geometry-inspection.d.ts.map +1 -0
- package/dist/geometry-inspection.js +61 -0
- package/dist/geometry-inspection.js.map +1 -0
- package/dist/index.cjs +3773 -846
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +173 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +115 -0
- package/dist/index.js.map +1 -1
- package/dist/line-simplification.d.ts +4 -0
- package/dist/line-simplification.d.ts.map +1 -0
- package/dist/line-simplification.js +83 -0
- package/dist/line-simplification.js.map +1 -0
- package/dist/linear-referencing.d.ts +6 -0
- package/dist/linear-referencing.d.ts.map +1 -0
- package/dist/linear-referencing.js +74 -0
- package/dist/linear-referencing.js.map +1 -0
- package/dist/lng-lat-rectangle.d.ts +1 -1
- package/dist/lng-lat-rectangle.d.ts.map +1 -1
- package/dist/lng-lat-rectangle.js +1 -1
- package/dist/lng-lat-rectangle.js.map +1 -1
- package/dist/local-reference-frame.d.ts +3 -3
- package/dist/local-reference-frame.d.ts.map +1 -1
- package/dist/local-reference-frame.js +2 -2
- package/dist/local-reference-frame.js.map +1 -1
- package/dist/make-obb-from-region.d.ts +1 -1
- package/dist/make-obb-from-region.d.ts.map +1 -1
- package/dist/make-obb-from-region.js +1 -1
- package/dist/make-obb-from-region.js.map +1 -1
- package/dist/maps/air-ocean-mesh.js +1 -1
- package/dist/maps/air-ocean-mesh.js.map +1 -1
- package/dist/maps/myriahedral/unfold.d.ts +1 -1
- package/dist/maps/myriahedral/unfold.d.ts.map +1 -1
- package/dist/maps/myriahedral/unfold.js +1 -1
- package/dist/maps/myriahedral/unfold.js.map +1 -1
- package/dist/maps/presets.cjs +6 -6
- package/dist/maps/presets.cjs.map +2 -2
- package/dist/maps.cjs +6 -6
- package/dist/maps.cjs.map +2 -2
- package/dist/projection/deformation.cjs +5 -5
- package/dist/projection/deformation.cjs.map +2 -2
- package/dist/projection/experimental/core.cjs +8 -4
- package/dist/projection/experimental/core.cjs.map +1 -1
- package/dist/projection/experimental/crs/spatial-reference.d.ts.map +1 -1
- package/dist/projection/experimental/crs/spatial-reference.js.map +1 -1
- package/dist/projection/experimental/crs/types.d.ts +1 -1
- package/dist/projection/experimental/crs/types.d.ts.map +1 -1
- package/dist/projection/experimental/crs-rendering-scale.d.ts.map +1 -1
- package/dist/projection/experimental/crs-rendering-scale.js +13 -2
- package/dist/projection/experimental/crs-rendering-scale.js.map +1 -1
- package/dist/projection/experimental/datum.js +1 -1
- package/dist/projection/experimental/datum.js.map +1 -1
- package/dist/projection/experimental/entries/projections/geocent.cjs +3 -3
- package/dist/projection/experimental/entries/projections/geocent.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/aea.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/aea.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/aea.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/aea.js +4 -1
- package/dist/projection/experimental/lazy-projections/aea.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/bonne.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/bonne.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/bonne.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/bonne.js +4 -1
- package/dist/projection/experimental/lazy-projections/bonne.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/cass.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/cass.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/cass.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/cass.js +4 -1
- package/dist/projection/experimental/lazy-projections/cass.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/eck6.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/eck6.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/eck6.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/eck6.js +4 -1
- package/dist/projection/experimental/lazy-projections/eck6.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqdc.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/eqdc.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqdc.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqdc.js +4 -1
- package/dist/projection/experimental/lazy-projections/eqdc.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqearth.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/eqearth.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqearth.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqearth.js +4 -1
- package/dist/projection/experimental/lazy-projections/eqearth.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/equi.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/equi.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/equi.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/equi.js +4 -1
- package/dist/projection/experimental/lazy-projections/equi.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/geocent.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/geocent.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/geocent.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/geocent.js +4 -1
- package/dist/projection/experimental/lazy-projections/geocent.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/geos.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/geos.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/geos.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/geos.js +4 -1
- package/dist/projection/experimental/lazy-projections/geos.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/gnom.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/gnom.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/gnom.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/gnom.js +4 -1
- package/dist/projection/experimental/lazy-projections/gnom.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/index.cjs +100 -27
- package/dist/projection/experimental/lazy-projections/index.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/krovak.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/krovak.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/krovak.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/krovak.js +4 -1
- package/dist/projection/experimental/lazy-projections/krovak.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/merc.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/merc.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/merc.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/merc.js +4 -1
- package/dist/projection/experimental/lazy-projections/merc.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/mill.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/mill.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/mill.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/mill.js +4 -1
- package/dist/projection/experimental/lazy-projections/mill.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/moll.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/moll.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/moll.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/moll.js +4 -1
- package/dist/projection/experimental/lazy-projections/moll.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/nzmg.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/nzmg.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/nzmg.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/nzmg.js +4 -1
- package/dist/projection/experimental/lazy-projections/nzmg.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/omerc.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/omerc.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/omerc.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/omerc.js +4 -1
- package/dist/projection/experimental/lazy-projections/omerc.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/ortho.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/ortho.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/ortho.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/ortho.js +4 -1
- package/dist/projection/experimental/lazy-projections/ortho.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/poly.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/poly.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/poly.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/poly.js +4 -1
- package/dist/projection/experimental/lazy-projections/poly.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/robin.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/robin.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/robin.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/robin.js +4 -1
- package/dist/projection/experimental/lazy-projections/robin.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/sinu.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/sinu.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/sinu.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/sinu.js +4 -1
- package/dist/projection/experimental/lazy-projections/sinu.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/stere.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/stere.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/stere.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/stere.js +4 -1
- package/dist/projection/experimental/lazy-projections/stere.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/tpers.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/tpers.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/tpers.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/tpers.js +4 -1
- package/dist/projection/experimental/lazy-projections/tpers.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/vandg.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/vandg.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/vandg.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/vandg.js +4 -1
- package/dist/projection/experimental/lazy-projections/vandg.js.map +1 -1
- package/dist/projection/experimental/spatial-deformation.js +1 -1
- package/dist/projection/experimental/spatial-deformation.js.map +1 -1
- package/dist/projection/index.cjs +8 -4
- package/dist/projection/index.cjs.map +1 -1
- package/dist/projection/index.d.ts.map +1 -1
- package/dist/projection/index.js.map +1 -1
- package/dist/projection/lib/projection.js.map +1 -1
- package/dist/projection/pipeline.cjs +3 -3
- package/dist/projection/pipeline.cjs.map +1 -1
- package/dist/projection/temporal.cjs +5 -5
- package/dist/projection/temporal.cjs.map +2 -2
- package/dist/projection/transform-analysis.cjs +3 -3
- package/dist/projection/transform-analysis.cjs.map +1 -1
- package/dist/rhumb-path.d.ts +1 -1
- package/dist/rhumb-path.d.ts.map +1 -1
- package/dist/spatial-planar-intersects.d.ts +4 -0
- package/dist/spatial-planar-intersects.d.ts.map +1 -0
- package/dist/spatial-planar-intersects.js +108 -0
- package/dist/spatial-planar-intersects.js.map +1 -0
- package/dist/spatial-planar.d.ts +16 -0
- package/dist/spatial-planar.d.ts.map +1 -0
- package/dist/spatial-planar.js +240 -0
- package/dist/spatial-planar.js.map +1 -0
- package/dist/spatial-sql.d.ts +45 -0
- package/dist/spatial-sql.d.ts.map +1 -0
- package/dist/spatial-sql.js +192 -0
- package/dist/spatial-sql.js.map +1 -0
- package/dist/st-functions.cjs +1616 -0
- package/dist/st-functions.cjs.map +6 -0
- package/dist/st-functions.d.ts +307 -0
- package/dist/st-functions.d.ts.map +1 -0
- package/dist/st-functions.js +593 -0
- package/dist/st-functions.js.map +1 -0
- package/dist/subdivide-globe-mesh.js +1 -1
- package/dist/subdivide-globe-mesh.js.map +1 -1
- package/dist/tasks/index.cjs +1266 -155
- package/dist/tasks/index.cjs.map +3 -3
- package/dist/tasks/index.d.ts +12 -0
- package/dist/tasks/index.d.ts.map +1 -1
- package/dist/tasks/index.js +26 -0
- package/dist/tasks/index.js.map +1 -1
- package/dist/tasks/terrain-coverage-worker.d.ts +2 -0
- package/dist/tasks/terrain-coverage-worker.d.ts.map +1 -0
- package/dist/tasks/terrain-coverage-worker.js +7 -0
- package/dist/tasks/terrain-coverage-worker.js.map +1 -0
- package/dist/tasks/terrain-coverage.d.ts +25 -0
- package/dist/tasks/terrain-coverage.d.ts.map +1 -0
- package/dist/tasks/terrain-coverage.js +15 -0
- package/dist/tasks/terrain-coverage.js.map +1 -0
- package/dist/tasks/terrain-residency-worker.d.ts +2 -0
- package/dist/tasks/terrain-residency-worker.d.ts.map +1 -0
- package/dist/tasks/terrain-residency-worker.js +7 -0
- package/dist/tasks/terrain-residency-worker.js.map +1 -0
- package/dist/tasks/terrain-residency.d.ts +73 -0
- package/dist/tasks/terrain-residency.d.ts.map +1 -0
- package/dist/tasks/terrain-residency.js +203 -0
- package/dist/tasks/terrain-residency.js.map +1 -0
- package/dist/terrain/breakline-mesh.d.ts +18 -0
- package/dist/terrain/breakline-mesh.d.ts.map +1 -0
- package/dist/terrain/breakline-mesh.js +126 -0
- package/dist/terrain/breakline-mesh.js.map +1 -0
- package/dist/terrain/breakline-preprocess.d.ts +11 -0
- package/dist/terrain/breakline-preprocess.d.ts.map +1 -0
- package/dist/terrain/breakline-preprocess.js +94 -0
- package/dist/terrain/breakline-preprocess.js.map +1 -0
- package/dist/terrain/continuous-mesh-error.d.ts +34 -0
- package/dist/terrain/continuous-mesh-error.d.ts.map +1 -0
- package/dist/terrain/continuous-mesh-error.js +221 -0
- package/dist/terrain/continuous-mesh-error.js.map +1 -0
- package/dist/terrain/cutout-polygons.d.ts +21 -0
- package/dist/terrain/cutout-polygons.d.ts.map +1 -0
- package/dist/terrain/cutout-polygons.js +172 -0
- package/dist/terrain/cutout-polygons.js.map +1 -0
- package/dist/terrain/cutout-region.d.ts +34 -0
- package/dist/terrain/cutout-region.d.ts.map +1 -0
- package/dist/terrain/cutout-region.js +33 -0
- package/dist/terrain/cutout-region.js.map +1 -0
- package/dist/terrain/cutout-skirts.d.ts +34 -0
- package/dist/terrain/cutout-skirts.d.ts.map +1 -0
- package/dist/terrain/cutout-skirts.js +29 -0
- package/dist/terrain/cutout-skirts.js.map +1 -0
- package/dist/terrain/depression-fill.d.ts +25 -0
- package/dist/terrain/depression-fill.d.ts.map +1 -0
- package/dist/terrain/depression-fill.js +106 -0
- package/dist/terrain/depression-fill.js.map +1 -0
- package/dist/terrain/geographic-cutout.d.ts +38 -0
- package/dist/terrain/geographic-cutout.d.ts.map +1 -0
- package/dist/terrain/geographic-cutout.js +120 -0
- package/dist/terrain/geographic-cutout.js.map +1 -0
- package/dist/terrain/geographic-lod-seams.d.ts +10 -0
- package/dist/terrain/geographic-lod-seams.d.ts.map +1 -0
- package/dist/terrain/geographic-lod-seams.js +100 -0
- package/dist/terrain/geographic-lod-seams.js.map +1 -0
- package/dist/terrain/geographic-neighbor.d.ts +18 -0
- package/dist/terrain/geographic-neighbor.d.ts.map +1 -0
- package/dist/terrain/geographic-neighbor.js +44 -0
- package/dist/terrain/geographic-neighbor.js.map +1 -0
- package/dist/terrain/geographic-poles.d.ts +24 -0
- package/dist/terrain/geographic-poles.d.ts.map +1 -0
- package/dist/terrain/geographic-poles.js +34 -0
- package/dist/terrain/geographic-poles.js.map +1 -0
- package/dist/terrain/geographic-seam.d.ts +21 -0
- package/dist/terrain/geographic-seam.d.ts.map +1 -0
- package/dist/terrain/geographic-seam.js +52 -0
- package/dist/terrain/geographic-seam.js.map +1 -0
- package/dist/terrain/hydrology.d.ts +42 -0
- package/dist/terrain/hydrology.d.ts.map +1 -0
- package/dist/terrain/hydrology.js +112 -0
- package/dist/terrain/hydrology.js.map +1 -0
- package/dist/terrain/index.cjs +3158 -213
- package/dist/terrain/index.cjs.map +3 -3
- package/dist/terrain/index.d.ts +32 -0
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js +30 -0
- package/dist/terrain/index.js.map +1 -1
- package/dist/terrain/lod-screen-error.d.ts +28 -0
- package/dist/terrain/lod-screen-error.d.ts.map +1 -0
- package/dist/terrain/lod-screen-error.js +95 -0
- package/dist/terrain/lod-screen-error.js.map +1 -0
- package/dist/terrain/lod-select.d.ts +48 -0
- package/dist/terrain/lod-select.d.ts.map +1 -0
- package/dist/terrain/lod-select.js +73 -0
- package/dist/terrain/lod-select.js.map +1 -0
- package/dist/terrain/lod-stitch.d.ts +15 -0
- package/dist/terrain/lod-stitch.d.ts.map +1 -0
- package/dist/terrain/lod-stitch.js +64 -0
- package/dist/terrain/lod-stitch.js.map +1 -0
- package/dist/terrain/mesh-coverage.d.ts +35 -0
- package/dist/terrain/mesh-coverage.d.ts.map +1 -0
- package/dist/terrain/mesh-coverage.js +186 -0
- package/dist/terrain/mesh-coverage.js.map +1 -0
- package/dist/terrain/mesh-cutout.d.ts +45 -0
- package/dist/terrain/mesh-cutout.d.ts.map +1 -0
- package/dist/terrain/mesh-cutout.js +336 -0
- package/dist/terrain/mesh-cutout.js.map +1 -0
- package/dist/terrain/mesh-regions-data.d.ts +2 -2
- package/dist/terrain/mesh-regions-data.d.ts.map +1 -1
- package/dist/terrain/mesh-regions-data.js +20 -10
- package/dist/terrain/mesh-regions-data.js.map +1 -1
- package/dist/terrain/mesh-skirts.d.ts +8 -2
- package/dist/terrain/mesh-skirts.d.ts.map +1 -1
- package/dist/terrain/mesh-skirts.js +5 -4
- package/dist/terrain/mesh-skirts.js.map +1 -1
- package/dist/terrain/mixed-halo-update.d.ts.map +1 -1
- package/dist/terrain/mixed-halo-update.js +138 -26
- package/dist/terrain/mixed-halo-update.js.map +1 -1
- package/dist/terrain/mixed-vertex-halos.d.ts +34 -1
- package/dist/terrain/mixed-vertex-halos.d.ts.map +1 -1
- package/dist/terrain/mixed-vertex-halos.js +98 -43
- package/dist/terrain/mixed-vertex-halos.js.map +1 -1
- package/dist/terrain/regional-viewshed.d.ts +55 -0
- package/dist/terrain/regional-viewshed.d.ts.map +1 -0
- package/dist/terrain/regional-viewshed.js +119 -0
- package/dist/terrain/regional-viewshed.js.map +1 -0
- package/dist/terrain/surface.d.ts +1 -1
- package/dist/terrain/surface.d.ts.map +1 -1
- package/dist/terrain/surface.js +1 -1
- package/dist/terrain/surface.js.map +1 -1
- package/dist/terrain/sweep-capsule.d.ts +27 -0
- package/dist/terrain/sweep-capsule.d.ts.map +1 -0
- package/dist/terrain/sweep-capsule.js +104 -0
- package/dist/terrain/sweep-capsule.js.map +1 -0
- package/dist/terrain/sweep-cylinder.d.ts +16 -0
- package/dist/terrain/sweep-cylinder.d.ts.map +1 -0
- package/dist/terrain/sweep-cylinder.js +52 -0
- package/dist/terrain/sweep-cylinder.js.map +1 -0
- package/dist/terrain/sweep-plane.d.ts +9 -0
- package/dist/terrain/sweep-plane.d.ts.map +1 -0
- package/dist/terrain/sweep-plane.js +52 -0
- package/dist/terrain/sweep-plane.js.map +1 -0
- package/dist/terrain/sweep-polytope.d.ts +42 -0
- package/dist/terrain/sweep-polytope.d.ts.map +1 -0
- package/dist/terrain/sweep-polytope.js +189 -0
- package/dist/terrain/sweep-polytope.js.map +1 -0
- package/dist/terrain/sweep-rotating-capsule.d.ts +17 -0
- package/dist/terrain/sweep-rotating-capsule.d.ts.map +1 -0
- package/dist/terrain/sweep-rotating-capsule.js +118 -0
- package/dist/terrain/sweep-rotating-capsule.js.map +1 -0
- package/dist/terrain/sweep-rotation.d.ts +35 -0
- package/dist/terrain/sweep-rotation.d.ts.map +1 -0
- package/dist/terrain/sweep-rotation.js +114 -0
- package/dist/terrain/sweep-rotation.js.map +1 -0
- package/dist/terrain/sweep-sphere.d.ts +27 -0
- package/dist/terrain/sweep-sphere.d.ts.map +1 -0
- package/dist/terrain/sweep-sphere.js +69 -0
- package/dist/terrain/sweep-sphere.js.map +1 -0
- package/dist/terrain/tile-cutout-update.d.ts +73 -0
- package/dist/terrain/tile-cutout-update.d.ts.map +1 -0
- package/dist/terrain/tile-cutout-update.js +181 -0
- package/dist/terrain/tile-cutout-update.js.map +1 -0
- package/dist/terrain/tile-cutout.d.ts +33 -0
- package/dist/terrain/tile-cutout.d.ts.map +1 -0
- package/dist/terrain/tile-cutout.js +93 -0
- package/dist/terrain/tile-cutout.js.map +1 -0
- package/dist/terrain/valid-domain-mesh.d.ts +29 -0
- package/dist/terrain/valid-domain-mesh.d.ts.map +1 -0
- package/dist/terrain/valid-domain-mesh.js +183 -0
- package/dist/terrain/valid-domain-mesh.js.map +1 -0
- package/dist/terrain/valid-domain-regions.d.ts +16 -0
- package/dist/terrain/valid-domain-regions.d.ts.map +1 -0
- package/dist/terrain/valid-domain-regions.js +19 -0
- package/dist/terrain/valid-domain-regions.js.map +1 -0
- package/dist/terrain/watershed-accumulation.d.ts +20 -0
- package/dist/terrain/watershed-accumulation.d.ts.map +1 -0
- package/dist/terrain/watershed-accumulation.js +53 -0
- package/dist/terrain/watershed-accumulation.js.map +1 -0
- package/dist/triaxial.d.ts +1 -1
- package/dist/triaxial.d.ts.map +1 -1
- package/dist/turf-expressions.cjs +1997 -0
- package/dist/turf-expressions.cjs.map +6 -0
- package/dist/turf-expressions.d.ts +3 -0
- package/dist/turf-expressions.d.ts.map +1 -0
- package/dist/turf-expressions.js +7 -0
- package/dist/turf-expressions.js.map +1 -0
- package/dist/turf-functions.cjs +743 -0
- package/dist/turf-functions.cjs.map +6 -0
- package/dist/turf-functions.d.ts +90 -0
- package/dist/turf-functions.d.ts.map +1 -0
- package/dist/{turf/expressions.js → turf-functions.js} +51 -5
- package/dist/turf-functions.js.map +1 -0
- package/dist/turf.cjs +25 -25
- package/dist/turf.cjs.map +2 -2
- package/dist/turf.d.ts +1 -1
- package/dist/turf.d.ts.map +1 -1
- package/dist/turf.js +2 -2
- package/dist/turf.js.map +1 -1
- package/dist/type-utils.d.ts +1 -1
- package/dist/type-utils.d.ts.map +1 -1
- package/dist/type-utils.js +1 -1
- package/dist/type-utils.js.map +1 -1
- package/dist/web-mercator/assert.d.ts +2 -0
- package/dist/web-mercator/assert.d.ts.map +1 -0
- package/dist/web-mercator/assert.js +12 -0
- package/dist/web-mercator/assert.js.map +1 -0
- package/dist/web-mercator/fit-bounds.d.ts +52 -0
- package/dist/web-mercator/fit-bounds.d.ts.map +1 -0
- package/dist/web-mercator/fit-bounds.js +70 -0
- package/dist/web-mercator/fit-bounds.js.map +1 -0
- package/dist/web-mercator/fly-to-viewport.d.ts +19 -0
- package/dist/web-mercator/fly-to-viewport.d.ts.map +1 -0
- package/dist/web-mercator/fly-to-viewport.js +94 -0
- package/dist/web-mercator/fly-to-viewport.js.map +1 -0
- package/dist/web-mercator/get-bounds.d.ts +3 -0
- package/dist/web-mercator/get-bounds.d.ts.map +1 -0
- package/dist/web-mercator/get-bounds.js +56 -0
- package/dist/web-mercator/get-bounds.js.map +1 -0
- package/dist/web-mercator/index.cjs +705 -0
- package/dist/web-mercator/index.cjs.map +6 -0
- package/dist/web-mercator/index.d.ts +14 -0
- package/dist/web-mercator/index.d.ts.map +1 -0
- package/dist/web-mercator/index.js +14 -0
- package/dist/web-mercator/index.js.map +1 -0
- package/dist/web-mercator/math-utils.d.ts +7 -0
- package/dist/web-mercator/math-utils.d.ts.map +1 -0
- package/dist/web-mercator/math-utils.js +30 -0
- package/dist/web-mercator/math-utils.js.map +1 -0
- package/dist/web-mercator/mercator-meters.d.ts +29 -0
- package/dist/web-mercator/mercator-meters.d.ts.map +1 -0
- package/dist/web-mercator/mercator-meters.js +61 -0
- package/dist/web-mercator/mercator-meters.js.map +1 -0
- package/dist/web-mercator/normalize-viewport-props.d.ts +16 -0
- package/dist/web-mercator/normalize-viewport-props.d.ts.map +1 -0
- package/dist/web-mercator/normalize-viewport-props.js +45 -0
- package/dist/web-mercator/normalize-viewport-props.js.map +1 -0
- package/dist/web-mercator/web-mercator-utils.d.ts +192 -0
- package/dist/web-mercator/web-mercator-utils.d.ts.map +1 -0
- package/dist/web-mercator/web-mercator-utils.js +321 -0
- package/dist/web-mercator/web-mercator-utils.js.map +1 -0
- package/dist/web-mercator/web-mercator-viewport.d.ts +177 -0
- package/dist/web-mercator/web-mercator-viewport.d.ts.map +1 -0
- package/dist/web-mercator/web-mercator-viewport.js +276 -0
- package/dist/web-mercator/web-mercator-viewport.js.map +1 -0
- package/dist/web-mercator.d.ts +1 -1
- package/dist/web-mercator.d.ts.map +1 -1
- package/dist/web-mercator.js +1 -1
- package/dist/web-mercator.js.map +1 -1
- package/package.json +35 -462
- package/src/crs/crs-descriptor-types.ts +2 -1
- package/src/crs/index.ts +7 -0
- package/src/crs/spatial-reference-metadata.ts +118 -0
- package/src/ellipsoid-helpers/ellipsoid-transform.ts +3 -3
- package/src/ellipsoid-helpers/scale-to-geodetic-surface.ts +1 -1
- package/src/ellipsoid-helpers/tangent-plane-numerics.ts +1 -1
- package/src/ellipsoid-tangent-plane.ts +2 -2
- package/src/ellipsoid-transforms.ts +2 -2
- package/src/ellipsoid.ts +7 -3
- package/src/expressions.ts +2 -2
- package/src/geodesic-buffer.ts +1 -1
- package/src/geodesic-path.ts +1 -1
- package/src/geometry-constructors.ts +36 -0
- package/src/geometry-inspection.ts +66 -0
- package/src/index.ts +314 -4
- package/src/line-simplification.ts +97 -0
- package/src/linear-referencing.ts +94 -0
- package/src/lng-lat-rectangle.ts +1 -1
- package/src/local-reference-frame.ts +4 -4
- package/src/make-obb-from-region.ts +9 -1
- package/src/maps/air-ocean-mesh.ts +1 -1
- package/src/maps/myriahedral/unfold.ts +1 -1
- package/src/projection/experimental/crs/spatial-reference.ts +1 -6
- package/src/projection/experimental/crs/types.ts +2 -2
- package/src/projection/experimental/crs/wkt.ts +1 -1
- package/src/projection/experimental/crs-descriptor.ts +1 -1
- package/src/projection/experimental/crs-rendering-scale.ts +16 -4
- package/src/projection/experimental/datum.ts +1 -1
- package/src/projection/experimental/lazy-projections/aea.ts +4 -1
- package/src/projection/experimental/lazy-projections/bonne.ts +4 -1
- package/src/projection/experimental/lazy-projections/cass.ts +4 -1
- package/src/projection/experimental/lazy-projections/eck6.ts +4 -1
- package/src/projection/experimental/lazy-projections/eqdc.ts +4 -1
- package/src/projection/experimental/lazy-projections/eqearth.ts +4 -1
- package/src/projection/experimental/lazy-projections/equi.ts +4 -1
- package/src/projection/experimental/lazy-projections/geocent.ts +4 -1
- package/src/projection/experimental/lazy-projections/geos.ts +4 -1
- package/src/projection/experimental/lazy-projections/gnom.ts +4 -1
- package/src/projection/experimental/lazy-projections/krovak.ts +4 -1
- package/src/projection/experimental/lazy-projections/merc.ts +4 -1
- package/src/projection/experimental/lazy-projections/mill.ts +4 -1
- package/src/projection/experimental/lazy-projections/moll.ts +4 -1
- package/src/projection/experimental/lazy-projections/nzmg.ts +4 -1
- package/src/projection/experimental/lazy-projections/omerc.ts +4 -1
- package/src/projection/experimental/lazy-projections/ortho.ts +4 -1
- package/src/projection/experimental/lazy-projections/poly.ts +4 -1
- package/src/projection/experimental/lazy-projections/robin.ts +4 -1
- package/src/projection/experimental/lazy-projections/sinu.ts +4 -1
- package/src/projection/experimental/lazy-projections/stere.ts +4 -1
- package/src/projection/experimental/lazy-projections/tpers.ts +4 -1
- package/src/projection/experimental/lazy-projections/vandg.ts +4 -1
- package/src/projection/experimental/spatial-deformation.ts +1 -1
- package/src/projection/index.ts +1 -1
- package/src/projection/lib/projection.ts +1 -1
- package/src/rhumb-path.ts +1 -1
- package/src/spatial-planar-intersects.ts +134 -0
- package/src/spatial-planar.ts +266 -0
- package/src/spatial-sql.ts +276 -0
- package/src/st-functions.ts +852 -0
- package/src/subdivide-globe-mesh.ts +1 -1
- package/src/tasks/index.ts +34 -0
- package/src/tasks/terrain-coverage-worker.ts +6 -0
- package/src/tasks/terrain-coverage.ts +25 -0
- package/src/tasks/terrain-residency-worker.ts +6 -0
- package/src/tasks/terrain-residency.ts +250 -0
- package/src/terrain/breakline-mesh.ts +164 -0
- package/src/terrain/breakline-preprocess.ts +106 -0
- package/src/terrain/cdt2d.d.ts +10 -0
- package/src/terrain/continuous-mesh-error.ts +321 -0
- package/src/terrain/cutout-polygons.ts +202 -0
- package/src/terrain/cutout-region.ts +54 -0
- package/src/terrain/cutout-skirts.ts +52 -0
- package/src/terrain/depression-fill.ts +125 -0
- package/src/terrain/geographic-cutout.ts +154 -0
- package/src/terrain/geographic-lod-seams.ts +109 -0
- package/src/terrain/geographic-neighbor.ts +58 -0
- package/src/terrain/geographic-poles.ts +52 -0
- package/src/terrain/geographic-seam.ts +73 -0
- package/src/terrain/hydrology.ts +149 -0
- package/src/terrain/index.ts +160 -0
- package/src/terrain/lod-screen-error.ts +128 -0
- package/src/terrain/lod-select.ts +129 -0
- package/src/terrain/lod-stitch.ts +88 -0
- package/src/terrain/mesh-coverage.ts +215 -0
- package/src/terrain/mesh-cutout.ts +420 -0
- package/src/terrain/mesh-regions-data.ts +21 -13
- package/src/terrain/mesh-skirts.ts +10 -7
- package/src/terrain/mixed-halo-update.ts +147 -25
- package/src/terrain/mixed-vertex-halos.ts +125 -55
- package/src/terrain/regional-viewshed.ts +177 -0
- package/src/terrain/surface.ts +1 -1
- package/src/terrain/sweep-capsule.ts +148 -0
- package/src/terrain/sweep-cylinder.ts +64 -0
- package/src/terrain/sweep-plane.ts +61 -0
- package/src/terrain/sweep-polytope.ts +253 -0
- package/src/terrain/sweep-rotating-capsule.ts +139 -0
- package/src/terrain/sweep-rotation.ts +149 -0
- package/src/terrain/sweep-sphere.ts +100 -0
- package/src/terrain/tile-cutout-update.ts +293 -0
- package/src/terrain/tile-cutout.ts +123 -0
- package/src/terrain/valid-domain-mesh.ts +221 -0
- package/src/terrain/valid-domain-regions.ts +41 -0
- package/src/terrain/watershed-accumulation.ts +67 -0
- package/src/triaxial.ts +1 -1
- package/src/turf-expressions.ts +7 -0
- package/src/{turf/expressions.ts → turf-functions.ts} +121 -6
- package/src/turf.ts +3 -7
- package/src/type-utils.ts +2 -2
- package/src/web-mercator/assert.ts +11 -0
- package/src/web-mercator/fit-bounds.ts +132 -0
- package/src/web-mercator/fly-to-viewport.ts +157 -0
- package/src/web-mercator/get-bounds.ts +62 -0
- package/src/web-mercator/index.ts +49 -0
- package/src/web-mercator/math-utils.ts +35 -0
- package/src/web-mercator/mercator-meters.ts +83 -0
- package/src/web-mercator/normalize-viewport-props.ts +58 -0
- package/src/web-mercator/web-mercator-utils.ts +468 -0
- package/src/web-mercator/web-mercator-viewport.ts +406 -0
- package/src/web-mercator.ts +1 -1
- package/dist/projection/experimental/index.cjs +0 -11707
- package/dist/projection/experimental/index.cjs.map +0 -6
- package/dist/turf/expressions.cjs +0 -87
- package/dist/turf/expressions.cjs.map +0 -6
- package/dist/turf/expressions.d.ts +0 -24
- package/dist/turf/expressions.d.ts.map +0 -1
- package/dist/turf/expressions.js.map +0 -1
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import triangulate from 'cdt2d';
|
|
6
|
+
import type {HeightField} from './height-field';
|
|
7
|
+
import {createTerrainMesh} from './mesh';
|
|
8
|
+
import type {TerrainMeshOptions} from './mesh-data';
|
|
9
|
+
|
|
10
|
+
export type ValidDomainMeshOptions = TerrainMeshOptions & {
|
|
11
|
+
maxError: number;
|
|
12
|
+
maxSamples?: number;
|
|
13
|
+
maxTriangles?: number;
|
|
14
|
+
maxSampleTests?: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ValidDomainTerrainMesh = {
|
|
18
|
+
positions: Float64Array;
|
|
19
|
+
gridCoordinates: Float64Array;
|
|
20
|
+
indices: Uint32Array;
|
|
21
|
+
origin: readonly [number, number, number];
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
heightReference: string;
|
|
25
|
+
maxSampleError: number;
|
|
26
|
+
certifiedSamples: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type Edge = [number, number];
|
|
30
|
+
type Triangle = [number, number, number];
|
|
31
|
+
|
|
32
|
+
function capacity(value: number): number {
|
|
33
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new Error('Invalid mesh work limit');
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Adaptively mesh precisely the union of valid regular triangles. */
|
|
38
|
+
export function createValidDomainTerrainMesh(
|
|
39
|
+
field: HeightField,
|
|
40
|
+
options: ValidDomainMeshOptions
|
|
41
|
+
): ValidDomainTerrainMesh {
|
|
42
|
+
return meshValidDomain(field, options);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type DomainConstraints = (
|
|
46
|
+
points: [number, number][],
|
|
47
|
+
heights: number[],
|
|
48
|
+
edges: Edge[],
|
|
49
|
+
selected: Int32Array,
|
|
50
|
+
originZ: number
|
|
51
|
+
) => {edges: Edge[]; excluded: Set<number>; fixedSamples: Set<number>};
|
|
52
|
+
|
|
53
|
+
export function meshValidDomain(
|
|
54
|
+
field: HeightField,
|
|
55
|
+
options: ValidDomainMeshOptions,
|
|
56
|
+
constraints?: DomainConstraints
|
|
57
|
+
): ValidDomainTerrainMesh {
|
|
58
|
+
const {maxError} = options;
|
|
59
|
+
const count = field.width * field.height;
|
|
60
|
+
if (!Number.isFinite(maxError) || maxError < 0) throw new Error('Invalid maximum error');
|
|
61
|
+
if (count > capacity(options.maxSamples ?? 1_100_000)) throw new Error('Sample limit exceeded');
|
|
62
|
+
const maxTriangles = capacity(options.maxTriangles ?? 2_200_000);
|
|
63
|
+
const maxTests = capacity(options.maxSampleTests ?? 40_000_000);
|
|
64
|
+
const regular = createTerrainMesh(field, options);
|
|
65
|
+
const {width, height, origin, heightReference} = regular;
|
|
66
|
+
const active = new Uint8Array(count);
|
|
67
|
+
const boundary = new Map<number, Edge>();
|
|
68
|
+
const edgeKey = (a: number, b: number) => Math.min(a, b) * count + Math.max(a, b);
|
|
69
|
+
for (let i = 0; i < regular.indices.length; i += 3) {
|
|
70
|
+
for (let j = 0; j < 3; j++) {
|
|
71
|
+
const a = regular.indices[i + j],
|
|
72
|
+
b = regular.indices[i + ((j + 1) % 3)];
|
|
73
|
+
active[a] = 1;
|
|
74
|
+
const key = edgeKey(a, b);
|
|
75
|
+
if (!boundary.delete(key)) boundary.set(key, [a, b]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const selected = new Int32Array(count).fill(-1);
|
|
79
|
+
const points: [number, number][] = [];
|
|
80
|
+
const heights: number[] = [];
|
|
81
|
+
const add = (i: number): number => {
|
|
82
|
+
if (selected[i] < 0) {
|
|
83
|
+
selected[i] = points.length;
|
|
84
|
+
points.push([i % width, Math.floor(i / width)]);
|
|
85
|
+
heights.push(regular.positions[3 * i + 2]);
|
|
86
|
+
}
|
|
87
|
+
return selected[i];
|
|
88
|
+
};
|
|
89
|
+
const edges = Array.from(boundary.values(), ([a, b]): Edge => [add(a), add(b)]);
|
|
90
|
+
const extra = constraints?.(points, heights, edges, selected, origin[2]);
|
|
91
|
+
const inDomain = ([a, b, c]: Triangle): boolean => {
|
|
92
|
+
const x = (points[a][0] + points[b][0] + points[c][0]) / 3;
|
|
93
|
+
const y = (points[a][1] + points[b][1] + points[c][1]) / 3;
|
|
94
|
+
const i = Math.floor(x),
|
|
95
|
+
j = Math.floor(y);
|
|
96
|
+
const u = x - i,
|
|
97
|
+
v = y - j;
|
|
98
|
+
const valid = (dx: number, dy: number) => field.getHeight(i + dx, j + dy) !== undefined;
|
|
99
|
+
if (field.diagonal === '00-11') {
|
|
100
|
+
return valid(0, 0) && valid(1, 1) && (u > v ? valid(1, 0) : valid(0, 1));
|
|
101
|
+
}
|
|
102
|
+
return valid(1, 0) && valid(0, 1) && (u + v < 1 ? valid(0, 0) : valid(1, 1));
|
|
103
|
+
};
|
|
104
|
+
const covered = new Uint8Array(count);
|
|
105
|
+
let triangles: Triangle[] = [];
|
|
106
|
+
let maxSampleError = 0;
|
|
107
|
+
let certifiedSamples = 0;
|
|
108
|
+
let tests = 0;
|
|
109
|
+
for (let pass = 0; points.length; pass++) {
|
|
110
|
+
triangles = triangulate(points, extra?.edges ?? edges, {
|
|
111
|
+
exterior: Boolean(extra),
|
|
112
|
+
delaunay: false
|
|
113
|
+
});
|
|
114
|
+
if (extra) triangles = triangles.filter(inDomain);
|
|
115
|
+
|
|
116
|
+
if (triangles.length > maxTriangles) throw new Error('Triangle limit exceeded');
|
|
117
|
+
covered.fill(0);
|
|
118
|
+
const refine = new Set<number>();
|
|
119
|
+
maxSampleError = 0;
|
|
120
|
+
certifiedSamples = 0;
|
|
121
|
+
for (const [a, b, c] of triangles) {
|
|
122
|
+
const [ax, ay] = points[a],
|
|
123
|
+
[bx, by] = points[b],
|
|
124
|
+
[cx, cy] = points[c];
|
|
125
|
+
const det = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
|
|
126
|
+
if (det === 0) throw new Error('Degenerate triangulation');
|
|
127
|
+
let worst = maxError;
|
|
128
|
+
let candidate = -1;
|
|
129
|
+
const sides = [
|
|
130
|
+
[ax, ay, bx, by],
|
|
131
|
+
[bx, by, cx, cy],
|
|
132
|
+
[cx, cy, ax, ay]
|
|
133
|
+
];
|
|
134
|
+
for (let y = Math.ceil(Math.min(ay, by, cy)); y <= Math.floor(Math.max(ay, by, cy)); y++) {
|
|
135
|
+
let left = Infinity;
|
|
136
|
+
let right = -Infinity;
|
|
137
|
+
for (const [x0, y0, x1, y1] of sides) {
|
|
138
|
+
if (y < Math.min(y0, y1) || y > Math.max(y0, y1)) continue;
|
|
139
|
+
const x = y0 === y1 ? x0 : x0 + ((x1 - x0) * (y - y0)) / (y1 - y0);
|
|
140
|
+
left = Math.min(left, x);
|
|
141
|
+
right = Math.max(right, y0 === y1 ? Math.max(x0, x1) : x);
|
|
142
|
+
if (y0 === y1) left = Math.min(left, x1);
|
|
143
|
+
}
|
|
144
|
+
for (let x = Math.ceil(left - 1e-10); x <= Math.floor(right + 1e-10); x++) {
|
|
145
|
+
if (++tests > maxTests) throw new Error('Sample test limit exceeded');
|
|
146
|
+
const i = y * width + x;
|
|
147
|
+
if (!active[i] || extra?.excluded.has(i)) continue;
|
|
148
|
+
const u = ((x - ax) * (cy - ay) - (y - ay) * (cx - ax)) / det;
|
|
149
|
+
const v = ((bx - ax) * (y - ay) - (by - ay) * (x - ax)) / det;
|
|
150
|
+
const w = 1 - u - v;
|
|
151
|
+
if (Math.min(u, v, w) < -1e-12) continue;
|
|
152
|
+
if (!covered[i]) certifiedSamples++;
|
|
153
|
+
covered[i] = 1;
|
|
154
|
+
const error =
|
|
155
|
+
!extra && (selected[i] === a || selected[i] === b || selected[i] === c)
|
|
156
|
+
? 0
|
|
157
|
+
: Math.abs(
|
|
158
|
+
w * heights[a] + u * heights[b] + v * heights[c] - regular.positions[3 * i + 2]
|
|
159
|
+
);
|
|
160
|
+
maxSampleError = Math.max(maxSampleError, error);
|
|
161
|
+
if (error > worst && !extra?.fixedSamples.has(i)) {
|
|
162
|
+
worst = error;
|
|
163
|
+
candidate = i;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (candidate >= 0) refine.add(candidate);
|
|
168
|
+
}
|
|
169
|
+
if (active.some((value, i) => value && !covered[i] && !extra?.excluded.has(i)))
|
|
170
|
+
throw new Error('Incomplete domain triangulation');
|
|
171
|
+
if (maxSampleError <= maxError) break;
|
|
172
|
+
if (!Array.from(refine).some(i => selected[i] < 0))
|
|
173
|
+
throw new Error('Cannot certify mesh tolerance');
|
|
174
|
+
if (pass === 63) {
|
|
175
|
+
for (let i = 0; i < count; i++) if (active[i] && !extra?.fixedSamples.has(i)) add(i);
|
|
176
|
+
} else {
|
|
177
|
+
for (const i of refine) add(i);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const reverse =
|
|
181
|
+
field.columnStep[0] * field.rowStep[1] - field.columnStep[1] * field.rowStep[0] < 0;
|
|
182
|
+
const positions = new Float64Array(points.length * 3);
|
|
183
|
+
const shift = field.registration === 'cell' ? 0.5 : 0;
|
|
184
|
+
for (let i = 0; i < points.length; i++) {
|
|
185
|
+
const [x, y] = points[i];
|
|
186
|
+
positions.set(
|
|
187
|
+
[
|
|
188
|
+
field.origin[0] -
|
|
189
|
+
origin[0] +
|
|
190
|
+
(x + shift) * field.columnStep[0] +
|
|
191
|
+
(y + shift) * field.rowStep[0],
|
|
192
|
+
field.origin[1] -
|
|
193
|
+
origin[1] +
|
|
194
|
+
(x + shift) * field.columnStep[1] +
|
|
195
|
+
(y + shift) * field.rowStep[1],
|
|
196
|
+
heights[i]
|
|
197
|
+
],
|
|
198
|
+
i * 3
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
const indices = new Uint32Array(triangles.length * 3);
|
|
202
|
+
for (let i = 0; i < triangles.length; i++) {
|
|
203
|
+
const [a, b, c] = triangles[i];
|
|
204
|
+
const [ax, ay] = points[a],
|
|
205
|
+
[bx, by] = points[b],
|
|
206
|
+
[cx, cy] = points[c];
|
|
207
|
+
const clockwise = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax) < 0;
|
|
208
|
+
indices.set(reverse === clockwise ? [a, b, c] : [a, c, b], 3 * i);
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
positions,
|
|
212
|
+
indices,
|
|
213
|
+
gridCoordinates: Float64Array.from(points.flat()),
|
|
214
|
+
origin,
|
|
215
|
+
width,
|
|
216
|
+
height,
|
|
217
|
+
heightReference,
|
|
218
|
+
maxSampleError,
|
|
219
|
+
certifiedSamples
|
|
220
|
+
};
|
|
221
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import type {TerrainDirtyWindow} from './dirty-regions';
|
|
5
|
+
import type {HeightField} from './height-field';
|
|
6
|
+
import {updateMeshRegions, type TerrainMeshRegions} from './mesh-regions-data';
|
|
7
|
+
import {createValidDomainTerrainMesh, type ValidDomainTerrainMesh} from './valid-domain-mesh';
|
|
8
|
+
|
|
9
|
+
export type TerrainValidDomainMeshRegions = TerrainMeshRegions<ValidDomainTerrainMesh>;
|
|
10
|
+
|
|
11
|
+
export type TerrainValidDomainRegionOptions = {
|
|
12
|
+
maxError: number;
|
|
13
|
+
cellsPerRegion?: number;
|
|
14
|
+
maxSamples?: number;
|
|
15
|
+
maxTests?: number;
|
|
16
|
+
maxTrianglesPerRegion?: number;
|
|
17
|
+
maxSampleTestsPerRegion?: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Rebuild only affected adaptive regions, retaining each valid regular half-cell domain. */
|
|
21
|
+
export function updateTerrainValidDomainMeshRegions(
|
|
22
|
+
previous: TerrainValidDomainMeshRegions | null,
|
|
23
|
+
field: HeightField,
|
|
24
|
+
dirty: readonly TerrainDirtyWindow[],
|
|
25
|
+
options: TerrainValidDomainRegionOptions
|
|
26
|
+
): TerrainValidDomainMeshRegions {
|
|
27
|
+
const {maxError, maxTrianglesPerRegion, maxSampleTestsPerRegion} = options;
|
|
28
|
+
if (!Number.isFinite(maxError) || maxError < 0) throw new Error('Invalid regional mesh error');
|
|
29
|
+
for (const limit of [maxTrianglesPerRegion, maxSampleTestsPerRegion]) {
|
|
30
|
+
if (limit !== undefined && (!Number.isSafeInteger(limit) || limit < 1))
|
|
31
|
+
throw new Error('Invalid regional mesh work limit');
|
|
32
|
+
}
|
|
33
|
+
const configuration = `valid-domain:${maxError}:${maxTrianglesPerRegion ?? ''}:${maxSampleTestsPerRegion ?? ''}`;
|
|
34
|
+
return updateMeshRegions(previous, field, dirty, options, configuration, region =>
|
|
35
|
+
createValidDomainTerrainMesh(region, {
|
|
36
|
+
maxError,
|
|
37
|
+
maxTriangles: maxTrianglesPerRegion,
|
|
38
|
+
maxSampleTests: maxSampleTestsPerRegion
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Outlet labels and upstream counts for a terrain receiver forest. */
|
|
6
|
+
export type TerrainWatershedAccumulation = {
|
|
7
|
+
/** Row-major outlet index, or -1 for excluded cells. */
|
|
8
|
+
terminal: Int32Array;
|
|
9
|
+
/** Number of contributing cells, including the cell itself. Excluded cells have zero. */
|
|
10
|
+
contributingCells: Uint32Array;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Controls allocation for watershed accumulation. */
|
|
14
|
+
export type TerrainWatershedAccumulationOptions = {
|
|
15
|
+
/** Limit before allocating working buffers. */
|
|
16
|
+
maxCells?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Accumulates a receiver forest such as that returned by fillTerrainDepressions.
|
|
21
|
+
* Each entry is a receiver index, -1 for an outlet, or -2 for an excluded cell.
|
|
22
|
+
* createTerrainDrainage uses -1 for nodata. Map nodata cells to -2 before calling.
|
|
23
|
+
* Rejects cycles and links to excluded cells. Time and storage are O(cell count).
|
|
24
|
+
*/
|
|
25
|
+
export function accumulateTerrainWatersheds(
|
|
26
|
+
receiver: Int32Array,
|
|
27
|
+
{maxCells = 4_194_304}: TerrainWatershedAccumulationOptions = {}
|
|
28
|
+
): TerrainWatershedAccumulation {
|
|
29
|
+
const count = receiver.length;
|
|
30
|
+
if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 0x7fffffff)
|
|
31
|
+
throw new RangeError('Terrain watershed accumulation exceeds its cell budget');
|
|
32
|
+
|
|
33
|
+
const incoming = new Uint32Array(count);
|
|
34
|
+
const contributingCells = new Uint32Array(count);
|
|
35
|
+
const terminal = new Int32Array(count).fill(-1);
|
|
36
|
+
const queue = new Int32Array(count);
|
|
37
|
+
let active = 0;
|
|
38
|
+
for (let i = 0; i < count; i++) {
|
|
39
|
+
const next = receiver[i];
|
|
40
|
+
if (next === -2) continue;
|
|
41
|
+
if (next < -1 || next >= count || (next >= 0 && receiver[next] === -2))
|
|
42
|
+
throw new RangeError('Invalid terrain watershed receiver');
|
|
43
|
+
active++;
|
|
44
|
+
contributingCells[i] = 1;
|
|
45
|
+
if (next >= 0) incoming[next]++;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let end = 0;
|
|
49
|
+
for (let i = 0; i < count; i++) {
|
|
50
|
+
if (contributingCells[i] && !incoming[i]) queue[end++] = i;
|
|
51
|
+
}
|
|
52
|
+
for (let cursor = 0; cursor < end; cursor++) {
|
|
53
|
+
const i = queue[cursor];
|
|
54
|
+
const next = receiver[i];
|
|
55
|
+
if (next < 0) continue;
|
|
56
|
+
contributingCells[next] += contributingCells[i];
|
|
57
|
+
if (--incoming[next] === 0) queue[end++] = next;
|
|
58
|
+
}
|
|
59
|
+
if (end !== active) throw new RangeError('Terrain watershed receiver graph contains a cycle');
|
|
60
|
+
|
|
61
|
+
for (let cursor = end - 1; cursor >= 0; cursor--) {
|
|
62
|
+
const i = queue[cursor];
|
|
63
|
+
const next = receiver[i];
|
|
64
|
+
terminal[i] = next < 0 ? i : terminal[next];
|
|
65
|
+
}
|
|
66
|
+
return {terminal, contributingCells};
|
|
67
|
+
}
|
package/src/triaxial.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
// SPDX-FileComment: Original normal/parametric/geocentric surface coordinates and Cartesian geodesic ODE. Qualified independently against GeographicLib 2.7 Jacobi trajectories (Charles Karney, MIT), not a port of that implementation.
|
|
5
|
-
import type {NumericArray} from '@math.gl/core';
|
|
5
|
+
import type {NumericArray} from '@math.gl/core/matrix';
|
|
6
6
|
import {integrateGeodesic} from './triaxial/integrate';
|
|
7
7
|
export type TriaxialCoordinates = 'geodetic' | 'parametric' | 'geocentric';
|
|
8
8
|
export type TriaxialParameters = {radii: readonly [number, number, number]};
|
|
@@ -2,11 +2,39 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import {
|
|
6
|
+
Binary,
|
|
7
|
+
Bool,
|
|
8
|
+
FixedSizeList,
|
|
9
|
+
Float64,
|
|
10
|
+
DataType,
|
|
11
|
+
Precision,
|
|
12
|
+
makeData,
|
|
13
|
+
makeVector,
|
|
14
|
+
Field
|
|
15
|
+
} from 'apache-arrow';
|
|
16
|
+
import type {ArrowTableFunction} from '@math.gl/sql/arrow';
|
|
17
|
+
import {makeGeoArrowColumnFromArrowVector} from '@math.gl/core/arrow';
|
|
18
|
+
import {
|
|
19
|
+
materializeGeoArrowRows,
|
|
20
|
+
writeWKB,
|
|
21
|
+
isGeoArrowValueValid,
|
|
22
|
+
type GeoArrowColumn
|
|
23
|
+
} from '@math.gl/core/arrow';
|
|
24
|
+
import type {TurfBatchResult} from './turf';
|
|
25
|
+
|
|
26
|
+
import {area, bearing, centroid, distance, length, midpoint} from './turf';
|
|
27
|
+
import {
|
|
28
|
+
column,
|
|
29
|
+
geometryTypes,
|
|
30
|
+
lineKinds,
|
|
31
|
+
pointInPolygon,
|
|
32
|
+
pointKinds,
|
|
33
|
+
polygonKinds,
|
|
34
|
+
scalar,
|
|
35
|
+
spatialFunction
|
|
36
|
+
} from './spatial-sql';
|
|
37
|
+
import {planarBounds} from './spatial-planar';
|
|
10
38
|
|
|
11
39
|
/** Adapter for row-preserving numeric/Boolean functions from @math.gl/geospatial/turf. */
|
|
12
40
|
export type TurfArrowFunctionOptions<Fields extends readonly Field[] = readonly Field[]> = {
|
|
@@ -45,7 +73,9 @@ export function createTurfArrowFunction<const Fields extends readonly Field[]>(
|
|
|
45
73
|
nullHandling: 'propagate',
|
|
46
74
|
evaluate(vectors, {activeRows, length}) {
|
|
47
75
|
const columns = vectors.map((vector, index) => {
|
|
48
|
-
const column = makeGeoArrowColumnFromArrowVector(vector, {
|
|
76
|
+
const column = makeGeoArrowColumnFromArrowVector(vector, {
|
|
77
|
+
field: fields[index]
|
|
78
|
+
});
|
|
49
79
|
let offset = 0;
|
|
50
80
|
return {
|
|
51
81
|
...column,
|
|
@@ -95,3 +125,88 @@ export function createTurfArrowFunction<const Fields extends readonly Field[]>(
|
|
|
95
125
|
]
|
|
96
126
|
};
|
|
97
127
|
}
|
|
128
|
+
|
|
129
|
+
/** Returns the first geometry from a single-row Turf batch as GeoArrow WKB. */
|
|
130
|
+
function geometryResult(result: GeoArrowColumn): Uint8Array | null {
|
|
131
|
+
const [geometry] = materializeGeoArrowRows(result);
|
|
132
|
+
return geometry ? writeWKB(geometry, 'xy') : null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Returns great-circle point distance in kilometers. */
|
|
136
|
+
export const TURF_DISTANCE = /* @__PURE__ */ spatialFunction(
|
|
137
|
+
'TURF_DISTANCE',
|
|
138
|
+
[pointKinds, pointKinds],
|
|
139
|
+
/* @__PURE__ */ new Float64(),
|
|
140
|
+
([a, b]) => scalar(distance(column(a!), column(b!)))
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
/** Returns initial great-circle bearing in degrees. */
|
|
144
|
+
export const TURF_BEARING = /* @__PURE__ */ spatialFunction(
|
|
145
|
+
'TURF_BEARING',
|
|
146
|
+
[pointKinds, pointKinds],
|
|
147
|
+
/* @__PURE__ */ new Float64(),
|
|
148
|
+
([a, b]) => scalar(bearing(column(a!), column(b!)))
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
/** Returns spherical polygon area in square meters. */
|
|
152
|
+
export const TURF_AREA = /* @__PURE__ */ spatialFunction(
|
|
153
|
+
'TURF_AREA',
|
|
154
|
+
[polygonKinds],
|
|
155
|
+
/* @__PURE__ */ new Float64(),
|
|
156
|
+
([geometry]) => scalar(area(column(geometry!)))
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
/** Returns great-circle line length in kilometers. */
|
|
160
|
+
export const TURF_LENGTH = /* @__PURE__ */ spatialFunction(
|
|
161
|
+
'TURF_LENGTH',
|
|
162
|
+
[lineKinds],
|
|
163
|
+
/* @__PURE__ */ new Float64(),
|
|
164
|
+
([geometry]) => scalar(length(column(geometry!)))
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
/** Returns the Turf vertex-mean centroid as GeoArrow WKB. */
|
|
168
|
+
export const TURF_CENTROID = /* @__PURE__ */ spatialFunction(
|
|
169
|
+
'TURF_CENTROID',
|
|
170
|
+
[geometryTypes],
|
|
171
|
+
/* @__PURE__ */ new Binary(),
|
|
172
|
+
([geometry]) => geometryResult(centroid(column(geometry!)))
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
/** Returns the Turf great-circle midpoint as GeoArrow WKB. */
|
|
176
|
+
export const TURF_MIDPOINT = /* @__PURE__ */ spatialFunction(
|
|
177
|
+
'TURF_MIDPOINT',
|
|
178
|
+
[pointKinds, pointKinds],
|
|
179
|
+
/* @__PURE__ */ new Binary(),
|
|
180
|
+
([a, b]) => geometryResult(midpoint(column(a!), column(b!)))
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
/** Returns [minX, minY, maxX, maxY] per geometry. */
|
|
184
|
+
export const TURF_BBOX = /* @__PURE__ */ spatialFunction(
|
|
185
|
+
'TURF_BBOX',
|
|
186
|
+
[geometryTypes],
|
|
187
|
+
/* @__PURE__ */ new FixedSizeList(
|
|
188
|
+
4,
|
|
189
|
+
/* @__PURE__ */ new Field('value', /* @__PURE__ */ new Float64(), false)
|
|
190
|
+
),
|
|
191
|
+
([geometry]) => planarBounds(geometry!)
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
/** Tests whether a point is in a polygon, including its boundary, with Turf argument order. */
|
|
195
|
+
export const TURF_BOOLEAN_POINT_IN_POLYGON = /* @__PURE__ */ spatialFunction(
|
|
196
|
+
'TURF_BOOLEAN_POINT_IN_POLYGON',
|
|
197
|
+
[pointKinds, polygonKinds],
|
|
198
|
+
/* @__PURE__ */ new Bool(),
|
|
199
|
+
([point, polygon]) => pointInPolygon(point!, polygon!)
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
/** Opt-in SQL declarations for the initial row-preserving Turf function library. */
|
|
203
|
+
export const TURF_FUNCTIONS: readonly ArrowTableFunction[] = /* @__PURE__ */ Object.freeze([
|
|
204
|
+
TURF_DISTANCE,
|
|
205
|
+
TURF_BEARING,
|
|
206
|
+
TURF_AREA,
|
|
207
|
+
TURF_LENGTH,
|
|
208
|
+
TURF_CENTROID,
|
|
209
|
+
TURF_MIDPOINT,
|
|
210
|
+
TURF_BBOX,
|
|
211
|
+
TURF_BOOLEAN_POINT_IN_POLYGON
|
|
212
|
+
]);
|
package/src/turf.ts
CHANGED
|
@@ -2,13 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {GeoArrowArray, GeoArrowColumn} from '@math.gl/arrow
|
|
6
|
-
import {isGeoArrowValueValid} from '@math.gl/arrow
|
|
7
|
-
import {
|
|
8
|
-
getGeoArrowRowBounds,
|
|
9
|
-
mapGeoArrowCoordinates,
|
|
10
|
-
rewindGeoArrow
|
|
11
|
-
} from '@math.gl/arrow/geoarrow-utils';
|
|
5
|
+
import type {GeoArrowArray, GeoArrowColumn} from '@math.gl/core/arrow';
|
|
6
|
+
import {isGeoArrowValueValid} from '@math.gl/core/arrow';
|
|
7
|
+
import {getGeoArrowRowBounds, mapGeoArrowCoordinates, rewindGeoArrow} from '@math.gl/core/arrow';
|
|
12
8
|
|
|
13
9
|
/** A nullable, row-aligned numeric or boolean result. Validity is an Arrow bitmap. */
|
|
14
10
|
export type TurfBatchResult<T extends Float64Array | Uint8Array> = {
|
package/src/type-utils.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
// This file is derived from the Cesium math library under Apache 2 license
|
|
8
8
|
// See ../LICENSE for the retained Cesium notice and Apache-2.0 terms.
|
|
9
9
|
|
|
10
|
-
import type {NumericArray} from '@math.gl/core';
|
|
11
|
-
import {Vector3, toRadians, toDegrees, config} from '@math.gl/core';
|
|
10
|
+
import type {NumericArray} from '@math.gl/core/matrix';
|
|
11
|
+
import {Vector3, toRadians, toDegrees, config} from '@math.gl/core/matrix';
|
|
12
12
|
import {WGS84_CONSTANTS} from './constants';
|
|
13
13
|
|
|
14
14
|
type LngLatHeightObject = {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// Replacement for the external assert method to reduce bundle size
|
|
5
|
+
// Note: We don't use the second "message" argument in calling code,
|
|
6
|
+
// so no need to support it here
|
|
7
|
+
export function assert(condition: unknown, message?: string): void {
|
|
8
|
+
if (!condition) {
|
|
9
|
+
throw new Error(message || '@math.gl/geospatial/web-mercator: assertion failed.');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import {assert} from './assert';
|
|
5
|
+
import {log2, clamp} from './math-utils';
|
|
6
|
+
import {MAX_LATITUDE, lngLatToWorld, worldToLngLat} from './web-mercator-utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options for fitBounds
|
|
10
|
+
*/
|
|
11
|
+
export type FitBoundsOptions = {
|
|
12
|
+
/** viewport width */
|
|
13
|
+
width: number;
|
|
14
|
+
/** viewport height */
|
|
15
|
+
height: number;
|
|
16
|
+
/** [[lon, lat], [lon, lat]] */
|
|
17
|
+
bounds: [[number, number], [number, number]];
|
|
18
|
+
/** The width/height of the bounded area will never be smaller than this. 0.01 would be about 1000 meters (degree is ~110KM) */
|
|
19
|
+
minExtent?: number;
|
|
20
|
+
/** The maximum zoom level to fit the bounds within. */
|
|
21
|
+
maxZoom?: number; // ~x4,000,000 => About 10 meter extents
|
|
22
|
+
/**
|
|
23
|
+
* padding - The amount of padding in pixels to add to the given bounds.
|
|
24
|
+
* Can also be an object with top, bottom, left and right properties defining the padding.
|
|
25
|
+
*/
|
|
26
|
+
padding?: number | Padding;
|
|
27
|
+
/** Pixel offset from the padded center. Positive x moves right and positive y moves down. */
|
|
28
|
+
offset?: number[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* An object describing the padding to add to the bounds.
|
|
33
|
+
*/
|
|
34
|
+
export type Padding = {
|
|
35
|
+
/** Padding from top in pixels to add to the given bounds */
|
|
36
|
+
top: number;
|
|
37
|
+
/** Padding from bottom in pixels to add to the given bounds */
|
|
38
|
+
bottom: number;
|
|
39
|
+
/** Padding from left in pixels to add to the given bounds */
|
|
40
|
+
left: number;
|
|
41
|
+
/** Padding from right in pixels to add to the given bounds */
|
|
42
|
+
right: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type ViewportProps = {
|
|
46
|
+
longitude: number;
|
|
47
|
+
latitude: number;
|
|
48
|
+
zoom: number;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Returns map settings {latitude, longitude, zoom}
|
|
53
|
+
* that will contain the provided corners within the provided width.
|
|
54
|
+
*
|
|
55
|
+
* > _Note: Only supports non-perspective mode._
|
|
56
|
+
*
|
|
57
|
+
* @param options fit bounds parameters
|
|
58
|
+
* @returns - latitude, longitude and zoom
|
|
59
|
+
*/
|
|
60
|
+
export function fitBounds(options: FitBoundsOptions): ViewportProps {
|
|
61
|
+
const {
|
|
62
|
+
width,
|
|
63
|
+
height,
|
|
64
|
+
bounds,
|
|
65
|
+
minExtent = 0, // 0.01 would be about 1000 meters (degree is ~110KM)
|
|
66
|
+
maxZoom = 24, // ~x4,000,000 => About 10 meter extents
|
|
67
|
+
offset = [0, 0]
|
|
68
|
+
} = options;
|
|
69
|
+
|
|
70
|
+
const [[west, south], [east, north]] = bounds;
|
|
71
|
+
const padding = getPaddingObject(options.padding);
|
|
72
|
+
|
|
73
|
+
const nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);
|
|
74
|
+
const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);
|
|
75
|
+
|
|
76
|
+
// width/height on the Web Mercator plane
|
|
77
|
+
const size = [
|
|
78
|
+
Math.max(Math.abs(se[0] - nw[0]), minExtent),
|
|
79
|
+
Math.max(Math.abs(se[1] - nw[1]), minExtent)
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const targetSize = [
|
|
83
|
+
width - padding.left - padding.right - Math.abs(offset[0]) * 2,
|
|
84
|
+
height - padding.top - padding.bottom - Math.abs(offset[1]) * 2
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
assert(targetSize[0] > 0 && targetSize[1] > 0);
|
|
88
|
+
|
|
89
|
+
// scale = screen pixels per unit on the Web Mercator plane
|
|
90
|
+
const scaleX = targetSize[0] / size[0];
|
|
91
|
+
const scaleY = targetSize[1] / size[1];
|
|
92
|
+
|
|
93
|
+
const zoom = Math.min(maxZoom, log2(Math.abs(Math.min(scaleX, scaleY))));
|
|
94
|
+
assert(Number.isFinite(zoom));
|
|
95
|
+
|
|
96
|
+
// Translate the viewport center by the inverse of the desired screen-space shift.
|
|
97
|
+
const scale = 2 ** zoom;
|
|
98
|
+
const shiftX = (padding.left - padding.right) / 2 + offset[0];
|
|
99
|
+
const shiftY = (padding.top - padding.bottom) / 2 + offset[1];
|
|
100
|
+
const centerLngLat = worldToLngLat([
|
|
101
|
+
(se[0] + nw[0]) / 2 - shiftX / scale,
|
|
102
|
+
(se[1] + nw[1]) / 2 + shiftY / scale
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
longitude: centerLngLat[0],
|
|
107
|
+
latitude: centerLngLat[1],
|
|
108
|
+
zoom
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Helpers
|
|
113
|
+
function getPaddingObject(padding: number | Padding = 0): Padding {
|
|
114
|
+
if (typeof padding === 'number') {
|
|
115
|
+
return {
|
|
116
|
+
top: padding,
|
|
117
|
+
bottom: padding,
|
|
118
|
+
left: padding,
|
|
119
|
+
right: padding
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Make sure all the required properties are set
|
|
124
|
+
assert(
|
|
125
|
+
Number.isFinite(padding.top) &&
|
|
126
|
+
Number.isFinite(padding.bottom) &&
|
|
127
|
+
Number.isFinite(padding.left) &&
|
|
128
|
+
Number.isFinite(padding.right)
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
return padding;
|
|
132
|
+
}
|