@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,460 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* The vertex data of the SDF line renderer (pure functions, no GL)
|
|
5
|
+
*
|
|
6
|
+
* The strip vertices shared by all instances, the coordinate texels and per-segment instances
|
|
7
|
+
* of a line, the instance color, and the number of subdivisions of a segment on terrain.
|
|
8
|
+
* Immediate mode and retained mode build their data with the same functions.
|
|
9
|
+
*/
|
|
10
|
+
import { EARTH } from '../../../shared/math/constants.js';
|
|
11
|
+
import { resolveContentPixelRatio, resolvePixelRatio } from '../../../shared/utils/pixel-ratio.js';
|
|
12
|
+
import { globeGridOf } from '../../globe-subdivision.js';
|
|
13
|
+
import { calculateLngLatOffset } from '../../shaders/helpers.js';
|
|
14
|
+
// The stride of the instance data (floats per instance)
|
|
15
|
+
// indices(4) + extra(4) + color(4) = 12 floats
|
|
16
|
+
export const INSTANCE_STRIDE = 12;
|
|
17
|
+
export const INSTANCE_BYTES = INSTANCE_STRIDE * 4;
|
|
18
|
+
/**
|
|
19
|
+
* The upper bound on subdivision points
|
|
20
|
+
*
|
|
21
|
+
* When terrain is enabled, a single segment is split into at most this many parts to draw it.
|
|
22
|
+
* A long straight line with only two vertices (34km as measured) sinks into the terrain
|
|
23
|
+
* between subdivision points when split coarsely, so the line looks broken up like a dashed
|
|
24
|
+
* line. The upper bound was decided from that (34km / 512 = 66m, which lands at the same
|
|
25
|
+
* granularity as the subdivision step).
|
|
26
|
+
* The vertex buffer of the strip statically holds this upper bound, but (512+1)*2 vertices =
|
|
27
|
+
* 4KB, so it is negligible as a resource. The number of vertices actually drawn is determined
|
|
28
|
+
* from u_stations every time.
|
|
29
|
+
*/
|
|
30
|
+
export const MAX_LINE_STATIONS = 512;
|
|
31
|
+
/**
|
|
32
|
+
* A guideline for how many post-split segments a single draw call may produce (a guard against
|
|
33
|
+
* a vertex-count blow-up)
|
|
34
|
+
*
|
|
35
|
+
* The number of subdivisions is determined by the longest segment in the batch, so a single
|
|
36
|
+
* long line mixed into a batch full of short lines makes the whole batch use the maximum
|
|
37
|
+
* subdivision. This caps that.
|
|
38
|
+
*/
|
|
39
|
+
export const LINE_STATION_BUDGET = 500000;
|
|
40
|
+
/**
|
|
41
|
+
* The strip vertices shared by all instances (side, station)
|
|
42
|
+
*
|
|
43
|
+
* side: 1=left, -1=right / station: the index of the subdivision point along the segment
|
|
44
|
+
*
|
|
45
|
+
* On terrain, a segment sinks into valleys unless it is subdivided. Here the subdivision is
|
|
46
|
+
* expressed as "the station index in the vertex buffer plus the vertex count at draw time".
|
|
47
|
+
* Neither the coordinate texture of the segment nor the instance array is touched, so both
|
|
48
|
+
* retained batches and the partial update for a vertex drag (patchRetainedBatchCoords) keep
|
|
49
|
+
* working as they are.
|
|
50
|
+
*
|
|
51
|
+
* With u_stations = 1, drawing only 4 vertices gives stations 0,0,1,1, which is exactly the
|
|
52
|
+
* same triangle strip as before terrain was introduced.
|
|
53
|
+
*/
|
|
54
|
+
// biome-ignore format: an array of vertex data
|
|
55
|
+
export const STATION_VERTICES = (() => {
|
|
56
|
+
const data = new Float32Array((MAX_LINE_STATIONS + 1) * 2 * 2);
|
|
57
|
+
for (let s = 0; s <= MAX_LINE_STATIONS; s++) {
|
|
58
|
+
data[s * 4 + 0] = 1; // left
|
|
59
|
+
data[s * 4 + 1] = s;
|
|
60
|
+
data[s * 4 + 2] = -1; // right
|
|
61
|
+
data[s * 4 + 3] = s;
|
|
62
|
+
}
|
|
63
|
+
return data;
|
|
64
|
+
})();
|
|
65
|
+
/**
|
|
66
|
+
* Computes the color to pass as an instance attribute
|
|
67
|
+
*
|
|
68
|
+
* The fragment shader multiplies every color component by the coverage before output
|
|
69
|
+
* (premultiplied alpha), so the opacity is folded into every component and not just alpha.
|
|
70
|
+
* This gives the same composited result as the previous `u_color * (coverage * u_opacity)`.
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export function toLineInstanceColor(color, opacity) {
|
|
75
|
+
const o = Number.isFinite(opacity) ? Math.min(Math.max(opacity, 0), 1) : 1;
|
|
76
|
+
return [color[0] * o, color[1] * o, color[2] * o, color[3] * o];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A Float32Array of at least `length` elements: the array itself when it is long enough,
|
|
80
|
+
* otherwise a new one of the next power of two
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
export function growFloat32(array, length) {
|
|
85
|
+
if (array.length >= length)
|
|
86
|
+
return array;
|
|
87
|
+
let size = 64;
|
|
88
|
+
while (size < length)
|
|
89
|
+
size *= 2;
|
|
90
|
+
return new Float32Array(size);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Rounds the origin of the relative coordinates to Float32
|
|
94
|
+
*
|
|
95
|
+
* u_center_lnglat, which is passed to the shader, is Float32, so the CPU-side subtraction uses
|
|
96
|
+
* the same rounded value to stay consistent (the same treatment as calculateOffsetUniforms).
|
|
97
|
+
*
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
export function normalizeOrigin(origin) {
|
|
101
|
+
return [Math.fround(origin[0]), Math.fround(origin[1])];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The default origin coordinate of a line batch (the first coordinate of the first item)
|
|
105
|
+
*
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
export function defaultLineOrigin(items) {
|
|
109
|
+
const first = items[0]?.coords[0];
|
|
110
|
+
return first ? [first[0], first[1]] : [0, 0];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Builds the coordinate texture and instance array of a line batch (a pure transformation)
|
|
114
|
+
*
|
|
115
|
+
* Shared between immediate mode (drawAll) and retained mode (buildRetainedBatch). Coordinates
|
|
116
|
+
* are stored as values relative to `origin`, so fixing `origin` makes the result independent
|
|
117
|
+
* of the camera.
|
|
118
|
+
*
|
|
119
|
+
* @param zoom The zoom used to compute the cumulative distance (for dashes; the zoom at draw
|
|
120
|
+
* time for a dashed line, since the distance is in px at that zoom)
|
|
121
|
+
* @param origin The origin of the relative coordinates
|
|
122
|
+
* @param pixelRatio The injected rendering ratio (read from window each time when unspecified)
|
|
123
|
+
*
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
export function buildLineBatchArrays(items, zoom, origin, pixelRatio) {
|
|
127
|
+
// Get the rendering ratio (to convert CSS pixels into physical pixels)
|
|
128
|
+
//
|
|
129
|
+
// The ratio is chosen by the sign of the width (the "two ratios" in
|
|
130
|
+
// shared/utils/pixel-ratio.ts). A negative value = a width fixed in screen pixels uses the
|
|
131
|
+
// ratio that includes renderScale; a positive value = a width that the shader scales by
|
|
132
|
+
// 2^(u_zoom - createdZoom) uses the ratio without renderScale applied.
|
|
133
|
+
const screenDpr = resolvePixelRatio(pixelRatio);
|
|
134
|
+
const contentDpr = resolveContentPixelRatio(pixelRatio);
|
|
135
|
+
// Compute the total number of coordinates
|
|
136
|
+
let totalCoords = 0;
|
|
137
|
+
for (const item of items) {
|
|
138
|
+
totalCoords += item.coords.length;
|
|
139
|
+
}
|
|
140
|
+
if (totalCoords < 2)
|
|
141
|
+
return null;
|
|
142
|
+
// The texture size
|
|
143
|
+
const texSize = Math.max(2, Math.ceil(Math.sqrt(totalCoords)));
|
|
144
|
+
// The texture data (stores the relative coordinates)
|
|
145
|
+
const texData = new Float32Array(texSize * texSize * 4);
|
|
146
|
+
let coordOffset = 0;
|
|
147
|
+
for (const item of items) {
|
|
148
|
+
writeLineCoordTexels(texData, coordOffset, item.coords, origin);
|
|
149
|
+
coordOffset += item.coords.length;
|
|
150
|
+
}
|
|
151
|
+
// Generate the instance data
|
|
152
|
+
// 12 floats per instance: indices(4) + extra(4) + color(4)
|
|
153
|
+
let totalInstances = 0;
|
|
154
|
+
for (const item of items) {
|
|
155
|
+
totalInstances += item.coords.length - 1;
|
|
156
|
+
}
|
|
157
|
+
const instanceData = new Float32Array(totalInstances * INSTANCE_STRIDE);
|
|
158
|
+
let instanceIdx = 0;
|
|
159
|
+
let maxSegmentMeters = 0;
|
|
160
|
+
coordOffset = 0;
|
|
161
|
+
for (const item of items) {
|
|
162
|
+
const n = item.coords.length;
|
|
163
|
+
const meters = writeLineInstances(instanceData, instanceIdx, coordOffset, item.coords, {
|
|
164
|
+
closed: item.closed,
|
|
165
|
+
zoom,
|
|
166
|
+
dashPixelRatio: screenDpr,
|
|
167
|
+
// a_extra.y: the original line width (physical pixels)
|
|
168
|
+
strokeWidth: item.strokeWidth * (item.strokeWidth < 0 ? screenDpr : contentDpr),
|
|
169
|
+
createdZoom: item.createdZoom,
|
|
170
|
+
color: toLineInstanceColor(item.color, item.opacity),
|
|
171
|
+
});
|
|
172
|
+
if (meters > maxSegmentMeters)
|
|
173
|
+
maxSegmentMeters = meters;
|
|
174
|
+
instanceIdx += n - 1;
|
|
175
|
+
coordOffset += n;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
texData,
|
|
179
|
+
texSize,
|
|
180
|
+
instanceData,
|
|
181
|
+
instanceCount: totalInstances,
|
|
182
|
+
maxSegmentMeters,
|
|
183
|
+
maxSegmentMercator: maxInstanceSegmentMercator(instanceData, totalInstances, zoom, screenDpr),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The length of the longest segment of written instances on the Mercator plane (world units)
|
|
188
|
+
*
|
|
189
|
+
* The instances carry the length of each segment on screen at `zoom` (a_extra.w, in drawing-
|
|
190
|
+
* buffer px), which is the length on the Mercator plane times the size of the world in those
|
|
191
|
+
* px, so nothing is measured again.
|
|
192
|
+
*
|
|
193
|
+
* @param instanceData The instances written by {@link writeLineInstances}
|
|
194
|
+
* @param instanceCount The number of instances to look at
|
|
195
|
+
* @param zoom The zoom the lengths were written at
|
|
196
|
+
* @param dashPixelRatio The ratio the lengths were written with
|
|
197
|
+
*
|
|
198
|
+
* @internal
|
|
199
|
+
*/
|
|
200
|
+
export function maxInstanceSegmentMercator(instanceData, instanceCount, zoom, dashPixelRatio) {
|
|
201
|
+
let max = 0;
|
|
202
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
203
|
+
const length = instanceData[i * INSTANCE_STRIDE + 7];
|
|
204
|
+
if (length > max)
|
|
205
|
+
max = length;
|
|
206
|
+
}
|
|
207
|
+
const world = WORLD_TILE_SIZE * 2 ** zoom * dashPixelRatio;
|
|
208
|
+
return world > 0 ? max / world : 0;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Builds the coordinate texture and instance array of packed lines
|
|
212
|
+
*
|
|
213
|
+
* It writes exactly what `buildLineBatchArrays` writes for the same lines (the same arithmetic in
|
|
214
|
+
* the same order), so the two paths draw the same picture.
|
|
215
|
+
*
|
|
216
|
+
* @internal
|
|
217
|
+
*/
|
|
218
|
+
export function buildPackedLineBatchArrays(lines, zoom, origin, pixelRatio) {
|
|
219
|
+
const screenDpr = resolvePixelRatio(pixelRatio);
|
|
220
|
+
const contentDpr = resolveContentPixelRatio(pixelRatio);
|
|
221
|
+
const { count, coords, stride, start, end } = lines;
|
|
222
|
+
let totalCoords = 0;
|
|
223
|
+
let totalInstances = 0;
|
|
224
|
+
for (let i = 0; i < count; i++) {
|
|
225
|
+
totalCoords += end[i] - start[i];
|
|
226
|
+
totalInstances += end[i] - start[i] - 1;
|
|
227
|
+
}
|
|
228
|
+
if (totalCoords < 2)
|
|
229
|
+
return null;
|
|
230
|
+
const texSize = Math.max(2, Math.ceil(Math.sqrt(totalCoords)));
|
|
231
|
+
const texData = new Float32Array(texSize * texSize * 4);
|
|
232
|
+
let coordOffset = 0;
|
|
233
|
+
for (let i = 0; i < count; i++) {
|
|
234
|
+
for (let v = start[i]; v < end[i]; v++) {
|
|
235
|
+
texData[coordOffset * 4] = coords[v * stride] - origin[0];
|
|
236
|
+
texData[coordOffset * 4 + 1] = coords[v * stride + 1] - origin[1];
|
|
237
|
+
coordOffset++;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const instanceData = new Float32Array(totalInstances * INSTANCE_STRIDE);
|
|
241
|
+
let instanceIdx = 0;
|
|
242
|
+
let maxSegmentMeters = 0;
|
|
243
|
+
coordOffset = 0;
|
|
244
|
+
for (let i = 0; i < count; i++) {
|
|
245
|
+
const first = start[i];
|
|
246
|
+
const n = end[i] - first;
|
|
247
|
+
const width = lines.strokeWidth[i];
|
|
248
|
+
const strokeWidth = width * (width < 0 ? screenDpr : contentDpr);
|
|
249
|
+
const createdZoom = lines.createdZoom[i];
|
|
250
|
+
const c = i * 4;
|
|
251
|
+
let linesofar = 0;
|
|
252
|
+
for (let k = 0; k < n - 1; k++) {
|
|
253
|
+
const ax = coords[(first + k) * stride];
|
|
254
|
+
const ay = coords[(first + k) * stride + 1];
|
|
255
|
+
const bx = coords[(first + k + 1) * stride];
|
|
256
|
+
const by = coords[(first + k + 1) * stride + 1];
|
|
257
|
+
const segmentLength = screenPixelDistanceXY(ax, ay, bx, by, zoom) * screenDpr;
|
|
258
|
+
const meters = segmentMetersXY(ax, ay, bx, by);
|
|
259
|
+
if (meters > maxSegmentMeters)
|
|
260
|
+
maxSegmentMeters = meters;
|
|
261
|
+
const base = (instanceIdx + k) * INSTANCE_STRIDE;
|
|
262
|
+
instanceData[base + 0] = coordOffset + k;
|
|
263
|
+
instanceData[base + 1] = coordOffset + k + 1;
|
|
264
|
+
instanceData[base + 2] = k > 0 ? coordOffset + k - 1 : -1;
|
|
265
|
+
instanceData[base + 3] = k + 1 < n - 1 ? coordOffset + k + 2 : -1;
|
|
266
|
+
instanceData[base + 4] = linesofar;
|
|
267
|
+
instanceData[base + 5] = strokeWidth;
|
|
268
|
+
instanceData[base + 6] = createdZoom;
|
|
269
|
+
instanceData[base + 7] = segmentLength;
|
|
270
|
+
instanceData[base + 8] = lines.color[c];
|
|
271
|
+
instanceData[base + 9] = lines.color[c + 1];
|
|
272
|
+
instanceData[base + 10] = lines.color[c + 2];
|
|
273
|
+
instanceData[base + 11] = lines.color[c + 3];
|
|
274
|
+
linesofar += segmentLength;
|
|
275
|
+
}
|
|
276
|
+
instanceIdx += n - 1;
|
|
277
|
+
coordOffset += n;
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
texData,
|
|
281
|
+
texSize,
|
|
282
|
+
instanceData,
|
|
283
|
+
instanceCount: totalInstances,
|
|
284
|
+
maxSegmentMeters,
|
|
285
|
+
maxSegmentMercator: maxInstanceSegmentMercator(instanceData, totalInstances, zoom, screenDpr),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Writes the coordinates of one line into coordinate texels, as offsets from `origin`
|
|
290
|
+
*
|
|
291
|
+
* Each coordinate takes one RGBA texel starting at `coordOffset`: x = dLng, y = dLat (the
|
|
292
|
+
* offset from the origin computed at 64-bit precision). z and w are not written.
|
|
293
|
+
*
|
|
294
|
+
* @internal
|
|
295
|
+
*/
|
|
296
|
+
export function writeLineCoordTexels(target, coordOffset, coords, origin) {
|
|
297
|
+
for (let i = 0; i < coords.length; i++) {
|
|
298
|
+
// Compute the offset from the origin at 64-bit precision
|
|
299
|
+
const offset = calculateLngLatOffset(coords[i], origin);
|
|
300
|
+
target[(coordOffset + i) * 4] = offset[0]; // dLng (relative coordinate)
|
|
301
|
+
target[(coordOffset + i) * 4 + 1] = offset[1]; // dLat (relative coordinate)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Writes the instances (one per segment) of one line
|
|
306
|
+
*
|
|
307
|
+
* 12 floats per instance: indices(4) + extra(4) + color(4). The indices point into the
|
|
308
|
+
* coordinate texels of the line, which start at `coordOffset`; the previous and next indices
|
|
309
|
+
* wrap around on a closed line and are -1 at the ends of an open one.
|
|
310
|
+
*
|
|
311
|
+
* @param instanceStart The index of the first instance of the line in `target`
|
|
312
|
+
* @returns The length of the longest segment of the line (meters, approximate)
|
|
313
|
+
*
|
|
314
|
+
* @internal
|
|
315
|
+
*/
|
|
316
|
+
export function writeLineInstances(target, instanceStart, coordOffset, coords, params) {
|
|
317
|
+
const n = coords.length;
|
|
318
|
+
const { color } = params;
|
|
319
|
+
let linesofar = 0;
|
|
320
|
+
let maxSegmentMeters = 0;
|
|
321
|
+
for (let i = 0; i < n - 1; i++) {
|
|
322
|
+
const startIdx = coordOffset + i;
|
|
323
|
+
const endIdx = coordOffset + i + 1;
|
|
324
|
+
const prevIdx = i > 0 ? coordOffset + i - 1 : params.closed ? coordOffset + n - 2 : -1;
|
|
325
|
+
const nextIdx = i + 1 < n - 1 ? coordOffset + i + 2 : params.closed ? coordOffset + 1 : -1;
|
|
326
|
+
// The segment length on screen, in drawing-buffer px: the same unit as the screen length
|
|
327
|
+
// the vertex shader adds inside a segment and as the dash pattern (resolveDashUniform)
|
|
328
|
+
const segmentLength = screenPixelDistance(coords[i], coords[i + 1], params.zoom) * params.dashPixelRatio;
|
|
329
|
+
const meters = segmentMeters(coords[i], coords[i + 1]);
|
|
330
|
+
if (meters > maxSegmentMeters)
|
|
331
|
+
maxSegmentMeters = meters;
|
|
332
|
+
const base = (instanceStart + i) * INSTANCE_STRIDE;
|
|
333
|
+
target[base + 0] = startIdx;
|
|
334
|
+
target[base + 1] = endIdx;
|
|
335
|
+
target[base + 2] = prevIdx;
|
|
336
|
+
target[base + 3] = nextIdx;
|
|
337
|
+
target[base + 4] = linesofar; // a_extra.x: the starting cumulative distance (buffer px)
|
|
338
|
+
target[base + 5] = params.strokeWidth; // a_extra.y: the original line width (px)
|
|
339
|
+
target[base + 6] = params.createdZoom; // a_extra.z: createdZoom
|
|
340
|
+
target[base + 7] = segmentLength; // a_extra.w: the segment length (buffer px)
|
|
341
|
+
target[base + 8] = color[0]; // a_color.r
|
|
342
|
+
target[base + 9] = color[1]; // a_color.g
|
|
343
|
+
target[base + 10] = color[2]; // a_color.b
|
|
344
|
+
target[base + 11] = color[3]; // a_color.a
|
|
345
|
+
linesofar += segmentLength;
|
|
346
|
+
}
|
|
347
|
+
return maxSegmentMeters;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* The side of the Web Mercator world at zoom 0, in CSS px
|
|
351
|
+
*
|
|
352
|
+
* maplibre lays the world out on 512 px tiles, so the world is `512 * 2^zoom` CSS px wide.
|
|
353
|
+
*
|
|
354
|
+
* @internal
|
|
355
|
+
*/
|
|
356
|
+
export const WORLD_TILE_SIZE = 512;
|
|
357
|
+
/**
|
|
358
|
+
* The distance between two points on a flat Web Mercator map, in CSS px at `zoom`
|
|
359
|
+
*
|
|
360
|
+
* The projection stretches the latitude by 1 / cos(latitude) exactly as it stretches the
|
|
361
|
+
* longitude, so a length measured here is the same number of px on screen at any latitude.
|
|
362
|
+
* It is exact for an untilted Mercator view; a tilted or globe view shrinks the far side, and
|
|
363
|
+
* the vertex shader measures that part itself.
|
|
364
|
+
*
|
|
365
|
+
* @internal
|
|
366
|
+
*/
|
|
367
|
+
export function screenPixelDistance(a, b, zoom) {
|
|
368
|
+
return screenPixelDistanceXY(a[0], a[1], b[0], b[1], zoom);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* {@link screenPixelDistance} with the coordinates as separate numbers
|
|
372
|
+
*
|
|
373
|
+
* @internal
|
|
374
|
+
*/
|
|
375
|
+
export function screenPixelDistanceXY(ax, ay, bx, by, zoom) {
|
|
376
|
+
const world = WORLD_TILE_SIZE * 2 ** zoom;
|
|
377
|
+
const dx = ((bx - ax) / 360) * world;
|
|
378
|
+
const dy = (mercatorY(by) - mercatorY(ay)) * world;
|
|
379
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
380
|
+
}
|
|
381
|
+
/** The Web Mercator y of a latitude, in world units (the world is 1 wide) */
|
|
382
|
+
function mercatorY(lat) {
|
|
383
|
+
const latRad = (lat * Math.PI) / 180;
|
|
384
|
+
return Math.log(Math.tan(Math.PI / 4 + latRad / 2)) / (2 * Math.PI);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* The distance between two points (meters, planar approximation)
|
|
388
|
+
*
|
|
389
|
+
* An approximation used only to decide the number of terrain subdivisions.
|
|
390
|
+
*
|
|
391
|
+
* @internal
|
|
392
|
+
*/
|
|
393
|
+
export function segmentMeters(a, b) {
|
|
394
|
+
return segmentMetersXY(a[0], a[1], b[0], b[1]);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* {@link segmentMeters} with the coordinates as separate numbers
|
|
398
|
+
*
|
|
399
|
+
* @internal
|
|
400
|
+
*/
|
|
401
|
+
export function segmentMetersXY(ax, ay, bx, by) {
|
|
402
|
+
const midLatRad = (((ay + by) / 2) * Math.PI) / 180;
|
|
403
|
+
const dx = (bx - ax) * EARTH.METERS_PER_DEGREE * Math.cos(midLatRad);
|
|
404
|
+
const dy = (by - ay) * EARTH.METERS_PER_DEGREE;
|
|
405
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Whether the stations of the segments are placed along the Mercator plane (the globe) rather
|
|
409
|
+
* than along the degrees (the terrain)
|
|
410
|
+
*
|
|
411
|
+
* On the terrain the stations follow the mesh of the ground, in degrees as before. On the
|
|
412
|
+
* globe they follow the straight line of the Mercator plane, the path maplibre draws an edge
|
|
413
|
+
* along (`view/globe-subdivision.ts`).
|
|
414
|
+
*
|
|
415
|
+
* @internal
|
|
416
|
+
*/
|
|
417
|
+
export function lineStationsOnMercatorPlane(context) {
|
|
418
|
+
return !isTerrainStationActive(context) && globeGridOf(context, 'line') > 0;
|
|
419
|
+
}
|
|
420
|
+
/** Whether the terrain decides the stations (the terrain is drawn with a step) */
|
|
421
|
+
function isTerrainStationActive(context) {
|
|
422
|
+
const terrain = context.renderState;
|
|
423
|
+
return terrain.active && terrain.stepMeters > 0;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Decides how many parts one segment is split into when drawn on terrain or on the globe
|
|
427
|
+
*
|
|
428
|
+
* On a flat map without terrain it always returns 1 (= the same 4-vertex strip as before).
|
|
429
|
+
* The terrain splits by its step in meters; the globe, when there is no terrain, by the line
|
|
430
|
+
* cell of maplibre's granularity on the Mercator plane.
|
|
431
|
+
*
|
|
432
|
+
* @param maxSegmentMercator The longest segment on the Mercator plane (world units; only the
|
|
433
|
+
* globe reads it)
|
|
434
|
+
*
|
|
435
|
+
* @internal
|
|
436
|
+
*/
|
|
437
|
+
export function resolveLineStations(context, maxSegmentMeters, instanceCount, maxSegmentMercator = 0) {
|
|
438
|
+
let wanted;
|
|
439
|
+
if (isTerrainStationActive(context)) {
|
|
440
|
+
if (!(maxSegmentMeters > 0))
|
|
441
|
+
return 1;
|
|
442
|
+
wanted = Math.ceil(maxSegmentMeters / context.renderState.stepMeters);
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
const grid = globeGridOf(context, 'line');
|
|
446
|
+
if (!(grid > 0) || !(maxSegmentMercator > 0))
|
|
447
|
+
return 1;
|
|
448
|
+
wanted = Math.ceil(maxSegmentMercator / grid);
|
|
449
|
+
}
|
|
450
|
+
let stations = Math.min(MAX_LINE_STATIONS, wanted);
|
|
451
|
+
if (stations <= 1)
|
|
452
|
+
return 1;
|
|
453
|
+
// Stop the vertex count from blowing up (a single long segment mixed in would otherwise
|
|
454
|
+
// make the whole batch use the maximum subdivision)
|
|
455
|
+
if (instanceCount > 0) {
|
|
456
|
+
const budget = Math.max(1, Math.floor(LINE_STATION_BUDGET / instanceCount));
|
|
457
|
+
stations = Math.min(stations, budget);
|
|
458
|
+
}
|
|
459
|
+
return Math.max(1, stations);
|
|
460
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* The GL resources of the SDF line renderer
|
|
5
|
+
*
|
|
6
|
+
* The vertex attribute layout shared by immediate mode and retained mode, the coordinate
|
|
7
|
+
* textures, and the create / patch / delete of a retained batch. The functions take the GL
|
|
8
|
+
* context and hold no state of their own, except the growable coordinate texture of
|
|
9
|
+
* immediate mode.
|
|
10
|
+
*/
|
|
11
|
+
import { calculateLngLatOffset } from '../../shaders/helpers.js';
|
|
12
|
+
import { INSTANCE_BYTES, STATION_VERTICES } from './line-geometry.js';
|
|
13
|
+
/**
|
|
14
|
+
* Sets up the quad vertex attributes (call it with the quad bound to ARRAY_BUFFER)
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export function setupQuadAttribs(gl) {
|
|
19
|
+
// location 0: side (float)
|
|
20
|
+
gl.enableVertexAttribArray(0);
|
|
21
|
+
gl.vertexAttribPointer(0, 1, gl.FLOAT, false, 8, 0);
|
|
22
|
+
// location 1: t (float)
|
|
23
|
+
gl.enableVertexAttribArray(1);
|
|
24
|
+
gl.vertexAttribPointer(1, 1, gl.FLOAT, false, 8, 4);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sets up the instance attributes (call it with the instances bound to ARRAY_BUFFER)
|
|
28
|
+
*
|
|
29
|
+
* Immediate mode and retained mode use the same layout (stride = 48 bytes = 12 floats).
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export function setupInstanceAttribs(gl) {
|
|
34
|
+
gl.enableVertexAttribArray(2);
|
|
35
|
+
gl.vertexAttribPointer(2, 4, gl.FLOAT, false, INSTANCE_BYTES, 0); // a_indices
|
|
36
|
+
gl.vertexAttribDivisor(2, 1);
|
|
37
|
+
gl.enableVertexAttribArray(3);
|
|
38
|
+
gl.vertexAttribPointer(3, 4, gl.FLOAT, false, INSTANCE_BYTES, 16); // a_extra (vec4)
|
|
39
|
+
gl.vertexAttribDivisor(3, 1);
|
|
40
|
+
gl.enableVertexAttribArray(4);
|
|
41
|
+
gl.vertexAttribPointer(4, 4, gl.FLOAT, false, INSTANCE_BYTES, 32); // a_color (vec4)
|
|
42
|
+
gl.vertexAttribDivisor(4, 1);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Resets the instance divisors and unbinds the vertex array (the end of an immediate draw)
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export function releaseInstanceAttribs(gl) {
|
|
50
|
+
gl.vertexAttribDivisor(2, 0);
|
|
51
|
+
gl.vertexAttribDivisor(3, 0);
|
|
52
|
+
gl.vertexAttribDivisor(4, 0);
|
|
53
|
+
gl.bindVertexArray(null);
|
|
54
|
+
}
|
|
55
|
+
/** Sets nearest filtering and edge clamping on the texture bound to TEXTURE_2D */
|
|
56
|
+
function setCoordTextureParams(gl) {
|
|
57
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
58
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
59
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
60
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates a coordinate texture (for retained mode; the size is allocated exactly)
|
|
64
|
+
*
|
|
65
|
+
* @param limit The largest side of a texture this GPU allows (MAX_TEXTURE_SIZE)
|
|
66
|
+
* @returns null when the coordinates do not fit in a texture of this GPU (the batch is then
|
|
67
|
+
* not built)
|
|
68
|
+
*
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export function createCoordTexture(gl, texData, texSize, limit) {
|
|
72
|
+
if (texSize > limit)
|
|
73
|
+
return null;
|
|
74
|
+
const texture = gl.createTexture();
|
|
75
|
+
if (!texture)
|
|
76
|
+
return null;
|
|
77
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
78
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA32F, texSize, texSize);
|
|
79
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, texSize, texSize, gl.RGBA, gl.FLOAT, texData);
|
|
80
|
+
setCoordTextureParams(gl);
|
|
81
|
+
return texture;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The coordinate texture reused by immediate mode
|
|
85
|
+
*
|
|
86
|
+
* It is an immutable texture allocated with texStorage2D, so it is recreated only when a
|
|
87
|
+
* texSize larger than the allocated one arrives. `size` is the allocated side length, which is
|
|
88
|
+
* distinct from u_tex_size (the texSize of the data) passed to the shader.
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
export class ImmediateCoordTexture {
|
|
93
|
+
constructor(gl) {
|
|
94
|
+
Object.defineProperty(this, "gl", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
configurable: true,
|
|
97
|
+
writable: true,
|
|
98
|
+
value: gl
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(this, "texture", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
writable: true,
|
|
104
|
+
value: null
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(this, "size", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
configurable: true,
|
|
109
|
+
writable: true,
|
|
110
|
+
value: 0
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Uploads the coordinates (returns with the texture bound to TEXTURE_2D)
|
|
115
|
+
*
|
|
116
|
+
* The allocated size is a power of two at least as large as texSize, which keeps
|
|
117
|
+
* reallocation infrequent. The upload covers only the texSize of the data, and the shader's
|
|
118
|
+
* u_tex_size is also given the texSize of the data. texelFetch only refers to the top-left
|
|
119
|
+
* texSize x texSize sub-rectangle, so the read is correct even when the allocated size is
|
|
120
|
+
* larger. The allocation never exceeds `limit` (MAX_TEXTURE_SIZE).
|
|
121
|
+
*
|
|
122
|
+
* @returns false when the coordinates do not fit in a texture of this GPU (nothing is drawn)
|
|
123
|
+
*/
|
|
124
|
+
upload(texData, texSize, limit) {
|
|
125
|
+
const gl = this.gl;
|
|
126
|
+
if (texSize > limit)
|
|
127
|
+
return false;
|
|
128
|
+
if (!this.texture || texSize > this.size) {
|
|
129
|
+
if (this.texture)
|
|
130
|
+
gl.deleteTexture(this.texture);
|
|
131
|
+
let size = 2;
|
|
132
|
+
while (size < texSize)
|
|
133
|
+
size *= 2;
|
|
134
|
+
size = Math.min(size, limit);
|
|
135
|
+
const texture = gl.createTexture();
|
|
136
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
137
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA32F, size, size);
|
|
138
|
+
setCoordTextureParams(gl);
|
|
139
|
+
this.texture = texture;
|
|
140
|
+
this.size = size;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
gl.bindTexture(gl.TEXTURE_2D, this.texture);
|
|
144
|
+
}
|
|
145
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, texSize, texSize, gl.RGBA, gl.FLOAT, texData);
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
/** Deletes the texture */
|
|
149
|
+
dispose() {
|
|
150
|
+
if (this.texture) {
|
|
151
|
+
this.gl.deleteTexture(this.texture);
|
|
152
|
+
this.texture = null;
|
|
153
|
+
this.size = 0;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Creates the GPU resources of a retained-mode line batch
|
|
159
|
+
*
|
|
160
|
+
* The batch owns its coordinate texture, quad vertex buffer, instance buffer, and VAO; none of
|
|
161
|
+
* them is shared with immediate mode.
|
|
162
|
+
*
|
|
163
|
+
* @param limit The largest side of a texture this GPU allows (MAX_TEXTURE_SIZE)
|
|
164
|
+
* @returns null when the coordinates do not fit in a texture of this GPU
|
|
165
|
+
*
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
export function createRetainedLineBatch(gl, arrays, shape, origin, widthZoom, limit) {
|
|
169
|
+
const texture = createCoordTexture(gl, arrays.texData, arrays.texSize, limit);
|
|
170
|
+
if (!texture)
|
|
171
|
+
return null;
|
|
172
|
+
const vao = gl.createVertexArray();
|
|
173
|
+
gl.bindVertexArray(vao);
|
|
174
|
+
// The quad vertices (held separately from the shared immediate-mode buffer)
|
|
175
|
+
const quadBuffer = gl.createBuffer();
|
|
176
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
|
|
177
|
+
gl.bufferData(gl.ARRAY_BUFFER, STATION_VERTICES, gl.STATIC_DRAW);
|
|
178
|
+
setupQuadAttribs(gl);
|
|
179
|
+
// The instance attributes (the layout is identical to immediate mode)
|
|
180
|
+
const instanceBuffer = gl.createBuffer();
|
|
181
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, instanceBuffer);
|
|
182
|
+
gl.bufferData(gl.ARRAY_BUFFER, arrays.instanceData, gl.STATIC_DRAW);
|
|
183
|
+
setupInstanceAttribs(gl);
|
|
184
|
+
gl.bindVertexArray(null);
|
|
185
|
+
return {
|
|
186
|
+
vao,
|
|
187
|
+
quadBuffer,
|
|
188
|
+
instanceBuffer,
|
|
189
|
+
texture,
|
|
190
|
+
texSize: arrays.texSize,
|
|
191
|
+
instanceCount: arrays.instanceCount,
|
|
192
|
+
shape,
|
|
193
|
+
origin,
|
|
194
|
+
widthZoom,
|
|
195
|
+
maxSegmentMeters: arrays.maxSegmentMeters,
|
|
196
|
+
maxSegmentMercator: arrays.maxSegmentMercator,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Rewrites single texels of the coordinate texture of a retained batch
|
|
201
|
+
*
|
|
202
|
+
* See SDFLineRenderer.patchRetainedBatchCoords for why only the texels are rewritten.
|
|
203
|
+
*
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
export function patchRetainedCoordTexels(gl, batch, updates) {
|
|
207
|
+
if (updates.length === 0)
|
|
208
|
+
return;
|
|
209
|
+
const texSize = batch.texSize;
|
|
210
|
+
const capacity = texSize * texSize;
|
|
211
|
+
// The upload buffer for one texel (z/w stay 0, the same as at build time)
|
|
212
|
+
const texel = new Float32Array(4);
|
|
213
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
214
|
+
gl.bindTexture(gl.TEXTURE_2D, batch.texture);
|
|
215
|
+
for (const { coordIndex, lngLat } of updates) {
|
|
216
|
+
// Ignore out-of-range indices (a safety net for when the batch and the caller diverge)
|
|
217
|
+
if (!Number.isInteger(coordIndex) || coordIndex < 0 || coordIndex >= capacity)
|
|
218
|
+
continue;
|
|
219
|
+
// The same conversion as at build time (the offset from the origin at 64-bit precision)
|
|
220
|
+
const offset = calculateLngLatOffset(lngLat, batch.origin);
|
|
221
|
+
texel[0] = offset[0];
|
|
222
|
+
texel[1] = offset[1];
|
|
223
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, coordIndex % texSize, Math.floor(coordIndex / texSize), 1, 1, gl.RGBA, gl.FLOAT, texel);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Deletes the GPU resources of a retained-mode line batch
|
|
228
|
+
*
|
|
229
|
+
* @internal
|
|
230
|
+
*/
|
|
231
|
+
export function deleteRetainedLineBatch(gl, batch) {
|
|
232
|
+
gl.deleteVertexArray(batch.vao);
|
|
233
|
+
gl.deleteBuffer(batch.quadBuffer);
|
|
234
|
+
gl.deleteBuffer(batch.instanceBuffer);
|
|
235
|
+
gl.deleteTexture(batch.texture);
|
|
236
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|