@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,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ground elevation of a single point, taken from the surface maplibre draws
|
|
3
|
+
*
|
|
4
|
+
* Symbols (points, handles, the anchors of custom renderers) are placed by one elevation per
|
|
5
|
+
* point, looked up on the CPU. It must be the elevation of the ground maplibre draws at that
|
|
6
|
+
* point, or the symbol floats above the slope or sinks into it.
|
|
7
|
+
*
|
|
8
|
+
* maplibre 6.11.1 samples the drawn surface in `Map.queryTerrainElevation`
|
|
9
|
+
* (`Terrain.getElevationForLngLat`, `src/render/terrain.ts:246`): where a terrain tile it draws
|
|
10
|
+
* covers the point and its DEM has arrived, it reads that tile's DEM with the placement its
|
|
11
|
+
* shader uses. That is what is used here, through the public method, and nothing of it is
|
|
12
|
+
* copied. `map.project` reads the same function (`MercatorTransform.locationToScreenPoint`), so
|
|
13
|
+
* the anchors agree with it as well.
|
|
14
|
+
*
|
|
15
|
+
* Where no drawn tile covers the point (off screen, or under the camera in a pitched view) the
|
|
16
|
+
* public method walks the covering tiles of the whole view for every call, about 40 us a point
|
|
17
|
+
* against 0.2 to 0.4 us inside the coverage (measured on maplibre 6.11.1, 10 000 points).
|
|
18
|
+
* Nothing is drawn there, so such a point is answered from the tile of the current zoom level
|
|
19
|
+
* (`Terrain.getElevationForLngLatZoom`, cheap) instead. {@link TerrainCoverage} tells the two
|
|
20
|
+
* apart from the tiles maplibre draws in this frame; when the coverage changes, the anchor
|
|
21
|
+
* generation advances and whatever baked an elevation is rebuilt.
|
|
22
|
+
*/
|
|
23
|
+
import { type RenderableTerrainTile, type TerrainLike } from './detect.js';
|
|
24
|
+
/** The part of the map the ground elevation is asked from (`Map.queryTerrainElevation`) */
|
|
25
|
+
export interface TerrainElevationQuery {
|
|
26
|
+
queryTerrainElevation(lngLat: [number, number]): number | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The terrain tiles maplibre draws in the current frame, indexed for a point lookup
|
|
30
|
+
*
|
|
31
|
+
* A point is covered here exactly when maplibre's coverage index (`wrap/z/x/y`, searched from
|
|
32
|
+
* the finest zoom) finds a drawn tile for it, which is when `queryTerrainElevation` samples the
|
|
33
|
+
* drawn surface.
|
|
34
|
+
*/
|
|
35
|
+
export declare class TerrainCoverage {
|
|
36
|
+
/** Identifies the tile set (it changes whenever the set changes) */
|
|
37
|
+
key: string;
|
|
38
|
+
/** The zoom levels present, finest first (the order maplibre searches them in) */
|
|
39
|
+
private zooms;
|
|
40
|
+
private tiles;
|
|
41
|
+
/**
|
|
42
|
+
* Replaces the tile set
|
|
43
|
+
*
|
|
44
|
+
* @returns Whether the set changed
|
|
45
|
+
*/
|
|
46
|
+
update(tiles: readonly RenderableTerrainTile[]): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Forgets the tile set
|
|
49
|
+
*
|
|
50
|
+
* @returns Whether there was one
|
|
51
|
+
*/
|
|
52
|
+
clear(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Whether a drawn tile covers a point
|
|
55
|
+
*
|
|
56
|
+
* @param lng The longitude in degrees, on the copy of the world it is drawn on (not wrapped)
|
|
57
|
+
* @param lat The latitude in degrees
|
|
58
|
+
*/
|
|
59
|
+
covers(lng: number, lat: number): boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The ground elevation of a point in meters, exaggeration included
|
|
63
|
+
*
|
|
64
|
+
* @param query The map, or null where there is none (then only the fallback is used)
|
|
65
|
+
* @param terrain The terrain of the map
|
|
66
|
+
* @param coverage The tiles drawn in this frame
|
|
67
|
+
* @param lng The longitude in degrees, on the copy of the world the point is drawn on
|
|
68
|
+
* @param lat The latitude in degrees
|
|
69
|
+
* @param tileZoom The zoom level of the fallback (maplibre's `tileZoom`, `floor(zoom)`)
|
|
70
|
+
* @returns The elevation; 0 when it cannot be obtained ("add no elevation")
|
|
71
|
+
*/
|
|
72
|
+
export declare function groundElevationMeters(query: TerrainElevationQuery | null, terrain: TerrainLike, coverage: TerrainCoverage, lng: number, lat: number, tileZoom: number): number;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* The ground elevation of a single point, taken from the surface maplibre draws
|
|
5
|
+
*
|
|
6
|
+
* Symbols (points, handles, the anchors of custom renderers) are placed by one elevation per
|
|
7
|
+
* point, looked up on the CPU. It must be the elevation of the ground maplibre draws at that
|
|
8
|
+
* point, or the symbol floats above the slope or sinks into it.
|
|
9
|
+
*
|
|
10
|
+
* maplibre 6.11.1 samples the drawn surface in `Map.queryTerrainElevation`
|
|
11
|
+
* (`Terrain.getElevationForLngLat`, `src/render/terrain.ts:246`): where a terrain tile it draws
|
|
12
|
+
* covers the point and its DEM has arrived, it reads that tile's DEM with the placement its
|
|
13
|
+
* shader uses. That is what is used here, through the public method, and nothing of it is
|
|
14
|
+
* copied. `map.project` reads the same function (`MercatorTransform.locationToScreenPoint`), so
|
|
15
|
+
* the anchors agree with it as well.
|
|
16
|
+
*
|
|
17
|
+
* Where no drawn tile covers the point (off screen, or under the camera in a pitched view) the
|
|
18
|
+
* public method walks the covering tiles of the whole view for every call, about 40 us a point
|
|
19
|
+
* against 0.2 to 0.4 us inside the coverage (measured on maplibre 6.11.1, 10 000 points).
|
|
20
|
+
* Nothing is drawn there, so such a point is answered from the tile of the current zoom level
|
|
21
|
+
* (`Terrain.getElevationForLngLatZoom`, cheap) instead. {@link TerrainCoverage} tells the two
|
|
22
|
+
* apart from the tiles maplibre draws in this frame; when the coverage changes, the anchor
|
|
23
|
+
* generation advances and whatever baked an elevation is rebuilt.
|
|
24
|
+
*/
|
|
25
|
+
import { getTerrainElevationMeters, } from './detect.js';
|
|
26
|
+
/** The copies of the world a coverage tells apart (more are treated as not covered) */
|
|
27
|
+
const MAX_WRAP = 7;
|
|
28
|
+
/** A numeric key of a tile (exact up to zoom 24) */
|
|
29
|
+
function tileKey(wrap, z, x, y) {
|
|
30
|
+
const size = 2 ** z;
|
|
31
|
+
return ((wrap + MAX_WRAP) * size + y) * size + x;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The terrain tiles maplibre draws in the current frame, indexed for a point lookup
|
|
35
|
+
*
|
|
36
|
+
* A point is covered here exactly when maplibre's coverage index (`wrap/z/x/y`, searched from
|
|
37
|
+
* the finest zoom) finds a drawn tile for it, which is when `queryTerrainElevation` samples the
|
|
38
|
+
* drawn surface.
|
|
39
|
+
*/
|
|
40
|
+
export class TerrainCoverage {
|
|
41
|
+
constructor() {
|
|
42
|
+
/** Identifies the tile set (it changes whenever the set changes) */
|
|
43
|
+
Object.defineProperty(this, "key", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: ''
|
|
48
|
+
});
|
|
49
|
+
/** The zoom levels present, finest first (the order maplibre searches them in) */
|
|
50
|
+
Object.defineProperty(this, "zooms", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: []
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(this, "tiles", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: new Set()
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Replaces the tile set
|
|
65
|
+
*
|
|
66
|
+
* @returns Whether the set changed
|
|
67
|
+
*/
|
|
68
|
+
update(tiles) {
|
|
69
|
+
let key = '';
|
|
70
|
+
for (const tile of tiles)
|
|
71
|
+
key += `${tile.wrap ?? 0}/${tile.z}/${tile.x}/${tile.y},`;
|
|
72
|
+
if (key === this.key)
|
|
73
|
+
return false;
|
|
74
|
+
this.key = key;
|
|
75
|
+
this.tiles = new Set();
|
|
76
|
+
const zooms = new Set();
|
|
77
|
+
for (const tile of tiles) {
|
|
78
|
+
const wrap = tile.wrap ?? 0;
|
|
79
|
+
if (Math.abs(wrap) > MAX_WRAP)
|
|
80
|
+
continue;
|
|
81
|
+
this.tiles.add(tileKey(wrap, tile.z, tile.x, tile.y));
|
|
82
|
+
zooms.add(tile.z);
|
|
83
|
+
}
|
|
84
|
+
this.zooms = [...zooms].sort((a, b) => b - a);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Forgets the tile set
|
|
89
|
+
*
|
|
90
|
+
* @returns Whether there was one
|
|
91
|
+
*/
|
|
92
|
+
clear() {
|
|
93
|
+
if (this.key === '')
|
|
94
|
+
return false;
|
|
95
|
+
this.key = '';
|
|
96
|
+
this.zooms = [];
|
|
97
|
+
this.tiles = new Set();
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Whether a drawn tile covers a point
|
|
102
|
+
*
|
|
103
|
+
* @param lng The longitude in degrees, on the copy of the world it is drawn on (not wrapped)
|
|
104
|
+
* @param lat The latitude in degrees
|
|
105
|
+
*/
|
|
106
|
+
covers(lng, lat) {
|
|
107
|
+
if (this.zooms.length === 0)
|
|
108
|
+
return false;
|
|
109
|
+
const mercatorX = (lng + 180) / 360;
|
|
110
|
+
const latRad = (lat * Math.PI) / 180;
|
|
111
|
+
const mercatorY = (1 - Math.log(Math.tan(latRad) + 1 / Math.cos(latRad)) / Math.PI) / 2;
|
|
112
|
+
if (!(mercatorY >= 0 && mercatorY < 1) || !Number.isFinite(mercatorX))
|
|
113
|
+
return false;
|
|
114
|
+
const wrap = Math.floor(mercatorX);
|
|
115
|
+
if (Math.abs(wrap) > MAX_WRAP)
|
|
116
|
+
return false;
|
|
117
|
+
const wrappedX = mercatorX - wrap;
|
|
118
|
+
for (const z of this.zooms) {
|
|
119
|
+
const scale = 2 ** z;
|
|
120
|
+
const key = tileKey(wrap, z, Math.floor(wrappedX * scale), Math.floor(mercatorY * scale));
|
|
121
|
+
if (this.tiles.has(key))
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The ground elevation of a point in meters, exaggeration included
|
|
129
|
+
*
|
|
130
|
+
* @param query The map, or null where there is none (then only the fallback is used)
|
|
131
|
+
* @param terrain The terrain of the map
|
|
132
|
+
* @param coverage The tiles drawn in this frame
|
|
133
|
+
* @param lng The longitude in degrees, on the copy of the world the point is drawn on
|
|
134
|
+
* @param lat The latitude in degrees
|
|
135
|
+
* @param tileZoom The zoom level of the fallback (maplibre's `tileZoom`, `floor(zoom)`)
|
|
136
|
+
* @returns The elevation; 0 when it cannot be obtained ("add no elevation")
|
|
137
|
+
*/
|
|
138
|
+
export function groundElevationMeters(query, terrain, coverage, lng, lat, tileZoom) {
|
|
139
|
+
if (query && coverage.covers(lng, lat)) {
|
|
140
|
+
let elevation = null;
|
|
141
|
+
try {
|
|
142
|
+
elevation = query.queryTerrainElevation([lng, lat]);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
elevation = null;
|
|
146
|
+
}
|
|
147
|
+
if (typeof elevation === 'number' && Number.isFinite(elevation))
|
|
148
|
+
return elevation;
|
|
149
|
+
}
|
|
150
|
+
return getTerrainElevationMeters(terrain, lng, lat, tileZoom);
|
|
151
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The center latitude of a tile
|
|
3
|
+
*
|
|
4
|
+
* Used to convert the gradient of the shading into meters (to derive the ground size of that
|
|
5
|
+
* tile).
|
|
6
|
+
*/
|
|
7
|
+
export declare function tileCenterLatitude(tileY: number, tileZ: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* Returns the factor that converts an elevation in meters to Mercator z units at a latitude.
|
|
10
|
+
*
|
|
11
|
+
* It is the factor for producing the same value as
|
|
12
|
+
* `MercatorCoordinate.fromLngLat(lngLat, meters).z`. The elevation handed to a vertex must
|
|
13
|
+
* always be in Mercator units (handing over meters as they are is wrong). The factor depends
|
|
14
|
+
* on the latitude, but MapLibre's matrices are assembled with the factor of the view center
|
|
15
|
+
* latitude, so within the viewport it is represented by the latitude of the screen center.
|
|
16
|
+
*
|
|
17
|
+
* @param centerLat The latitude in degrees (the view center)
|
|
18
|
+
* @returns Mercator units per meter
|
|
19
|
+
*/
|
|
20
|
+
export declare function metersToMercatorScale(centerLat: number): number;
|
|
21
|
+
/**
|
|
22
|
+
* The grid spacing of MapLibre's terrain mesh (in meters)
|
|
23
|
+
*
|
|
24
|
+
* MapLibre draws the terrain with a regular mesh that splits one tile into 128. This value is
|
|
25
|
+
* "the granularity to match" when putting our own geometry onto the ground.
|
|
26
|
+
*/
|
|
27
|
+
export declare const TERRAIN_MESH_DIVISIONS = 128;
|
|
28
|
+
/**
|
|
29
|
+
* The factor of the lift amount (the ratio to the terrain mesh grid spacing)
|
|
30
|
+
*
|
|
31
|
+
* This is not an exaggeration of the terrain. The relief is drawn with the same exaggeration
|
|
32
|
+
* as the map's own terrain and nothing is added to it. What is added here is purely a
|
|
33
|
+
* rendering implementation value to avoid Z-fighting: our own geometry (the bilinear
|
|
34
|
+
* interpolation of the DEM turned into a polyline / faceted surface on the grid) and
|
|
35
|
+
* MapLibre's terrain mesh (linear
|
|
36
|
+
* interpolation with 128 subdivisions per tile) are different surfaces and therefore
|
|
37
|
+
* necessarily intersect. It is not made a public option.
|
|
38
|
+
*
|
|
39
|
+
* The amount required is decided by "the maximum amount by which the mesh comes above the
|
|
40
|
+
* bilinear surface", which with the four corners of a grid cell as e00, e10, e01, e11 is
|
|
41
|
+
* |e00 + e11 - e10 - e01| / 4. Values measured in the Northern Alps (Kamikochi to Hotaka, an
|
|
42
|
+
* elevation difference of 750 m per 10 km):
|
|
43
|
+
*
|
|
44
|
+
* | display zoom | terrain tile z | grid spacing | required (max) | grid ratio |
|
|
45
|
+
* | --- | --- | --- | --- | --- |
|
|
46
|
+
* | 10 | 10 | 246.5m | 61.0m | 0.25 |
|
|
47
|
+
* | 12 | 12 | 61.6m | 37.3m | 0.60 |
|
|
48
|
+
* | 14 | 14 | 15.4m | 10.3m | 0.67 |
|
|
49
|
+
*
|
|
50
|
+
* This table gives the values "when the subdivision points are placed at an arbitrary
|
|
51
|
+
* spacing". The current implementation aligns the subdivision points with the nodes of
|
|
52
|
+
* MapLibre's terrain mesh themselves and matches the direction of the cell diagonals too, so
|
|
53
|
+
* the two surfaces agree both at the nodes and inside the cells. All that remains is
|
|
54
|
+
* floating-point rounding, so the world lift is shrunk down to an invisible amount (a factor
|
|
55
|
+
* of 0.15) and the main depth bias is left to the slope-proportional gl.polygonOffset (the
|
|
56
|
+
* depth settings in view/layer/gl-state.ts). A large world lift is avoided because it "looks like it is
|
|
57
|
+
* floating" at close zooms.
|
|
58
|
+
*/
|
|
59
|
+
export declare const TERRAIN_LIFT_RATIO = 0.15;
|
|
60
|
+
/** The lower bound of the lift (in meters). A floor for the depth buffer's resolution */
|
|
61
|
+
export declare const TERRAIN_LIFT_MIN_METERS = 0.05;
|
|
62
|
+
/**
|
|
63
|
+
* The subdivision step (in meters)
|
|
64
|
+
*
|
|
65
|
+
* It is bounded above by "the ground size of a DEM pixel at the zoom being displayed" and
|
|
66
|
+
* below by "the grid spacing of the terrain mesh". The implementation aims at the grid spacing
|
|
67
|
+
* of the terrain mesh, and since going finer than a DEM pixel adds no information, a floor is
|
|
68
|
+
* set at the DEM pixel.
|
|
69
|
+
*
|
|
70
|
+
* @param zoom The representative zoom of the terrain tiles
|
|
71
|
+
* @param lat The latitude of the screen center
|
|
72
|
+
* @param demPixelMeters The ground size of a DEM pixel (0 when unknown)
|
|
73
|
+
*/
|
|
74
|
+
export declare function terrainTessellationStepMeters(zoom: number, lat: number, demPixelMeters: number): number;
|
|
75
|
+
/**
|
|
76
|
+
* Quantizes the step to a power of 2
|
|
77
|
+
*
|
|
78
|
+
* Redoing the subdivision every time the zoom moves continuously would break retained batches
|
|
79
|
+
* every frame. The step is rounded to a power of 2 and rebuilt only when one is crossed (which
|
|
80
|
+
* is the same thing as crossing an integer zoom).
|
|
81
|
+
*/
|
|
82
|
+
export declare function quantizeStepMeters(stepMeters: number): number;
|
|
83
|
+
/**
|
|
84
|
+
* The upper bound on the number of subdivision points per feature (stopping a blow-up of the
|
|
85
|
+
* vertex count)
|
|
86
|
+
*
|
|
87
|
+
* This is not "the number at which it is cut off" but "the number at which the step starts to
|
|
88
|
+
* be coarsened" (polygonTessellationStep in terrain/polygon.ts). The larger the feature, the
|
|
89
|
+
* coarser the step, so the vertex count is capped around this value. Subdividing a 10 km
|
|
90
|
+
* square polygon with the zoom 12 step (64 m) gives about 26,000 points, so the value is set
|
|
91
|
+
* such that polygons of ordinary size get by without being coarsened.
|
|
92
|
+
*/
|
|
93
|
+
export declare const TERRAIN_MAX_SUBDIVISION_POINTS = 120000;
|
|
94
|
+
/**
|
|
95
|
+
* The upper bound on the number of subdivision points per feature when subdividing to match
|
|
96
|
+
* the tile's actual mesh
|
|
97
|
+
*
|
|
98
|
+
* When the step matches the tile's actual mesh (with a tiling), the amount subdivided is
|
|
99
|
+
* capped by "the number of tiles in the view x the square of the mesh subdivisions". That is
|
|
100
|
+
* the same order of magnitude as the vertex count MapLibre itself uses for the terrain mesh,
|
|
101
|
+
* and it is decided by the extent of the view alone (it depends on neither the number of
|
|
102
|
+
* features nor the zoom).
|
|
103
|
+
*
|
|
104
|
+
* Cutting at the upper bound would mean "coarsening and subdividing again" from there on, and
|
|
105
|
+
* the coarse chord would dive under ridges and the fill would drop out. Only an exact match is
|
|
106
|
+
* safe, so the value is set high enough that even a single polygon covering the whole view can
|
|
107
|
+
* be subdivided fully.
|
|
108
|
+
*/
|
|
109
|
+
export declare const TERRAIN_MAX_TILED_SUBDIVISION_POINTS = 800000;
|
|
110
|
+
/**
|
|
111
|
+
* The upper bound on the number of cells that may be subdivided across one whole batch build
|
|
112
|
+
*
|
|
113
|
+
* The per-feature upper bound (TERRAIN_MAX_SUBDIVISION_POINTS) alone is no brake when there
|
|
114
|
+
* are thousands of features. Measuring a dataset (8,172 administrative
|
|
115
|
+
* boundaries, 1.1 million vertices in total), each individual feature stayed far below the
|
|
116
|
+
* bound (a few hundred cells) yet the total reached about 1.7 million cells and a single
|
|
117
|
+
* retained batch build blocked the main thread for 34 seconds. The cost of the subdivision is
|
|
118
|
+
* proportional to the pairs of "cell x triangle", so the only way to hold it back is by the
|
|
119
|
+
* total across all features.
|
|
120
|
+
*
|
|
121
|
+
* When the total is expected to exceed this value, the step of the whole batch is coarsened by
|
|
122
|
+
* a power of 2 (batchTessellationFactor in terrain/polygon.ts). Even coarsened it still lies
|
|
123
|
+
* on a subset of the terrain mesh nodes, so the agreement between the fill and the outline is
|
|
124
|
+
* preserved.
|
|
125
|
+
*
|
|
126
|
+
* The value was taken from "keeping one build with terrain to about 1 second".
|
|
127
|
+
*/
|
|
128
|
+
export declare const TERRAIN_MAX_BATCH_SUBDIVISION_CELLS = 1000000;
|
|
129
|
+
/**
|
|
130
|
+
* The depth bias when there is terrain (the factor / units of gl.polygonOffset)
|
|
131
|
+
*
|
|
132
|
+
* It is the amount per one level of step coarseness. The value actually used is this
|
|
133
|
+
* multiplied by "the coarsest factor subdivided with in that generation"
|
|
134
|
+
* (view/layer/terrain-resolver.ts).
|
|
135
|
+
*
|
|
136
|
+
* 16 was decided by measurement. With 1 (the previous value), spotty holes remained on hill
|
|
137
|
+
* tops even when the step was the terrain mesh nodes themselves (no coarsening). With 8 a few
|
|
138
|
+
* remained at a coarsening of 2, and they disappeared at 16 to 32 (hands-on in the north of
|
|
139
|
+
* Kawasaki, zoom 15.7, pitch 60).
|
|
140
|
+
*/
|
|
141
|
+
export declare const TERRAIN_DEPTH_BIAS = 16;
|
|
142
|
+
/**
|
|
143
|
+
* The margin added to the subdivision range (the ratio to the atlas side length)
|
|
144
|
+
*
|
|
145
|
+
* The subdivision is done only inside the rectangle the DEM atlas covers. Making the range
|
|
146
|
+
* exactly the atlas would change the range on every small movement and trigger a re-bake of
|
|
147
|
+
* the retained batches, so a margin is added around it and the range is recomputed only when
|
|
148
|
+
* the atlas moves outside the margin.
|
|
149
|
+
*
|
|
150
|
+
* 0.2 = 20 percent of the view on each side (about twice the area). Since the step came to
|
|
151
|
+
* match the tile's actual mesh, the amount can no longer be reduced by coarsening (coarsening
|
|
152
|
+
* makes it drop out on ridges), so a thicker margin makes construction correspondingly
|
|
153
|
+
* heavier. 20 percent of the view is the compromise for "no re-bake on a light gesture, a
|
|
154
|
+
* re-bake on a heavy one".
|
|
155
|
+
*/
|
|
156
|
+
export declare const TERRAIN_REGION_MARGIN = 0.2;
|
|
157
|
+
/**
|
|
158
|
+
* The upper bound on the number of levels the step may be coarsened by (powers of 2)
|
|
159
|
+
*
|
|
160
|
+
* The upper bound of the subdivision criterion is "the ground size of a DEM pixel". Coarsening
|
|
161
|
+
* for budget reasons goes in the direction of coarser than that bound, so it is not allowed to
|
|
162
|
+
* act without limit. It is capped at 6 levels (a factor of 64), and anything that still does
|
|
163
|
+
* not fit is emitted without being subdivided fully.
|
|
164
|
+
*/
|
|
165
|
+
export declare const TERRAIN_MAX_COARSEN_STEPS = 6;
|
|
166
|
+
/**
|
|
167
|
+
* The upper bound on the coarsening allowed when subdividing to match the tile's actual mesh
|
|
168
|
+
* (powers of 2)
|
|
169
|
+
*
|
|
170
|
+
* The actual mesh as is would be ideal, but with a wide view and a strong pitch the amount
|
|
171
|
+
* subdivided jumps and frames of several hundred milliseconds appear every time new ground
|
|
172
|
+
* enters the view (measured). As long as the coarsening is by a power of 2 the subdivision
|
|
173
|
+
* points still lie on a subset of the actual mesh nodes, so the problem of sinking in valley
|
|
174
|
+
* floors (whose cause is leaving the nodes) does not occur. The slight dive of the chord on
|
|
175
|
+
* ridges is covered by the step-proportional depth bias.
|
|
176
|
+
*
|
|
177
|
+
* 2 is where "the amount can be quartered and the dive on ridges can still be covered by the
|
|
178
|
+
* bias".
|
|
179
|
+
*/
|
|
180
|
+
export declare const TERRAIN_MAX_TILED_COARSEN = 2;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* The dimensions around terrain rendering
|
|
5
|
+
*
|
|
6
|
+
* The conventions for units, the lift amount and the subdivision step are collected here.
|
|
7
|
+
*/
|
|
8
|
+
import { UPSTREAM_EARTH_CIRCUMFERENCE_METERS } from './upstream-terrain.js';
|
|
9
|
+
/**
|
|
10
|
+
* The length of one circuit of the Earth at a latitude (in meters)
|
|
11
|
+
*
|
|
12
|
+
* 1.0 in Mercator coordinates corresponds to this length. It is measured on maplibre's sphere
|
|
13
|
+
* (`upstream-terrain.ts`), so an elevation turned into Mercator units lands on maplibre's
|
|
14
|
+
* terrain mesh.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export function circumferenceAtLatitude(lat) {
|
|
19
|
+
return UPSTREAM_EARTH_CIRCUMFERENCE_METERS * Math.cos((lat * Math.PI) / 180);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The center latitude of a tile
|
|
23
|
+
*
|
|
24
|
+
* Used to convert the gradient of the shading into meters (to derive the ground size of that
|
|
25
|
+
* tile).
|
|
26
|
+
*/
|
|
27
|
+
export function tileCenterLatitude(tileY, tileZ) {
|
|
28
|
+
const n = Math.PI - (2 * Math.PI * (tileY + 0.5)) / 2 ** tileZ;
|
|
29
|
+
return (180 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns the factor that converts an elevation in meters to Mercator z units at a latitude.
|
|
33
|
+
*
|
|
34
|
+
* It is the factor for producing the same value as
|
|
35
|
+
* `MercatorCoordinate.fromLngLat(lngLat, meters).z`. The elevation handed to a vertex must
|
|
36
|
+
* always be in Mercator units (handing over meters as they are is wrong). The factor depends
|
|
37
|
+
* on the latitude, but MapLibre's matrices are assembled with the factor of the view center
|
|
38
|
+
* latitude, so within the viewport it is represented by the latitude of the screen center.
|
|
39
|
+
*
|
|
40
|
+
* @param centerLat The latitude in degrees (the view center)
|
|
41
|
+
* @returns Mercator units per meter
|
|
42
|
+
*/
|
|
43
|
+
export function metersToMercatorScale(centerLat) {
|
|
44
|
+
const circumference = circumferenceAtLatitude(centerLat);
|
|
45
|
+
return circumference > 0 ? 1 / circumference : 0;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The grid spacing of MapLibre's terrain mesh (in meters)
|
|
49
|
+
*
|
|
50
|
+
* MapLibre draws the terrain with a regular mesh that splits one tile into 128. This value is
|
|
51
|
+
* "the granularity to match" when putting our own geometry onto the ground.
|
|
52
|
+
*/
|
|
53
|
+
export const TERRAIN_MESH_DIVISIONS = 128;
|
|
54
|
+
/**
|
|
55
|
+
* The grid spacing of the terrain mesh (in meters)
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export function terrainMeshSpacingMeters(zoom, lat) {
|
|
60
|
+
const tileWidth = circumferenceAtLatitude(lat) / 2 ** zoom;
|
|
61
|
+
return tileWidth / TERRAIN_MESH_DIVISIONS;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The factor of the lift amount (the ratio to the terrain mesh grid spacing)
|
|
65
|
+
*
|
|
66
|
+
* This is not an exaggeration of the terrain. The relief is drawn with the same exaggeration
|
|
67
|
+
* as the map's own terrain and nothing is added to it. What is added here is purely a
|
|
68
|
+
* rendering implementation value to avoid Z-fighting: our own geometry (the bilinear
|
|
69
|
+
* interpolation of the DEM turned into a polyline / faceted surface on the grid) and
|
|
70
|
+
* MapLibre's terrain mesh (linear
|
|
71
|
+
* interpolation with 128 subdivisions per tile) are different surfaces and therefore
|
|
72
|
+
* necessarily intersect. It is not made a public option.
|
|
73
|
+
*
|
|
74
|
+
* The amount required is decided by "the maximum amount by which the mesh comes above the
|
|
75
|
+
* bilinear surface", which with the four corners of a grid cell as e00, e10, e01, e11 is
|
|
76
|
+
* |e00 + e11 - e10 - e01| / 4. Values measured in the Northern Alps (Kamikochi to Hotaka, an
|
|
77
|
+
* elevation difference of 750 m per 10 km):
|
|
78
|
+
*
|
|
79
|
+
* | display zoom | terrain tile z | grid spacing | required (max) | grid ratio |
|
|
80
|
+
* | --- | --- | --- | --- | --- |
|
|
81
|
+
* | 10 | 10 | 246.5m | 61.0m | 0.25 |
|
|
82
|
+
* | 12 | 12 | 61.6m | 37.3m | 0.60 |
|
|
83
|
+
* | 14 | 14 | 15.4m | 10.3m | 0.67 |
|
|
84
|
+
*
|
|
85
|
+
* This table gives the values "when the subdivision points are placed at an arbitrary
|
|
86
|
+
* spacing". The current implementation aligns the subdivision points with the nodes of
|
|
87
|
+
* MapLibre's terrain mesh themselves and matches the direction of the cell diagonals too, so
|
|
88
|
+
* the two surfaces agree both at the nodes and inside the cells. All that remains is
|
|
89
|
+
* floating-point rounding, so the world lift is shrunk down to an invisible amount (a factor
|
|
90
|
+
* of 0.15) and the main depth bias is left to the slope-proportional gl.polygonOffset (the
|
|
91
|
+
* depth settings in view/layer/gl-state.ts). A large world lift is avoided because it "looks like it is
|
|
92
|
+
* floating" at close zooms.
|
|
93
|
+
*/
|
|
94
|
+
export const TERRAIN_LIFT_RATIO = 0.15;
|
|
95
|
+
/** The lower bound of the lift (in meters). A floor for the depth buffer's resolution */
|
|
96
|
+
export const TERRAIN_LIFT_MIN_METERS = 0.05;
|
|
97
|
+
/**
|
|
98
|
+
* The lift amount (in meters)
|
|
99
|
+
*
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
export function terrainLiftMeters(zoom, lat) {
|
|
103
|
+
const spacing = terrainMeshSpacingMeters(zoom, lat);
|
|
104
|
+
return Math.max(TERRAIN_LIFT_MIN_METERS, spacing * TERRAIN_LIFT_RATIO);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The subdivision step (in meters)
|
|
108
|
+
*
|
|
109
|
+
* It is bounded above by "the ground size of a DEM pixel at the zoom being displayed" and
|
|
110
|
+
* below by "the grid spacing of the terrain mesh". The implementation aims at the grid spacing
|
|
111
|
+
* of the terrain mesh, and since going finer than a DEM pixel adds no information, a floor is
|
|
112
|
+
* set at the DEM pixel.
|
|
113
|
+
*
|
|
114
|
+
* @param zoom The representative zoom of the terrain tiles
|
|
115
|
+
* @param lat The latitude of the screen center
|
|
116
|
+
* @param demPixelMeters The ground size of a DEM pixel (0 when unknown)
|
|
117
|
+
*/
|
|
118
|
+
export function terrainTessellationStepMeters(zoom, lat, demPixelMeters) {
|
|
119
|
+
const spacing = terrainMeshSpacingMeters(zoom, lat);
|
|
120
|
+
return Math.max(spacing, demPixelMeters, 1);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Quantizes the step to a power of 2
|
|
124
|
+
*
|
|
125
|
+
* Redoing the subdivision every time the zoom moves continuously would break retained batches
|
|
126
|
+
* every frame. The step is rounded to a power of 2 and rebuilt only when one is crossed (which
|
|
127
|
+
* is the same thing as crossing an integer zoom).
|
|
128
|
+
*/
|
|
129
|
+
export function quantizeStepMeters(stepMeters) {
|
|
130
|
+
if (!(stepMeters > 0))
|
|
131
|
+
return 0;
|
|
132
|
+
return 2 ** Math.round(Math.log2(stepMeters));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The upper bound on the number of subdivision points per feature (stopping a blow-up of the
|
|
136
|
+
* vertex count)
|
|
137
|
+
*
|
|
138
|
+
* This is not "the number at which it is cut off" but "the number at which the step starts to
|
|
139
|
+
* be coarsened" (polygonTessellationStep in terrain/polygon.ts). The larger the feature, the
|
|
140
|
+
* coarser the step, so the vertex count is capped around this value. Subdividing a 10 km
|
|
141
|
+
* square polygon with the zoom 12 step (64 m) gives about 26,000 points, so the value is set
|
|
142
|
+
* such that polygons of ordinary size get by without being coarsened.
|
|
143
|
+
*/
|
|
144
|
+
export const TERRAIN_MAX_SUBDIVISION_POINTS = 120000;
|
|
145
|
+
/**
|
|
146
|
+
* The upper bound on the number of subdivision points per feature when subdividing to match
|
|
147
|
+
* the tile's actual mesh
|
|
148
|
+
*
|
|
149
|
+
* When the step matches the tile's actual mesh (with a tiling), the amount subdivided is
|
|
150
|
+
* capped by "the number of tiles in the view x the square of the mesh subdivisions". That is
|
|
151
|
+
* the same order of magnitude as the vertex count MapLibre itself uses for the terrain mesh,
|
|
152
|
+
* and it is decided by the extent of the view alone (it depends on neither the number of
|
|
153
|
+
* features nor the zoom).
|
|
154
|
+
*
|
|
155
|
+
* Cutting at the upper bound would mean "coarsening and subdividing again" from there on, and
|
|
156
|
+
* the coarse chord would dive under ridges and the fill would drop out. Only an exact match is
|
|
157
|
+
* safe, so the value is set high enough that even a single polygon covering the whole view can
|
|
158
|
+
* be subdivided fully.
|
|
159
|
+
*/
|
|
160
|
+
export const TERRAIN_MAX_TILED_SUBDIVISION_POINTS = 800000;
|
|
161
|
+
/**
|
|
162
|
+
* The upper bound on the number of cells that may be subdivided across one whole batch build
|
|
163
|
+
*
|
|
164
|
+
* The per-feature upper bound (TERRAIN_MAX_SUBDIVISION_POINTS) alone is no brake when there
|
|
165
|
+
* are thousands of features. Measuring a dataset (8,172 administrative
|
|
166
|
+
* boundaries, 1.1 million vertices in total), each individual feature stayed far below the
|
|
167
|
+
* bound (a few hundred cells) yet the total reached about 1.7 million cells and a single
|
|
168
|
+
* retained batch build blocked the main thread for 34 seconds. The cost of the subdivision is
|
|
169
|
+
* proportional to the pairs of "cell x triangle", so the only way to hold it back is by the
|
|
170
|
+
* total across all features.
|
|
171
|
+
*
|
|
172
|
+
* When the total is expected to exceed this value, the step of the whole batch is coarsened by
|
|
173
|
+
* a power of 2 (batchTessellationFactor in terrain/polygon.ts). Even coarsened it still lies
|
|
174
|
+
* on a subset of the terrain mesh nodes, so the agreement between the fill and the outline is
|
|
175
|
+
* preserved.
|
|
176
|
+
*
|
|
177
|
+
* The value was taken from "keeping one build with terrain to about 1 second".
|
|
178
|
+
*/
|
|
179
|
+
export const TERRAIN_MAX_BATCH_SUBDIVISION_CELLS = 1000000;
|
|
180
|
+
/**
|
|
181
|
+
* The depth bias when there is terrain (the factor / units of gl.polygonOffset)
|
|
182
|
+
*
|
|
183
|
+
* It is the amount per one level of step coarseness. The value actually used is this
|
|
184
|
+
* multiplied by "the coarsest factor subdivided with in that generation"
|
|
185
|
+
* (view/layer/terrain-resolver.ts).
|
|
186
|
+
*
|
|
187
|
+
* 16 was decided by measurement. With 1 (the previous value), spotty holes remained on hill
|
|
188
|
+
* tops even when the step was the terrain mesh nodes themselves (no coarsening). With 8 a few
|
|
189
|
+
* remained at a coarsening of 2, and they disappeared at 16 to 32 (hands-on in the north of
|
|
190
|
+
* Kawasaki, zoom 15.7, pitch 60).
|
|
191
|
+
*/
|
|
192
|
+
export const TERRAIN_DEPTH_BIAS = 16;
|
|
193
|
+
/**
|
|
194
|
+
* The margin added to the subdivision range (the ratio to the atlas side length)
|
|
195
|
+
*
|
|
196
|
+
* The subdivision is done only inside the rectangle the DEM atlas covers. Making the range
|
|
197
|
+
* exactly the atlas would change the range on every small movement and trigger a re-bake of
|
|
198
|
+
* the retained batches, so a margin is added around it and the range is recomputed only when
|
|
199
|
+
* the atlas moves outside the margin.
|
|
200
|
+
*
|
|
201
|
+
* 0.2 = 20 percent of the view on each side (about twice the area). Since the step came to
|
|
202
|
+
* match the tile's actual mesh, the amount can no longer be reduced by coarsening (coarsening
|
|
203
|
+
* makes it drop out on ridges), so a thicker margin makes construction correspondingly
|
|
204
|
+
* heavier. 20 percent of the view is the compromise for "no re-bake on a light gesture, a
|
|
205
|
+
* re-bake on a heavy one".
|
|
206
|
+
*/
|
|
207
|
+
export const TERRAIN_REGION_MARGIN = 0.2;
|
|
208
|
+
/**
|
|
209
|
+
* The upper bound on the number of levels the step may be coarsened by (powers of 2)
|
|
210
|
+
*
|
|
211
|
+
* The upper bound of the subdivision criterion is "the ground size of a DEM pixel". Coarsening
|
|
212
|
+
* for budget reasons goes in the direction of coarser than that bound, so it is not allowed to
|
|
213
|
+
* act without limit. It is capped at 6 levels (a factor of 64), and anything that still does
|
|
214
|
+
* not fit is emitted without being subdivided fully.
|
|
215
|
+
*/
|
|
216
|
+
export const TERRAIN_MAX_COARSEN_STEPS = 6;
|
|
217
|
+
/**
|
|
218
|
+
* The upper bound on the coarsening allowed when subdividing to match the tile's actual mesh
|
|
219
|
+
* (powers of 2)
|
|
220
|
+
*
|
|
221
|
+
* The actual mesh as is would be ideal, but with a wide view and a strong pitch the amount
|
|
222
|
+
* subdivided jumps and frames of several hundred milliseconds appear every time new ground
|
|
223
|
+
* enters the view (measured). As long as the coarsening is by a power of 2 the subdivision
|
|
224
|
+
* points still lie on a subset of the actual mesh nodes, so the problem of sinking in valley
|
|
225
|
+
* floors (whose cause is leaving the nodes) does not occur. The slight dive of the chord on
|
|
226
|
+
* ridges is covered by the step-proportional depth bias.
|
|
227
|
+
*
|
|
228
|
+
* 2 is where "the amount can be quartered and the dive on ridges can still be covered by the
|
|
229
|
+
* bias".
|
|
230
|
+
*/
|
|
231
|
+
export const TERRAIN_MAX_TILED_COARSEN = 2;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TerrainContext } from './context.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the opacity for a symbol at a point: 0.35 when the terrain hides it from the camera,
|
|
4
|
+
* 1 otherwise.
|
|
5
|
+
*
|
|
6
|
+
* @param context The terrain state of the draw instance
|
|
7
|
+
* @param lng The longitude in degrees
|
|
8
|
+
* @param lat The latitude in degrees
|
|
9
|
+
* @returns 0.35 or 1. Always 1 when the terrain is disabled
|
|
10
|
+
*/
|
|
11
|
+
export declare function anchorGhostOpacity(context: TerrainContext, lng: number, lat: number): number;
|