@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,158 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
import { generateCirclePolygon } from '../../shared/math/index.js';
|
|
4
|
+
import { getCircleRadius } from '../../shared/utils/property.js';
|
|
5
|
+
import { getDisplayFeatures } from '../../store/local-visibility.js';
|
|
6
|
+
import { isFeatureLocked } from '../../store/lock.js';
|
|
7
|
+
/**
|
|
8
|
+
* Whether the feature can be a target of a boolean operation.
|
|
9
|
+
*
|
|
10
|
+
* The area types (Polygon / MultiPolygon / Circle) only. A Circle without a radius has no
|
|
11
|
+
* area, so it is excluded from the targets.
|
|
12
|
+
*/
|
|
13
|
+
export function isAreaFeature(feature) {
|
|
14
|
+
if (feature.type === 'Circle') {
|
|
15
|
+
const radiusMeters = getCircleRadius(feature);
|
|
16
|
+
return radiusMeters !== undefined && radiusMeters > 0;
|
|
17
|
+
}
|
|
18
|
+
return feature.type === 'Polygon' || feature.type === 'MultiPolygon';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Converts a feature into the area coordinates of the geometry module.
|
|
22
|
+
*
|
|
23
|
+
* A Circle is reduced to a ring with the default number of segments (64) of
|
|
24
|
+
* generateCirclePolygon, the same as in the rendering (view/renderers/drawer.ts). An input
|
|
25
|
+
* that has no area returns null.
|
|
26
|
+
*/
|
|
27
|
+
export function toAreaCoordinates(feature) {
|
|
28
|
+
if (feature.type === 'Circle') {
|
|
29
|
+
const radiusMeters = getCircleRadius(feature);
|
|
30
|
+
if (radiusMeters === undefined || radiusMeters <= 0)
|
|
31
|
+
return null;
|
|
32
|
+
return [generateCirclePolygon(feature.coordinates, radiusMeters)];
|
|
33
|
+
}
|
|
34
|
+
if (feature.type === 'Polygon' || feature.type === 'MultiPolygon') {
|
|
35
|
+
return feature.coordinates;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The feature types that can be the cutting side of a split.
|
|
41
|
+
*
|
|
42
|
+
* Only the types whose coordinates can be read as a polyline are accepted. The area types
|
|
43
|
+
* cannot be a "cutting line" (cutting with a polygon is the job of punching out = subtract).
|
|
44
|
+
*/
|
|
45
|
+
const SPLIT_LINE_TYPES = new Set([
|
|
46
|
+
'LineString',
|
|
47
|
+
'MultiLineString',
|
|
48
|
+
'Freehand',
|
|
49
|
+
]);
|
|
50
|
+
/**
|
|
51
|
+
* Whether the feature can be the cutting side of a split.
|
|
52
|
+
*/
|
|
53
|
+
export function isSplitLineFeature(feature) {
|
|
54
|
+
return SPLIT_LINE_TYPES.has(feature.type);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reduces a line feature to an array of polylines.
|
|
58
|
+
*
|
|
59
|
+
* A MultiLineString becomes one polyline per part. A type that cannot be the cutting side
|
|
60
|
+
* returns an empty array.
|
|
61
|
+
*/
|
|
62
|
+
export function toSplitPaths(feature) {
|
|
63
|
+
if (feature.type === 'MultiLineString')
|
|
64
|
+
return feature.coordinates;
|
|
65
|
+
if (isSplitLineFeature(feature))
|
|
66
|
+
return [feature.coordinates];
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The feature types that are targets of the buffer.
|
|
71
|
+
*
|
|
72
|
+
* The types that can be reduced to the GeometryInput of the geometry module, plus Circle,
|
|
73
|
+
* which is handled as a special case. The other types such as Freehand / Image / Text are
|
|
74
|
+
* excluded from the targets because the meaning of their coordinates does not match a
|
|
75
|
+
* geometry (an image is a rectangle, a text is an anchor point).
|
|
76
|
+
*/
|
|
77
|
+
const BUFFERABLE_TYPES = new Set([
|
|
78
|
+
'Point',
|
|
79
|
+
'MultiPoint',
|
|
80
|
+
'LineString',
|
|
81
|
+
'MultiLineString',
|
|
82
|
+
'Polygon',
|
|
83
|
+
'MultiPolygon',
|
|
84
|
+
'Circle',
|
|
85
|
+
]);
|
|
86
|
+
/**
|
|
87
|
+
* Whether the feature can be a target of the buffer.
|
|
88
|
+
*
|
|
89
|
+
* Only a Circle that has a radius is a target (a Circle without a radius has no starting
|
|
90
|
+
* point to grow or shrink from).
|
|
91
|
+
*/
|
|
92
|
+
export function isBufferableFeature(feature) {
|
|
93
|
+
if (feature.type === 'Circle') {
|
|
94
|
+
const radiusMeters = getCircleRadius(feature);
|
|
95
|
+
return radiusMeters !== undefined && radiusMeters > 0;
|
|
96
|
+
}
|
|
97
|
+
return BUFFERABLE_TYPES.has(feature.type);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Converts a feature into the GeometryInput of the geometry module.
|
|
101
|
+
*
|
|
102
|
+
* The shape of the coordinates matches the shape of the core Feature coordinates and is
|
|
103
|
+
* GeoJSON compatible, so it can be passed by only re-typing it. A Circle is handled as a
|
|
104
|
+
* special case (growing or shrinking the radius), so it is not converted here.
|
|
105
|
+
*/
|
|
106
|
+
export function toBufferGeometry(feature) {
|
|
107
|
+
switch (feature.type) {
|
|
108
|
+
case 'Point':
|
|
109
|
+
case 'MultiPoint':
|
|
110
|
+
case 'LineString':
|
|
111
|
+
case 'MultiLineString':
|
|
112
|
+
case 'Polygon':
|
|
113
|
+
case 'MultiPolygon':
|
|
114
|
+
return { type: feature.type, coordinates: feature.coordinates };
|
|
115
|
+
default:
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Builds the type and coordinates of the feature to create from the MultiPolygon coordinates
|
|
121
|
+
* returned by the geometry module.
|
|
122
|
+
*
|
|
123
|
+
* Polygon when there is one part, MultiPolygon when there are several. An empty array (no
|
|
124
|
+
* area) returns null.
|
|
125
|
+
*/
|
|
126
|
+
export function toResultGeometry(parts) {
|
|
127
|
+
if (parts.length === 0)
|
|
128
|
+
return null;
|
|
129
|
+
if (parts.length === 1)
|
|
130
|
+
return { type: 'Polygon', coordinates: parts[0] };
|
|
131
|
+
return { type: 'MultiPolygon', coordinates: parts };
|
|
132
|
+
}
|
|
133
|
+
/** The IDs of the current feature selection (empty on a group or layer selection). */
|
|
134
|
+
export function currentSelectionIds(store) {
|
|
135
|
+
const selection = store.getSelection();
|
|
136
|
+
return selection.type === 'feature' ? selection.ids : [];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Resolves the targets of an operation in z order (the head is the backmost, the tail is the
|
|
140
|
+
* frontmost).
|
|
141
|
+
*
|
|
142
|
+
* The order follows getDisplayFeatures (= getOrderedFeatures with the locally hidden features
|
|
143
|
+
* removed). That is "the order between the layers -> the order within a layer -> the
|
|
144
|
+
* featureIds within a group", which is the draw order of core itself. Hidden features (both
|
|
145
|
+
* the shared visible and the local hidden) do not appear in this list, so they are
|
|
146
|
+
* automatically excluded from the targets here.
|
|
147
|
+
* Locked features (the effective lock) are excluded explicitly.
|
|
148
|
+
*
|
|
149
|
+
* @param ids The target IDs. When undefined, the current selection
|
|
150
|
+
* @param accept The acceptance test, on the type and so on
|
|
151
|
+
*/
|
|
152
|
+
export function resolveTargetFeatures(store, ids, accept) {
|
|
153
|
+
const wanted = ids ?? currentSelectionIds(store);
|
|
154
|
+
if (wanted.length === 0)
|
|
155
|
+
return [];
|
|
156
|
+
const wantedIds = new Set(wanted);
|
|
157
|
+
return getDisplayFeatures(store).filter((feature) => wantedIds.has(feature.id) && accept(feature) && !isFeatureLocked(feature, store));
|
|
158
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The option and dependency types of the draw.geometry namespace
|
|
3
|
+
*/
|
|
4
|
+
import type { EventEmitter } from '../../shared/utils/event-emitter.js';
|
|
5
|
+
import type { Store } from '../../store/store.js';
|
|
6
|
+
/**
|
|
7
|
+
* The options of `draw.geometry.buffer` (see {@link GeometryOperations.buffer})
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* draw.geometry.buffer({ distanceMeters: 250, segments: 32 });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export interface GeometryBufferOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The buffer distance (in meters). A negative value shrinks (area types only); 0 or a value
|
|
17
|
+
* that is not finite does nothing
|
|
18
|
+
*/
|
|
19
|
+
distanceMeters: number;
|
|
20
|
+
/**
|
|
21
|
+
* The number of segments of a full circle for the rounded parts (64 by default). It is
|
|
22
|
+
* rounded down and clamped to 3-1024
|
|
23
|
+
*/
|
|
24
|
+
segments?: number;
|
|
25
|
+
}
|
|
26
|
+
/** The dependencies of the geometry operations (a bare Store is enough for tests) */
|
|
27
|
+
export interface GeometryApiDeps {
|
|
28
|
+
store: Store;
|
|
29
|
+
eventEmitter: EventEmitter;
|
|
30
|
+
generateFeatureId: () => string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { MapLibreGLDraw } from './api.js';
|
|
2
|
+
import type { GeometryApiDeps, GeometryBufferOptions } from './geometry/types.js';
|
|
3
|
+
export type { GeometryApiDeps, GeometryBufferOptions } from './geometry/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The geometry operations of a draw instance, reached as `draw.geometry`.
|
|
6
|
+
*
|
|
7
|
+
* When the arguments are omitted, the current feature selection is the target (a group or
|
|
8
|
+
* layer selection gives no target). Locked features (either the feature itself, the group it
|
|
9
|
+
* belongs to, or the layer it belongs to) and hidden features (by the shared visible flag or
|
|
10
|
+
* by local hiding) are excluded from the targets, and nothing happens while read-only.
|
|
11
|
+
*
|
|
12
|
+
* Each operation is one transaction, so one undo reverts it, and the result features become
|
|
13
|
+
* selected. When it ran, `draw.geometry.applied` reports the inputs and the results, with
|
|
14
|
+
* `status: 'empty'` when the result had no area and nothing changed. The computation is done
|
|
15
|
+
* by the pure functions of `@sakuzu/maplibre-gl-draw/geometry`.
|
|
16
|
+
*
|
|
17
|
+
* The boolean editing operations (union / subtract / intersect) take the area types
|
|
18
|
+
* (Polygon / MultiPolygon / Circle) and need at least two targets. They replace the inputs
|
|
19
|
+
* with one feature, a Polygon or else a MultiPolygon (a Circle becomes a 64-segment polygon
|
|
20
|
+
* first), which takes the style, the properties and the place of the frontmost input. The
|
|
21
|
+
* buffer and the split instead return an array of IDs, since they can create several
|
|
22
|
+
* features.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* draw.on('draw.geometry.applied', ({ operation, status, resultIds }) => {
|
|
27
|
+
* if (status === 'empty') console.log(operation, 'left nothing');
|
|
28
|
+
* });
|
|
29
|
+
* const merged = draw.geometry.union(); // the selected areas
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface GeometryOperations {
|
|
33
|
+
/**
|
|
34
|
+
* Merges the targets into a single feature.
|
|
35
|
+
*
|
|
36
|
+
* Areas that do not touch give a MultiPolygon.
|
|
37
|
+
*
|
|
38
|
+
* @param ids The IDs of the target features. When omitted, the current selection
|
|
39
|
+
* @returns The ID of the result feature. null when there are fewer than 2 targets
|
|
40
|
+
* @throws {@link geometry!GeometryError} when the computation fails on the input (a degenerate or
|
|
41
|
+
* malformed ring, for example); nothing changes
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const id = draw.geometry.union([parcelA, parcelB]);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
union(ids?: string[]): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* Punches out: subtracts the other targets from the target.
|
|
51
|
+
*
|
|
52
|
+
* When `targetId` is given it is a target even when `ids` does not list it. The result
|
|
53
|
+
* still takes the style and the properties of the frontmost input, not of the target.
|
|
54
|
+
*
|
|
55
|
+
* @param targetId The ID of the feature that is subtracted from. When omitted, the
|
|
56
|
+
* backmost of the targets
|
|
57
|
+
* @param ids The IDs of the target features. When omitted, the current selection
|
|
58
|
+
* @returns The ID of the result feature. null when there are fewer than 2 targets or the
|
|
59
|
+
* result is empty
|
|
60
|
+
* @throws {@link geometry!GeometryError} when the computation fails on the input; nothing changes
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // Subtract the selected features in front from the backmost one
|
|
65
|
+
* draw.geometry.subtract();
|
|
66
|
+
* // Name the feature to subtract from
|
|
67
|
+
* draw.geometry.subtract(parcelId, [parcelId, roadId]);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
subtract(targetId?: string, ids?: string[]): string | null;
|
|
71
|
+
/**
|
|
72
|
+
* Keeps the part that is common to all the targets.
|
|
73
|
+
*
|
|
74
|
+
* @param ids The IDs of the target features. When omitted, the current selection
|
|
75
|
+
* @returns The ID of the result feature. null when there are fewer than 2 targets or they
|
|
76
|
+
* do not overlap
|
|
77
|
+
* @throws {@link geometry!GeometryError} when the computation fails on the input; nothing changes
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const id = draw.geometry.intersect();
|
|
82
|
+
* if (id === null) {
|
|
83
|
+
* // no overlap, or fewer than two targets
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
intersect(ids?: string[]): string | null;
|
|
88
|
+
/**
|
|
89
|
+
* Creates the area within the given distance of the targets as new features.
|
|
90
|
+
*
|
|
91
|
+
* The inputs remain, and one result is created per input, just in front of it, with its
|
|
92
|
+
* style and properties. The targets are all geometries
|
|
93
|
+
* (Point / MultiPoint / LineString / MultiLineString / Polygon / MultiPolygon / Circle),
|
|
94
|
+
* and every other type is excluded from the targets. It works from a single target.
|
|
95
|
+
* A negative value (shrinking) applies to the area types only; an input that is a point or
|
|
96
|
+
* a line given a negative value produces no result, and parts of an area narrower than twice
|
|
97
|
+
* the distance disappear. A Circle stays a Circle whose radius grows or shrinks. The
|
|
98
|
+
* distance is laid out along great circles, so it holds at any latitude. A distance of 0 or
|
|
99
|
+
* one that is not finite does nothing.
|
|
100
|
+
*
|
|
101
|
+
* @param options The distance (in meters) and the number of segments
|
|
102
|
+
* @returns The IDs of the result features that were created (in z order). An empty array
|
|
103
|
+
* when nothing was created
|
|
104
|
+
* @throws {@link geometry!GeometryError} when the computation fails on the input; nothing changes
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // The area within 100 m of the selected features
|
|
109
|
+
* const ids = draw.geometry.buffer({ distanceMeters: 100 });
|
|
110
|
+
* // Shrink two areas by 50 m
|
|
111
|
+
* draw.geometry.buffer([parcelA, parcelB], { distanceMeters: -50 });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
buffer(options: GeometryBufferOptions): string[];
|
|
115
|
+
/**
|
|
116
|
+
* Creates the area within the given distance of the named features as new features (see
|
|
117
|
+
* the other overload for the details).
|
|
118
|
+
*
|
|
119
|
+
* @param ids The IDs of the target features. When undefined, the current selection
|
|
120
|
+
* @param options The distance (in meters) and the number of segments
|
|
121
|
+
* @returns The IDs of the result features that were created (in z order). An empty array
|
|
122
|
+
* when nothing was created
|
|
123
|
+
*/
|
|
124
|
+
buffer(ids: string[] | undefined, options: GeometryBufferOptions): string[];
|
|
125
|
+
/**
|
|
126
|
+
* Cuts a polygon with a line and replaces it with the several features that result from the
|
|
127
|
+
* split.
|
|
128
|
+
*
|
|
129
|
+
* The targets are one polygon (Polygon / MultiPolygon / Circle) and one line (LineString /
|
|
130
|
+
* MultiLineString / Freehand). The side that is omitted is picked from the current
|
|
131
|
+
* selection by type; when it does not come down to exactly one of each, nothing happens and
|
|
132
|
+
* no event is emitted. The cutting line is not deleted and remains, and the results inherit
|
|
133
|
+
* the place, the style and the properties of the original polygon.
|
|
134
|
+
*
|
|
135
|
+
* When the line does not pass through the polygon (it does not intersect, it stops inside
|
|
136
|
+
* the polygon, or it only touches), nothing is changed. When the line crosses several times
|
|
137
|
+
* the polygon is split into three or more, and when only a part of a MultiPolygon is cut the
|
|
138
|
+
* parts that were not cut also become a single feature. A hole stays on the side that holds
|
|
139
|
+
* it.
|
|
140
|
+
*
|
|
141
|
+
* @param targetId The ID of the polygon feature to be cut. When omitted, the selected polygon
|
|
142
|
+
* @param lineId The ID of the line feature that cuts. When omitted, the selected line
|
|
143
|
+
* @returns The IDs of the result features that were created (in z order). An empty array
|
|
144
|
+
* when nothing was split
|
|
145
|
+
* @throws {@link geometry!GeometryError} when the computation fails on the input; nothing changes
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // With one area and one line selected
|
|
150
|
+
* const ids = draw.geometry.split();
|
|
151
|
+
* // Or by name
|
|
152
|
+
* draw.geometry.split(parcelId, cutLineId);
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
split(targetId?: string, lineId?: string): string[];
|
|
156
|
+
}
|
|
157
|
+
/** The `geometry` namespace on its own (what `createGeometryApi` returns) */
|
|
158
|
+
export type GeometryApi = Pick<MapLibreGLDraw, 'geometry'>;
|
|
159
|
+
/**
|
|
160
|
+
* Creates the draw.geometry namespace.
|
|
161
|
+
*/
|
|
162
|
+
export declare function createGeometryApi(deps: GeometryApiDeps): GeometryApi;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* Geometry API (the draw.geometry namespace)
|
|
5
|
+
*
|
|
6
|
+
* Provides the boolean editing operations (union / subtract / intersect), the buffer (buffer)
|
|
7
|
+
* and the split (split) on the selected features. The computation itself lives in the pure
|
|
8
|
+
* functions of the geometry module (src/geometry); this file and api/geometry/ are the
|
|
9
|
+
* integration layer that connects the selection, the transactions, the spatial index and the
|
|
10
|
+
* events.
|
|
11
|
+
*
|
|
12
|
+
* This file holds the namespace and its entry checks. The steps live in api/geometry/.
|
|
13
|
+
*
|
|
14
|
+
* targets.ts which features each operation accepts, feature <-> geometry module input and
|
|
15
|
+
* result, and resolveTargetFeatures (selection / z order / lock / hidden)
|
|
16
|
+
* apply.ts the common part: applyResult places one result, commitResult wraps it in one
|
|
17
|
+
* transaction and moves the selection, emitApplied emits draw.geometry.applied
|
|
18
|
+
* boolean.ts union / subtract / intersect on the area types
|
|
19
|
+
* buffer.ts the buffer (keeps the inputs, one result per input)
|
|
20
|
+
* split.ts the split of a polygon by a line
|
|
21
|
+
* types.ts the option and dependency types
|
|
22
|
+
*/
|
|
23
|
+
import { differenceAll, intersectionAll, unionAll } from '../geometry/index.js';
|
|
24
|
+
import { resolveSubtractInputs, runAreaOperation } from './geometry/boolean.js';
|
|
25
|
+
import { runBuffer } from './geometry/buffer.js';
|
|
26
|
+
import { runSplit } from './geometry/split.js';
|
|
27
|
+
import { isAreaFeature, isBufferableFeature, isSplitLineFeature, resolveTargetFeatures, } from './geometry/targets.js';
|
|
28
|
+
/**
|
|
29
|
+
* Creates the draw.geometry namespace.
|
|
30
|
+
*/
|
|
31
|
+
export function createGeometryApi(deps) {
|
|
32
|
+
const { store } = deps;
|
|
33
|
+
// While readOnly, writes to the Store become a no-op, so an operation would report results
|
|
34
|
+
// that were never created. It is rejected at the entry point.
|
|
35
|
+
const blocked = () => store.isReadOnly();
|
|
36
|
+
return {
|
|
37
|
+
geometry: {
|
|
38
|
+
union(ids) {
|
|
39
|
+
if (blocked())
|
|
40
|
+
return null;
|
|
41
|
+
const inputs = resolveTargetFeatures(store, ids, isAreaFeature);
|
|
42
|
+
if (inputs.length < 2)
|
|
43
|
+
return null;
|
|
44
|
+
return runAreaOperation(deps, 'union', inputs, (areas) => unionAll(areas));
|
|
45
|
+
},
|
|
46
|
+
subtract(targetId, ids) {
|
|
47
|
+
if (blocked())
|
|
48
|
+
return null;
|
|
49
|
+
const resolved = resolveSubtractInputs(store, targetId, ids);
|
|
50
|
+
if (resolved === null)
|
|
51
|
+
return null;
|
|
52
|
+
const { inputs, targetIndex } = resolved;
|
|
53
|
+
return runAreaOperation(deps, 'subtract', inputs, (areas) => differenceAll(areas[targetIndex], areas.filter((_, index) => index !== targetIndex)));
|
|
54
|
+
},
|
|
55
|
+
intersect(ids) {
|
|
56
|
+
if (blocked())
|
|
57
|
+
return null;
|
|
58
|
+
const inputs = resolveTargetFeatures(store, ids, isAreaFeature);
|
|
59
|
+
if (inputs.length < 2)
|
|
60
|
+
return null;
|
|
61
|
+
return runAreaOperation(deps, 'intersect', inputs, (areas) => intersectionAll(areas));
|
|
62
|
+
},
|
|
63
|
+
buffer(idsOrOptions, maybeOptions) {
|
|
64
|
+
// It accepts the two forms buffer(options) and buffer(ids, options).
|
|
65
|
+
const ids = Array.isArray(idsOrOptions) ? idsOrOptions : undefined;
|
|
66
|
+
const options = Array.isArray(idsOrOptions) ? maybeOptions : idsOrOptions;
|
|
67
|
+
if (blocked() || options === undefined)
|
|
68
|
+
return [];
|
|
69
|
+
// A distance of 0 is "a copy of the original shape", a non-finite value is meaningless.
|
|
70
|
+
// The operation itself is not performed.
|
|
71
|
+
const { distanceMeters } = options;
|
|
72
|
+
if (!Number.isFinite(distanceMeters) || distanceMeters === 0)
|
|
73
|
+
return [];
|
|
74
|
+
const inputs = resolveTargetFeatures(store, ids, isBufferableFeature);
|
|
75
|
+
// Unlike the boolean operations, it works from a single target.
|
|
76
|
+
if (inputs.length === 0)
|
|
77
|
+
return [];
|
|
78
|
+
return runBuffer(deps, inputs, options);
|
|
79
|
+
},
|
|
80
|
+
split(targetId, lineId) {
|
|
81
|
+
if (blocked())
|
|
82
|
+
return [];
|
|
83
|
+
// The polygon and the line are resolved separately. When omitted, both are picked from
|
|
84
|
+
// the current selection by type.
|
|
85
|
+
const areas = resolveTargetFeatures(store, targetId === undefined ? undefined : [targetId], isAreaFeature);
|
|
86
|
+
const lines = resolveTargetFeatures(store, lineId === undefined ? undefined : [lineId], isSplitLineFeature);
|
|
87
|
+
// When it does not come down to exactly one polygon and one line, nothing is done.
|
|
88
|
+
if (areas.length !== 1 || lines.length !== 1)
|
|
89
|
+
return [];
|
|
90
|
+
return runSplit(deps, areas[0], lines[0]);
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AutoNameGenerator } from '../shared/utils/name-generator.js';
|
|
2
|
+
import type { Store } from '../store/store.js';
|
|
3
|
+
import type { MapLibreGLDraw } from './api.js';
|
|
4
|
+
export type GroupApi = Pick<MapLibreGLDraw, 'getAllGroups' | 'getGroup' | 'addGroup' | 'updateGroup' | 'deleteGroup' | 'reorderInGroup' | 'addFeatureToGroup' | 'removeFeatureFromGroup' | 'groupSelection' | 'ungroupSelection' | 'ungroupGroup'>;
|
|
5
|
+
export interface GroupApiDeps {
|
|
6
|
+
store: Store;
|
|
7
|
+
generateFeatureId: () => string;
|
|
8
|
+
autoNameGenerator: AutoNameGenerator;
|
|
9
|
+
}
|
|
10
|
+
export declare function createGroupApi(deps: GroupApiDeps): GroupApi;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* Group API
|
|
5
|
+
*
|
|
6
|
+
* Provides the Group CRUD and grouping operations of MapLibreGLDraw.
|
|
7
|
+
*/
|
|
8
|
+
import { addFeatureToGroup as addFeatureToGroupImpl, groupSelection as groupSelectionImpl, removeFeatureFromGroup as removeFeatureFromGroupImpl, ungroupGroup as ungroupGroupImpl, ungroupSelection as ungroupSelectionImpl, } from '../operations/layer-operations.js';
|
|
9
|
+
import { isGroupLocked } from '../store/lock.js';
|
|
10
|
+
import { onlyLockOrVisibility } from './feature-api.js';
|
|
11
|
+
export function createGroupApi(deps) {
|
|
12
|
+
const { store, generateFeatureId, autoNameGenerator } = deps;
|
|
13
|
+
return {
|
|
14
|
+
getAllGroups() {
|
|
15
|
+
return store.getAllGroups();
|
|
16
|
+
},
|
|
17
|
+
getGroup(id) {
|
|
18
|
+
return store.getGroup(id);
|
|
19
|
+
},
|
|
20
|
+
addGroup(featureIds, layerId, name) {
|
|
21
|
+
// While read-only every write below would be refused: report it as null up front
|
|
22
|
+
if (store.isReadOnly())
|
|
23
|
+
return null;
|
|
24
|
+
const id = generateFeatureId();
|
|
25
|
+
const groupName = name || autoNameGenerator.generateGroupName();
|
|
26
|
+
const group = {
|
|
27
|
+
id,
|
|
28
|
+
name: groupName,
|
|
29
|
+
featureIds: [...featureIds],
|
|
30
|
+
locked: false,
|
|
31
|
+
visible: true,
|
|
32
|
+
};
|
|
33
|
+
// Remove the features from the order of the layer
|
|
34
|
+
const layer = store.getLayer(layerId);
|
|
35
|
+
if (layer) {
|
|
36
|
+
const newOrder = layer.order.filter((itemId) => !featureIds.includes(itemId));
|
|
37
|
+
// Add the group to the order
|
|
38
|
+
newOrder.push(id);
|
|
39
|
+
store.updateLayer(layerId, { order: newOrder });
|
|
40
|
+
}
|
|
41
|
+
// Create the group (this sets groupId on the features)
|
|
42
|
+
return store.createGroup(group) ? id : null;
|
|
43
|
+
},
|
|
44
|
+
updateGroup(id, updates) {
|
|
45
|
+
const group = store.getGroup(id);
|
|
46
|
+
if (group && !onlyLockOrVisibility(updates)) {
|
|
47
|
+
// While locked (itself or its layer), reject any change other than locked/visible
|
|
48
|
+
// (full protection)
|
|
49
|
+
const findLayerOfGroup = (gid) => store.getAllLayers().find((l) => l.order.includes(gid));
|
|
50
|
+
if (isGroupLocked(group, findLayerOfGroup))
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return store.updateGroup(id, updates);
|
|
54
|
+
},
|
|
55
|
+
deleteGroup(id) {
|
|
56
|
+
// The Store puts the features of the group in its place in the order of its layer
|
|
57
|
+
return store.deleteGroup(id);
|
|
58
|
+
},
|
|
59
|
+
reorderInGroup(featureId, groupId, newIndex) {
|
|
60
|
+
return store.reorderInGroup(featureId, groupId, newIndex);
|
|
61
|
+
},
|
|
62
|
+
addFeatureToGroup(featureId, groupId, index) {
|
|
63
|
+
addFeatureToGroupImpl(store, featureId, groupId, index);
|
|
64
|
+
},
|
|
65
|
+
removeFeatureFromGroup(featureId) {
|
|
66
|
+
removeFeatureFromGroupImpl(store, featureId);
|
|
67
|
+
},
|
|
68
|
+
groupSelection() {
|
|
69
|
+
return groupSelectionImpl(store, generateFeatureId, autoNameGenerator);
|
|
70
|
+
},
|
|
71
|
+
ungroupSelection() {
|
|
72
|
+
ungroupSelectionImpl(store);
|
|
73
|
+
},
|
|
74
|
+
ungroupGroup(groupId) {
|
|
75
|
+
ungroupGroupImpl(store, groupId);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants related to Import/Export
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Version of the native format
|
|
6
|
+
*
|
|
7
|
+
* Semantic versioning. A minor version only adds fields; a major version can change the
|
|
8
|
+
* meaning of any field, and data of another major version is rejected. 2.0.0 made the
|
|
9
|
+
* stacking order (`layerOrder`) a required part of the data.
|
|
10
|
+
*/
|
|
11
|
+
export declare const NATIVE_VERSION = "2.0.0";
|
|
12
|
+
/** Prefix of the GeoJSON properties that hold this library's own data */
|
|
13
|
+
export declare const GEOJSON_PREFIX = "maplibre-gl-draw:";
|
|
14
|
+
/**
|
|
15
|
+
* The properties this library itself keeps in `Feature.properties`
|
|
16
|
+
*
|
|
17
|
+
* They are stored without a prefix in the native format, and the
|
|
18
|
+
* `maplibre-gl-draw:` prefix is added when exporting to GeoJSON. Every other property, those
|
|
19
|
+
* of the host and of extensions included, is written as a plain key. `name` and `description`
|
|
20
|
+
* are plain keys too: other GIS tools read them as the name and the description.
|
|
21
|
+
*/
|
|
22
|
+
export declare const LIBRARY_PROPERTIES: ReadonlySet<string>;
|
|
23
|
+
/**
|
|
24
|
+
* The number of decimal places the GeoJSON export keeps in a coordinate
|
|
25
|
+
*
|
|
26
|
+
* 1e-7 degrees is about 1.1 cm at the equator, finer than any edit on the map, and it keeps
|
|
27
|
+
* the file from carrying the noise digits of floating-point arithmetic (RFC 7946, 11.2).
|
|
28
|
+
*/
|
|
29
|
+
export declare const GEOJSON_COORDINATE_DECIMALS = 7;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* Constants related to Import/Export
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Version of the native format
|
|
8
|
+
*
|
|
9
|
+
* Semantic versioning. A minor version only adds fields; a major version can change the
|
|
10
|
+
* meaning of any field, and data of another major version is rejected. 2.0.0 made the
|
|
11
|
+
* stacking order (`layerOrder`) a required part of the data.
|
|
12
|
+
*/
|
|
13
|
+
export const NATIVE_VERSION = '2.0.0';
|
|
14
|
+
/** Prefix of the GeoJSON properties that hold this library's own data */
|
|
15
|
+
export const GEOJSON_PREFIX = 'maplibre-gl-draw:';
|
|
16
|
+
/**
|
|
17
|
+
* The properties this library itself keeps in `Feature.properties`
|
|
18
|
+
*
|
|
19
|
+
* They are stored without a prefix in the native format, and the
|
|
20
|
+
* `maplibre-gl-draw:` prefix is added when exporting to GeoJSON. Every other property, those
|
|
21
|
+
* of the host and of extensions included, is written as a plain key. `name` and `description`
|
|
22
|
+
* are plain keys too: other GIS tools read them as the name and the description.
|
|
23
|
+
*/
|
|
24
|
+
export const LIBRARY_PROPERTIES = new Set([
|
|
25
|
+
// Common
|
|
26
|
+
'createdZoom',
|
|
27
|
+
'rotation',
|
|
28
|
+
'scale',
|
|
29
|
+
// Image
|
|
30
|
+
'imageFileId',
|
|
31
|
+
'imageWidth',
|
|
32
|
+
'imageHeight',
|
|
33
|
+
]);
|
|
34
|
+
/**
|
|
35
|
+
* The number of decimal places the GeoJSON export keeps in a coordinate
|
|
36
|
+
*
|
|
37
|
+
* 1e-7 degrees is about 1.1 cm at the equator, finer than any edit on the map, and it keeps
|
|
38
|
+
* the file from carrying the noise digits of floating-point arithmetic (RFC 7946, 11.2).
|
|
39
|
+
*/
|
|
40
|
+
export const GEOJSON_COORDINATE_DECIMALS = 7;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** An embedded image accepted for import */
|
|
2
|
+
export interface EmbeddedFileContent {
|
|
3
|
+
mimeType: string;
|
|
4
|
+
dataURL: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validates and normalizes an embedded image
|
|
8
|
+
*
|
|
9
|
+
* @param dataURL - the image data URL found in the data
|
|
10
|
+
* @param mimeType - the MIME type declared next to it
|
|
11
|
+
* @returns the content to store, or null when it is not an accepted embedded image
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeEmbeddedFile(dataURL: unknown, mimeType: unknown): Promise<EmbeddedFileContent | null>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* Validation of the image data carried by imported files
|
|
5
|
+
*
|
|
6
|
+
* Both the native format (`files[].dataURL`) and GeoJSON (`maplibre-gl-draw:imageData`) carry
|
|
7
|
+
* the pixels of an Image feature as a data URL. Only an embedded PNG / JPEG / WebP / GIF is
|
|
8
|
+
* accepted, its header must agree with the declared MIME type, and an image larger than the
|
|
9
|
+
* texture limit is scaled down here, the same as when an image file is loaded.
|
|
10
|
+
*/
|
|
11
|
+
import { readEmbeddedImage } from '../../shared/utils/embedded-image.js';
|
|
12
|
+
import { exceedsMaxImageSize, processImageDataUrl } from '../../shared/utils/image.js';
|
|
13
|
+
/**
|
|
14
|
+
* Validates and normalizes an embedded image
|
|
15
|
+
*
|
|
16
|
+
* @param dataURL - the image data URL found in the data
|
|
17
|
+
* @param mimeType - the MIME type declared next to it
|
|
18
|
+
* @returns the content to store, or null when it is not an accepted embedded image
|
|
19
|
+
*/
|
|
20
|
+
export async function normalizeEmbeddedFile(dataURL, mimeType) {
|
|
21
|
+
const info = readEmbeddedImage(dataURL);
|
|
22
|
+
if (!info || typeof dataURL !== 'string')
|
|
23
|
+
return null;
|
|
24
|
+
if (mimeType !== info.mimeType)
|
|
25
|
+
return null;
|
|
26
|
+
if (exceedsMaxImageSize(info.width, info.height)) {
|
|
27
|
+
const processed = await processImageDataUrl(dataURL);
|
|
28
|
+
return { mimeType: processed.mimeType, dataURL: processed.dataUrl };
|
|
29
|
+
}
|
|
30
|
+
return { mimeType: info.mimeType, dataURL };
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation of the export file name
|
|
3
|
+
*/
|
|
4
|
+
import type { Metadata } from '../../store/types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Builds the export file name
|
|
7
|
+
*
|
|
8
|
+
* Format: `{title}_{YYYY-MM-DD}_{HHMMSS}{suffix}`
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildExportFileName(metadata: Metadata, suffix: string): string;
|