@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,738 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
import { resolvePixelRatio } from '../../../shared/utils/pixel-ratio.js';
|
|
4
|
+
import { getRenderFrame } from '../../shaders/frame.js';
|
|
5
|
+
import { calculateLngLatOffset, calculateOffsetUniforms, createProgram, getProjectionTransitionUniform, OFFSET_MODE_GLSL, } from '../../shaders/helpers.js';
|
|
6
|
+
import { ProjectionUniformManager } from '../../shaders/projection.js';
|
|
7
|
+
import { anchorElevationMeters } from '../../terrain/anchor.js';
|
|
8
|
+
import { TerrainContext } from '../../terrain/context.js';
|
|
9
|
+
import { NEUTRAL_DRAW_FACTORS } from '../draw-factors.js';
|
|
10
|
+
import { drawBillboardsWithoutDepth } from './billboard-depth.js';
|
|
11
|
+
import { POINT_SDF_GLSL, POINT_SHAPE_CODE } from './point-sdf.js';
|
|
12
|
+
/**
|
|
13
|
+
* The instanced shape a point style is drawn with, or null for a shape the instanced renderer
|
|
14
|
+
* does not draw (`'icon'`, which goes through the per-point renderer)
|
|
15
|
+
*
|
|
16
|
+
* The retained batches (Store and datasets) and the immediate batches all decide
|
|
17
|
+
* with this function, so the three paths agree on which points are instanced.
|
|
18
|
+
*/
|
|
19
|
+
export function toInstancedPointShape(shape) {
|
|
20
|
+
return INSTANCED_SHAPES.has(shape) ? shape : null;
|
|
21
|
+
}
|
|
22
|
+
/** The shapes the instanced renderer draws */
|
|
23
|
+
const INSTANCED_SHAPES = new Set(Object.keys(POINT_SHAPE_CODE));
|
|
24
|
+
/**
|
|
25
|
+
* Half width of the antialiasing band (device pixels)
|
|
26
|
+
*
|
|
27
|
+
* The billboard is placed one to one with device pixels (the offset is computed in pixels and
|
|
28
|
+
* converted to NDC), so smoothing 0.5px on either side of the boundary yields a 1px wide band.
|
|
29
|
+
*/
|
|
30
|
+
const AA_HALF_WIDTH_PX = 0.5;
|
|
31
|
+
/**
|
|
32
|
+
* Padding added to the billboard (device pixels)
|
|
33
|
+
*
|
|
34
|
+
* Cutting the billboard exactly at the outer radius loses the outer half of the antialiasing.
|
|
35
|
+
*/
|
|
36
|
+
export const POINT_AA_PADDING_PX = 1;
|
|
37
|
+
// Stride of the instance data (floats per instance)
|
|
38
|
+
// position(2) + fillColor(4) + strokeColor(4) + size(1) + strokeWidth(1)
|
|
39
|
+
// + elevation(1) = 13 floats
|
|
40
|
+
const INSTANCE_STRIDE = 13;
|
|
41
|
+
const INSTANCE_BYTES = INSTANCE_STRIDE * 4;
|
|
42
|
+
/** Number of vertices of the billboard (quad) */
|
|
43
|
+
const QUAD_VERTEX_COUNT = 4;
|
|
44
|
+
/** Value of the uniform that represents the shape */
|
|
45
|
+
const SHAPE_UNIFORM = POINT_SHAPE_CODE;
|
|
46
|
+
/**
|
|
47
|
+
* Computes the SDF boundaries
|
|
48
|
+
*
|
|
49
|
+
* This is the same computation the shader performs in the vertex and fragment stages (the GLSL
|
|
50
|
+
* side writes these formulas as they are, and embeds the same constant `POINT_AA_PADDING_PX` for
|
|
51
|
+
* the padding). Negative values are treated as 0, and when the stroke width is 0 the outer
|
|
52
|
+
* radius equals the radius.
|
|
53
|
+
*
|
|
54
|
+
* @param fillSizePx Radius of the fill (device pixels)
|
|
55
|
+
* @param strokeWidthPx Stroke width (device pixels)
|
|
56
|
+
* @param sizeScale Size factor at draw time (default 1)
|
|
57
|
+
*/
|
|
58
|
+
export function pointSdfEdges(fillSizePx, strokeWidthPx, sizeScale = 1) {
|
|
59
|
+
const radius = Math.max(0, fillSizePx) * sizeScale;
|
|
60
|
+
const outer = radius + Math.max(0, strokeWidthPx) * sizeScale;
|
|
61
|
+
return { radius, outer, extent: outer + POINT_AA_PADDING_PX };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Rounds the origin of the relative coordinates to Float32
|
|
65
|
+
*/
|
|
66
|
+
function normalizeOrigin(origin) {
|
|
67
|
+
return [Math.fround(origin[0]), Math.fround(origin[1])];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Default origin of a point batch (the first point)
|
|
71
|
+
*/
|
|
72
|
+
function defaultPointOrigin(points) {
|
|
73
|
+
const first = points[0]?.coord;
|
|
74
|
+
return first ? [first[0], first[1]] : [0, 0];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Builds the instance array (shared by the immediate mode and the retained mode)
|
|
78
|
+
*
|
|
79
|
+
* The order is exactly the order of the input (since the instance order directly becomes the
|
|
80
|
+
* front-to-back order of the rendering, nothing is reordered or thinned out). Coordinates are
|
|
81
|
+
* stored as values relative to `origin`, so with a fixed `origin` the result does not depend on
|
|
82
|
+
* the camera.
|
|
83
|
+
*/
|
|
84
|
+
export function buildPointInstanceData(points, origin, pixelRatio, terrain) {
|
|
85
|
+
const dpr = resolvePixelRatio(pixelRatio);
|
|
86
|
+
const data = new Float32Array(points.length * INSTANCE_STRIDE);
|
|
87
|
+
for (let i = 0; i < points.length; i++) {
|
|
88
|
+
const p = points[i];
|
|
89
|
+
const offset = i * INSTANCE_STRIDE;
|
|
90
|
+
// Compute the relative coordinates (the origin is already rounded to Float32, and the
|
|
91
|
+
// relative coordinates are small enough for sufficient precision)
|
|
92
|
+
const lngLatOffset = calculateLngLatOffset(p.coord, origin);
|
|
93
|
+
data[offset] = lngLatOffset[0]; // dLng (relative coordinate)
|
|
94
|
+
data[offset + 1] = lngLatOffset[1]; // dLat (relative coordinate)
|
|
95
|
+
// The faintness used when occluded is folded into the alpha (no extra attribute)
|
|
96
|
+
const ghost = p.ghost ?? 1;
|
|
97
|
+
data[offset + 2] = p.fillColor[0];
|
|
98
|
+
data[offset + 3] = p.fillColor[1];
|
|
99
|
+
data[offset + 4] = p.fillColor[2];
|
|
100
|
+
data[offset + 5] = p.fillColor[3] * ghost;
|
|
101
|
+
data[offset + 6] = p.strokeColor[0];
|
|
102
|
+
data[offset + 7] = p.strokeColor[1];
|
|
103
|
+
data[offset + 8] = p.strokeColor[2];
|
|
104
|
+
data[offset + 9] = p.strokeColor[3] * ghost;
|
|
105
|
+
// Convert CSS pixels to device pixels
|
|
106
|
+
data[offset + 10] = p.fillSize * dpr;
|
|
107
|
+
data[offset + 11] = p.strokeWidth * dpr;
|
|
108
|
+
// Ground elevation of the anchor (meters). Without an explicit value it is sampled from the
|
|
109
|
+
// single source of truth. Making each caller attach the elevation lets the defect come back
|
|
110
|
+
// on whichever path forgot it, dropping to sea level 0 (which actually happened for points
|
|
111
|
+
// and handles), so it is placed where every default path goes through. When terrain is
|
|
112
|
+
// disabled it returns 0 and the result is identical to before.
|
|
113
|
+
data[offset + 12] =
|
|
114
|
+
p.elevationMeters ?? (terrain ? anchorElevationMeters(terrain, p.coord[0], p.coord[1]) : 0);
|
|
115
|
+
}
|
|
116
|
+
return data;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The number of values of the style of one point in {@link PackedPointInstances}
|
|
120
|
+
*
|
|
121
|
+
* fill color (4, the opacity already folded into the alpha) + stroke color (4, likewise) + radius
|
|
122
|
+
* of the fill (CSS pixels) + stroke width (CSS pixels)
|
|
123
|
+
*
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
export const PACKED_POINT_STYLE_STRIDE = 10;
|
|
127
|
+
/**
|
|
128
|
+
* Builds the instance array from packed points
|
|
129
|
+
*
|
|
130
|
+
* It writes exactly what `buildPointInstanceData` writes for the same points (the same arithmetic
|
|
131
|
+
* in the same order), so the two paths draw the same picture.
|
|
132
|
+
*
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
export function buildPackedPointInstanceData(points, origin, pixelRatio, terrain) {
|
|
136
|
+
const dpr = resolvePixelRatio(pixelRatio);
|
|
137
|
+
const { count, lngLat, style } = points;
|
|
138
|
+
const data = new Float32Array(count * INSTANCE_STRIDE);
|
|
139
|
+
for (let i = 0; i < count; i++) {
|
|
140
|
+
const offset = i * INSTANCE_STRIDE;
|
|
141
|
+
const lng = lngLat[i * 2];
|
|
142
|
+
const lat = lngLat[i * 2 + 1];
|
|
143
|
+
const s = i * PACKED_POINT_STYLE_STRIDE;
|
|
144
|
+
data[offset] = lng - origin[0];
|
|
145
|
+
data[offset + 1] = lat - origin[1];
|
|
146
|
+
data[offset + 2] = style[s];
|
|
147
|
+
data[offset + 3] = style[s + 1];
|
|
148
|
+
data[offset + 4] = style[s + 2];
|
|
149
|
+
data[offset + 5] = style[s + 3];
|
|
150
|
+
data[offset + 6] = style[s + 4];
|
|
151
|
+
data[offset + 7] = style[s + 5];
|
|
152
|
+
data[offset + 8] = style[s + 6];
|
|
153
|
+
data[offset + 9] = style[s + 7];
|
|
154
|
+
data[offset + 10] = style[s + 8] * dpr;
|
|
155
|
+
data[offset + 11] = style[s + 9] * dpr;
|
|
156
|
+
data[offset + 12] = terrain ? anchorElevationMeters(terrain, lng, lat) : 0;
|
|
157
|
+
}
|
|
158
|
+
return data;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Generates the vertices of the billboard (quad) (for TRIANGLE_STRIP)
|
|
162
|
+
*
|
|
163
|
+
* The difference between shapes (circle, square, triangle, star) is absorbed by the distance
|
|
164
|
+
* function in the fragment shader, so the vertices may be the same billboard regardless of the
|
|
165
|
+
* shape.
|
|
166
|
+
*/
|
|
167
|
+
function generateQuadVertices() {
|
|
168
|
+
return new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Creates a record in the never-written state
|
|
172
|
+
*/
|
|
173
|
+
function createPointMemo() {
|
|
174
|
+
return {
|
|
175
|
+
factorsFrame: -1,
|
|
176
|
+
shapeFrame: -1,
|
|
177
|
+
pixelToClipFrame: -1,
|
|
178
|
+
canvasWidth: Number.NaN,
|
|
179
|
+
canvasHeight: Number.NaN,
|
|
180
|
+
sizeScale: Number.NaN,
|
|
181
|
+
opacity: Number.NaN,
|
|
182
|
+
shape: Number.NaN,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* PointInstanceRenderer
|
|
187
|
+
*
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
export class PointInstanceRenderer {
|
|
191
|
+
constructor(_map, gl, pixelRatio, terrain = new TerrainContext()) {
|
|
192
|
+
Object.defineProperty(this, "gl", {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
configurable: true,
|
|
195
|
+
writable: true,
|
|
196
|
+
value: void 0
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(this, "program", {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
configurable: true,
|
|
201
|
+
writable: true,
|
|
202
|
+
value: null
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(this, "variantName", {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
configurable: true,
|
|
207
|
+
writable: true,
|
|
208
|
+
value: ''
|
|
209
|
+
});
|
|
210
|
+
// Vertices of the billboard (the vertex buffer is created per VAO)
|
|
211
|
+
Object.defineProperty(this, "quadVertices", {
|
|
212
|
+
enumerable: true,
|
|
213
|
+
configurable: true,
|
|
214
|
+
writable: true,
|
|
215
|
+
value: void 0
|
|
216
|
+
});
|
|
217
|
+
// VAO (created per program; points at the shared instance buffer of the immediate mode)
|
|
218
|
+
Object.defineProperty(this, "quadVaos", {
|
|
219
|
+
enumerable: true,
|
|
220
|
+
configurable: true,
|
|
221
|
+
writable: true,
|
|
222
|
+
value: new Map()
|
|
223
|
+
});
|
|
224
|
+
// Instance buffer
|
|
225
|
+
Object.defineProperty(this, "instanceBuffer", {
|
|
226
|
+
enumerable: true,
|
|
227
|
+
configurable: true,
|
|
228
|
+
writable: true,
|
|
229
|
+
value: null
|
|
230
|
+
});
|
|
231
|
+
// Projection uniform locations and the values written last (per program)
|
|
232
|
+
Object.defineProperty(this, "programStates", {
|
|
233
|
+
enumerable: true,
|
|
234
|
+
configurable: true,
|
|
235
|
+
writable: true,
|
|
236
|
+
value: new Map()
|
|
237
|
+
});
|
|
238
|
+
// ProjectionData
|
|
239
|
+
Object.defineProperty(this, "projectionData", {
|
|
240
|
+
enumerable: true,
|
|
241
|
+
configurable: true,
|
|
242
|
+
writable: true,
|
|
243
|
+
value: null
|
|
244
|
+
});
|
|
245
|
+
// Canvas size for pixel to clip conversion
|
|
246
|
+
Object.defineProperty(this, "canvasWidth", {
|
|
247
|
+
enumerable: true,
|
|
248
|
+
configurable: true,
|
|
249
|
+
writable: true,
|
|
250
|
+
value: 0
|
|
251
|
+
});
|
|
252
|
+
Object.defineProperty(this, "canvasHeight", {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
configurable: true,
|
|
255
|
+
writable: true,
|
|
256
|
+
value: 0
|
|
257
|
+
});
|
|
258
|
+
// Stores the offset uniforms
|
|
259
|
+
Object.defineProperty(this, "offsetUniforms", {
|
|
260
|
+
enumerable: true,
|
|
261
|
+
configurable: true,
|
|
262
|
+
writable: true,
|
|
263
|
+
value: null
|
|
264
|
+
});
|
|
265
|
+
/** Injected device pixel ratio (when not injected, it is read from window each time) */
|
|
266
|
+
Object.defineProperty(this, "pixelRatio", {
|
|
267
|
+
enumerable: true,
|
|
268
|
+
configurable: true,
|
|
269
|
+
writable: true,
|
|
270
|
+
value: void 0
|
|
271
|
+
});
|
|
272
|
+
/** The terrain state of the draw instance this renderer belongs to */
|
|
273
|
+
Object.defineProperty(this, "terrain", {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
configurable: true,
|
|
276
|
+
writable: true,
|
|
277
|
+
value: void 0
|
|
278
|
+
});
|
|
279
|
+
this.gl = gl;
|
|
280
|
+
this.pixelRatio = pixelRatio;
|
|
281
|
+
this.terrain = terrain;
|
|
282
|
+
this.instanceBuffer = gl.createBuffer();
|
|
283
|
+
this.quadVertices = generateQuadVertices();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Ensures the shader exists (recreating it when necessary)
|
|
287
|
+
*/
|
|
288
|
+
ensureShader(shaderData) {
|
|
289
|
+
// The clip conversion uses the drawing buffer, which is what the viewport covers (the
|
|
290
|
+
// canvas attribute can be larger when the browser could not allocate the full size)
|
|
291
|
+
this.canvasWidth = this.gl.drawingBufferWidth;
|
|
292
|
+
this.canvasHeight = this.gl.drawingBufferHeight;
|
|
293
|
+
if (this.variantName !== shaderData.variantName) {
|
|
294
|
+
this.disposePrograms();
|
|
295
|
+
this.program = this.createPointProgram(shaderData.vertexShaderPrelude, shaderData.define);
|
|
296
|
+
this.variantName = shaderData.variantName;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Creates the shader program (offset mode, high precision version)
|
|
301
|
+
*
|
|
302
|
+
* The fill and the stroke are drawn by one program. The vertex stage spans a billboard of the
|
|
303
|
+
* outer radius plus the padding, and the fragment stage separates fill, stroke and outside by
|
|
304
|
+
* the signed distance to the outer edge of the shape.
|
|
305
|
+
*/
|
|
306
|
+
createPointProgram(prelude, define) {
|
|
307
|
+
const projTransitionUniform = getProjectionTransitionUniform(prelude);
|
|
308
|
+
const vertexSource = `#version 300 es
|
|
309
|
+
${prelude}
|
|
310
|
+
${define}
|
|
311
|
+
${projTransitionUniform}${OFFSET_MODE_GLSL}
|
|
312
|
+
layout(location = 0) in vec2 a_quad; // billboard vertex (±1)
|
|
313
|
+
layout(location = 1) in vec2 a_instance_lnglat_offset; // offset from center (64-bit on CPU)
|
|
314
|
+
layout(location = 2) in vec4 a_instance_fill_color; // fill color
|
|
315
|
+
layout(location = 3) in vec4 a_instance_stroke_color; // stroke color
|
|
316
|
+
layout(location = 4) in float a_instance_size; // fill radius (pixels)
|
|
317
|
+
layout(location = 5) in float a_instance_stroke_width; // stroke width (pixels)
|
|
318
|
+
layout(location = 6) in float a_instance_elevation_m; // anchor ground elevation (meters)
|
|
319
|
+
|
|
320
|
+
uniform vec2 u_pixel_to_clip; // pixel-to-clip-space conversion factor
|
|
321
|
+
uniform float u_size_scale; // size factor at draw time (default 1)
|
|
322
|
+
|
|
323
|
+
// Values constant per instance are passed as flat (avoids both interpolation error and cost)
|
|
324
|
+
flat out vec4 v_fill_color;
|
|
325
|
+
flat out vec4 v_stroke_color;
|
|
326
|
+
out vec2 v_offset_px;
|
|
327
|
+
flat out float v_radius_px;
|
|
328
|
+
flat out float v_outer_px;
|
|
329
|
+
|
|
330
|
+
void main() {
|
|
331
|
+
// The anchor elevation comes from the CPU (the same source as hit testing).
|
|
332
|
+
// The DEM atlas is not sampled (two sources make the rendering and the hit area disagree).
|
|
333
|
+
g_anchor_elevation_m = a_instance_elevation_m;
|
|
334
|
+
g_anchor_elevation_on = 1.0;
|
|
335
|
+
|
|
336
|
+
// High precision version: uses relative coordinates computed with 64-bit precision on the CPU
|
|
337
|
+
vec4 centerClip = project_position_to_clipspace_from_offset(a_instance_lnglat_offset, u_projection_matrix);
|
|
338
|
+
|
|
339
|
+
float radius = max(a_instance_size, 0.0) * u_size_scale;
|
|
340
|
+
float outer = radius + max(a_instance_stroke_width, 0.0) * u_size_scale;
|
|
341
|
+
// The billboard is sized as the outer radius plus the antialiasing padding
|
|
342
|
+
// (so that the edge is not clipped)
|
|
343
|
+
vec2 offsetPx = a_quad * (outer + ${POINT_AA_PADDING_PX.toFixed(1)});
|
|
344
|
+
|
|
345
|
+
gl_Position = vec4(centerClip.xy / centerClip.w + offsetPx * u_pixel_to_clip, centerClip.z / centerClip.w, 1.0);
|
|
346
|
+
|
|
347
|
+
v_fill_color = a_instance_fill_color;
|
|
348
|
+
v_stroke_color = a_instance_stroke_color;
|
|
349
|
+
v_offset_px = offsetPx;
|
|
350
|
+
v_radius_px = radius;
|
|
351
|
+
v_outer_px = outer;
|
|
352
|
+
}`;
|
|
353
|
+
const fragmentSource = `#version 300 es
|
|
354
|
+
precision highp float;
|
|
355
|
+
flat in vec4 v_fill_color;
|
|
356
|
+
flat in vec4 v_stroke_color;
|
|
357
|
+
in vec2 v_offset_px;
|
|
358
|
+
flat in float v_radius_px;
|
|
359
|
+
flat in float v_outer_px;
|
|
360
|
+
uniform float u_opacity; // opacity factor at draw time (default 1)
|
|
361
|
+
uniform float u_shape; // shape (0 = circle, 1 = square, 2 = triangle, 3 = star)
|
|
362
|
+
out vec4 fragColor;
|
|
363
|
+
|
|
364
|
+
const float AA = ${AA_HALF_WIDTH_PX.toFixed(1)};
|
|
365
|
+
${POINT_SDF_GLSL}
|
|
366
|
+
void main() {
|
|
367
|
+
// Points of size 0 are not drawn (same as before, when the billboard collapsed)
|
|
368
|
+
if (v_outer_px <= 0.0) discard;
|
|
369
|
+
|
|
370
|
+
// The billboard is one to one with screen pixels, so the distance can be measured in pixels.
|
|
371
|
+
// d is the signed distance to the outer edge (negative inside)
|
|
372
|
+
float d = pointShapeSdf(v_offset_px, v_outer_px, u_shape);
|
|
373
|
+
|
|
374
|
+
// Coverage of the outer edge. Outside it, everything but the antialiasing band is discarded
|
|
375
|
+
float coverage = 1.0 - smoothstep(-AA, AA, d);
|
|
376
|
+
if (coverage <= 0.0) discard;
|
|
377
|
+
|
|
378
|
+
// The band of the stroke width inside the edge is the stroke; deeper is the fill. The inside
|
|
379
|
+
// takes the fill color only when there is a stroke (width 0 means all fill)
|
|
380
|
+
float band = v_outer_px - v_radius_px;
|
|
381
|
+
float fillMix = band > 0.0
|
|
382
|
+
? 1.0 - smoothstep(-band - AA, -band + AA, d)
|
|
383
|
+
: 1.0;
|
|
384
|
+
vec4 color = mix(v_stroke_color, v_fill_color, fillMix);
|
|
385
|
+
|
|
386
|
+
// Blending is non-premultiplied, so the factors are applied to the alpha only
|
|
387
|
+
fragColor = vec4(color.rgb, color.a * u_opacity * coverage);
|
|
388
|
+
}`;
|
|
389
|
+
return createProgram(this.gl, vertexSource, fragmentSource);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Creates a VAO (with the given instance buffer)
|
|
393
|
+
*
|
|
394
|
+
* The immediate mode passes the shared instance buffer, and the retained mode passes the
|
|
395
|
+
* instance buffer dedicated to the batch. The attribute layout is common to both.
|
|
396
|
+
*/
|
|
397
|
+
createVAOWith(instanceBuffer) {
|
|
398
|
+
const gl = this.gl;
|
|
399
|
+
const vao = gl.createVertexArray();
|
|
400
|
+
gl.bindVertexArray(vao);
|
|
401
|
+
// Vertex buffer of the billboard (location = 0)
|
|
402
|
+
const vertexBuffer = gl.createBuffer();
|
|
403
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
|
404
|
+
gl.bufferData(gl.ARRAY_BUFFER, this.quadVertices, gl.STATIC_DRAW);
|
|
405
|
+
gl.enableVertexAttribArray(0); // a_quad
|
|
406
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
|
|
407
|
+
// Instance buffer
|
|
408
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, instanceBuffer);
|
|
409
|
+
// Relative coordinates: location=1, offset 0, 2 floats
|
|
410
|
+
gl.enableVertexAttribArray(1);
|
|
411
|
+
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, INSTANCE_BYTES, 0);
|
|
412
|
+
gl.vertexAttribDivisor(1, 1);
|
|
413
|
+
// Fill color: location=2, offset 8, 4 floats
|
|
414
|
+
gl.enableVertexAttribArray(2);
|
|
415
|
+
gl.vertexAttribPointer(2, 4, gl.FLOAT, false, INSTANCE_BYTES, 8);
|
|
416
|
+
gl.vertexAttribDivisor(2, 1);
|
|
417
|
+
// Stroke color: location=3, offset 24, 4 floats
|
|
418
|
+
gl.enableVertexAttribArray(3);
|
|
419
|
+
gl.vertexAttribPointer(3, 4, gl.FLOAT, false, INSTANCE_BYTES, 24);
|
|
420
|
+
gl.vertexAttribDivisor(3, 1);
|
|
421
|
+
// Radius: location=4, offset 40, 1 float
|
|
422
|
+
gl.enableVertexAttribArray(4);
|
|
423
|
+
gl.vertexAttribPointer(4, 1, gl.FLOAT, false, INSTANCE_BYTES, 40);
|
|
424
|
+
gl.vertexAttribDivisor(4, 1);
|
|
425
|
+
// Stroke width: location=5, offset 44, 1 float
|
|
426
|
+
gl.enableVertexAttribArray(5);
|
|
427
|
+
gl.vertexAttribPointer(5, 1, gl.FLOAT, false, INSTANCE_BYTES, 44);
|
|
428
|
+
gl.vertexAttribDivisor(5, 1);
|
|
429
|
+
// Ground elevation of the anchor (meters): location=6, offset 48, 1 float
|
|
430
|
+
gl.enableVertexAttribArray(6);
|
|
431
|
+
gl.vertexAttribPointer(6, 1, gl.FLOAT, false, INSTANCE_BYTES, 48);
|
|
432
|
+
gl.vertexAttribDivisor(6, 1);
|
|
433
|
+
gl.bindVertexArray(null);
|
|
434
|
+
return { vao, shapeBuffer: vertexBuffer };
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Gets or creates the VAO of the immediate mode
|
|
438
|
+
*/
|
|
439
|
+
getVAO(program) {
|
|
440
|
+
let entry = this.quadVaos.get(program);
|
|
441
|
+
if (!entry) {
|
|
442
|
+
entry = this.createVAOWith(this.instanceBuffer);
|
|
443
|
+
this.quadVaos.set(program, entry);
|
|
444
|
+
}
|
|
445
|
+
return entry.vao;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Sets the ProjectionData
|
|
449
|
+
*/
|
|
450
|
+
setProjectionData(projectionData) {
|
|
451
|
+
this.projectionData = projectionData;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Sets the uniforms for the offset mode
|
|
455
|
+
*/
|
|
456
|
+
setOffsetUniforms(uniforms) {
|
|
457
|
+
this.offsetUniforms = uniforms;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Gets the per-program state (creating it if absent)
|
|
461
|
+
*
|
|
462
|
+
* Locations stay unchanged until the program is relinked, and the uniform values also remain
|
|
463
|
+
* until it is relinked. Therefore, when the program is disposed of, this cache (including the
|
|
464
|
+
* record) must always be discarded too.
|
|
465
|
+
*/
|
|
466
|
+
getProgramState(program) {
|
|
467
|
+
const cached = this.programStates.get(program);
|
|
468
|
+
if (cached)
|
|
469
|
+
return cached;
|
|
470
|
+
const gl = this.gl;
|
|
471
|
+
const locs = {
|
|
472
|
+
pixelToClip: gl.getUniformLocation(program, 'u_pixel_to_clip'),
|
|
473
|
+
sizeScale: gl.getUniformLocation(program, 'u_size_scale'),
|
|
474
|
+
opacity: gl.getUniformLocation(program, 'u_opacity'),
|
|
475
|
+
shape: gl.getUniformLocation(program, 'u_shape'),
|
|
476
|
+
};
|
|
477
|
+
const projection = new ProjectionUniformManager(gl, { terrain: this.terrain });
|
|
478
|
+
projection.getLocations(program);
|
|
479
|
+
const state = { locs, memo: createPointMemo(), projection };
|
|
480
|
+
this.programStates.set(program, state);
|
|
481
|
+
return state;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Writes the draw-time factors
|
|
485
|
+
*
|
|
486
|
+
* Uniforms are per-program state that persists, so the paths that do not use the factors (the
|
|
487
|
+
* immediate mode, and the Store's retained rendering) always reset them to 1. If the value
|
|
488
|
+
* already written is the same, it is not written again.
|
|
489
|
+
*/
|
|
490
|
+
setDrawFactors(program, factors) {
|
|
491
|
+
const { locs, memo } = this.getProgramState(program);
|
|
492
|
+
const frame = getRenderFrame();
|
|
493
|
+
const staleFrame = memo.factorsFrame !== frame;
|
|
494
|
+
if (locs.sizeScale && (staleFrame || memo.sizeScale !== factors.scale)) {
|
|
495
|
+
this.gl.uniform1f(locs.sizeScale, factors.scale);
|
|
496
|
+
memo.sizeScale = factors.scale;
|
|
497
|
+
}
|
|
498
|
+
if (locs.opacity && (staleFrame || memo.opacity !== factors.opacity)) {
|
|
499
|
+
this.gl.uniform1f(locs.opacity, factors.opacity);
|
|
500
|
+
memo.opacity = factors.opacity;
|
|
501
|
+
}
|
|
502
|
+
memo.factorsFrame = frame;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Writes the shape (switches the distance function in the fragment shader)
|
|
506
|
+
*/
|
|
507
|
+
setShape(program, shape) {
|
|
508
|
+
const { locs, memo } = this.getProgramState(program);
|
|
509
|
+
const frame = getRenderFrame();
|
|
510
|
+
const value = SHAPE_UNIFORM[shape] ?? 0;
|
|
511
|
+
if (locs.shape && (memo.shapeFrame !== frame || memo.shape !== value)) {
|
|
512
|
+
this.gl.uniform1f(locs.shape, value);
|
|
513
|
+
memo.shape = value;
|
|
514
|
+
}
|
|
515
|
+
memo.shapeFrame = frame;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Sets the projection uniforms (supporting the offset mode and the globe mode)
|
|
519
|
+
* @param program The shader program
|
|
520
|
+
* @param zoom The current zoom level (used to switch the offset mode)
|
|
521
|
+
*/
|
|
522
|
+
setProjectionUniforms(program, zoom) {
|
|
523
|
+
if (!this.projectionData)
|
|
524
|
+
return;
|
|
525
|
+
this.setProjectionUniformsWith(program, zoom, this.projectionData, this.offsetUniforms);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Sets the projection uniforms (with the ProjectionData and the offset given explicitly)
|
|
529
|
+
*
|
|
530
|
+
* A batch of the retained mode uses its own origin rather than the camera center, so the
|
|
531
|
+
* offset uniforms can be received as an argument.
|
|
532
|
+
*
|
|
533
|
+
* Uniforms whose value is the same as last time are not written again. The retained mode goes
|
|
534
|
+
* through here once per chunk, but the only thing that changes between chunks is
|
|
535
|
+
* u_origin_shift: the matrices, the canvas dimensions and the camera-related values are
|
|
536
|
+
* invariant within a frame (see frame.ts).
|
|
537
|
+
*
|
|
538
|
+
* @param originShift The gap between the origin of the vertex offsets and the linearization
|
|
539
|
+
* center (defaults to [0,0])
|
|
540
|
+
*/
|
|
541
|
+
setProjectionUniformsWith(program, zoom, projectionData, offsetUniforms, originShift = [0, 0]) {
|
|
542
|
+
const gl = this.gl;
|
|
543
|
+
const { locs, memo, projection } = this.getProgramState(program);
|
|
544
|
+
const frame = getRenderFrame();
|
|
545
|
+
// The projection uniforms (offset mode, globe, terrain) are delegated to the shared manager.
|
|
546
|
+
// Writing them here by hand would make this renderer alone miss uniforms added to the
|
|
547
|
+
// projection (which is exactly what happened with the terrain uniforms added later).
|
|
548
|
+
projection.setUniforms(projectionData, zoom, offsetUniforms, originShift);
|
|
549
|
+
// Only the factor that places the billboard in pixels is specific to this renderer, so it is
|
|
550
|
+
// written here by hand
|
|
551
|
+
if (locs.pixelToClip &&
|
|
552
|
+
(memo.pixelToClipFrame !== frame ||
|
|
553
|
+
memo.canvasWidth !== this.canvasWidth ||
|
|
554
|
+
memo.canvasHeight !== this.canvasHeight)) {
|
|
555
|
+
gl.uniform2f(locs.pixelToClip, 2 / this.canvasWidth, 2 / this.canvasHeight);
|
|
556
|
+
memo.canvasWidth = this.canvasWidth;
|
|
557
|
+
memo.canvasHeight = this.canvasHeight;
|
|
558
|
+
}
|
|
559
|
+
memo.pixelToClipFrame = frame;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Draws all points in batches by shape
|
|
563
|
+
*
|
|
564
|
+
* The fill and the stroke are completed in a single draw call, so they stack from back to
|
|
565
|
+
* front in instance order (= the order of the given array = feature order).
|
|
566
|
+
*
|
|
567
|
+
* @param points The array of point data
|
|
568
|
+
* @param shape The point shape
|
|
569
|
+
* @param zoom The current zoom level
|
|
570
|
+
* @param factors The draw-time factors (the opacity of the layer being drawn; scale 1 and
|
|
571
|
+
* opacity 1 when omitted)
|
|
572
|
+
*/
|
|
573
|
+
drawAll(points, shape, zoom, factors = NEUTRAL_DRAW_FACTORS) {
|
|
574
|
+
if (!this.program || !this.projectionData)
|
|
575
|
+
return;
|
|
576
|
+
if (points.length === 0)
|
|
577
|
+
return;
|
|
578
|
+
const gl = this.gl;
|
|
579
|
+
// Get the center coordinates already rounded to Float32 (for the CPU-side offset computation)
|
|
580
|
+
// In the offset mode, the CPU side and the shader side must use the same center coordinates.
|
|
581
|
+
// Since projectionCenter is computed from these center coordinates with 64-bit precision,
|
|
582
|
+
// using the same Float32-rounded center coordinates on the CPU side keeps them consistent.
|
|
583
|
+
const centerLngLat = this.offsetUniforms?.centerLngLat ?? [0, 0];
|
|
584
|
+
// Prepare the instance data (the relative coordinates are computed on the CPU side)
|
|
585
|
+
const instanceData = buildPointInstanceData(points, centerLngLat, this.pixelRatio, this.terrain);
|
|
586
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.instanceBuffer);
|
|
587
|
+
gl.bufferData(gl.ARRAY_BUFFER, instanceData, gl.DYNAMIC_DRAW);
|
|
588
|
+
gl.useProgram(this.program);
|
|
589
|
+
this.setProjectionUniforms(this.program, zoom);
|
|
590
|
+
// Always written (1 when the caller has none) so that no factor of an earlier draw is left
|
|
591
|
+
this.setDrawFactors(this.program, factors);
|
|
592
|
+
this.setShape(this.program, shape);
|
|
593
|
+
gl.bindVertexArray(this.getVAO(this.program));
|
|
594
|
+
drawBillboardsWithoutDepth(gl, () => {
|
|
595
|
+
gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, QUAD_VERTEX_COUNT, points.length);
|
|
596
|
+
});
|
|
597
|
+
gl.bindVertexArray(null);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Builds a point batch of the retained mode
|
|
601
|
+
*
|
|
602
|
+
* It creates the instance array and the VAO so that in later frames the points can be drawn
|
|
603
|
+
* with only the bind, the uniforms and the draw call of `drawRetained`. The position, color
|
|
604
|
+
* and size of the points do not depend on the camera (the projection is done by the uniforms
|
|
605
|
+
* of each frame).
|
|
606
|
+
*
|
|
607
|
+
* @returns The built batch, or null when the shader is not initialized or there are no points
|
|
608
|
+
*/
|
|
609
|
+
buildRetained(points, shape, options = {}) {
|
|
610
|
+
if (!this.program)
|
|
611
|
+
return null;
|
|
612
|
+
if (points.length === 0)
|
|
613
|
+
return null;
|
|
614
|
+
const gl = this.gl;
|
|
615
|
+
// The origin of the relative coordinates is fixed per batch (it must not depend on the
|
|
616
|
+
// camera center)
|
|
617
|
+
const origin = normalizeOrigin(options.origin ?? defaultPointOrigin(points));
|
|
618
|
+
const instanceBuffer = gl.createBuffer();
|
|
619
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, instanceBuffer);
|
|
620
|
+
gl.bufferData(gl.ARRAY_BUFFER, buildPointInstanceData(points, origin, this.pixelRatio, this.terrain), gl.STATIC_DRAW);
|
|
621
|
+
const { vao, shapeBuffer } = this.createVAOWith(instanceBuffer);
|
|
622
|
+
return {
|
|
623
|
+
shape,
|
|
624
|
+
vao,
|
|
625
|
+
shapeBuffer,
|
|
626
|
+
instanceBuffer,
|
|
627
|
+
instanceCount: points.length,
|
|
628
|
+
origin,
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Builds a point batch of the retained mode from packed points
|
|
633
|
+
*
|
|
634
|
+
* The same batch as `buildRetained` builds for the same points, without an object per point.
|
|
635
|
+
*
|
|
636
|
+
* @returns The built batch, or null when the shader is not initialized or there are no points
|
|
637
|
+
*
|
|
638
|
+
* @internal
|
|
639
|
+
*/
|
|
640
|
+
buildRetainedPacked(points, shape, options = {}) {
|
|
641
|
+
if (!this.program)
|
|
642
|
+
return null;
|
|
643
|
+
if (points.count === 0)
|
|
644
|
+
return null;
|
|
645
|
+
const gl = this.gl;
|
|
646
|
+
const origin = normalizeOrigin(options.origin ?? [points.lngLat[0], points.lngLat[1]]);
|
|
647
|
+
const instanceBuffer = gl.createBuffer();
|
|
648
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, instanceBuffer);
|
|
649
|
+
gl.bufferData(gl.ARRAY_BUFFER, buildPackedPointInstanceData(points, origin, this.pixelRatio, this.terrain), gl.STATIC_DRAW);
|
|
650
|
+
const { vao, shapeBuffer } = this.createVAOWith(instanceBuffer);
|
|
651
|
+
return {
|
|
652
|
+
shape,
|
|
653
|
+
vao,
|
|
654
|
+
shapeBuffer,
|
|
655
|
+
instanceBuffer,
|
|
656
|
+
instanceCount: points.count,
|
|
657
|
+
origin,
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Draws a point batch of the retained mode
|
|
662
|
+
*
|
|
663
|
+
* No bufferData is performed. The projection uniforms are recomputed every frame from the
|
|
664
|
+
* origin of the batch (the instance array is not rebuilt).
|
|
665
|
+
*
|
|
666
|
+
* @param factors The draw-time factors (when omitted, scale 1 and opacity 1, as before)
|
|
667
|
+
*/
|
|
668
|
+
drawRetained(batch, zoom, projectionData, factors = NEUTRAL_DRAW_FACTORS) {
|
|
669
|
+
if (!this.program)
|
|
670
|
+
return;
|
|
671
|
+
if (batch.instanceCount === 0)
|
|
672
|
+
return;
|
|
673
|
+
const gl = this.gl;
|
|
674
|
+
// The linearization center is aligned with the camera center (linearizing around the origin
|
|
675
|
+
// of the batch turns the residual of the Mercator approximation into a displacement of
|
|
676
|
+
// pixel order at vertices far from the center).
|
|
677
|
+
// The instances are relative to the origin, so that difference is passed as u_origin_shift
|
|
678
|
+
const cameraUniforms = this.offsetUniforms;
|
|
679
|
+
const offsetUniforms = cameraUniforms ??
|
|
680
|
+
// Fallback (normally custom-layer has already called setOffsetUniforms every frame)
|
|
681
|
+
calculateOffsetUniforms(batch.origin, projectionData.mainMatrix);
|
|
682
|
+
const originShift = cameraUniforms
|
|
683
|
+
? [
|
|
684
|
+
batch.origin[0] - cameraUniforms.centerLngLat[0],
|
|
685
|
+
batch.origin[1] - cameraUniforms.centerLngLat[1],
|
|
686
|
+
]
|
|
687
|
+
: [0, 0];
|
|
688
|
+
gl.useProgram(this.program);
|
|
689
|
+
this.setProjectionUniformsWith(this.program, zoom, projectionData, offsetUniforms, originShift);
|
|
690
|
+
this.setDrawFactors(this.program, factors);
|
|
691
|
+
this.setShape(this.program, batch.shape);
|
|
692
|
+
gl.bindVertexArray(batch.vao);
|
|
693
|
+
drawBillboardsWithoutDepth(gl, () => {
|
|
694
|
+
gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, QUAD_VERTEX_COUNT, batch.instanceCount);
|
|
695
|
+
});
|
|
696
|
+
gl.bindVertexArray(null);
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Disposes of a point batch of the retained mode
|
|
700
|
+
*/
|
|
701
|
+
disposeRetained(batch) {
|
|
702
|
+
const gl = this.gl;
|
|
703
|
+
gl.deleteVertexArray(batch.vao);
|
|
704
|
+
gl.deleteBuffer(batch.shapeBuffer);
|
|
705
|
+
gl.deleteBuffer(batch.instanceBuffer);
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Disposes of the program
|
|
709
|
+
*/
|
|
710
|
+
disposePrograms() {
|
|
711
|
+
const gl = this.gl;
|
|
712
|
+
if (this.program) {
|
|
713
|
+
gl.deleteProgram(this.program);
|
|
714
|
+
this.program = null;
|
|
715
|
+
}
|
|
716
|
+
// The uniform locations and the record of the values written last are tied to the program,
|
|
717
|
+
// so they are discarded along with it (a recreated program also resets its uniforms to their
|
|
718
|
+
// initial values)
|
|
719
|
+
this.programStates.clear();
|
|
720
|
+
// Clear the VAOs and the vertex buffers of the billboard
|
|
721
|
+
for (const entry of this.quadVaos.values()) {
|
|
722
|
+
gl.deleteVertexArray(entry.vao);
|
|
723
|
+
gl.deleteBuffer(entry.shapeBuffer);
|
|
724
|
+
}
|
|
725
|
+
this.quadVaos.clear();
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Disposes of the resources
|
|
729
|
+
*/
|
|
730
|
+
dispose() {
|
|
731
|
+
const gl = this.gl;
|
|
732
|
+
this.disposePrograms();
|
|
733
|
+
if (this.instanceBuffer) {
|
|
734
|
+
gl.deleteBuffer(this.instanceBuffer);
|
|
735
|
+
this.instanceBuffer = null;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|