@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,1259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public API interface of MapLibreGLDraw and the createDrawAPI orchestrator
|
|
3
|
+
*
|
|
4
|
+
* The interface definitions are gathered in this file, while the implementation of each
|
|
5
|
+
* method is spread across the sub-api files per functional domain (feature-api / layer-api /
|
|
6
|
+
* group-api / selection-api / event-api / extension-api / instance-api). createDrawAPI is a
|
|
7
|
+
* thin orchestrator that composes them by spreading.
|
|
8
|
+
*/
|
|
9
|
+
import type { Map as MapLibreMap } from 'maplibre-gl';
|
|
10
|
+
import type { MapClickEventPayload } from '../dispatcher/types.js';
|
|
11
|
+
import type { Dataset, DatasetClickEventPayload, DatasetOptions, DatasetPlacement } from '../display/types.js';
|
|
12
|
+
import type { CustomFeatureHandler, CustomOverlayRenderer } from '../extension/index.js';
|
|
13
|
+
import type { ModeHandler } from '../modes/handler.js';
|
|
14
|
+
import type { Plugin } from '../plugins/plugin.js';
|
|
15
|
+
import type { FeaturesChangePayload, GeometryAppliedPayload, LoadErrorPayload } from '../shared/utils/event-emitter.js';
|
|
16
|
+
import type { SnapResult } from '../snapping/types.js';
|
|
17
|
+
import type { StoreView } from '../store/store.js';
|
|
18
|
+
import type { ExportFormat, ExportOptions, ExportResult, Feature, FeatureInput, Group, Layer, LoadOptions, LoadResult, Metadata, Mode, Selection, SelectionType, VertexRef, VertexSelection } from '../store/types.js';
|
|
19
|
+
import type { FeatureCompanionProvider } from '../view/feature-companion.js';
|
|
20
|
+
import type { RenderSlot } from '../view/layer/slots.js';
|
|
21
|
+
import type { TerrainDrapeDebug } from '../view/terrain/state.js';
|
|
22
|
+
import type { AuxiliaryHandleProvider } from '../view/ui/auxiliary-handles.js';
|
|
23
|
+
import type { GeometryOperations } from './geometry-operations.js';
|
|
24
|
+
import type { InputOperations } from './input-api.js';
|
|
25
|
+
import type { SnappingOperations } from './snapping-api.js';
|
|
26
|
+
import type { TopologyOperations } from './topology-api.js';
|
|
27
|
+
import type { TracingOperations } from './tracing-api.js';
|
|
28
|
+
/**
|
|
29
|
+
* The events of a draw instance and the payload each one carries.
|
|
30
|
+
*
|
|
31
|
+
* Subscribe with {@link MapLibreGLDraw.on}; the key is the event name. The methods of the
|
|
32
|
+
* instance work synchronously, and the events are how the host learns the result of a change,
|
|
33
|
+
* whatever made it (a method call, a user operation, a change applied from outside).
|
|
34
|
+
*
|
|
35
|
+
* The per-item events (`draw.feature.*`, `draw.layer.*`, `draw.group.*`) are emitted once for
|
|
36
|
+
* every change, so a bulk load of 1000 features emits `draw.feature.create` 1000 times.
|
|
37
|
+
* A subscriber that only rebuilds a view on any change subscribes to `draw.features.change`
|
|
38
|
+
* instead, which is emitted once per flush. A listener that throws is reported with
|
|
39
|
+
* `console.error` and does not stop the other listeners.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* draw.on('draw.feature.create', ({ feature }) => {
|
|
44
|
+
* console.log('Created', feature.id, feature.type);
|
|
45
|
+
* });
|
|
46
|
+
* draw.on('draw.selection.change', ({ ids }) => {
|
|
47
|
+
* updatePropertyPanel(ids);
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export interface EventPayloads {
|
|
52
|
+
/** A feature was created. Emitted once per feature, whatever created it */
|
|
53
|
+
'draw.feature.create': {
|
|
54
|
+
/** The feature as it was created */
|
|
55
|
+
feature: Feature;
|
|
56
|
+
};
|
|
57
|
+
/** A feature was updated. Emitted once per feature and per change */
|
|
58
|
+
'draw.feature.update': {
|
|
59
|
+
/** The feature after the update */
|
|
60
|
+
feature: Feature;
|
|
61
|
+
/** The feature before the update */
|
|
62
|
+
previous: Feature;
|
|
63
|
+
};
|
|
64
|
+
/** A feature was deleted. Emitted once per feature */
|
|
65
|
+
'draw.feature.delete': {
|
|
66
|
+
/** The feature as it was when it was deleted */
|
|
67
|
+
feature: Feature;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The feature changes of one flush, emitted after the per-feature events of that flush.
|
|
71
|
+
*
|
|
72
|
+
* A flush is one transaction (a load, an import, a drag commit, an undo and so on) or one
|
|
73
|
+
* write made outside a transaction. Subscribe to this instead of the per-feature events to
|
|
74
|
+
* rebuild a view once per change rather than once per feature.
|
|
75
|
+
*/
|
|
76
|
+
'draw.features.change': FeaturesChangePayload;
|
|
77
|
+
/** A layer was created */
|
|
78
|
+
'draw.layer.create': {
|
|
79
|
+
/** The layer as it was created */
|
|
80
|
+
layer: Layer;
|
|
81
|
+
};
|
|
82
|
+
/** A layer was updated (its name, visibility, lock, order of items, style rule and so on) */
|
|
83
|
+
'draw.layer.update': {
|
|
84
|
+
/** The layer after the update */
|
|
85
|
+
layer: Layer;
|
|
86
|
+
/** The layer before the update */
|
|
87
|
+
previous: Layer;
|
|
88
|
+
};
|
|
89
|
+
/** A layer was deleted */
|
|
90
|
+
'draw.layer.delete': {
|
|
91
|
+
/** The layer as it was when it was deleted */
|
|
92
|
+
layer: Layer;
|
|
93
|
+
};
|
|
94
|
+
/** The stacking order of the layers changed (see {@link MapLibreGLDraw.setLayerOrder}) */
|
|
95
|
+
'draw.layer.reorder': {
|
|
96
|
+
/** The new order; the last entry is the frontmost */
|
|
97
|
+
order: string[];
|
|
98
|
+
/** The order before the change */
|
|
99
|
+
previous: string[];
|
|
100
|
+
};
|
|
101
|
+
/** A group was created */
|
|
102
|
+
'draw.group.create': {
|
|
103
|
+
/** The group as it was created */
|
|
104
|
+
group: Group;
|
|
105
|
+
};
|
|
106
|
+
/** A group was updated (its members, name, visibility, lock and so on) */
|
|
107
|
+
'draw.group.update': {
|
|
108
|
+
/** The group after the update */
|
|
109
|
+
group: Group;
|
|
110
|
+
/** The group before the update */
|
|
111
|
+
previous: Group;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* A group was deleted, explicitly or because its last member left it (an empty group is not
|
|
115
|
+
* kept)
|
|
116
|
+
*/
|
|
117
|
+
'draw.group.delete': {
|
|
118
|
+
/** The group as it was when it was deleted */
|
|
119
|
+
group: Group;
|
|
120
|
+
};
|
|
121
|
+
/** The selection changed, by a method call or by a user operation */
|
|
122
|
+
'draw.selection.change': {
|
|
123
|
+
/** What is selected now; null when nothing is selected */
|
|
124
|
+
type: SelectionType | null;
|
|
125
|
+
/** The IDs of the selected items */
|
|
126
|
+
ids: string[];
|
|
127
|
+
/** What was selected before */
|
|
128
|
+
previousType: SelectionType | null;
|
|
129
|
+
/** The IDs that were selected before */
|
|
130
|
+
previousIds: string[];
|
|
131
|
+
};
|
|
132
|
+
/** The mode changed. Not emitted when a request is refused or asks for the current mode */
|
|
133
|
+
'draw.mode.change': {
|
|
134
|
+
/** The mode now */
|
|
135
|
+
mode: Mode;
|
|
136
|
+
/** The mode before the change */
|
|
137
|
+
previousMode: Mode;
|
|
138
|
+
};
|
|
139
|
+
/** The metadata (the title, the description and so on) changed */
|
|
140
|
+
'draw.metadata.change': {
|
|
141
|
+
/** The metadata after the change */
|
|
142
|
+
metadata: Metadata;
|
|
143
|
+
/** The metadata before the change */
|
|
144
|
+
previous: Metadata;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* The image drawing mode asks the host for an image file.
|
|
148
|
+
*
|
|
149
|
+
* Entering `draw_image` emits it and returns to select mode. The host lets the user choose a
|
|
150
|
+
* file and passes it to {@link MapLibreGLDraw.load} with the carried coordinate, zoom and
|
|
151
|
+
* layer as its {@link LoadOptions}.
|
|
152
|
+
*/
|
|
153
|
+
'draw.image.request': {
|
|
154
|
+
/** The center of the map when the mode was entered, `[lng, lat]` */
|
|
155
|
+
coordinate: [number, number];
|
|
156
|
+
/** The zoom of the map when the mode was entered */
|
|
157
|
+
zoom: number;
|
|
158
|
+
/** The writable layer the image should go into */
|
|
159
|
+
layerId: string;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* An operation of {@link MapLibreGLDraw.geometry} finished.
|
|
163
|
+
*
|
|
164
|
+
* `status: 'applied'` means result features were created; `'empty'` means the operation ran
|
|
165
|
+
* but its result had no area, and nothing changed. Nothing is emitted when the operation did
|
|
166
|
+
* not run (too few targets, read-only).
|
|
167
|
+
*/
|
|
168
|
+
'draw.geometry.applied': GeometryAppliedPayload;
|
|
169
|
+
/**
|
|
170
|
+
* The snapping result changed: the target changed, or it was lost (then a result with no
|
|
171
|
+
* target is emitted once)
|
|
172
|
+
*/
|
|
173
|
+
'draw.snap.change': SnapResult;
|
|
174
|
+
/**
|
|
175
|
+
* A click in select mode was resolved against the datasets.
|
|
176
|
+
*
|
|
177
|
+
* `datasetId` and `feature` are set when an interactive dataset took the click, and
|
|
178
|
+
* both are null when it hit none (a click on empty space). Not emitted for a click that hit
|
|
179
|
+
* a feature of the Store, nor in any mode other than select.
|
|
180
|
+
*/
|
|
181
|
+
'draw.dataset.click': DatasetClickEventPayload;
|
|
182
|
+
/**
|
|
183
|
+
* A dataset was added.
|
|
184
|
+
*
|
|
185
|
+
* Emitted by {@link MapLibreGLDraw.addDataset} once the dataset is listed, so
|
|
186
|
+
* {@link MapLibreGLDraw.getDataset} returns it inside the handler. The datasets
|
|
187
|
+
* that existed before the subscription are not announced; read them with
|
|
188
|
+
* {@link MapLibreGLDraw.getDatasets}.
|
|
189
|
+
*/
|
|
190
|
+
'draw.dataset.add': {
|
|
191
|
+
/** The id of the dataset that was added */
|
|
192
|
+
datasetId: string;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* A dataset was removed, by {@link MapLibreGLDraw.removeDataset}
|
|
196
|
+
* or by {@link Dataset.remove}.
|
|
197
|
+
*
|
|
198
|
+
* Emitted once the dataset is no longer listed. Not emitted when the draw instance is
|
|
199
|
+
* destroyed. A dataset added again under the same id is a new object, announced by a new
|
|
200
|
+
* `draw.dataset.add`.
|
|
201
|
+
*/
|
|
202
|
+
'draw.dataset.remove': {
|
|
203
|
+
/** The id of the dataset that was removed */
|
|
204
|
+
datasetId: string;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* The order of the datasets changed: {@link MapLibreGLDraw.moveDataset}
|
|
208
|
+
* moved a dataset within its side or to another side.
|
|
209
|
+
*
|
|
210
|
+
* Not emitted for a move that leaves everything where it was. Adding or removing a
|
|
211
|
+
* dataset emits `draw.dataset.add` or `draw.dataset.remove` instead.
|
|
212
|
+
*/
|
|
213
|
+
'draw.dataset.reorder': {
|
|
214
|
+
/**
|
|
215
|
+
* The ids of the datasets in display order, from the back to the front (the same as
|
|
216
|
+
* {@link MapLibreGLDraw.getDatasets})
|
|
217
|
+
*/
|
|
218
|
+
order: string[];
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* A click on the map in select mode, whether or not it hit anything.
|
|
222
|
+
*
|
|
223
|
+
* The coordinates are the raw ones, before snapping. It is a read-only notification that
|
|
224
|
+
* does not affect the selection, for a host that needs any click on the map (placing a pin,
|
|
225
|
+
* for example). Not emitted in any mode other than select.
|
|
226
|
+
*/
|
|
227
|
+
'draw.map.click': MapClickEventPayload;
|
|
228
|
+
/**
|
|
229
|
+
* Frames were added or removed, or the interval of a frame changed.
|
|
230
|
+
*
|
|
231
|
+
* The payload is the same as {@link MapLibreGLDraw.getRenderSlots}. On receiving it, the
|
|
232
|
+
* host places its native layers between the frames again (see
|
|
233
|
+
* {@link Options.isExternalEntry}).
|
|
234
|
+
*/
|
|
235
|
+
'draw.renderslots.change': {
|
|
236
|
+
/** Every frame, from the backmost */
|
|
237
|
+
slots: RenderSlot[];
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* An asynchronous load that no call returns failed.
|
|
241
|
+
*
|
|
242
|
+
* With `source: 'image'`, the image of an Image feature could not be decoded (`featureId`);
|
|
243
|
+
* it is emitted once per image, the image is not retried, and the feature is drawn without
|
|
244
|
+
* it.
|
|
245
|
+
*/
|
|
246
|
+
'draw.load.error': LoadErrorPayload;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* A draw instance: the drawing and editing tools attached to one MapLibre map.
|
|
250
|
+
*
|
|
251
|
+
* Create one with {@link createMapLibreGLDraw}. Every method works synchronously on the
|
|
252
|
+
* document held by the Store (only {@link MapLibreGLDraw.load} returns a Promise), and the
|
|
253
|
+
* result of a change reaches the host through the events (see {@link EventPayloads}).
|
|
254
|
+
*
|
|
255
|
+
* The methods report a problem in one of three ways, by its cause:
|
|
256
|
+
*
|
|
257
|
+
* - An argument that cannot apply throws an `Error` and changes nothing: an ID that does not
|
|
258
|
+
* exist, a `layerId` or `groupId` that names nothing, an ID that is already taken.
|
|
259
|
+
* - A write refused because of the state does not throw. While read-only is on, every write
|
|
260
|
+
* to the document is refused, and so is a write that would change a locked feature, group
|
|
261
|
+
* or layer beyond `locked` and `visible`. The methods that return a boolean return false,
|
|
262
|
+
* and nothing changes. Read-only is checked first, so a write while read-only returns false
|
|
263
|
+
* even for an ID that does not exist.
|
|
264
|
+
* - Data that a load cannot use is left out and listed in `LoadResult.skipped`.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* const draw = createMapLibreGLDraw(map);
|
|
269
|
+
* draw.on('draw.feature.create', ({ feature }) => console.log(feature.id));
|
|
270
|
+
* draw.setMode('draw_polygon');
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
export interface MapLibreGLDraw {
|
|
274
|
+
/**
|
|
275
|
+
* Gets the MapLibre map the instance was created with.
|
|
276
|
+
*
|
|
277
|
+
* A plugin that needs the map itself (to place a DOM overlay, for example) reaches it with
|
|
278
|
+
* `ctx.draw.getMap()`.
|
|
279
|
+
*/
|
|
280
|
+
getMap(): MapLibreMap;
|
|
281
|
+
/**
|
|
282
|
+
* Gets a read-only view of the Store: the reads, `subscribe` for the changes, and
|
|
283
|
+
* `transact` to group writes into one notification.
|
|
284
|
+
*
|
|
285
|
+
* It has no write methods: the host writes through the methods of this instance, and a
|
|
286
|
+
* plugin through its {@link PluginContext} (`ctx.getStore()` when it needs the Store
|
|
287
|
+
* itself). The objects it returns are read-only; the in-memory store freezes them.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* // One transaction: one notification (one step for a subscriber that records changes) for several
|
|
292
|
+
* // writes, labeled with the source 'batch'
|
|
293
|
+
* draw.getStore().transact(() => {
|
|
294
|
+
* const layerId = draw.addLayer('Imported');
|
|
295
|
+
* if (layerId === null) return; // read-only
|
|
296
|
+
* draw.setActiveLayer(layerId);
|
|
297
|
+
* draw.addFeature({ type: 'Point', coordinates: [139.767, 35.681] });
|
|
298
|
+
* }, 'batch');
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
getStore(): StoreView;
|
|
302
|
+
/**
|
|
303
|
+
* Gets the current mode.
|
|
304
|
+
*
|
|
305
|
+
* Read it after {@link MapLibreGLDraw.setMode} to tell whether a request was refused.
|
|
306
|
+
*/
|
|
307
|
+
getMode(): Mode;
|
|
308
|
+
/**
|
|
309
|
+
* Changes the mode.
|
|
310
|
+
*
|
|
311
|
+
* The built-in modes are `select`, `draw_point`, `draw_line`, `draw_polygon`, `draw_image`,
|
|
312
|
+
* `draw_circle` and `draw_freehand`; others are added with
|
|
313
|
+
* {@link MapLibreGLDraw.registerMode}. A drawing mode writes new features into the active
|
|
314
|
+
* layer when it can be written (it exists, is not locked, is visible and is not locally
|
|
315
|
+
* hidden), otherwise into the first writable layer.
|
|
316
|
+
*
|
|
317
|
+
* A request is refused, with nothing changed and no event, for a name with no registered
|
|
318
|
+
* mode (with a console warning), for any mode other than select while the interaction lock
|
|
319
|
+
* is on, and for a mode that writes features while no layer can be written (for example with
|
|
320
|
+
* `initDefaultLayer: false` before the host creates a layer). Asking for the current mode
|
|
321
|
+
* does nothing and does not restart it. Emits `draw.mode.change` when the mode changed.
|
|
322
|
+
*
|
|
323
|
+
* @param mode the mode to enter
|
|
324
|
+
* @returns whether the mode is `mode` after the call; false when the request was refused
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* if (!draw.setMode('draw_line')) {
|
|
329
|
+
* console.warn('Cannot draw now; the mode stays', draw.getMode());
|
|
330
|
+
* }
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
setMode(mode: Mode): boolean;
|
|
334
|
+
/** Whether read-only is on (see {@link MapLibreGLDraw.setReadOnly}) */
|
|
335
|
+
isReadOnly(): boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Turns read-only on or off.
|
|
338
|
+
*
|
|
339
|
+
* While it is on, every local write to the document (features, layers, groups, metadata) is
|
|
340
|
+
* refused: the methods that return a boolean return false and nothing changes. Local state
|
|
341
|
+
* still changes: the selection, the mode and local hiding. Read-only is local to this client
|
|
342
|
+
* is not part of the document; changes applied to the document store below it keep
|
|
343
|
+
* arriving.
|
|
344
|
+
*
|
|
345
|
+
* @param value true to stop the writes, false to allow them again
|
|
346
|
+
*/
|
|
347
|
+
setReadOnly(value: boolean): void;
|
|
348
|
+
/** Whether the interaction lock is on (see {@link MapLibreGLDraw.setInteractionLock}) */
|
|
349
|
+
isInteractionLocked(): boolean;
|
|
350
|
+
/**
|
|
351
|
+
* Turns the interaction lock on or off.
|
|
352
|
+
*
|
|
353
|
+
* While it is on, the user can still select features, select vertices and toggle local
|
|
354
|
+
* hiding, but no editing interaction starts from user input: no drag, resize, rotation or
|
|
355
|
+
* vertex edit, no delete or group shortcut and no drawing mode. It does not
|
|
356
|
+
* stop writes made through the methods or by plugins; that is read-only's job, and the two
|
|
357
|
+
* are independent. Turning it on while drawing discards the drawing and returns to select.
|
|
358
|
+
*
|
|
359
|
+
* @param value true to lock the interactions, false to release them
|
|
360
|
+
*/
|
|
361
|
+
setInteractionLock(value: boolean): void;
|
|
362
|
+
/**
|
|
363
|
+
* Gets the frames that draw the stacking order, from the backmost.
|
|
364
|
+
*
|
|
365
|
+
* Each frame covers an interval `[from, to)` of the layer order and is drawn by one
|
|
366
|
+
* MapLibre custom layer, whose id it carries. The entries for which
|
|
367
|
+
* {@link Options.isExternalEntry} returns true are separators between the frames: the host
|
|
368
|
+
* places the native layer of a separator just before the frame directly above it
|
|
369
|
+
* (`map.moveLayer(id, slot.layerId)`), or in the foreground when no frame is above it.
|
|
370
|
+
* Without separators there is a single frame, `maplibre-gl-draw-layer`. The event
|
|
371
|
+
* `draw.renderslots.change` announces every change of this list.
|
|
372
|
+
*
|
|
373
|
+
* @returns the frames, from the backmost
|
|
374
|
+
*/
|
|
375
|
+
getRenderSlots(): RenderSlot[];
|
|
376
|
+
/**
|
|
377
|
+
* Gets the current coefficient of the render scale (default 1).
|
|
378
|
+
*/
|
|
379
|
+
getRenderScale(): number;
|
|
380
|
+
/**
|
|
381
|
+
* Sets the coefficient of the render scale (default 1).
|
|
382
|
+
*
|
|
383
|
+
* The dimensions fixed in screen pixels, such as line widths, point sizes, outlines and
|
|
384
|
+
* glyphs, are drawn as CSS pixels times the render scale, and this coefficient multiplies
|
|
385
|
+
* it: 0.5 halves only this library's own screen-pixel dimensions. The positions of the
|
|
386
|
+
* features and the dimensions given in meters do not change, and neither does the width of
|
|
387
|
+
* a line that scales with the zoom (a feature with a created zoom).
|
|
388
|
+
*
|
|
389
|
+
* Use it when the map is shown enlarged or reduced, for example with a CSS transform: a map
|
|
390
|
+
* shown at 1/k, such as a page preview, calls `setRenderScale(1 / k)` so that this library's
|
|
391
|
+
* lines and points shrink with the basemap. A change triggers a repaint, and the baked
|
|
392
|
+
* batches are rebuilt on the next frame.
|
|
393
|
+
*
|
|
394
|
+
* @param scale the coefficient; anything other than a finite positive number is ignored
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```typescript
|
|
398
|
+
* draw.setRenderScale(0.5); // while the map is shown at half size
|
|
399
|
+
* draw.setRenderScale(1); // back to normal
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
setRenderScale(scale: number): void;
|
|
403
|
+
/**
|
|
404
|
+
* Gets the resolved render scale: {@link Options.pixelRatio}, or else the map's
|
|
405
|
+
* `getPixelRatio()`, times the coefficient of {@link MapLibreGLDraw.setRenderScale}.
|
|
406
|
+
*
|
|
407
|
+
* An extension that draws with a renderer of its own (text, for example) passes it on so
|
|
408
|
+
* that its drawing matches, typically as a function: `pixelRatio: () => draw.getPixelRatio()`.
|
|
409
|
+
*/
|
|
410
|
+
getPixelRatio(): number;
|
|
411
|
+
/**
|
|
412
|
+
* Gets the terrain diagnostics of this instance, as of the last frame drawn.
|
|
413
|
+
*
|
|
414
|
+
* For debugging and measurement tools only. The value is a layer 2 type: its fields follow
|
|
415
|
+
* the rendering and can change in a minor release. `render` holds the numbers of the terrain
|
|
416
|
+
* state the frame drew with (whether the terrain was active, where the DEM atlas lies, the
|
|
417
|
+
* subdivision step and its generation), and `drape` reports whether the analytic drape was
|
|
418
|
+
* used and why not. Both are snapshots of plain values: a later frame does not change them.
|
|
419
|
+
* A map without terrain reports `render.active === false`.
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```typescript
|
|
423
|
+
* const { render, drape } = draw.getTerrainDiagnostics();
|
|
424
|
+
* console.log(render.active, render.stepMeters, drape.used, drape.reason);
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
getTerrainDiagnostics(): TerrainDiagnostics;
|
|
428
|
+
/**
|
|
429
|
+
* Whether the renderer still has work that later frames finish on their own and that will
|
|
430
|
+
* change the picture.
|
|
431
|
+
*
|
|
432
|
+
* It is true while the most recent frame left chunks of a dataset unbuilt or the tile index
|
|
433
|
+
* of the terrain drape incomplete, while a huge polygon is being triangulated, while a
|
|
434
|
+
* provider call waits for its debounce or its response, and while an overlay renderer reports
|
|
435
|
+
* work of its own (`CustomOverlayRenderer.hasPendingWork`). The renderer requests the repaints
|
|
436
|
+
* that finish this work itself.
|
|
437
|
+
*
|
|
438
|
+
* A host that reads the picture back (a print, a thumbnail) waits for the map's `idle`, which
|
|
439
|
+
* covers the tiles and the DEM of the map, and then for this to return false after a frame:
|
|
440
|
+
* maplibre fires `idle` even when this library asked for another frame during the last one,
|
|
441
|
+
* so `idle` alone does not mean the picture is complete. With `timeSlicing: false` in the
|
|
442
|
+
* rendering settings, the frames themselves are complete, and this usually turns false right
|
|
443
|
+
* after the first frame. A change made after the last frame is drawn by the next one; ask
|
|
444
|
+
* after that frame.
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* ```typescript
|
|
448
|
+
* // Resolves once the picture on the canvas is complete
|
|
449
|
+
* async function whenPictureComplete(map: maplibregl.Map, draw: MapLibreGLDraw): Promise<void> {
|
|
450
|
+
* map.triggerRepaint();
|
|
451
|
+
* await map.once('idle');
|
|
452
|
+
* while (draw.hasPendingWork()) await map.once('render');
|
|
453
|
+
* }
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
hasPendingWork(): boolean;
|
|
457
|
+
/**
|
|
458
|
+
* Whether a feature, group or layer is hidden for this client only (it does not look at
|
|
459
|
+
* the shared `visible`)
|
|
460
|
+
*
|
|
461
|
+
* @param id the ID of a feature, a group or a layer
|
|
462
|
+
*/
|
|
463
|
+
isLocallyHidden(id: string): boolean;
|
|
464
|
+
/** Gets the IDs that are hidden for this client only */
|
|
465
|
+
getLocallyHidden(): ReadonlySet<string>;
|
|
466
|
+
/**
|
|
467
|
+
* Hides or shows a feature, group or layer for this client only.
|
|
468
|
+
*
|
|
469
|
+
* It does not change `visible`, which is part of the document. What is hidden
|
|
470
|
+
* is not drawn, hit or box selected, hiding a group or a layer hides everything in it, and
|
|
471
|
+
* hidden items leave the selection. It works while read-only is on.
|
|
472
|
+
*
|
|
473
|
+
* @param id the ID of a feature, a group or a layer
|
|
474
|
+
* @param hidden true to hide, false to show again
|
|
475
|
+
*/
|
|
476
|
+
setLocallyHidden(id: string, hidden: boolean): void;
|
|
477
|
+
/**
|
|
478
|
+
* Adds a feature.
|
|
479
|
+
*
|
|
480
|
+
* Only `type` and `coordinates` are required. The rest take defaults: a generated `id`, the
|
|
481
|
+
* active layer, empty `properties`, `locked: false` and `visible: true`. The feature is
|
|
482
|
+
* placed at the front of its layer, and `draw.feature.create` is emitted.
|
|
483
|
+
*
|
|
484
|
+
* @param feature the feature to add
|
|
485
|
+
* @returns the ID of the feature; null when the write was refused because the Store is
|
|
486
|
+
* read-only (nothing is added)
|
|
487
|
+
* @throws Error when the ID is already taken, or when `layerId` (or the active layer, when
|
|
488
|
+
* it is omitted) names no layer; nothing is added
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```typescript
|
|
492
|
+
* const id = draw.addFeature({
|
|
493
|
+
* type: 'Point',
|
|
494
|
+
* coordinates: [139.767, 35.681],
|
|
495
|
+
* properties: { name: 'Tokyo Station' },
|
|
496
|
+
* });
|
|
497
|
+
* if (id !== null) draw.select(id);
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
addFeature(feature: FeatureInput): string | null;
|
|
501
|
+
/**
|
|
502
|
+
* Gets a feature by ID.
|
|
503
|
+
*
|
|
504
|
+
* @returns the feature, or undefined when no feature has the ID
|
|
505
|
+
*/
|
|
506
|
+
getFeature(id: string): Feature | undefined;
|
|
507
|
+
/** Gets every feature, in display order (from the back), hidden ones included */
|
|
508
|
+
getAllFeatures(): Feature[];
|
|
509
|
+
/**
|
|
510
|
+
* Gets the features the shared visible flag shows (the feature, its group and its layer are
|
|
511
|
+
* all visible), in display order (from the back). Local hiding is not applied.
|
|
512
|
+
*/
|
|
513
|
+
getVisibleFeatures(): Feature[];
|
|
514
|
+
/**
|
|
515
|
+
* Updates a feature.
|
|
516
|
+
*
|
|
517
|
+
* Any field can be updated partially. Changing `layerId` or `groupId` moves the feature to
|
|
518
|
+
* its new container, at the front; to choose the position use
|
|
519
|
+
* {@link MapLibreGLDraw.moveToLayer}, {@link MapLibreGLDraw.addFeatureToGroup} or
|
|
520
|
+
* {@link MapLibreGLDraw.removeFeatureFromGroup}. Emits `draw.feature.update`.
|
|
521
|
+
*
|
|
522
|
+
* @param id the ID of the feature
|
|
523
|
+
* @param updates the fields to change
|
|
524
|
+
* @returns true when applied; false when refused because the Store is read-only, or
|
|
525
|
+
* because the feature, its group or its layer is locked and the update changes more
|
|
526
|
+
* than `locked` / `visible`
|
|
527
|
+
* @throws Error when no feature has the ID, or when `layerId` names no layer
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* draw.updateFeature(id, {
|
|
532
|
+
* properties: { name: 'Updated name' },
|
|
533
|
+
* style: { strokeColor: '#e11d48' },
|
|
534
|
+
* });
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
updateFeature(id: string, updates: Partial<Feature>): boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Deletes a feature. A group that the deletion leaves empty is deleted with it.
|
|
540
|
+
*
|
|
541
|
+
* @param id the ID of the feature
|
|
542
|
+
* @returns true when deleted; false when refused because the Store is read-only
|
|
543
|
+
* @throws Error when no feature has the ID
|
|
544
|
+
*/
|
|
545
|
+
deleteFeature(id: string): boolean;
|
|
546
|
+
/**
|
|
547
|
+
* Deletes every feature (hidden ones included) in one notification.
|
|
548
|
+
*
|
|
549
|
+
* @returns true when deleted; false when refused because the Store is read-only
|
|
550
|
+
*/
|
|
551
|
+
deleteAllFeatures(): boolean;
|
|
552
|
+
/** Gets every layer */
|
|
553
|
+
getAllLayers(): Layer[];
|
|
554
|
+
/**
|
|
555
|
+
* Gets a layer by ID.
|
|
556
|
+
*
|
|
557
|
+
* @returns the layer, or undefined when no layer has the ID
|
|
558
|
+
*/
|
|
559
|
+
getLayer(id: string): Layer | undefined;
|
|
560
|
+
/**
|
|
561
|
+
* Adds an empty layer at the front of the stacking order.
|
|
562
|
+
*
|
|
563
|
+
* The new layer does not become the active layer; call {@link MapLibreGLDraw.setActiveLayer}
|
|
564
|
+
* to draw into it. Emits `draw.layer.create`.
|
|
565
|
+
*
|
|
566
|
+
* @param name the name; when omitted, a name from the automatic naming
|
|
567
|
+
* ({@link Options.autoName}), or the word of Layer alone when it is off
|
|
568
|
+
* @returns the ID of the layer; null when the write was refused because the Store is
|
|
569
|
+
* read-only (nothing is added)
|
|
570
|
+
*/
|
|
571
|
+
addLayer(name?: string): string | null;
|
|
572
|
+
/**
|
|
573
|
+
* Updates a layer.
|
|
574
|
+
*
|
|
575
|
+
* Any field can be updated partially, the style rule (`styleRule`) included. Emits
|
|
576
|
+
* `draw.layer.update`.
|
|
577
|
+
*
|
|
578
|
+
* @param id the ID of the layer
|
|
579
|
+
* @param updates the fields to change
|
|
580
|
+
* @returns true when applied; false when refused because the Store is read-only, or
|
|
581
|
+
* because the layer is locked and the update changes more than `locked` / `visible`
|
|
582
|
+
* @throws Error when no layer has the ID
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```typescript
|
|
586
|
+
* draw.updateLayer(layerId, { name: 'Parcels', locked: true });
|
|
587
|
+
* ```
|
|
588
|
+
*/
|
|
589
|
+
updateLayer(id: string, updates: Partial<Layer>): boolean;
|
|
590
|
+
/**
|
|
591
|
+
* Deletes a layer with every feature and group in it, and removes its ID from the stacking
|
|
592
|
+
* order. Emits `draw.layer.delete`.
|
|
593
|
+
*
|
|
594
|
+
* @param id the ID of the layer
|
|
595
|
+
* @returns true when deleted; false when refused because the Store is read-only
|
|
596
|
+
* @throws Error when no layer has the ID
|
|
597
|
+
*/
|
|
598
|
+
deleteLayer(id: string): boolean;
|
|
599
|
+
/**
|
|
600
|
+
* Gets the stacking order: the IDs of the layers (and of any other entries set with
|
|
601
|
+
* {@link MapLibreGLDraw.setLayerOrder}), where the last one is the frontmost.
|
|
602
|
+
*/
|
|
603
|
+
getLayerOrder(): readonly string[];
|
|
604
|
+
/**
|
|
605
|
+
* Sets the stacking order. The last entry is the frontmost.
|
|
606
|
+
*
|
|
607
|
+
* The order is part of the document: the native format saves it and a replaced store
|
|
608
|
+
* holds it. Its entries are not only layer IDs: a dataset with
|
|
609
|
+
* `order: 'layer-order'` takes part in the same order, and a separator for a native layer
|
|
610
|
+
* of the host (see {@link Options.isExternalEntry}) too. What such an entry means is the
|
|
611
|
+
* application's; the library keeps it at its position and never removes it (deleting a
|
|
612
|
+
* layer removes only that layer's ID), and one that names nothing is skipped when drawing
|
|
613
|
+
* and hit testing. Removing it is the caller's job. Empty strings are dropped and a
|
|
614
|
+
* repeated entry is kept at its first position. Emits `draw.layer.reorder`.
|
|
615
|
+
*
|
|
616
|
+
* @param order the new order, from the back
|
|
617
|
+
* @returns true when applied; false when refused because the Store is read-only
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```typescript
|
|
621
|
+
* // Put a dataset between two layers
|
|
622
|
+
* draw.addDataset({ id: 'parcels', features, order: 'layer-order' });
|
|
623
|
+
* draw.setLayerOrder([baseLayerId, 'parcels', notesLayerId]);
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
setLayerOrder(order: string[]): boolean;
|
|
627
|
+
/**
|
|
628
|
+
* Moves a feature or a group to another position inside its layer.
|
|
629
|
+
*
|
|
630
|
+
* @param itemId the ID of a feature or a group directly in the layer
|
|
631
|
+
* @param layerId the ID of the layer
|
|
632
|
+
* @param newIndex the new position in the order of the layer; 0 is the backmost
|
|
633
|
+
* @returns true when applied; false when refused because the Store is read-only
|
|
634
|
+
* @throws Error when no layer has the ID, or when the item is not in that layer
|
|
635
|
+
*/
|
|
636
|
+
reorderInLayer(itemId: string, layerId: string, newIndex: number): boolean;
|
|
637
|
+
/**
|
|
638
|
+
* Moves a feature or a group to the front of another layer.
|
|
639
|
+
*
|
|
640
|
+
* A feature that was in a group leaves the group. Nothing happens when the item or the
|
|
641
|
+
* layer does not exist, or when the item is already directly in that layer.
|
|
642
|
+
*
|
|
643
|
+
* @param itemId the ID of a feature or a group
|
|
644
|
+
* @param targetLayerId the ID of the destination layer
|
|
645
|
+
*/
|
|
646
|
+
moveToLayer(itemId: string, targetLayerId: string): void;
|
|
647
|
+
/**
|
|
648
|
+
* Gets the ID of the active layer, the layer new features go into by default.
|
|
649
|
+
*
|
|
650
|
+
* When the active layer has been deleted, the first layer becomes active.
|
|
651
|
+
*/
|
|
652
|
+
getActiveLayer(): string;
|
|
653
|
+
/**
|
|
654
|
+
* Sets the active layer, the layer new features go into by default.
|
|
655
|
+
*
|
|
656
|
+
* @param layerId the ID of the layer; an ID that names no layer is ignored
|
|
657
|
+
*/
|
|
658
|
+
setActiveLayer(layerId: string): void;
|
|
659
|
+
/** Gets every group */
|
|
660
|
+
getAllGroups(): Group[];
|
|
661
|
+
/**
|
|
662
|
+
* Gets a group by ID.
|
|
663
|
+
*
|
|
664
|
+
* @returns the group, or undefined when no group has the ID
|
|
665
|
+
*/
|
|
666
|
+
getGroup(id: string): Group | undefined;
|
|
667
|
+
/**
|
|
668
|
+
* Groups features.
|
|
669
|
+
*
|
|
670
|
+
* The features leave the order of the layer, and the group takes their place at the front
|
|
671
|
+
* of the layer. Emits `draw.group.create`.
|
|
672
|
+
*
|
|
673
|
+
* @param featureIds the IDs of the features to group, from the back
|
|
674
|
+
* @param layerId the ID of the layer the features are in
|
|
675
|
+
* @param name the name; when omitted, a name from the automatic naming
|
|
676
|
+
* ({@link Options.autoName}), or the word of Group alone when it is off
|
|
677
|
+
* @returns the ID of the group; null when the write was refused because the Store is
|
|
678
|
+
* read-only (nothing changes)
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* ```typescript
|
|
682
|
+
* const groupId = draw.addGroup([idA, idB], draw.getActiveLayer(), 'Station area');
|
|
683
|
+
* ```
|
|
684
|
+
*/
|
|
685
|
+
addGroup(featureIds: string[], layerId: string, name?: string): string | null;
|
|
686
|
+
/**
|
|
687
|
+
* Updates a group. Emits `draw.group.update`.
|
|
688
|
+
*
|
|
689
|
+
* @param id the ID of the group
|
|
690
|
+
* @param updates the fields to change
|
|
691
|
+
* @returns true when applied; false when refused because the Store is read-only, or
|
|
692
|
+
* because the group or its layer is locked and the update changes more than `locked` /
|
|
693
|
+
* `visible`
|
|
694
|
+
* @throws Error when no group has the ID
|
|
695
|
+
*/
|
|
696
|
+
updateGroup(id: string, updates: Partial<Group>): boolean;
|
|
697
|
+
/**
|
|
698
|
+
* Deletes a group; its features stay, in the group's place in the order of its layer.
|
|
699
|
+
*
|
|
700
|
+
* @param id the ID of the group
|
|
701
|
+
* @returns true when deleted; false when refused because the Store is read-only
|
|
702
|
+
* @throws Error when no group has the ID
|
|
703
|
+
*/
|
|
704
|
+
deleteGroup(id: string): boolean;
|
|
705
|
+
/**
|
|
706
|
+
* Moves a feature to another position inside its group.
|
|
707
|
+
*
|
|
708
|
+
* @param featureId the ID of a member of the group
|
|
709
|
+
* @param groupId the ID of the group
|
|
710
|
+
* @param newIndex the new position among the members; 0 is the backmost
|
|
711
|
+
* @returns true when applied; false when refused because the Store is read-only
|
|
712
|
+
* @throws Error when no group has the ID, or when the feature is not a member of it
|
|
713
|
+
*/
|
|
714
|
+
reorderInGroup(featureId: string, groupId: string, newIndex: number): boolean;
|
|
715
|
+
/**
|
|
716
|
+
* Adds a feature to a group.
|
|
717
|
+
*
|
|
718
|
+
* A feature in another group leaves that group first. Nothing happens when the feature or
|
|
719
|
+
* the group does not exist, or when the feature is already a member.
|
|
720
|
+
*
|
|
721
|
+
* @param featureId the ID of the feature
|
|
722
|
+
* @param groupId the ID of the group
|
|
723
|
+
* @param index the position among the members; when omitted, the front
|
|
724
|
+
*/
|
|
725
|
+
addFeatureToGroup(featureId: string, groupId: string, index?: number): void;
|
|
726
|
+
/**
|
|
727
|
+
* Takes a feature out of its group and places it just in front of the group in the layer.
|
|
728
|
+
*
|
|
729
|
+
* A group that the removal leaves empty is deleted. Nothing happens for a feature in no
|
|
730
|
+
* group.
|
|
731
|
+
*
|
|
732
|
+
* @param featureId the ID of the feature
|
|
733
|
+
*/
|
|
734
|
+
removeFeatureFromGroup(featureId: string): void;
|
|
735
|
+
/**
|
|
736
|
+
* Groups the selected features, the same as Cmd/Ctrl+G in select mode.
|
|
737
|
+
*
|
|
738
|
+
* It groups when two or more features are selected, all in the same layer, and none of
|
|
739
|
+
* them in a group that exists.
|
|
740
|
+
*
|
|
741
|
+
* @returns the ID of the new group, or null when the selection cannot be grouped
|
|
742
|
+
*/
|
|
743
|
+
groupSelection(): string | null;
|
|
744
|
+
/**
|
|
745
|
+
* Takes the selection out of the group structure, the same as Shift+Cmd/Ctrl+G in select
|
|
746
|
+
* mode.
|
|
747
|
+
*
|
|
748
|
+
* A selected group is dissolved: its members take its place and the group is deleted. A
|
|
749
|
+
* selected member leaves its group and is placed just in front of it; a group left empty is
|
|
750
|
+
* deleted. Anything else does nothing. It is one transaction, one notification.
|
|
751
|
+
*/
|
|
752
|
+
ungroupSelection(): void;
|
|
753
|
+
/**
|
|
754
|
+
* Dissolves a group whatever is selected: its members take its place in the layer and the
|
|
755
|
+
* group is deleted, in one transaction.
|
|
756
|
+
*
|
|
757
|
+
* @param groupId the ID of the group
|
|
758
|
+
*/
|
|
759
|
+
ungroupGroup(groupId: string): void;
|
|
760
|
+
/**
|
|
761
|
+
* Gets the selection: its type (`feature`, `group` or `layer`, or null) and the selected
|
|
762
|
+
* IDs.
|
|
763
|
+
*
|
|
764
|
+
* @example
|
|
765
|
+
* ```typescript
|
|
766
|
+
* const selection = draw.getSelection();
|
|
767
|
+
* if (selection.type === 'feature') {
|
|
768
|
+
* console.log('Selected features:', selection.ids);
|
|
769
|
+
* }
|
|
770
|
+
* ```
|
|
771
|
+
*/
|
|
772
|
+
getSelection(): Selection;
|
|
773
|
+
/**
|
|
774
|
+
* Selects items, replacing the current selection.
|
|
775
|
+
*
|
|
776
|
+
* Locked items can be selected. Emits `draw.selection.change` when the selection changed.
|
|
777
|
+
*
|
|
778
|
+
* @param ids the IDs of the items to select (a single one or a list)
|
|
779
|
+
* @param type the selection type (when omitted, it is 'feature')
|
|
780
|
+
*
|
|
781
|
+
* @example
|
|
782
|
+
* ```typescript
|
|
783
|
+
* draw.select(featureId);
|
|
784
|
+
* draw.select([idA, idB]);
|
|
785
|
+
* draw.select(layerId, 'layer');
|
|
786
|
+
* ```
|
|
787
|
+
*/
|
|
788
|
+
select(ids: string | string[], type?: SelectionType): void;
|
|
789
|
+
/** Clears the selection. Emits `draw.selection.change` when something was selected */
|
|
790
|
+
deselect(): void;
|
|
791
|
+
/** Gets the selected features; an empty array unless the selection type is 'feature' */
|
|
792
|
+
getSelectedFeatures(): Feature[];
|
|
793
|
+
/** Gets the IDs of the selected items, whatever their type */
|
|
794
|
+
getSelectedIds(): string[];
|
|
795
|
+
/**
|
|
796
|
+
* Deletes what is selected as one change, the same as the Delete key of the select mode:
|
|
797
|
+
* the selected vertices when there are any, otherwise the selected features, the contents of
|
|
798
|
+
* the selected groups, or the selected layers (at least one layer is kept). Locked items are
|
|
799
|
+
* kept: a group loses only its unlocked members, and a layer holding a locked feature or
|
|
800
|
+
* group is not deleted.
|
|
801
|
+
*
|
|
802
|
+
* @returns true when something was deleted; false while read-only or the interaction lock
|
|
803
|
+
* is on, when nothing is selected, or when everything selected is locked
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* ```typescript
|
|
807
|
+
* deleteButton.onclick = () => draw.deleteSelection();
|
|
808
|
+
* ```
|
|
809
|
+
*/
|
|
810
|
+
deleteSelection(): boolean;
|
|
811
|
+
/**
|
|
812
|
+
* Selects vertices of a feature, replacing the vertex selection.
|
|
813
|
+
*
|
|
814
|
+
* @param featureId the ID of the feature
|
|
815
|
+
* @param vertices an array of vertex references (part number + ring number + vertex index).
|
|
816
|
+
* For a Polygon, ring 0 is the exterior ring and 1 onwards are the interior rings (holes).
|
|
817
|
+
* For LineString / Point it is ring 0. part is the part number of the Multi geometries,
|
|
818
|
+
* and when omitted it is 0 (for a single geometry it is always 0)
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```typescript
|
|
822
|
+
* draw.selectVertices(polygonId, [{ ring: 0, index: 0 }, { ring: 0, index: 2 }]);
|
|
823
|
+
* // A vertex of a hole of the second polygon of a MultiPolygon
|
|
824
|
+
* draw.selectVertices(multiPolygonId, [{ part: 1, ring: 1, index: 2 }]);
|
|
825
|
+
* ```
|
|
826
|
+
*/
|
|
827
|
+
selectVertices(featureId: string, vertices: VertexRef[]): void;
|
|
828
|
+
/** Clears the vertex selection */
|
|
829
|
+
deselectVertices(): void;
|
|
830
|
+
/**
|
|
831
|
+
* Gets the selected vertices: the feature and the references of its vertices.
|
|
832
|
+
*
|
|
833
|
+
* @returns the vertex selection, or null when no vertex is selected
|
|
834
|
+
*/
|
|
835
|
+
getSelectedVertices(): VertexSelection | null;
|
|
836
|
+
/**
|
|
837
|
+
* Deletes vertices of a feature in one change, and clears the vertex selection of that
|
|
838
|
+
* feature.
|
|
839
|
+
*
|
|
840
|
+
* A vertex whose deletion would leave its ring or part below the minimum (2 for a line,
|
|
841
|
+
* 3 for a polygon ring) is kept; the test is made per ring and per part, so the others are
|
|
842
|
+
* still deleted. Deleting a vertex of a MultiPoint removes that part, and the last part is
|
|
843
|
+
* kept.
|
|
844
|
+
*
|
|
845
|
+
* @param featureId the ID of the feature
|
|
846
|
+
* @param vertices the references of the vertices to delete
|
|
847
|
+
* @returns the number of vertices deleted; 0 when the feature does not exist
|
|
848
|
+
*
|
|
849
|
+
* @example
|
|
850
|
+
* ```typescript
|
|
851
|
+
* const selection = draw.getSelectedVertices();
|
|
852
|
+
* if (selection) {
|
|
853
|
+
* draw.deleteVertices(selection.featureId, selection.vertexIndices);
|
|
854
|
+
* }
|
|
855
|
+
* ```
|
|
856
|
+
*/
|
|
857
|
+
deleteVertices(featureId: string, vertices: VertexRef[]): number;
|
|
858
|
+
/**
|
|
859
|
+
* The geometry operations on features: union, subtract, intersect, buffer and split.
|
|
860
|
+
*
|
|
861
|
+
* When the arguments are omitted, the current selection is the target. The computation is
|
|
862
|
+
* done by the pure functions of `@sakuzu/maplibre-gl-draw/geometry`, and this namespace
|
|
863
|
+
* adds the selection, the transaction (one notification) and the `draw.geometry.applied`
|
|
864
|
+
* event.
|
|
865
|
+
*/
|
|
866
|
+
geometry: GeometryOperations;
|
|
867
|
+
/**
|
|
868
|
+
* Snapping: switching it at runtime and adding candidates.
|
|
869
|
+
*
|
|
870
|
+
* The coordinates of clicks, moves and drags are snapped before any mode sees them, so
|
|
871
|
+
* snapping works the same way in every mode and for vertex dragging. By default the
|
|
872
|
+
* candidates are the vertices and edges of the Store; more come from providers added with
|
|
873
|
+
* `draw.snapping.register()`. The initial settings are {@link Options.snap}.
|
|
874
|
+
*/
|
|
875
|
+
snapping: SnappingOperations;
|
|
876
|
+
/**
|
|
877
|
+
* Edge tracing: switching it at runtime.
|
|
878
|
+
*
|
|
879
|
+
* In draw_line / draw_polygon, when the previous click and this click both snapped to the
|
|
880
|
+
* boundary (a vertex or an edge) of the same feature, the boundary vertices between them
|
|
881
|
+
* are inserted automatically. It is enabled by default ({@link Options.trace}).
|
|
882
|
+
*/
|
|
883
|
+
tracing: TracingOperations;
|
|
884
|
+
/**
|
|
885
|
+
* Topology: switching at runtime the settings that keep editing from breaking boundaries
|
|
886
|
+
* shared by adjacent features.
|
|
887
|
+
*
|
|
888
|
+
* The initial settings are {@link Options.topology}. A switch takes effect from the next
|
|
889
|
+
* drag start.
|
|
890
|
+
*/
|
|
891
|
+
topology: TopologyOperations;
|
|
892
|
+
/**
|
|
893
|
+
* Synthetic input: clicks, moves and keys given to the modes from code.
|
|
894
|
+
*
|
|
895
|
+
* The events take the same path as real input, so snapping and the plugins see them in the
|
|
896
|
+
* same way. Use it for numeric input (a distance and a bearing, absolute coordinates), for
|
|
897
|
+
* tests and for automation. The input fields of a numeric input UI are not part of the
|
|
898
|
+
* library.
|
|
899
|
+
*/
|
|
900
|
+
input: InputOperations;
|
|
901
|
+
/**
|
|
902
|
+
* Adds a dataset: many features that are shown, with an attribute-driven
|
|
903
|
+
* style, but never edited.
|
|
904
|
+
*
|
|
905
|
+
* It is a path independent of the Store, meant for overlaying external data of tens of
|
|
906
|
+
* thousands of features. The features are not editable, not selectable with the selection
|
|
907
|
+
* UI, not on the undo history, not in the `draw.feature.*` events and not in
|
|
908
|
+
* {@link MapLibreGLDraw.export}. To edit one, copy it into the Store with
|
|
909
|
+
* {@link MapLibreGLDraw.addFeature}. Give either `features` or `provider`, not both.
|
|
910
|
+
* Emits `draw.dataset.add`.
|
|
911
|
+
*
|
|
912
|
+
* @param options the ID, the features or the provider, the style and the placement
|
|
913
|
+
* @returns the dataset, which is also how it is updated and removed
|
|
914
|
+
* @throws Error when the ID is already taken, when both `features` and `provider` are
|
|
915
|
+
* given, or when the instance has been destroyed
|
|
916
|
+
*
|
|
917
|
+
* @example
|
|
918
|
+
* ```typescript
|
|
919
|
+
* const dataset = draw.addDataset({
|
|
920
|
+
* id: 'districts',
|
|
921
|
+
* features: districtFeatures,
|
|
922
|
+
* styleRule: {
|
|
923
|
+
* kind: 'graduated',
|
|
924
|
+
* property: 'population',
|
|
925
|
+
* breaks: [1000, 5000, 10000],
|
|
926
|
+
* colors: ['#eff3ff', '#bdd7e7', '#6baed6', '#2171b5'],
|
|
927
|
+
* other: '#cccccc',
|
|
928
|
+
* },
|
|
929
|
+
* interactive: true,
|
|
930
|
+
* });
|
|
931
|
+
* dataset.on('click', ({ feature }) => console.log(feature.properties));
|
|
932
|
+
* ```
|
|
933
|
+
*/
|
|
934
|
+
addDataset(options: DatasetOptions): Dataset;
|
|
935
|
+
/**
|
|
936
|
+
* Gets a dataset by ID.
|
|
937
|
+
*
|
|
938
|
+
* @returns the dataset, or undefined when no dataset has the ID
|
|
939
|
+
*/
|
|
940
|
+
getDataset(id: string): Dataset | undefined;
|
|
941
|
+
/**
|
|
942
|
+
* Gets the datasets in display order (from the back to the front).
|
|
943
|
+
*
|
|
944
|
+
* It starts at the backmost of below-store and ends at the frontmost of above-store. The
|
|
945
|
+
* array is a copy; reorder with {@link MapLibreGLDraw.moveDataset}.
|
|
946
|
+
*/
|
|
947
|
+
getDatasets(): Dataset[];
|
|
948
|
+
/**
|
|
949
|
+
* Reorders a dataset.
|
|
950
|
+
*
|
|
951
|
+
* `order` changes the side (in front of or behind the Store) and `index` changes the
|
|
952
|
+
* position within that side (0 is the backmost; out-of-range values are clamped). When
|
|
953
|
+
* `index` is omitted, a dataset that changes side goes to the front of it, and one that
|
|
954
|
+
* stays keeps its position. The visibility, the features and the GPU resources are not
|
|
955
|
+
* affected, and hit testing follows the same order as the drawing. Emits
|
|
956
|
+
* `draw.dataset.reorder` when the order or the side changed.
|
|
957
|
+
*
|
|
958
|
+
* @param id the ID of the dataset
|
|
959
|
+
* @param placement the side and the position
|
|
960
|
+
* @returns true if it was moved (false for an ID that does not exist)
|
|
961
|
+
*
|
|
962
|
+
* @example
|
|
963
|
+
* ```typescript
|
|
964
|
+
* draw.moveDataset('parcels', { order: 'above-store' });
|
|
965
|
+
* draw.moveDataset('parcels', { index: 0 }); // to the back of its side
|
|
966
|
+
* ```
|
|
967
|
+
*/
|
|
968
|
+
moveDataset(id: string, placement: DatasetPlacement): boolean;
|
|
969
|
+
/**
|
|
970
|
+
* Removes a dataset and releases its GPU resources.
|
|
971
|
+
*
|
|
972
|
+
* Its ID is not removed from the stacking order; that is the caller's job when it was added
|
|
973
|
+
* with `order: 'layer-order'`. Emits `draw.dataset.remove` when it was removed.
|
|
974
|
+
*
|
|
975
|
+
* @param id the ID of the dataset
|
|
976
|
+
* @returns true if it was removed (false if it does not exist)
|
|
977
|
+
*/
|
|
978
|
+
removeDataset(id: string): boolean;
|
|
979
|
+
/**
|
|
980
|
+
* Subscribes to an event.
|
|
981
|
+
*
|
|
982
|
+
* See {@link EventPayloads} for the events and their payloads.
|
|
983
|
+
*
|
|
984
|
+
* @param event the event name
|
|
985
|
+
* @param handler the function called with the payload of each event
|
|
986
|
+
* @returns the function that unsubscribes the handler (the same as calling `off`)
|
|
987
|
+
*
|
|
988
|
+
* @example
|
|
989
|
+
* ```typescript
|
|
990
|
+
* const unsubscribe = draw.on('draw.features.change', ({ created, updated, deleted }) => {
|
|
991
|
+
* rebuildList();
|
|
992
|
+
* });
|
|
993
|
+
* // Later
|
|
994
|
+
* unsubscribe();
|
|
995
|
+
* ```
|
|
996
|
+
*/
|
|
997
|
+
on<K extends keyof EventPayloads>(event: K, handler: (data: EventPayloads[K]) => void): () => void;
|
|
998
|
+
/**
|
|
999
|
+
* Unsubscribes a handler given to {@link MapLibreGLDraw.on}.
|
|
1000
|
+
*
|
|
1001
|
+
* @param event the event name
|
|
1002
|
+
* @param handler the same function that was subscribed
|
|
1003
|
+
*/
|
|
1004
|
+
off<K extends keyof EventPayloads>(event: K, handler: (data: EventPayloads[K]) => void): void;
|
|
1005
|
+
/**
|
|
1006
|
+
* Loads data or a file.
|
|
1007
|
+
*
|
|
1008
|
+
* The kind of the source is detected: a `File` (a `.json` or `.geojson` file, or an image),
|
|
1009
|
+
* or an object in the native format or a GeoJSON FeatureCollection. The native format
|
|
1010
|
+
* replaces the existing data; GeoJSON and an image are added to it. The data is validated
|
|
1011
|
+
* before the Store changes, so a rejected load leaves the existing data as it was. A GeoJSON
|
|
1012
|
+
* feature whose geometry cannot be used is left out and listed in `skipped`, and one whose
|
|
1013
|
+
* ID is taken gets a new ID. The whole load is one transaction: a GeoJSON or image load is
|
|
1014
|
+
* one change, and a native load is notified with the source 'silent'.
|
|
1015
|
+
*
|
|
1016
|
+
* @param source a `File`, or a parsed native or GeoJSON object
|
|
1017
|
+
* @param options the placement of an image (required for an image file) and the handling
|
|
1018
|
+
* of Multi geometries
|
|
1019
|
+
* @returns the format that was detected, the IDs of the added features and what was
|
|
1020
|
+
* skipped
|
|
1021
|
+
* @throws Error (the Promise rejects) for an unsupported file or data format, a JSON file
|
|
1022
|
+
* that does not parse, native data that is malformed or of another major version, an
|
|
1023
|
+
* embedded image that is not accepted, or an image file without a coordinate
|
|
1024
|
+
*
|
|
1025
|
+
* @example
|
|
1026
|
+
* ```typescript
|
|
1027
|
+
* const result = await draw.load(file);
|
|
1028
|
+
* console.log(result.format, result.featureIds.length, result.skipped);
|
|
1029
|
+
*
|
|
1030
|
+
* // An image needs a coordinate
|
|
1031
|
+
* await draw.load(imageFile, {
|
|
1032
|
+
* coordinate: [139.767, 35.681],
|
|
1033
|
+
* zoom: map.getZoom(),
|
|
1034
|
+
* layerId: draw.getActiveLayer(),
|
|
1035
|
+
* });
|
|
1036
|
+
* ```
|
|
1037
|
+
*/
|
|
1038
|
+
load(source: File | unknown, options?: LoadOptions): Promise<LoadResult>;
|
|
1039
|
+
/**
|
|
1040
|
+
* Exports the data as a string in the given format.
|
|
1041
|
+
*
|
|
1042
|
+
* `native` holds everything (layers, groups, features, files and metadata) and loads back
|
|
1043
|
+
* as it was. `geojson` is a FeatureCollection that follows RFC 7946: rings follow the
|
|
1044
|
+
* right-hand rule, positions are rounded to 7 decimal places, and the FeatureCollection carries a
|
|
1045
|
+
* `bbox`.
|
|
1046
|
+
*
|
|
1047
|
+
* @param format `native` or `geojson`
|
|
1048
|
+
* @param options the features to include and the file name
|
|
1049
|
+
* @returns the data, its MIME type and a file name
|
|
1050
|
+
* @throws Error for an unsupported format
|
|
1051
|
+
*
|
|
1052
|
+
* @example
|
|
1053
|
+
* ```typescript
|
|
1054
|
+
* const { data, mimeType, fileName } = draw.export('geojson');
|
|
1055
|
+
* const url = URL.createObjectURL(new Blob([data], { type: mimeType }));
|
|
1056
|
+
* // Offer url for download as fileName
|
|
1057
|
+
*
|
|
1058
|
+
* // Only some features
|
|
1059
|
+
* draw.export('geojson', { featureIds: [idA, idB] });
|
|
1060
|
+
* ```
|
|
1061
|
+
*/
|
|
1062
|
+
export(format: ExportFormat, options?: ExportOptions): ExportResult;
|
|
1063
|
+
/**
|
|
1064
|
+
* Gets a file name for a native export: the metadata title (or `drawing`) with the date and
|
|
1065
|
+
* the time, such as `My map_2026-09-24_153000.maplibre-gl-draw.json`.
|
|
1066
|
+
*/
|
|
1067
|
+
getSuggestedFileName(): string;
|
|
1068
|
+
/** Gets the metadata of the document (the title, the description and so on) */
|
|
1069
|
+
getMetadata(): Metadata;
|
|
1070
|
+
/**
|
|
1071
|
+
* Updates the metadata; the fields left out keep their values. Emits
|
|
1072
|
+
* `draw.metadata.change`.
|
|
1073
|
+
*
|
|
1074
|
+
* @param metadata the fields to change
|
|
1075
|
+
* @returns true when applied; false when refused because the Store is read-only
|
|
1076
|
+
*
|
|
1077
|
+
* @example
|
|
1078
|
+
* ```typescript
|
|
1079
|
+
* draw.setMetadata({ title: 'Survey 2026', description: 'Field notes' });
|
|
1080
|
+
* ```
|
|
1081
|
+
*/
|
|
1082
|
+
setMetadata(metadata: Partial<Metadata>): boolean;
|
|
1083
|
+
/**
|
|
1084
|
+
* Destroys the instance: removes its layers and listeners from the map and unregisters
|
|
1085
|
+
* every plugin (each one's `onUninstall` runs).
|
|
1086
|
+
*
|
|
1087
|
+
* The registrations of the extension points (feature handlers, auxiliary handles, snapping
|
|
1088
|
+
* candidates and so on) belong to this instance and are cleared; another instance on the
|
|
1089
|
+
* page is not touched. What the instance changed on the map is given back as it was found
|
|
1090
|
+
* (box zoom, the `tabIndex` of the canvas). A second call does nothing.
|
|
1091
|
+
*
|
|
1092
|
+
* The calls made afterwards do not throw and reach neither the map nor a timer: a
|
|
1093
|
+
* registration is ignored and returns a cancel function that does nothing, and
|
|
1094
|
+
* {@link MapLibreGLDraw.addDataset} throws. The other calls work on the Store the
|
|
1095
|
+
* destroyed instance keeps in memory.
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* ```typescript
|
|
1099
|
+
* // In the teardown of a component
|
|
1100
|
+
* draw.destroy();
|
|
1101
|
+
* map.remove();
|
|
1102
|
+
* ```
|
|
1103
|
+
*/
|
|
1104
|
+
destroy(): void;
|
|
1105
|
+
/**
|
|
1106
|
+
* Adds a custom overlay renderer after initialization.
|
|
1107
|
+
*
|
|
1108
|
+
* An extension uses it to draw with WebGL behind the features (`background`), in front of
|
|
1109
|
+
* them (`foreground`) or in front of the selection UI (`overlay`). The renderer receives
|
|
1110
|
+
* `onAdd(gl, map)` when the rendering engine is built and `onRemove()` when it is torn down,
|
|
1111
|
+
* which can happen several times (after `setStyle`, after a lost WebGL context): create the
|
|
1112
|
+
* GL objects in `onAdd` and release them in `onRemove`.
|
|
1113
|
+
*
|
|
1114
|
+
* @param renderer the renderer to add
|
|
1115
|
+
* @returns a function that removes the renderer (it gets its onRemove when the rendering
|
|
1116
|
+
* is on the map)
|
|
1117
|
+
*/
|
|
1118
|
+
addOverlayRenderer(renderer: CustomOverlayRenderer): () => void;
|
|
1119
|
+
/**
|
|
1120
|
+
* Registers a plugin.
|
|
1121
|
+
*
|
|
1122
|
+
* The plugin's `onInstall` receives a {@link PluginContext}, its modes are registered and
|
|
1123
|
+
* its hooks are called from then on. The registration belongs to this instance.
|
|
1124
|
+
*
|
|
1125
|
+
* @param plugin the plugin to register
|
|
1126
|
+
* @returns a function that unregisters the plugin (its modes are removed and its
|
|
1127
|
+
* onUninstall runs); a plugin whose name is already registered is skipped, and the
|
|
1128
|
+
* function returned then does nothing
|
|
1129
|
+
*
|
|
1130
|
+
* @example
|
|
1131
|
+
* ```typescript
|
|
1132
|
+
* const unregister = draw.addPlugin({
|
|
1133
|
+
* name: 'logger',
|
|
1134
|
+
* onInstall(ctx) {
|
|
1135
|
+
* ctx.on('feature.create', ({ feature }) => console.log('created', feature.id));
|
|
1136
|
+
* },
|
|
1137
|
+
* });
|
|
1138
|
+
* ```
|
|
1139
|
+
*/
|
|
1140
|
+
addPlugin(plugin: Plugin): () => void;
|
|
1141
|
+
/**
|
|
1142
|
+
* Gets the API a plugin publishes (the `api` of the {@link Plugin}).
|
|
1143
|
+
*
|
|
1144
|
+
* @param name the name of the plugin
|
|
1145
|
+
* @returns the API, or undefined when no plugin of that name is registered or it publishes
|
|
1146
|
+
* none
|
|
1147
|
+
*/
|
|
1148
|
+
getPluginApi<T>(name: string): T | undefined;
|
|
1149
|
+
/**
|
|
1150
|
+
* Registers a custom mode, entered with {@link MapLibreGLDraw.setMode}.
|
|
1151
|
+
*
|
|
1152
|
+
* A mode that creates features declares `writesFeatures` on its handler: it is then entered
|
|
1153
|
+
* only while a layer can be written, and it reads `ModeContext.getCurrentLayerId()` again
|
|
1154
|
+
* when it commits (an empty string means no layer can be written: discard the drawing and
|
|
1155
|
+
* return to select). A mode consumes a double click or a key by calling
|
|
1156
|
+
* `event.originalEvent.preventDefault()`, so the map does not also zoom or pan.
|
|
1157
|
+
*
|
|
1158
|
+
* @param mode the name of the mode
|
|
1159
|
+
* @param factory creates the handler each time the mode is entered
|
|
1160
|
+
* @returns a function that removes the mode (select is entered first when it is the
|
|
1161
|
+
* current mode); it does nothing once the name has been registered again
|
|
1162
|
+
*
|
|
1163
|
+
* @example
|
|
1164
|
+
* ```typescript
|
|
1165
|
+
* const unregister = draw.registerMode('measure', () => new MeasureMode());
|
|
1166
|
+
* draw.setMode('measure');
|
|
1167
|
+
* ```
|
|
1168
|
+
*/
|
|
1169
|
+
registerMode(mode: Mode, factory: () => ModeHandler): () => void;
|
|
1170
|
+
/**
|
|
1171
|
+
* Registers a custom feature type: how it is drawn, hit, box selected, measured, resized
|
|
1172
|
+
* and snapped to.
|
|
1173
|
+
*
|
|
1174
|
+
* `type`, `renderer` and `hitTest` are required; the other parts fall back to the built-in
|
|
1175
|
+
* behavior. Registering re-measures the features of the type already in the Store. A part
|
|
1176
|
+
* registered for a built-in type replaces the built-in one until it is cancelled.
|
|
1177
|
+
*
|
|
1178
|
+
* @param handler the parts of the feature type
|
|
1179
|
+
* @returns a function that cancels every registration the handler made (renderer, hit
|
|
1180
|
+
* test, box selection, extents, resize, snapping); a part that another handler has
|
|
1181
|
+
* registered again for the type since is left in place
|
|
1182
|
+
*
|
|
1183
|
+
* @example
|
|
1184
|
+
* ```typescript
|
|
1185
|
+
* const unregister = draw.registerFeatureHandler({
|
|
1186
|
+
* type: 'Star',
|
|
1187
|
+
* renderer: new StarRenderer(),
|
|
1188
|
+
* hitTest: new StarHitTest(),
|
|
1189
|
+
* getBoundingBox: (feature) => starBounds(feature),
|
|
1190
|
+
* });
|
|
1191
|
+
* draw.addFeature({ type: 'Star', coordinates: [139.767, 35.681] });
|
|
1192
|
+
* ```
|
|
1193
|
+
*/
|
|
1194
|
+
registerFeatureHandler(handler: CustomFeatureHandler): () => void;
|
|
1195
|
+
/**
|
|
1196
|
+
* Registers a provider of auxiliary handles.
|
|
1197
|
+
*
|
|
1198
|
+
* It is the extension point for showing, on the selected feature, handles of your own that
|
|
1199
|
+
* are neither vertices nor resize handles, and for grabbing them. The rendering is the
|
|
1200
|
+
* responsibility of the registering side; the library only performs the hit testing and
|
|
1201
|
+
* the delegation of the drag.
|
|
1202
|
+
*
|
|
1203
|
+
* @param provider the provider to register
|
|
1204
|
+
* @returns a function that cancels the registration
|
|
1205
|
+
*/
|
|
1206
|
+
registerAuxiliaryHandleProvider(provider: AuxiliaryHandleProvider): () => void;
|
|
1207
|
+
/**
|
|
1208
|
+
* Registers a provider of companion rendering and companion hits.
|
|
1209
|
+
*
|
|
1210
|
+
* It is the extension point for drawing something just behind a feature (one step below it
|
|
1211
|
+
* in the stacking order) and for making it grabbable at the same position in the order of
|
|
1212
|
+
* a click. The library does not know the meaning of the companion, the rendering is the
|
|
1213
|
+
* responsibility of the registering side, and a click that hits is simply handed back to
|
|
1214
|
+
* the provider.
|
|
1215
|
+
*
|
|
1216
|
+
* @param provider the provider to register
|
|
1217
|
+
* @returns a function that cancels the registration
|
|
1218
|
+
*/
|
|
1219
|
+
registerFeatureCompanionProvider(provider: FeatureCompanionProvider): () => void;
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* The terrain diagnostics of a draw instance, as of the last frame it drew (see
|
|
1223
|
+
* {@link MapLibreGLDraw.getTerrainDiagnostics}).
|
|
1224
|
+
*
|
|
1225
|
+
* For debugging and measurement tools only: the fields follow the rendering and can change in
|
|
1226
|
+
* a minor release (it is a layer 2 type). Both values are snapshots of plain values that a
|
|
1227
|
+
* later frame does not change.
|
|
1228
|
+
*/
|
|
1229
|
+
export interface TerrainDiagnostics {
|
|
1230
|
+
/**
|
|
1231
|
+
* The terrain state the last frame drew with: whether the terrain was active, where the DEM
|
|
1232
|
+
* atlas lies, the subdivision step and its generation
|
|
1233
|
+
*/
|
|
1234
|
+
readonly render: TerrainRenderDiagnostics;
|
|
1235
|
+
/** Whether the last frame used the analytic drape, why not when it did not, and its counters */
|
|
1236
|
+
readonly drape: Readonly<TerrainDrapeDebug>;
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* The numbers of the terrain state a frame drew with, for diagnostics (see
|
|
1240
|
+
* {@link TerrainDiagnostics}). It is a layer 2 type and can change in a minor release.
|
|
1241
|
+
*/
|
|
1242
|
+
export interface TerrainRenderDiagnostics {
|
|
1243
|
+
/** Whether the terrain was enabled and the DEM atlas usable */
|
|
1244
|
+
readonly active: boolean;
|
|
1245
|
+
/** The Mercator rectangle the DEM atlas covers, [x0, y0, 1/width, 1/height] */
|
|
1246
|
+
readonly atlasRect: readonly [number, number, number, number];
|
|
1247
|
+
/** The number of texels of the DEM atlas, [width, height] */
|
|
1248
|
+
readonly atlasSize: readonly [number, number];
|
|
1249
|
+
/** The conversion factor from meters to Mercator z at the latitude of the screen center */
|
|
1250
|
+
readonly elevationScale: number;
|
|
1251
|
+
/** The lift above the ground in meters, against Z-fighting */
|
|
1252
|
+
readonly liftMeters: number;
|
|
1253
|
+
/** The subdivision step in meters (0 means no subdivision) */
|
|
1254
|
+
readonly stepMeters: number;
|
|
1255
|
+
/** The grid spacing of the subdivision, in Mercator units */
|
|
1256
|
+
readonly stepGrid: number;
|
|
1257
|
+
/** The generation of the subdivision (it counts the changes of the step, per instance) */
|
|
1258
|
+
readonly generation: number;
|
|
1259
|
+
}
|