@sakuzu/maplibre-gl-draw 1.0.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/CHANGELOG.md +43 -0
- package/LICENSE +661 -0
- package/README.ja.md +248 -0
- package/README.md +255 -0
- package/THIRD_PARTY_NOTICES.md +275 -0
- package/dist/api/api.d.ts +1259 -0
- package/dist/api/api.js +86 -0
- package/dist/api/context.d.ts +173 -0
- package/dist/api/context.js +193 -0
- package/dist/api/display-api.d.ts +1 -0
- package/dist/api/display-api.js +23 -0
- package/dist/api/event-api.d.ts +13 -0
- package/dist/api/event-api.js +17 -0
- package/dist/api/extension-api.d.ts +46 -0
- package/dist/api/extension-api.js +85 -0
- package/dist/api/feature-api.d.ts +11 -0
- package/dist/api/feature-api.js +101 -0
- package/dist/api/geometry/apply.d.ts +51 -0
- package/dist/api/geometry/apply.js +114 -0
- package/dist/api/geometry/boolean.d.ts +28 -0
- package/dist/api/geometry/boolean.js +65 -0
- package/dist/api/geometry/buffer.d.ts +11 -0
- package/dist/api/geometry/buffer.js +105 -0
- package/dist/api/geometry/split.d.ts +16 -0
- package/dist/api/geometry/split.js +75 -0
- package/dist/api/geometry/targets.d.ts +76 -0
- package/dist/api/geometry/targets.js +158 -0
- package/dist/api/geometry/types.d.ts +31 -0
- package/dist/api/geometry/types.js +3 -0
- package/dist/api/geometry-operations.d.ts +162 -0
- package/dist/api/geometry-operations.js +94 -0
- package/dist/api/group-api.d.ts +10 -0
- package/dist/api/group-api.js +78 -0
- package/dist/api/import-export/constants.d.ts +29 -0
- package/dist/api/import-export/constants.js +40 -0
- package/dist/api/import-export/embedded-file.d.ts +13 -0
- package/dist/api/import-export/embedded-file.js +31 -0
- package/dist/api/import-export/file-name.d.ts +10 -0
- package/dist/api/import-export/file-name.js +20 -0
- package/dist/api/import-export/format-detection.d.ts +12 -0
- package/dist/api/import-export/format-detection.js +29 -0
- package/dist/api/import-export/geojson-export.d.ts +19 -0
- package/dist/api/import-export/geojson-export.js +262 -0
- package/dist/api/import-export/geojson-import.d.ts +34 -0
- package/dist/api/import-export/geojson-import.js +538 -0
- package/dist/api/import-export/geometry-validation.d.ts +20 -0
- package/dist/api/import-export/geometry-validation.js +107 -0
- package/dist/api/import-export/image-import.d.ts +12 -0
- package/dist/api/import-export/image-import.js +53 -0
- package/dist/api/import-export/index.d.ts +9 -0
- package/dist/api/import-export/index.js +107 -0
- package/dist/api/import-export/native-format.d.ts +15 -0
- package/dist/api/import-export/native-format.js +126 -0
- package/dist/api/import-export/native-validation.d.ts +28 -0
- package/dist/api/import-export/native-validation.js +212 -0
- package/dist/api/import-export/own-property.d.ts +10 -0
- package/dist/api/import-export/own-property.js +19 -0
- package/dist/api/import-export/style-validation.d.ts +27 -0
- package/dist/api/import-export/style-validation.js +49 -0
- package/dist/api/import-export/types.d.ts +26 -0
- package/dist/api/import-export/types.js +3 -0
- package/dist/api/index.d.ts +15 -0
- package/dist/api/index.js +3 -0
- package/dist/api/input-api.d.ts +158 -0
- package/dist/api/input-api.js +144 -0
- package/dist/api/instance-api.d.ts +38 -0
- package/dist/api/instance-api.js +136 -0
- package/dist/api/layer-api.d.ts +12 -0
- package/dist/api/layer-api.js +62 -0
- package/dist/api/selection-api.d.ts +7 -0
- package/dist/api/selection-api.js +78 -0
- package/dist/api/snapping-api.d.ts +125 -0
- package/dist/api/snapping-api.js +50 -0
- package/dist/api/topology-api.d.ts +30 -0
- package/dist/api/topology-api.js +16 -0
- package/dist/api/tracing-api.d.ts +31 -0
- package/dist/api/tracing-api.js +16 -0
- package/dist/dispatcher/hit-test/box-strategies.d.ts +19 -0
- package/dist/dispatcher/hit-test/box-strategies.js +275 -0
- package/dist/dispatcher/hit-test/box-strategy.d.ts +59 -0
- package/dist/dispatcher/hit-test/box-strategy.js +37 -0
- package/dist/dispatcher/hit-test/globe-shape.d.ts +46 -0
- package/dist/dispatcher/hit-test/globe-shape.js +70 -0
- package/dist/dispatcher/hit-test/index.d.ts +14 -0
- package/dist/dispatcher/hit-test/index.js +9 -0
- package/dist/dispatcher/hit-test/local-frame.d.ts +77 -0
- package/dist/dispatcher/hit-test/local-frame.js +112 -0
- package/dist/dispatcher/hit-test/segment-grid.d.ts +32 -0
- package/dist/dispatcher/hit-test/segment-grid.js +79 -0
- package/dist/dispatcher/hit-test/service.d.ts +120 -0
- package/dist/dispatcher/hit-test/service.js +333 -0
- package/dist/dispatcher/hit-test/strategies/base.d.ts +136 -0
- package/dist/dispatcher/hit-test/strategies/base.js +66 -0
- package/dist/dispatcher/hit-test/strategies/circle.d.ts +10 -0
- package/dist/dispatcher/hit-test/strategies/circle.js +56 -0
- package/dist/dispatcher/hit-test/strategies/image.d.ts +22 -0
- package/dist/dispatcher/hit-test/strategies/image.js +115 -0
- package/dist/dispatcher/hit-test/strategies/index.d.ts +11 -0
- package/dist/dispatcher/hit-test/strategies/index.js +10 -0
- package/dist/dispatcher/hit-test/strategies/line.d.ts +17 -0
- package/dist/dispatcher/hit-test/strategies/line.js +30 -0
- package/dist/dispatcher/hit-test/strategies/multi.d.ts +44 -0
- package/dist/dispatcher/hit-test/strategies/multi.js +141 -0
- package/dist/dispatcher/hit-test/strategies/point.d.ts +20 -0
- package/dist/dispatcher/hit-test/strategies/point.js +29 -0
- package/dist/dispatcher/hit-test/strategies/polygon.d.ts +52 -0
- package/dist/dispatcher/hit-test/strategies/polygon.js +138 -0
- package/dist/dispatcher/hit-test/topmost.d.ts +48 -0
- package/dist/dispatcher/hit-test/topmost.js +157 -0
- package/dist/dispatcher/hit-test/visibility-lookup.d.ts +23 -0
- package/dist/dispatcher/hit-test/visibility-lookup.js +40 -0
- package/dist/dispatcher/index.d.ts +15 -0
- package/dist/dispatcher/index.js +3 -0
- package/dist/dispatcher/input-router.d.ts +1 -0
- package/dist/dispatcher/input-router.js +288 -0
- package/dist/dispatcher/normalizer.d.ts +1 -0
- package/dist/dispatcher/normalizer.js +513 -0
- package/dist/dispatcher/types.d.ts +144 -0
- package/dist/dispatcher/types.js +15 -0
- package/dist/display/chunk-set.d.ts +24 -0
- package/dist/display/chunk-set.js +533 -0
- package/dist/display/chunk.d.ts +1 -0
- package/dist/display/chunk.js +104 -0
- package/dist/display/columnar/index.d.ts +12 -0
- package/dist/display/columnar/index.js +13 -0
- package/dist/display/columnar/prepare.d.ts +42 -0
- package/dist/display/columnar/prepare.js +116 -0
- package/dist/display/columnar/source.d.ts +1 -0
- package/dist/display/columnar/source.js +531 -0
- package/dist/display/columnar/table.d.ts +1 -0
- package/dist/display/columnar/table.js +471 -0
- package/dist/display/columnar/types.d.ts +223 -0
- package/dist/display/columnar/types.js +3 -0
- package/dist/display/dataset.d.ts +2 -0
- package/dist/display/dataset.js +891 -0
- package/dist/display/index.d.ts +13 -0
- package/dist/display/index.js +3 -0
- package/dist/display/interaction.d.ts +1 -0
- package/dist/display/interaction.js +90 -0
- package/dist/display/manager.d.ts +1 -0
- package/dist/display/manager.js +440 -0
- package/dist/display/packed-rtree.d.ts +1 -0
- package/dist/display/packed-rtree.js +244 -0
- package/dist/display/partition.d.ts +1 -0
- package/dist/display/partition.js +226 -0
- package/dist/display/provider.d.ts +1 -0
- package/dist/display/provider.js +342 -0
- package/dist/display/retained.d.ts +40 -0
- package/dist/display/retained.js +898 -0
- package/dist/display/selection.d.ts +13 -0
- package/dist/display/selection.js +226 -0
- package/dist/display/source.d.ts +1 -0
- package/dist/display/source.js +119 -0
- package/dist/display/spatial.d.ts +1 -0
- package/dist/display/spatial.js +71 -0
- package/dist/display/style.d.ts +1 -0
- package/dist/display/style.js +126 -0
- package/dist/display/thinning.d.ts +65 -0
- package/dist/display/thinning.js +910 -0
- package/dist/display/triangulation.d.ts +1 -0
- package/dist/display/triangulation.js +0 -0
- package/dist/display/types.d.ts +561 -0
- package/dist/display/types.js +43 -0
- package/dist/extension/feature-handler.d.ts +182 -0
- package/dist/extension/feature-handler.js +3 -0
- package/dist/extension/index.d.ts +9 -0
- package/dist/extension/index.js +3 -0
- package/dist/extension/renderers.d.ts +208 -0
- package/dist/extension/renderers.js +3 -0
- package/dist/geometry/angle.d.ts +47 -0
- package/dist/geometry/angle.js +44 -0
- package/dist/geometry/bbox.d.ts +48 -0
- package/dist/geometry/bbox.js +83 -0
- package/dist/geometry/boolean.d.ts +162 -0
- package/dist/geometry/boolean.js +331 -0
- package/dist/geometry/buffer.d.ts +72 -0
- package/dist/geometry/buffer.js +218 -0
- package/dist/geometry/circle.d.ts +55 -0
- package/dist/geometry/circle.js +107 -0
- package/dist/geometry/coords.d.ts +97 -0
- package/dist/geometry/coords.js +149 -0
- package/dist/geometry/distance.d.ts +79 -0
- package/dist/geometry/distance.js +111 -0
- package/dist/geometry/errors.d.ts +74 -0
- package/dist/geometry/errors.js +104 -0
- package/dist/geometry/index.d.ts +28 -0
- package/dist/geometry/index.js +38 -0
- package/dist/geometry/measure.d.ts +81 -0
- package/dist/geometry/measure.js +236 -0
- package/dist/geometry/predicates.d.ts +62 -0
- package/dist/geometry/predicates.js +132 -0
- package/dist/geometry/simplify.d.ts +74 -0
- package/dist/geometry/simplify.js +159 -0
- package/dist/geometry/split.d.ts +68 -0
- package/dist/geometry/split.js +430 -0
- package/dist/geometry/types.d.ts +95 -0
- package/dist/geometry/types.js +3 -0
- package/dist/geometry/units.d.ts +35 -0
- package/dist/geometry/units.js +41 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.js +20 -0
- package/dist/maplibre-gl-draw.d.ts +47 -0
- package/dist/maplibre-gl-draw.js +407 -0
- package/dist/messages.d.ts +64 -0
- package/dist/messages.js +36 -0
- package/dist/modes/cursor.d.ts +1 -0
- package/dist/modes/cursor.js +72 -0
- package/dist/modes/draw/circle.d.ts +1 -0
- package/dist/modes/draw/circle.js +222 -0
- package/dist/modes/draw/commit-layer.d.ts +26 -0
- package/dist/modes/draw/commit-layer.js +31 -0
- package/dist/modes/draw/freehand.d.ts +1 -0
- package/dist/modes/draw/freehand.js +264 -0
- package/dist/modes/draw/image.d.ts +1 -0
- package/dist/modes/draw/image.js +60 -0
- package/dist/modes/draw/index.d.ts +9 -0
- package/dist/modes/draw/index.js +11 -0
- package/dist/modes/draw/line.d.ts +1 -0
- package/dist/modes/draw/line.js +363 -0
- package/dist/modes/draw/point.d.ts +1 -0
- package/dist/modes/draw/point.js +87 -0
- package/dist/modes/draw/polygon.d.ts +1 -0
- package/dist/modes/draw/polygon.js +378 -0
- package/dist/modes/draw/trace-support.d.ts +79 -0
- package/dist/modes/draw/trace-support.js +161 -0
- package/dist/modes/handler.d.ts +285 -0
- package/dist/modes/handler.js +3 -0
- package/dist/modes/index.d.ts +7 -0
- package/dist/modes/index.js +3 -0
- package/dist/modes/manager.d.ts +15 -0
- package/dist/modes/manager.js +196 -0
- package/dist/modes/select/box-selection.d.ts +52 -0
- package/dist/modes/select/box-selection.js +140 -0
- package/dist/modes/select/click-handler.d.ts +32 -0
- package/dist/modes/select/click-handler.js +166 -0
- package/dist/modes/select/cursor-handler.d.ts +15 -0
- package/dist/modes/select/cursor-handler.js +59 -0
- package/dist/modes/select/drag/auxiliary.d.ts +26 -0
- package/dist/modes/select/drag/auxiliary.js +56 -0
- package/dist/modes/select/drag/intermediate-writes.d.ts +1 -0
- package/dist/modes/select/drag/intermediate-writes.js +171 -0
- package/dist/modes/select/drag/move.d.ts +24 -0
- package/dist/modes/select/drag/move.js +59 -0
- package/dist/modes/select/drag/operation.d.ts +30 -0
- package/dist/modes/select/drag/operation.js +18 -0
- package/dist/modes/select/drag/radius.d.ts +15 -0
- package/dist/modes/select/drag/radius.js +49 -0
- package/dist/modes/select/drag/transform.d.ts +17 -0
- package/dist/modes/select/drag/transform.js +155 -0
- package/dist/modes/select/drag/vertex.d.ts +17 -0
- package/dist/modes/select/drag/vertex.js +163 -0
- package/dist/modes/select/drag-handler.d.ts +1 -0
- package/dist/modes/select/drag-handler.js +254 -0
- package/dist/modes/select/hit-helpers.d.ts +40 -0
- package/dist/modes/select/hit-helpers.js +51 -0
- package/dist/modes/select/mode.d.ts +1 -0
- package/dist/modes/select/mode.js +397 -0
- package/dist/modes/select/shortcut-handler.d.ts +40 -0
- package/dist/modes/select/shortcut-handler.js +128 -0
- package/dist/operations/index.d.ts +9 -0
- package/dist/operations/index.js +3 -0
- package/dist/operations/layer-operations.d.ts +1 -0
- package/dist/operations/layer-operations.js +350 -0
- package/dist/operations/resize.d.ts +71 -0
- package/dist/operations/resize.js +252 -0
- package/dist/operations/rotate.d.ts +17 -0
- package/dist/operations/rotate.js +166 -0
- package/dist/operations/selection-operations.d.ts +20 -0
- package/dist/operations/selection-operations.js +159 -0
- package/dist/operations/shared-vertex.d.ts +1 -0
- package/dist/operations/shared-vertex.js +210 -0
- package/dist/operations/trace-graph.d.ts +96 -0
- package/dist/operations/trace-graph.js +283 -0
- package/dist/operations/vertex.d.ts +1 -0
- package/dist/operations/vertex.js +538 -0
- package/dist/plugins/index.d.ts +10 -0
- package/dist/plugins/index.js +3 -0
- package/dist/plugins/mutation-hooks.d.ts +28 -0
- package/dist/plugins/mutation-hooks.js +84 -0
- package/dist/plugins/plugin-context.d.ts +1 -0
- package/dist/plugins/plugin-context.js +367 -0
- package/dist/plugins/plugin-manager.d.ts +103 -0
- package/dist/plugins/plugin-manager.js +316 -0
- package/dist/plugins/plugin.d.ts +529 -0
- package/dist/plugins/plugin.js +3 -0
- package/dist/shared/config/constants.d.ts +66 -0
- package/dist/shared/config/constants.js +60 -0
- package/dist/shared/config/feature-style.d.ts +155 -0
- package/dist/shared/config/feature-style.js +154 -0
- package/dist/shared/config/index.d.ts +17 -0
- package/dist/shared/config/index.js +8 -0
- package/dist/shared/config/rendering.d.ts +107 -0
- package/dist/shared/config/rendering.js +33 -0
- package/dist/shared/config/selection-highlight.d.ts +29 -0
- package/dist/shared/config/selection-highlight.js +35 -0
- package/dist/shared/config/selection.d.ts +273 -0
- package/dist/shared/config/selection.js +266 -0
- package/dist/shared/config/topology.d.ts +33 -0
- package/dist/shared/config/topology.js +17 -0
- package/dist/shared/config/trace.d.ts +40 -0
- package/dist/shared/config/trace.js +17 -0
- package/dist/shared/math/angle.d.ts +21 -0
- package/dist/shared/math/angle.js +34 -0
- package/dist/shared/math/circle.d.ts +6 -0
- package/dist/shared/math/circle.js +10 -0
- package/dist/shared/math/constants.d.ts +48 -0
- package/dist/shared/math/constants.js +59 -0
- package/dist/shared/math/distance.d.ts +78 -0
- package/dist/shared/math/distance.js +147 -0
- package/dist/shared/math/globe-subdivision.d.ts +62 -0
- package/dist/shared/math/globe-subdivision.js +99 -0
- package/dist/shared/math/index.d.ts +17 -0
- package/dist/shared/math/index.js +21 -0
- package/dist/shared/math/intersection.d.ts +63 -0
- package/dist/shared/math/intersection.js +236 -0
- package/dist/shared/math/longitude.d.ts +20 -0
- package/dist/shared/math/longitude.js +31 -0
- package/dist/shared/math/mercator-plane.d.ts +27 -0
- package/dist/shared/math/mercator-plane.js +26 -0
- package/dist/shared/math/obb.d.ts +65 -0
- package/dist/shared/math/obb.js +107 -0
- package/dist/shared/math/rotation.d.ts +93 -0
- package/dist/shared/math/rotation.js +186 -0
- package/dist/shared/math/segment-grid.d.ts +69 -0
- package/dist/shared/math/segment-grid.js +159 -0
- package/dist/shared/math/transform.d.ts +140 -0
- package/dist/shared/math/transform.js +189 -0
- package/dist/shared/types/events.d.ts +128 -0
- package/dist/shared/types/events.js +3 -0
- package/dist/shared/types/model.d.ts +950 -0
- package/dist/shared/types/model.js +3 -0
- package/dist/shared/types/selection-box.d.ts +23 -0
- package/dist/shared/types/selection-box.js +3 -0
- package/dist/shared/types/style.d.ts +68 -0
- package/dist/shared/types/style.js +3 -0
- package/dist/shared/utils/color.d.ts +49 -0
- package/dist/shared/utils/color.js +180 -0
- package/dist/shared/utils/coordinates.d.ts +52 -0
- package/dist/shared/utils/coordinates.js +75 -0
- package/dist/shared/utils/embedded-image.d.ts +34 -0
- package/dist/shared/utils/embedded-image.js +161 -0
- package/dist/shared/utils/event-emitter.d.ts +262 -0
- package/dist/shared/utils/event-emitter.js +44 -0
- package/dist/shared/utils/feature-bbox.d.ts +8 -0
- package/dist/shared/utils/feature-bbox.js +207 -0
- package/dist/shared/utils/feature-segments.d.ts +23 -0
- package/dist/shared/utils/feature-segments.js +179 -0
- package/dist/shared/utils/id.d.ts +1 -0
- package/dist/shared/utils/id.js +35 -0
- package/dist/shared/utils/image.d.ts +34 -0
- package/dist/shared/utils/image.js +106 -0
- package/dist/shared/utils/index.d.ts +15 -0
- package/dist/shared/utils/index.js +24 -0
- package/dist/shared/utils/map.d.ts +26 -0
- package/dist/shared/utils/map.js +35 -0
- package/dist/shared/utils/name-generator.d.ts +197 -0
- package/dist/shared/utils/name-generator.js +337 -0
- package/dist/shared/utils/pixel-ratio.d.ts +111 -0
- package/dist/shared/utils/pixel-ratio.js +85 -0
- package/dist/shared/utils/property.d.ts +88 -0
- package/dist/shared/utils/property.js +140 -0
- package/dist/shared/utils/vertex-ref.d.ts +23 -0
- package/dist/shared/utils/vertex-ref.js +20 -0
- package/dist/snapping/custom-targets.d.ts +1 -0
- package/dist/snapping/custom-targets.js +21 -0
- package/dist/snapping/geometry.d.ts +1 -0
- package/dist/snapping/geometry.js +61 -0
- package/dist/snapping/index.d.ts +14 -0
- package/dist/snapping/index.js +4 -0
- package/dist/snapping/indicator.d.ts +19 -0
- package/dist/snapping/indicator.js +145 -0
- package/dist/snapping/providers/display.d.ts +72 -0
- package/dist/snapping/providers/display.js +268 -0
- package/dist/snapping/providers/guide.d.ts +69 -0
- package/dist/snapping/providers/guide.js +187 -0
- package/dist/snapping/providers/intersection.d.ts +1 -0
- package/dist/snapping/providers/intersection.js +92 -0
- package/dist/snapping/providers/shared.d.ts +39 -0
- package/dist/snapping/providers/shared.js +146 -0
- package/dist/snapping/providers/store.d.ts +1 -0
- package/dist/snapping/providers/store.js +132 -0
- package/dist/snapping/service.d.ts +1 -0
- package/dist/snapping/service.js +272 -0
- package/dist/snapping/types.d.ts +267 -0
- package/dist/snapping/types.js +66 -0
- package/dist/store/change-merger.d.ts +1 -0
- package/dist/store/change-merger.js +102 -0
- package/dist/store/draw-store.d.ts +1 -0
- package/dist/store/draw-store.js +396 -0
- package/dist/store/event-bridge.d.ts +1 -0
- package/dist/store/event-bridge.js +161 -0
- package/dist/store/index.d.ts +12 -0
- package/dist/store/index.js +4 -0
- package/dist/store/local-visibility.d.ts +21 -0
- package/dist/store/local-visibility.js +27 -0
- package/dist/store/lock.d.ts +67 -0
- package/dist/store/lock.js +54 -0
- package/dist/store/memory/change-bus.d.ts +60 -0
- package/dist/store/memory/change-bus.js +232 -0
- package/dist/store/memory/file-store.d.ts +15 -0
- package/dist/store/memory/file-store.js +33 -0
- package/dist/store/memory/frozen.d.ts +21 -0
- package/dist/store/memory/frozen.js +51 -0
- package/dist/store/memory/ui-state.d.ts +51 -0
- package/dist/store/memory/ui-state.js +223 -0
- package/dist/store/memory.d.ts +26 -0
- package/dist/store/memory.js +708 -0
- package/dist/store/spatial/index.d.ts +6 -0
- package/dist/store/spatial/index.js +4 -0
- package/dist/store/spatial/spatial-index.d.ts +90 -0
- package/dist/store/spatial/spatial-index.js +148 -0
- package/dist/store/spatial/store-spatial-index.d.ts +60 -0
- package/dist/store/spatial/store-spatial-index.js +125 -0
- package/dist/store/store.d.ts +417 -0
- package/dist/store/store.js +3 -0
- package/dist/store/types.d.ts +8 -0
- package/dist/store/types.js +3 -0
- package/dist/store/writable-layer.d.ts +35 -0
- package/dist/store/writable-layer.js +20 -0
- package/dist/view/cache/buffer.d.ts +28 -0
- package/dist/view/cache/buffer.js +176 -0
- package/dist/view/cache/earcut.d.ts +1 -0
- package/dist/view/cache/earcut.js +122 -0
- package/dist/view/cache/style-rule.d.ts +1 -0
- package/dist/view/cache/style-rule.js +97 -0
- package/dist/view/cache/terrain-fill.d.ts +30 -0
- package/dist/view/cache/terrain-fill.js +60 -0
- package/dist/view/cache/texture.d.ts +14 -0
- package/dist/view/cache/texture.js +292 -0
- package/dist/view/coordinator.d.ts +27 -0
- package/dist/view/coordinator.js +72 -0
- package/dist/view/feature-companion.d.ts +173 -0
- package/dist/view/feature-companion.js +108 -0
- package/dist/view/globe-subdivision.d.ts +78 -0
- package/dist/view/globe-subdivision.js +128 -0
- package/dist/view/index.d.ts +47 -0
- package/dist/view/index.js +20 -0
- package/dist/view/layer/attach.d.ts +20 -0
- package/dist/view/layer/attach.js +47 -0
- package/dist/view/layer/blend.d.ts +57 -0
- package/dist/view/layer/blend.js +14 -0
- package/dist/view/layer/custom-layer.d.ts +1 -0
- package/dist/view/layer/custom-layer.js +509 -0
- package/dist/view/layer/depth-state.d.ts +14 -0
- package/dist/view/layer/depth-state.js +44 -0
- package/dist/view/layer/display-list.d.ts +1 -0
- package/dist/view/layer/display-list.js +111 -0
- package/dist/view/layer/drape-planner.d.ts +139 -0
- package/dist/view/layer/drape-planner.js +726 -0
- package/dist/view/layer/frame-render.d.ts +57 -0
- package/dist/view/layer/frame-render.js +209 -0
- package/dist/view/layer/frame-state.d.ts +147 -0
- package/dist/view/layer/frame-state.js +484 -0
- package/dist/view/layer/gl-state.d.ts +77 -0
- package/dist/view/layer/gl-state.js +132 -0
- package/dist/view/layer/index.d.ts +6 -0
- package/dist/view/layer/index.js +5 -0
- package/dist/view/layer/render-scope.d.ts +30 -0
- package/dist/view/layer/render-scope.js +28 -0
- package/dist/view/layer/render.d.ts +87 -0
- package/dist/view/layer/render.js +187 -0
- package/dist/view/layer/renderers.d.ts +81 -0
- package/dist/view/layer/renderers.js +142 -0
- package/dist/view/layer/slot-manager.d.ts +26 -0
- package/dist/view/layer/slot-manager.js +133 -0
- package/dist/view/layer/slots.d.ts +33 -0
- package/dist/view/layer/slots.js +50 -0
- package/dist/view/layer/store-retained-bbox.d.ts +36 -0
- package/dist/view/layer/store-retained-bbox.js +188 -0
- package/dist/view/layer/store-retained-chunk.d.ts +97 -0
- package/dist/view/layer/store-retained-chunk.js +94 -0
- package/dist/view/layer/store-retained-classify.d.ts +34 -0
- package/dist/view/layer/store-retained-classify.js +88 -0
- package/dist/view/layer/store-retained-collect.d.ts +24 -0
- package/dist/view/layer/store-retained-collect.js +121 -0
- package/dist/view/layer/store-retained-coord-patch.d.ts +119 -0
- package/dist/view/layer/store-retained-coord-patch.js +168 -0
- package/dist/view/layer/store-retained-immediate.d.ts +63 -0
- package/dist/view/layer/store-retained-immediate.js +49 -0
- package/dist/view/layer/store-retained-invalidation.d.ts +96 -0
- package/dist/view/layer/store-retained-invalidation.js +192 -0
- package/dist/view/layer/store-retained.d.ts +198 -0
- package/dist/view/layer/store-retained.js +430 -0
- package/dist/view/layer/terrain-resolver.d.ts +1 -0
- package/dist/view/layer/terrain-resolver.js +174 -0
- package/dist/view/renderers/batch-manager.d.ts +61 -0
- package/dist/view/renderers/batch-manager.js +718 -0
- package/dist/view/renderers/draw-factors.d.ts +60 -0
- package/dist/view/renderers/draw-factors.js +35 -0
- package/dist/view/renderers/drawer.d.ts +1 -0
- package/dist/view/renderers/drawer.js +346 -0
- package/dist/view/renderers/image.d.ts +1 -0
- package/dist/view/renderers/image.js +255 -0
- package/dist/view/renderers/line/dash.d.ts +31 -0
- package/dist/view/renderers/line/dash.js +152 -0
- package/dist/view/renderers/line/line-geometry.d.ts +39 -0
- package/dist/view/renderers/line/line-geometry.js +460 -0
- package/dist/view/renderers/line/line-gl.d.ts +1 -0
- package/dist/view/renderers/line/line-gl.js +236 -0
- package/dist/view/renderers/line/line-shader.d.ts +1 -0
- package/dist/view/renderers/line/line-shader.js +364 -0
- package/dist/view/renderers/line/line-types.d.ts +43 -0
- package/dist/view/renderers/line/line-types.js +3 -0
- package/dist/view/renderers/line/line-uniforms.d.ts +1 -0
- package/dist/view/renderers/line/line-uniforms.js +390 -0
- package/dist/view/renderers/line/sdf-line.d.ts +92 -0
- package/dist/view/renderers/line/sdf-line.js +567 -0
- package/dist/view/renderers/point/billboard-depth.d.ts +10 -0
- package/dist/view/renderers/point/billboard-depth.js +56 -0
- package/dist/view/renderers/point/point-instance.d.ts +124 -0
- package/dist/view/renderers/point/point-instance.js +738 -0
- package/dist/view/renderers/point/point-sdf.d.ts +58 -0
- package/dist/view/renderers/point/point-sdf.js +170 -0
- package/dist/view/renderers/point/point-shape.d.ts +99 -0
- package/dist/view/renderers/point/point-shape.js +504 -0
- package/dist/view/renderers/point/point-style.d.ts +1 -0
- package/dist/view/renderers/point/point-style.js +46 -0
- package/dist/view/renderers/polygon/batch.d.ts +26 -0
- package/dist/view/renderers/polygon/batch.js +336 -0
- package/dist/view/renderers/polygon/earcut-input.d.ts +37 -0
- package/dist/view/renderers/polygon/earcut-input.js +55 -0
- package/dist/view/renderers/polygon/earcut-sliced.d.ts +69 -0
- package/dist/view/renderers/polygon/earcut-sliced.js +960 -0
- package/dist/view/renderers/polygon/fill.d.ts +74 -0
- package/dist/view/renderers/polygon/fill.js +251 -0
- package/dist/view/renderers/polygon/sdf-polygon.d.ts +62 -0
- package/dist/view/renderers/polygon/sdf-polygon.js +919 -0
- package/dist/view/renderers/polygon/terrain-cull.d.ts +3 -0
- package/dist/view/renderers/polygon/terrain-cull.js +14 -0
- package/dist/view/renderers/polygon/triangulator.d.ts +41 -0
- package/dist/view/renderers/polygon/triangulator.js +3 -0
- package/dist/view/renderers/retained.d.ts +43 -0
- package/dist/view/renderers/retained.js +3 -0
- package/dist/view/renderers/stroke.d.ts +121 -0
- package/dist/view/renderers/stroke.js +621 -0
- package/dist/view/shaders/frame.d.ts +8 -0
- package/dist/view/shaders/frame.js +37 -0
- package/dist/view/shaders/helpers.d.ts +238 -0
- package/dist/view/shaders/helpers.js +611 -0
- package/dist/view/shaders/initializer.d.ts +27 -0
- package/dist/view/shaders/initializer.js +125 -0
- package/dist/view/shaders/projection.d.ts +123 -0
- package/dist/view/shaders/projection.js +299 -0
- package/dist/view/shaders/quad-grid.d.ts +77 -0
- package/dist/view/shaders/quad-grid.js +128 -0
- package/dist/view/shaders/quad.d.ts +189 -0
- package/dist/view/shaders/quad.js +582 -0
- package/dist/view/shaders/retained-origin.d.ts +50 -0
- package/dist/view/shaders/retained-origin.js +67 -0
- package/dist/view/shaders/terrain-shade.d.ts +23 -0
- package/dist/view/shaders/terrain-shade.js +93 -0
- package/dist/view/style-rule.d.ts +166 -0
- package/dist/view/style-rule.js +300 -0
- package/dist/view/terrain/anchor.d.ts +135 -0
- package/dist/view/terrain/anchor.js +226 -0
- package/dist/view/terrain/context.d.ts +132 -0
- package/dist/view/terrain/context.js +437 -0
- package/dist/view/terrain/dem-atlas.d.ts +97 -0
- package/dist/view/terrain/dem-atlas.js +534 -0
- package/dist/view/terrain/detect.d.ts +126 -0
- package/dist/view/terrain/detect.js +198 -0
- package/dist/view/terrain/drape/bin-store.d.ts +179 -0
- package/dist/view/terrain/drape/bin-store.js +529 -0
- package/dist/view/terrain/drape/binning.d.ts +259 -0
- package/dist/view/terrain/drape/binning.js +604 -0
- package/dist/view/terrain/drape/edge-constrain.d.ts +37 -0
- package/dist/view/terrain/drape/edge-constrain.js +175 -0
- package/dist/view/terrain/drape/geometry.d.ts +95 -0
- package/dist/view/terrain/drape/geometry.js +260 -0
- package/dist/view/terrain/drape/mesh.d.ts +50 -0
- package/dist/view/terrain/drape/mesh.js +86 -0
- package/dist/view/terrain/drape/pass.d.ts +122 -0
- package/dist/view/terrain/drape/pass.js +379 -0
- package/dist/view/terrain/drape/quad-glyphs.d.ts +64 -0
- package/dist/view/terrain/drape/quad-glyphs.js +117 -0
- package/dist/view/terrain/drape/quad.d.ts +249 -0
- package/dist/view/terrain/drape/quad.js +835 -0
- package/dist/view/terrain/drape/renderer.d.ts +184 -0
- package/dist/view/terrain/drape/renderer.js +706 -0
- package/dist/view/terrain/drape/shared.d.ts +80 -0
- package/dist/view/terrain/drape/shared.js +173 -0
- package/dist/view/terrain/drape/stitch.d.ts +155 -0
- package/dist/view/terrain/drape/stitch.js +228 -0
- package/dist/view/terrain/ground.d.ts +72 -0
- package/dist/view/terrain/ground.js +151 -0
- package/dist/view/terrain/metrics.d.ts +180 -0
- package/dist/view/terrain/metrics.js +231 -0
- package/dist/view/terrain/occlusion.d.ts +11 -0
- package/dist/view/terrain/occlusion.js +129 -0
- package/dist/view/terrain/polygon.d.ts +86 -0
- package/dist/view/terrain/polygon.js +301 -0
- package/dist/view/terrain/shade.d.ts +48 -0
- package/dist/view/terrain/shade.js +45 -0
- package/dist/view/terrain/state.d.ts +99 -0
- package/dist/view/terrain/state.js +186 -0
- package/dist/view/terrain/tessellation.d.ts +265 -0
- package/dist/view/terrain/tessellation.js +924 -0
- package/dist/view/terrain/tiling.d.ts +56 -0
- package/dist/view/terrain/tiling.js +155 -0
- package/dist/view/terrain/upstream-terrain.d.ts +82 -0
- package/dist/view/terrain/upstream-terrain.js +116 -0
- package/dist/view/ui/auxiliary-handles.d.ts +151 -0
- package/dist/view/ui/auxiliary-handles.js +22 -0
- package/dist/view/ui/bounds.d.ts +53 -0
- package/dist/view/ui/bounds.js +149 -0
- package/dist/view/ui/box-selection.d.ts +1 -0
- package/dist/view/ui/box-selection.js +83 -0
- package/dist/view/ui/handle-test.d.ts +1 -0
- package/dist/view/ui/handle-test.js +437 -0
- package/dist/view/ui/handle-thinning.d.ts +122 -0
- package/dist/view/ui/handle-thinning.js +430 -0
- package/dist/view/ui/handles.d.ts +25 -0
- package/dist/view/ui/handles.js +673 -0
- package/dist/view/ui/helper.d.ts +19 -0
- package/dist/view/ui/helper.js +76 -0
- package/dist/view/ui/index.d.ts +15 -0
- package/dist/view/ui/index.js +15 -0
- package/dist/view/ui/selection-scope.d.ts +25 -0
- package/dist/view/ui/selection-scope.js +34 -0
- package/dist/view/ui/selection-ui/bounding-box.d.ts +44 -0
- package/dist/view/ui/selection-ui/bounding-box.js +240 -0
- package/dist/view/ui/selection-ui/extension-registry.d.ts +76 -0
- package/dist/view/ui/selection-ui/extension-registry.js +78 -0
- package/dist/view/ui/selection-ui/index.d.ts +12 -0
- package/dist/view/ui/selection-ui/index.js +12 -0
- package/dist/view/ui/selection-ui/renderer.d.ts +29 -0
- package/dist/view/ui/selection-ui/renderer.js +227 -0
- package/dist/view/ui/selection-ui/types.d.ts +55 -0
- package/dist/view/ui/selection-ui/types.js +3 -0
- package/dist/view/ui/selection-ui-drawer.d.ts +52 -0
- package/dist/view/ui/selection-ui-drawer.js +329 -0
- package/dist/view/ui/tentative.d.ts +1 -0
- package/dist/view/ui/tentative.js +320 -0
- package/dist/view/viewport.d.ts +119 -0
- package/dist/view/viewport.js +254 -0
- package/package.json +113 -0
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only AND BSD-3-Clause
|
|
3
|
+
/**
|
|
4
|
+
* The DEM atlas
|
|
5
|
+
*
|
|
6
|
+
* MapLibre's terrain holds the DEM in a separate texture per tile and references it with a
|
|
7
|
+
* different `u_terrain_matrix` per tile. core's rendering is built to draw once per layer /
|
|
8
|
+
* chunk in one go, so bringing "a split per terrain tile" into it would multiply the draw
|
|
9
|
+
* calls by the number of tiles and break the premise of retained batches as well.
|
|
10
|
+
*
|
|
11
|
+
* So the DEM tiles being drawn are re-baked into a single texture (the atlas) at the head of
|
|
12
|
+
* the frame. From then on every vertex shader can look an elevation up with nothing but the
|
|
13
|
+
* simple linear transform "Mercator coordinate -> atlas uv". Since the vertex buffers are
|
|
14
|
+
* never touched, there is no need to rebuild retained batches when the DEM arrives (the point
|
|
15
|
+
* of the shader-based approach).
|
|
16
|
+
*
|
|
17
|
+
* The contents of the atlas are not terrarium but elevation meters repacked into a 24-bit
|
|
18
|
+
* fixed point value (a resolution of 0.0039 m). Decoding then takes a single dot product.
|
|
19
|
+
*
|
|
20
|
+
* The bake is skipped when nothing it reads has changed: the same layout, the same tiles with
|
|
21
|
+
* the same DEM textures, matrices and unpack vectors, and the same exaggeration. maplibre
|
|
22
|
+
* rewrites a DEM texture in place when a tile is reloaded or its border is filled from a
|
|
23
|
+
* neighbour that just arrived, which none of those show, so the atlas is also baked on every
|
|
24
|
+
* frame while tiles are loading and on the first frame after they have all arrived
|
|
25
|
+
* (maplibre-coupling.md, "DEM textures").
|
|
26
|
+
*
|
|
27
|
+
* The elevation is baked after the terrain's vertical exaggeration has been applied, the
|
|
28
|
+
* same way MapLibre displaces its own mesh (`getTerrainExaggeration` in `detect.ts`). Every
|
|
29
|
+
* reader of the atlas (vertex displacement and the shading of the fill) then sees the
|
|
30
|
+
* surface the map actually draws, and agrees with the anchors, whose CPU-side elevation
|
|
31
|
+
* already includes the factor. The range of the fixed point value (+-32768 m) applies to
|
|
32
|
+
* the exaggerated elevation.
|
|
33
|
+
*/
|
|
34
|
+
import { createProgram } from '../shaders/helpers.js';
|
|
35
|
+
import { getRenderableTerrainTiles, getTerrainExaggeration, getTerrainTileData, } from './detect.js';
|
|
36
|
+
import { UPSTREAM_DEM_GLSL } from './upstream-terrain.js';
|
|
37
|
+
/** Target number of texels assigned to one tile (the terrain mesh splits a tile into 128) */
|
|
38
|
+
const ATLAS_CELL_TEXELS = 256;
|
|
39
|
+
/** Upper bound on the side of the atlas (2048x2048 of RGBA8 = 16MB) */
|
|
40
|
+
const ATLAS_MAX_TEXELS = 2048;
|
|
41
|
+
/** The EXTENT of MapLibre's tile coordinate system */
|
|
42
|
+
const TILE_EXTENT = 8192;
|
|
43
|
+
/**
|
|
44
|
+
* The span of zooms admitted into the range the atlas covers
|
|
45
|
+
*
|
|
46
|
+
* Once the pitch is raised, the terrain tiles being drawn include very coarse tiles on the
|
|
47
|
+
* horizon side (measured: two zoom 7 tiles in a zoom 12 view). Trying to cover the coarse
|
|
48
|
+
* tiles too would make the atlas range as much as 64 times the width of the finest tile, and
|
|
49
|
+
* the resolution in the foreground would end up coarser than the terrain mesh (128
|
|
50
|
+
* subdivisions per tile).
|
|
51
|
+
*
|
|
52
|
+
* So the range is decided by "only the tiles within this span from the finest zoom". The
|
|
53
|
+
* coarse tiles are baked in a way that sticks out beyond the range, so no elevation is missing
|
|
54
|
+
* inside that range. Outside the range (on the horizon side) it is clamped to the edge value.
|
|
55
|
+
*/
|
|
56
|
+
const ATLAS_ZOOM_SPAN = 2;
|
|
57
|
+
const QUAD = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
|
|
58
|
+
const VERTEX_SOURCE = `#version 300 es
|
|
59
|
+
layout(location = 0) in vec2 a_corner;
|
|
60
|
+
uniform vec4 u_dest; // [x0, y0, width, height] in the atlas 0..1 space
|
|
61
|
+
uniform float u_extent; // The EXTENT of the tile coordinate system
|
|
62
|
+
out vec2 v_tile_pos;
|
|
63
|
+
void main() {
|
|
64
|
+
vec2 p = u_dest.xy + a_corner * u_dest.zw;
|
|
65
|
+
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
66
|
+
v_tile_pos = a_corner * u_extent;
|
|
67
|
+
}`;
|
|
68
|
+
// The DEM is read with the layout of maplibre's DEM textures (upstream-terrain.ts), the same way
|
|
69
|
+
// the drape and maplibre's own terrain read it.
|
|
70
|
+
const FRAGMENT_SOURCE = `#version 300 es
|
|
71
|
+
precision highp float;
|
|
72
|
+
in vec2 v_tile_pos;
|
|
73
|
+
uniform highp sampler2D u_terrain;
|
|
74
|
+
uniform mat4 u_terrain_matrix;
|
|
75
|
+
uniform float u_terrain_dim;
|
|
76
|
+
uniform vec4 u_terrain_unpack;
|
|
77
|
+
uniform float u_terrain_exaggeration;
|
|
78
|
+
out vec4 fragColor;
|
|
79
|
+
${UPSTREAM_DEM_GLSL}
|
|
80
|
+
void main() {
|
|
81
|
+
vec2 uv = (u_terrain_matrix * vec4(v_tile_pos, 0.0, 1.0)).xy;
|
|
82
|
+
float elevation = upstream_dem_bilinear(
|
|
83
|
+
u_terrain, u_terrain_unpack, upstream_dem_coord(uv, u_terrain_dim)) *
|
|
84
|
+
u_terrain_exaggeration;
|
|
85
|
+
|
|
86
|
+
// Meters into a 24-bit fixed point value (-32768 m to +32768 m, resolution 0.0039 m)
|
|
87
|
+
float v = clamp((elevation + 32768.0) / 65536.0, 0.0, 0.99999994);
|
|
88
|
+
float r = floor(v * 256.0);
|
|
89
|
+
float g = floor((v * 256.0 - r) * 256.0);
|
|
90
|
+
float b = floor(((v * 256.0 - r) * 256.0 - g) * 256.0);
|
|
91
|
+
fragColor = vec4(r / 255.0, g / 255.0, b / 255.0, 1.0);
|
|
92
|
+
}`;
|
|
93
|
+
/**
|
|
94
|
+
* The DEM atlas
|
|
95
|
+
*/
|
|
96
|
+
export class DemAtlas {
|
|
97
|
+
constructor(gl) {
|
|
98
|
+
Object.defineProperty(this, "gl", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
value: void 0
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(this, "program", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
configurable: true,
|
|
107
|
+
writable: true,
|
|
108
|
+
value: null
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(this, "vao", {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
configurable: true,
|
|
113
|
+
writable: true,
|
|
114
|
+
value: null
|
|
115
|
+
});
|
|
116
|
+
Object.defineProperty(this, "quadBuffer", {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
configurable: true,
|
|
119
|
+
writable: true,
|
|
120
|
+
value: null
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(this, "framebuffer", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
configurable: true,
|
|
125
|
+
writable: true,
|
|
126
|
+
value: null
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(this, "texture", {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
configurable: true,
|
|
131
|
+
writable: true,
|
|
132
|
+
value: null
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(this, "textureWidth", {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
configurable: true,
|
|
137
|
+
writable: true,
|
|
138
|
+
value: 0
|
|
139
|
+
});
|
|
140
|
+
Object.defineProperty(this, "textureHeight", {
|
|
141
|
+
enumerable: true,
|
|
142
|
+
configurable: true,
|
|
143
|
+
writable: true,
|
|
144
|
+
value: 0
|
|
145
|
+
});
|
|
146
|
+
// Uniform locations
|
|
147
|
+
Object.defineProperty(this, "destLoc", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
configurable: true,
|
|
150
|
+
writable: true,
|
|
151
|
+
value: null
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(this, "extentLoc", {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
configurable: true,
|
|
156
|
+
writable: true,
|
|
157
|
+
value: null
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(this, "terrainLoc", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
configurable: true,
|
|
162
|
+
writable: true,
|
|
163
|
+
value: null
|
|
164
|
+
});
|
|
165
|
+
Object.defineProperty(this, "matrixLoc", {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
configurable: true,
|
|
168
|
+
writable: true,
|
|
169
|
+
value: null
|
|
170
|
+
});
|
|
171
|
+
Object.defineProperty(this, "dimLoc", {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
configurable: true,
|
|
174
|
+
writable: true,
|
|
175
|
+
value: null
|
|
176
|
+
});
|
|
177
|
+
Object.defineProperty(this, "unpackLoc", {
|
|
178
|
+
enumerable: true,
|
|
179
|
+
configurable: true,
|
|
180
|
+
writable: true,
|
|
181
|
+
value: null
|
|
182
|
+
});
|
|
183
|
+
Object.defineProperty(this, "exaggerationLoc", {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
configurable: true,
|
|
186
|
+
writable: true,
|
|
187
|
+
value: null
|
|
188
|
+
});
|
|
189
|
+
/** What the atlas holds now, for skipping a bake that would give the same texels */
|
|
190
|
+
Object.defineProperty(this, "bakedKey", {
|
|
191
|
+
enumerable: true,
|
|
192
|
+
configurable: true,
|
|
193
|
+
writable: true,
|
|
194
|
+
value: null
|
|
195
|
+
});
|
|
196
|
+
Object.defineProperty(this, "bakedResult", {
|
|
197
|
+
enumerable: true,
|
|
198
|
+
configurable: true,
|
|
199
|
+
writable: true,
|
|
200
|
+
value: null
|
|
201
|
+
});
|
|
202
|
+
/** A number per DEM texture object (the key compares textures by identity) */
|
|
203
|
+
Object.defineProperty(this, "textureIds", {
|
|
204
|
+
enumerable: true,
|
|
205
|
+
configurable: true,
|
|
206
|
+
writable: true,
|
|
207
|
+
value: new WeakMap()
|
|
208
|
+
});
|
|
209
|
+
Object.defineProperty(this, "nextTextureId", {
|
|
210
|
+
enumerable: true,
|
|
211
|
+
configurable: true,
|
|
212
|
+
writable: true,
|
|
213
|
+
value: 1
|
|
214
|
+
});
|
|
215
|
+
/** The number of bakes done (diagnostics and tests) */
|
|
216
|
+
Object.defineProperty(this, "bakeCount", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
configurable: true,
|
|
219
|
+
writable: true,
|
|
220
|
+
value: 0
|
|
221
|
+
});
|
|
222
|
+
this.gl = gl;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Bakes the DEM tiles being drawn into the atlas
|
|
226
|
+
*
|
|
227
|
+
* @param centerMercatorX The Mercator x of the camera center. Each tile is placed on the copy
|
|
228
|
+
* of the world nearest to it, so the tiles on both sides of the antimeridian sit next to
|
|
229
|
+
* each other (see `computeAtlasLayout`)
|
|
230
|
+
* @param tilesLoaded Whether every tile of the map has arrived (`map.areTilesLoaded()`).
|
|
231
|
+
* While they have not, the DEM textures can be rewritten in place, so the atlas is baked
|
|
232
|
+
* again on every frame; once they have, an unchanged frame reuses the last bake
|
|
233
|
+
* @returns null when it cannot be baked (the terrain is disabled, there is not a single
|
|
234
|
+
* tile, or a GL resource could not be allocated)
|
|
235
|
+
*/
|
|
236
|
+
build(terrain, centerMercatorX = 0.5, tilesLoaded = false) {
|
|
237
|
+
const tiles = getRenderableTerrainTiles(terrain);
|
|
238
|
+
if (tiles.length === 0)
|
|
239
|
+
return null;
|
|
240
|
+
const layout = computeAtlasLayout(tiles, centerMercatorX);
|
|
241
|
+
if (!layout)
|
|
242
|
+
return null;
|
|
243
|
+
// Coarse tiles are baked first and finer tiles overwrite them
|
|
244
|
+
const ordered = [...tiles].sort((a, b) => a.z - b.z);
|
|
245
|
+
const sources = ordered.map((tile) => getTerrainTileData(terrain, tile));
|
|
246
|
+
const exaggeration = getTerrainExaggeration(terrain);
|
|
247
|
+
const key = this.bakeKey(layout, ordered, sources, exaggeration);
|
|
248
|
+
if (key === this.bakedKey && this.bakedResult && this.texture)
|
|
249
|
+
return this.bakedResult;
|
|
250
|
+
const gl = this.gl;
|
|
251
|
+
if (!this.ensureProgram())
|
|
252
|
+
return null;
|
|
253
|
+
if (!this.ensureTarget(layout.width, layout.height))
|
|
254
|
+
return null;
|
|
255
|
+
this.bakeCount++;
|
|
256
|
+
// Saves the draw state. This runs in the middle of MapLibre's rendering, and restoring it
|
|
257
|
+
// is the caller's responsibility.
|
|
258
|
+
const prevFbo = gl.getParameter(gl.FRAMEBUFFER_BINDING);
|
|
259
|
+
const prevViewport = gl.getParameter(gl.VIEWPORT);
|
|
260
|
+
const prevDepth = gl.getParameter(gl.DEPTH_TEST);
|
|
261
|
+
const prevBlend = gl.getParameter(gl.BLEND);
|
|
262
|
+
const prevScissor = gl.getParameter(gl.SCISSOR_TEST);
|
|
263
|
+
const prevCull = gl.getParameter(gl.CULL_FACE);
|
|
264
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
|
|
265
|
+
gl.viewport(0, 0, layout.width, layout.height);
|
|
266
|
+
gl.disable(gl.DEPTH_TEST);
|
|
267
|
+
gl.disable(gl.BLEND);
|
|
268
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
269
|
+
gl.disable(gl.CULL_FACE);
|
|
270
|
+
// Fills with elevation 0 (outside the coverage is treated as sea level 0)
|
|
271
|
+
gl.clearColor(128 / 255, 0, 0, 1);
|
|
272
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
273
|
+
gl.useProgram(this.program);
|
|
274
|
+
gl.bindVertexArray(this.vao);
|
|
275
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
276
|
+
if (this.terrainLoc)
|
|
277
|
+
gl.uniform1i(this.terrainLoc, 0);
|
|
278
|
+
if (this.extentLoc)
|
|
279
|
+
gl.uniform1f(this.extentLoc, TILE_EXTENT);
|
|
280
|
+
if (this.exaggerationLoc)
|
|
281
|
+
gl.uniform1f(this.exaggerationLoc, exaggeration);
|
|
282
|
+
let demDim = 0;
|
|
283
|
+
let drawn = 0;
|
|
284
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
285
|
+
const tile = ordered[i];
|
|
286
|
+
const data = sources[i];
|
|
287
|
+
if (!data)
|
|
288
|
+
continue;
|
|
289
|
+
const tileSize = 1 / 2 ** tile.z;
|
|
290
|
+
const x0 = (tileMercatorX(tile, centerMercatorX) - layout.minX) / layout.spanX;
|
|
291
|
+
const y0 = (tile.y * tileSize - layout.minY) / layout.spanY;
|
|
292
|
+
const w = tileSize / layout.spanX;
|
|
293
|
+
const h = tileSize / layout.spanY;
|
|
294
|
+
gl.bindTexture(gl.TEXTURE_2D, data.texture);
|
|
295
|
+
if (this.destLoc)
|
|
296
|
+
gl.uniform4f(this.destLoc, x0, y0, w, h);
|
|
297
|
+
if (this.matrixLoc) {
|
|
298
|
+
gl.uniformMatrix4fv(this.matrixLoc, false, toFloat32(data.matrix));
|
|
299
|
+
}
|
|
300
|
+
if (this.dimLoc)
|
|
301
|
+
gl.uniform1f(this.dimLoc, data.dim);
|
|
302
|
+
if (this.unpackLoc) {
|
|
303
|
+
gl.uniform4f(this.unpackLoc, data.unpack[0], data.unpack[1], data.unpack[2], data.unpack[3]);
|
|
304
|
+
}
|
|
305
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
306
|
+
demDim = Math.max(demDim, data.dim);
|
|
307
|
+
drawn++;
|
|
308
|
+
}
|
|
309
|
+
gl.bindVertexArray(null);
|
|
310
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
311
|
+
// Restores the saved state
|
|
312
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, prevFbo);
|
|
313
|
+
gl.viewport(prevViewport[0], prevViewport[1], prevViewport[2], prevViewport[3]);
|
|
314
|
+
if (prevDepth)
|
|
315
|
+
gl.enable(gl.DEPTH_TEST);
|
|
316
|
+
else
|
|
317
|
+
gl.disable(gl.DEPTH_TEST);
|
|
318
|
+
if (prevBlend)
|
|
319
|
+
gl.enable(gl.BLEND);
|
|
320
|
+
else
|
|
321
|
+
gl.disable(gl.BLEND);
|
|
322
|
+
if (prevScissor)
|
|
323
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
324
|
+
else
|
|
325
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
326
|
+
if (prevCull)
|
|
327
|
+
gl.enable(gl.CULL_FACE);
|
|
328
|
+
else
|
|
329
|
+
gl.disable(gl.CULL_FACE);
|
|
330
|
+
if (drawn === 0 || !this.texture) {
|
|
331
|
+
this.bakedKey = null;
|
|
332
|
+
this.bakedResult = null;
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
const result = {
|
|
336
|
+
texture: this.texture,
|
|
337
|
+
rect: [layout.minX, layout.minY, 1 / layout.spanX, 1 / layout.spanY],
|
|
338
|
+
size: [layout.width, layout.height],
|
|
339
|
+
maxTileZoom: layout.maxZoom,
|
|
340
|
+
demDim: demDim || 256,
|
|
341
|
+
};
|
|
342
|
+
// Only a bake made after every tile arrived can be reused (see the module comment)
|
|
343
|
+
this.bakedKey = tilesLoaded ? key : null;
|
|
344
|
+
this.bakedResult = result;
|
|
345
|
+
return result;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* The key of everything a bake reads (two bakes with the same key give the same texels, as
|
|
349
|
+
* long as no DEM texture was rewritten in place)
|
|
350
|
+
*/
|
|
351
|
+
bakeKey(layout, tiles, sources, exaggeration) {
|
|
352
|
+
let key = `${layout.width}x${layout.height}@${layout.minX},${layout.minY},${layout.spanX},${layout.spanY}|${exaggeration}`;
|
|
353
|
+
for (let i = 0; i < tiles.length; i++) {
|
|
354
|
+
const tile = tiles[i];
|
|
355
|
+
const data = sources[i];
|
|
356
|
+
key += `|${tile.z}/${tile.x}/${tile.y}`;
|
|
357
|
+
if (!data)
|
|
358
|
+
continue;
|
|
359
|
+
let id = this.textureIds.get(data.texture);
|
|
360
|
+
if (id === undefined) {
|
|
361
|
+
id = this.nextTextureId++;
|
|
362
|
+
this.textureIds.set(data.texture, id);
|
|
363
|
+
}
|
|
364
|
+
key += `:${id}:${data.dim}:${Array.prototype.join.call(data.unpack)}:${Array.prototype.join.call(data.matrix)}`;
|
|
365
|
+
}
|
|
366
|
+
return key;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Releases the GL resources
|
|
370
|
+
*/
|
|
371
|
+
dispose() {
|
|
372
|
+
const gl = this.gl;
|
|
373
|
+
this.bakedKey = null;
|
|
374
|
+
this.bakedResult = null;
|
|
375
|
+
if (this.program) {
|
|
376
|
+
gl.deleteProgram(this.program);
|
|
377
|
+
this.program = null;
|
|
378
|
+
}
|
|
379
|
+
if (this.vao) {
|
|
380
|
+
gl.deleteVertexArray(this.vao);
|
|
381
|
+
this.vao = null;
|
|
382
|
+
}
|
|
383
|
+
if (this.quadBuffer) {
|
|
384
|
+
gl.deleteBuffer(this.quadBuffer);
|
|
385
|
+
this.quadBuffer = null;
|
|
386
|
+
}
|
|
387
|
+
if (this.framebuffer) {
|
|
388
|
+
gl.deleteFramebuffer(this.framebuffer);
|
|
389
|
+
this.framebuffer = null;
|
|
390
|
+
}
|
|
391
|
+
if (this.texture) {
|
|
392
|
+
gl.deleteTexture(this.texture);
|
|
393
|
+
this.texture = null;
|
|
394
|
+
}
|
|
395
|
+
this.textureWidth = 0;
|
|
396
|
+
this.textureHeight = 0;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Compiles the baking program once (false when it cannot be created)
|
|
400
|
+
*/
|
|
401
|
+
ensureProgram() {
|
|
402
|
+
if (this.program)
|
|
403
|
+
return true;
|
|
404
|
+
const gl = this.gl;
|
|
405
|
+
try {
|
|
406
|
+
this.program = createProgram(gl, VERTEX_SOURCE, FRAGMENT_SOURCE);
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
this.destLoc = gl.getUniformLocation(this.program, 'u_dest');
|
|
412
|
+
this.extentLoc = gl.getUniformLocation(this.program, 'u_extent');
|
|
413
|
+
this.terrainLoc = gl.getUniformLocation(this.program, 'u_terrain');
|
|
414
|
+
this.matrixLoc = gl.getUniformLocation(this.program, 'u_terrain_matrix');
|
|
415
|
+
this.dimLoc = gl.getUniformLocation(this.program, 'u_terrain_dim');
|
|
416
|
+
this.unpackLoc = gl.getUniformLocation(this.program, 'u_terrain_unpack');
|
|
417
|
+
this.exaggerationLoc = gl.getUniformLocation(this.program, 'u_terrain_exaggeration');
|
|
418
|
+
this.quadBuffer = gl.createBuffer();
|
|
419
|
+
this.vao = gl.createVertexArray();
|
|
420
|
+
gl.bindVertexArray(this.vao);
|
|
421
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.quadBuffer);
|
|
422
|
+
gl.bufferData(gl.ARRAY_BUFFER, QUAD, gl.STATIC_DRAW);
|
|
423
|
+
gl.enableVertexAttribArray(0);
|
|
424
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 8, 0);
|
|
425
|
+
gl.bindVertexArray(null);
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
ensureTarget(width, height) {
|
|
429
|
+
const gl = this.gl;
|
|
430
|
+
if (this.texture && this.textureWidth === width && this.textureHeight === height)
|
|
431
|
+
return true;
|
|
432
|
+
if (this.texture)
|
|
433
|
+
gl.deleteTexture(this.texture);
|
|
434
|
+
if (this.framebuffer)
|
|
435
|
+
gl.deleteFramebuffer(this.framebuffer);
|
|
436
|
+
const texture = gl.createTexture();
|
|
437
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
438
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA8, width, height);
|
|
439
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
440
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
441
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
442
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
443
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
444
|
+
const prevFbo = gl.getParameter(gl.FRAMEBUFFER_BINDING);
|
|
445
|
+
const framebuffer = gl.createFramebuffer();
|
|
446
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
447
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
448
|
+
const complete = gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE;
|
|
449
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, prevFbo);
|
|
450
|
+
if (!complete) {
|
|
451
|
+
gl.deleteTexture(texture);
|
|
452
|
+
gl.deleteFramebuffer(framebuffer);
|
|
453
|
+
this.texture = null;
|
|
454
|
+
this.framebuffer = null;
|
|
455
|
+
this.textureWidth = 0;
|
|
456
|
+
this.textureHeight = 0;
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
this.texture = texture;
|
|
460
|
+
this.framebuffer = framebuffer;
|
|
461
|
+
this.textureWidth = width;
|
|
462
|
+
this.textureHeight = height;
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* The Mercator x of the west edge of a tile, on the copy of the world nearest to the camera
|
|
468
|
+
*
|
|
469
|
+
* The tiles carry canonical x (0 to 2^z - 1). Across the antimeridian the view holds tiles from
|
|
470
|
+
* both ends of that range, and with canonical x their union would be the whole width of the
|
|
471
|
+
* world, crushing the resolution of the atlas. The tile is moved by whole turns (1 in Mercator
|
|
472
|
+
* units) so that its center is within half a turn of the camera center. This is the same
|
|
473
|
+
* placement maplibre gives the wrapped copies it draws.
|
|
474
|
+
*/
|
|
475
|
+
export function tileMercatorX(tile, centerMercatorX) {
|
|
476
|
+
const size = 1 / 2 ** tile.z;
|
|
477
|
+
const x0 = tile.x * size;
|
|
478
|
+
const turns = Math.round(centerMercatorX - (x0 + size / 2));
|
|
479
|
+
return x0 + turns;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Decides the layout of the atlas from the tiles being drawn
|
|
483
|
+
*
|
|
484
|
+
* The range covered is the union of the Mercator rectangles of the tiles (each placed on the
|
|
485
|
+
* copy nearest to the camera, `tileMercatorX`), and the resolution aims at "assigning
|
|
486
|
+
* ATLAS_CELL_TEXELS to the finest tile", lowered only when it would exceed the upper bound.
|
|
487
|
+
*/
|
|
488
|
+
export function computeAtlasLayout(tiles, centerMercatorX) {
|
|
489
|
+
let maxZoom = 0;
|
|
490
|
+
for (const tile of tiles) {
|
|
491
|
+
if (tile.z > maxZoom)
|
|
492
|
+
maxZoom = tile.z;
|
|
493
|
+
}
|
|
494
|
+
const minZoom = maxZoom - ATLAS_ZOOM_SPAN;
|
|
495
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
496
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
497
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
498
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
499
|
+
for (const tile of tiles) {
|
|
500
|
+
if (tile.z < minZoom)
|
|
501
|
+
continue;
|
|
502
|
+
const size = 1 / 2 ** tile.z;
|
|
503
|
+
const x0 = tileMercatorX(tile, centerMercatorX);
|
|
504
|
+
const y0 = tile.y * size;
|
|
505
|
+
if (x0 < minX)
|
|
506
|
+
minX = x0;
|
|
507
|
+
if (y0 < minY)
|
|
508
|
+
minY = y0;
|
|
509
|
+
if (x0 + size > maxX)
|
|
510
|
+
maxX = x0 + size;
|
|
511
|
+
if (y0 + size > maxY)
|
|
512
|
+
maxY = y0 + size;
|
|
513
|
+
}
|
|
514
|
+
const spanX = maxX - minX;
|
|
515
|
+
const spanY = maxY - minY;
|
|
516
|
+
if (!(spanX > 0) || !(spanY > 0))
|
|
517
|
+
return null;
|
|
518
|
+
const finest = 1 / 2 ** maxZoom;
|
|
519
|
+
let cell = ATLAS_CELL_TEXELS;
|
|
520
|
+
while (cell > 16 &&
|
|
521
|
+
((spanX / finest) * cell > ATLAS_MAX_TEXELS || (spanY / finest) * cell > ATLAS_MAX_TEXELS)) {
|
|
522
|
+
cell /= 2;
|
|
523
|
+
}
|
|
524
|
+
const width = Math.min(ATLAS_MAX_TEXELS, Math.max(2, Math.ceil((spanX / finest) * cell)));
|
|
525
|
+
const height = Math.min(ATLAS_MAX_TEXELS, Math.max(2, Math.ceil((spanY / finest) * cell)));
|
|
526
|
+
return { minX, minY, spanX, spanY, width, height, maxZoom };
|
|
527
|
+
}
|
|
528
|
+
/** ArrayLike into a Float32Array (a mat4 can arrive as a Float64Array) */
|
|
529
|
+
function toFloat32(source) {
|
|
530
|
+
const out = new Float32Array(16);
|
|
531
|
+
for (let i = 0; i < 16; i++)
|
|
532
|
+
out[i] = source[i];
|
|
533
|
+
return out;
|
|
534
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reaching MapLibre's terrain
|
|
3
|
+
*
|
|
4
|
+
* Parts of the terrain's internal API have no published types (maplibre-coupling.md, item 7).
|
|
5
|
+
* They are confined to this single place, and in environments where they are absent null is
|
|
6
|
+
* returned and rendering falls back to the path without terrain.
|
|
7
|
+
*/
|
|
8
|
+
import type { Map as MapLibreMap } from 'maplibre-gl';
|
|
9
|
+
/** Rendering data for one DEM tile (the necessary part of MapLibre's TerrainData) */
|
|
10
|
+
export interface TerrainTileData {
|
|
11
|
+
texture: WebGLTexture;
|
|
12
|
+
/** 4x4 that maps tile EXTENT coordinates to the 0..1 space of the DEM texture */
|
|
13
|
+
matrix: ArrayLike<number>;
|
|
14
|
+
/** Decoding coefficients such as terrarium's [r, g, b, offset] */
|
|
15
|
+
unpack: ArrayLike<number>;
|
|
16
|
+
/** One side of the DEM (excluding the border) */
|
|
17
|
+
dim: number;
|
|
18
|
+
/** The vertical exaggeration of the terrain (see `getTerrainExaggeration`) */
|
|
19
|
+
exaggeration: number;
|
|
20
|
+
}
|
|
21
|
+
/** A terrain tile to be rendered */
|
|
22
|
+
export interface RenderableTerrainTile {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
z: number;
|
|
26
|
+
/** The copy of the world the tile is drawn on (0 for the main copy; absent in tests) */
|
|
27
|
+
wrap?: number;
|
|
28
|
+
/** The OverscaledTileID passed to getTerrainData (its type is internal to maplibre) */
|
|
29
|
+
tileID: unknown;
|
|
30
|
+
}
|
|
31
|
+
/** The necessary part of the terrain object */
|
|
32
|
+
export interface TerrainLike {
|
|
33
|
+
getTerrainData(tileID: unknown): unknown;
|
|
34
|
+
/** The vertical exaggeration MapLibre applies to the terrain (see `getTerrainExaggeration`) */
|
|
35
|
+
exaggeration?: number;
|
|
36
|
+
/** The TerrainSpecification passed to `setTerrain` (used only as a fallback) */
|
|
37
|
+
options?: {
|
|
38
|
+
exaggeration?: number;
|
|
39
|
+
};
|
|
40
|
+
/** Number of subdivisions of one tile (MapLibre's default is 128) */
|
|
41
|
+
meshSize?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Looks up the elevation of a single point (in meters, after the exaggeration factor is
|
|
44
|
+
* applied) on the CPU, in the DEM tile of the given zoom level
|
|
45
|
+
*
|
|
46
|
+
* Used only where no drawn tile covers the point (`ground.ts`); where one does, the
|
|
47
|
+
* elevation comes from `map.queryTerrainElevation`, which samples the drawn tile.
|
|
48
|
+
*/
|
|
49
|
+
getElevationForLngLatZoom?(lngLat: TerrainLngLat, zoom: number): number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The shape of longitude and latitude that MapLibre's elevation lookup requires
|
|
53
|
+
*
|
|
54
|
+
* Only `wrap()` is called, rather than the `LngLat` class itself, so the value container
|
|
55
|
+
* is provided here (no value is imported from maplibre-gl = the peer's version differences
|
|
56
|
+
* are not touched).
|
|
57
|
+
*/
|
|
58
|
+
interface TerrainLngLat {
|
|
59
|
+
lng: number;
|
|
60
|
+
lat: number;
|
|
61
|
+
wrap(): TerrainLngLat;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets the elevation of a single point from the DEM tile of one zoom level (in meters)
|
|
65
|
+
*
|
|
66
|
+
* This is the fallback of `groundElevationMeters` (`ground.ts`) for points no drawn tile
|
|
67
|
+
* covers. When it cannot be obtained (no terrain / the DEM has not arrived / the function is
|
|
68
|
+
* missing due to a version difference) 0 is returned. Here 0 does not mean "sea level" but
|
|
69
|
+
* "do not add an elevation", and the result is exactly the same as the rendering and hit
|
|
70
|
+
* testing before the terrain was introduced.
|
|
71
|
+
*
|
|
72
|
+
* @param tileZoom The same value as MapLibre's `transform.tileZoom` (= floor(zoom))
|
|
73
|
+
*/
|
|
74
|
+
export declare function getTerrainElevationMeters(terrain: TerrainLike | null, lng: number, lat: number, tileZoom: number): number;
|
|
75
|
+
/**
|
|
76
|
+
* Extracts the camera position (in Mercator)
|
|
77
|
+
*
|
|
78
|
+
* The occlusion test for symbols (`occlusion.ts`) uses it to draw a segment from the
|
|
79
|
+
* camera to the anchor.
|
|
80
|
+
*
|
|
81
|
+
* `transform.cameraPosition` is not used. That one is "the same space as the 3D features
|
|
82
|
+
* of that projection", and in measurements its units are mixed, with x and y in world
|
|
83
|
+
* pixels and z on yet another scale, so the factor for converting it into this Mercator
|
|
84
|
+
* space depends on the version. Instead it is assembled from `getCameraLngLat()` and
|
|
85
|
+
* `getCameraAltitude()`, because their meaning is unambiguous and they can be written in
|
|
86
|
+
* the same "longitude and latitude + meters" language as the elevation of the anchor.
|
|
87
|
+
*
|
|
88
|
+
* The location of transform differs between versions (v6 has `map.painter.transform`, v5
|
|
89
|
+
* has `map.transform`). In environments where it is absent null is returned, and the
|
|
90
|
+
* occlusion test falls back to "not occluded".
|
|
91
|
+
*/
|
|
92
|
+
export declare function getCameraMercator(map: MapLibreMap | null | undefined, elevationScale: number): readonly [number, number, number] | null;
|
|
93
|
+
/**
|
|
94
|
+
* The vertical exaggeration MapLibre applies to the terrain
|
|
95
|
+
*
|
|
96
|
+
* MapLibre multiplies every elevation by this factor: the terrain mesh it draws
|
|
97
|
+
* (`u_terrain_exaggeration` of `getTerrainData`) and `queryTerrainElevation`, which the
|
|
98
|
+
* anchors use (`ground.ts`). So that polygons, lines and symbols sit on the same surface as the map, every
|
|
99
|
+
* GPU path here (the DEM atlas and the drape) multiplies by the same factor.
|
|
100
|
+
*
|
|
101
|
+
* The factor is read from the terrain object itself (`terrain.exaggeration`, present in v5
|
|
102
|
+
* and v6), which is the very field MapLibre multiplies by, rather than from
|
|
103
|
+
* `map.getTerrain()`, which returns the specification as passed and can leave the factor
|
|
104
|
+
* undefined. When the field is missing, the specification (`terrain.options`) is consulted,
|
|
105
|
+
* and failing that 1 (MapLibre's default) is returned. A negative or non-finite value is
|
|
106
|
+
* treated as missing.
|
|
107
|
+
*/
|
|
108
|
+
export declare function getTerrainExaggeration(terrain: TerrainLike | null): number;
|
|
109
|
+
/** The number of subdivisions of MapLibre's terrain mesh (128 by default) */
|
|
110
|
+
export declare function getTerrainMeshSize(terrain: TerrainLike): number;
|
|
111
|
+
/**
|
|
112
|
+
* Extracts the terrain object from the map (null when it is disabled)
|
|
113
|
+
*/
|
|
114
|
+
export declare function getMapTerrain(map: MapLibreMap | null | undefined): TerrainLike | null;
|
|
115
|
+
/**
|
|
116
|
+
* Enumerates the terrain tiles to be rendered
|
|
117
|
+
*
|
|
118
|
+
* In v6 they live in `tileManager`, in v5 in `sourceCache`. When neither exists, an empty
|
|
119
|
+
* result is returned.
|
|
120
|
+
*/
|
|
121
|
+
export declare function getRenderableTerrainTiles(terrain: TerrainLike): RenderableTerrainTile[];
|
|
122
|
+
/**
|
|
123
|
+
* Extracts the DEM rendering data for one tile (null when something is missing)
|
|
124
|
+
*/
|
|
125
|
+
export declare function getTerrainTileData(terrain: TerrainLike, tile: RenderableTerrainTile): TerrainTileData | null;
|
|
126
|
+
export {};
|