import CancelablePromise from 'apprt-core/CancelablePromise'; import { Geometry } from '@arcgis/core/geometry'; import { QueryExecutions } from 'store-api/QueryExecutions'; import { Store, QueryOptions, IndexableThing } from 'store-api/api'; import { Watchable } from 'apprt-core/Types'; import { ServiceProperties } from 'apprt/api'; /** * @module api */ /** * Declares common properties and defines the interface of all InputActions. */ interface SpatialInputAction { /** * The ID of this action. Required. */ readonly id: string; /** * The title shown as label on buttons. * Required. */ readonly title: string; /** * The description of this action. * Currently not used, but it is intended to provide the user a hint about this action in the future. * Optional. */ readonly description?: string; /** * The iconClass to provide a nice icon to the button related to this action. */ readonly iconClass: string; /** * By default a SpatialInputAction is assumed to be interactive. * But this can set to `false` explicitly. */ readonly interactive?: boolean; /** * Hook triggered before the {@link trigger} function is used, e.g. to show supporting widgets. * The {@link trigger} function maybe invoked multiple times after that method is invoked. */ enable?(): void; /** * Hook triggered after {@link enable} and after maybe 0 to n invocations of the {@link trigger} function * to indicate that this action is not longer in use e.g. to hide supporting widgets. * The trigger function may invoked multiple times after that method is invoked. */ disable?(): void; /** * Triggers this action. * @param options currently unspecified. */ trigger(options?: Record): Promise | CancelablePromise; } /** * Collects all registered selection-services.SpatialInputAction instances and provides access to them. * Registered as `selection-services.SpatialInputActionService` at the system. */ interface SpatialInputActionService extends Watchable<{ actions: ReadonlyArray; }> { /** * Array of all available action instances. */ readonly actions: ReadonlyArray; /** * Gets all action ids as array. */ getIds(): ReadonlyArray; /** * Gets action by ID or `undefined` if not found. * @param id ID of a {@link SpatialInputAction} to be returned. */ getById(id: string): SpatialInputAction | undefined; } /** * Searches the given sources using a given geometry. * Registered as `selection-services.SpatialSearchService` at the system. */ interface SpatialSearchService { /** * Searches the given sources. * @param sources search sources * @param geometry filter geometry * @param options modification flags */ search(sources: ReadonlyArray, geometry: Geometry, options: { returnIds: boolean; }): QueryExecutions; } /** * Represents a source for the spatial search. * The default implementation wraps the store api to match "normal" promises. * A SearchSource is created internally by the SearchSourceModel implementation. */ interface SearchSource { /** * The ID of the source. */ id: string; /** * The title of the source. */ title: string; /** * An optional description of the source. */ description?: string; /** * The layer ID of the layer if this store is backed by a map layer. */ layerId: string; /** * The underlying store. */ store: Store; /** * The store properties. */ storeProperties: ServiceProperties | undefined; /** * Optional search query modifiers. * Currently only the "operator" = "$intersects" can be changed. */ modifiers?: SpatialQueryModifier; /** * Queries for matching features. */ query(geometry: Geometry, opts?: QueryOptions & { returnIds?: boolean; }): CancelablePromise & { total: number; }>; } /** * A way to modify the spatial operator used by this source. */ interface SpatialQueryModifier { /** * modifies the operator used by the spatial search. */ operator: "$intersects" | "$contains" | "$crosses" | "$envelope-intersects" | "$overlaps" | "$touches" | "$within"; } /** * A model to manage search sources. * Registered as `selection-services.SearchSourceModel` at the system. */ interface SearchSourceModel extends Watchable<{ effectiveSources: SearchSource[]; hasEffectiveSources: boolean; allSources: SearchSource[]; hasSources: boolean; }> { /** * Gets sources which fulfill visibility constraints. */ readonly effectiveSources: ReadonlyArray; /** * true if effective sources available. */ readonly hasEffectiveSources: boolean; /** * Gets all registered search sources. */ readonly allSources: ReadonlyArray; /** * true if sources are available. */ readonly hasSources: boolean; /** * Gets source by id or `undefined` if not found. */ getSourceById(id: string): SearchSource | undefined; /** * Gets sources by the given ids. * The order of the result may not the same as the input array. * @param ids list of ids. */ getSourcesByIds(ids: string[]): ReadonlyArray; } /** * Encapsulates a selection process. * This trigger is used by the ui as kind of model. */ interface SelectionTrigger extends Watchable<{ active: boolean; sourceIds: string[]; searchAllSources: boolean; actionId: string | undefined; replaceExistingSelection: boolean | undefined; selectionFinishedNonEmpty: boolean | undefined; selectionIsRunning: boolean; }> { /** * A selection is currently active. * Only if the ui sets this to `true` a selection action activated to perform a selection. */ active: boolean; /** * Options to customize the selection actions. */ actionOptions: Record>; /** * Ids of stores to search. */ sourceIds: string[]; /** * Flag if all stores should be searched. * If true the sourceId list is ignored. */ searchAllSources: boolean; /** * Current selected spatial input action. */ actionId: string | undefined; /** * Flag to signal that the selection receiver should replace the last selection state * (if set to `true`) or try to to add it (if set to `false`). * If set to `undefined` the default behavior of the receiver should be used. */ replaceExistingSelection: boolean | undefined; /** * Flag if selection was finished successful or not. * `undefined` if no selection is running. */ selectionFinishedNonEmpty: boolean | undefined; /** * Flag if a selection process is currently running. */ selectionIsRunning: boolean; } /** * Options to init a SelectionTrigger. */ interface SelectionTriggerOptions { /** * Ids of stores to search. */ sourceIds?: string[]; /** * Flag to signal whether all stores should be searched. * If `true` the {@link sourceIds} list is ignored. */ searchAllSources?: boolean; /** * Currently selected spatial input action. */ actionId?: string | undefined; /** * Action options. * @example { rectangle: { ... }} */ actionOptions?: Record>; /** * Flag to signal whether the selection receiver should replace the last selection state * (if set to `true`) or try to add it (if set to `false`). * If set to `undefined` the default behavior of the receiver should be used. */ replaceExistingSelection?: boolean | undefined; } /** * A factory class to ensure that the required services are injected into the SelectionTrigger. * It is registered as `selection-services.SelectionTriggerFactory` to the system. */ interface SelectionTriggerFactory { /** * Informs about the capability of the SelectionReceiver to support adding of selections. * This is introduced, to allow the selection ui to detect if the user can choose * between adding and overwriting of selection results. * * Note: If `undefined` is returned, there is no SelectionReceiver available. */ selectionReceiverSupportsAdding: boolean | undefined; /** * Creates a SelectionTrigger instance. * @param options the options. */ create(options: SelectionTriggerOptions): SelectionTrigger; } /** * Result transported as topic event `selection/EXECUTING` or directly transported to a SelectionReceiver. */ interface SelectionResult { /** * The created query executions. */ executions: QueryExecutions; /** * Flag to signal whether existing selections should be replaced (if set to `true`) or added (if set to `false`). */ replaceExistingSelection?: boolean; } /** * An instance of this interface must be registered as `selection-services.SelectionReceiver`. */ interface SelectionReceiver { /** * Flag if the receiver supports adding new selection results to existing ones. */ supportsAdding?: boolean; /** * Receives a selection. * @param result the ongoing selection queries. */ receive(result: SelectionResult): void; } export type { SearchSource, SearchSourceModel, SelectionReceiver, SelectionResult, SelectionTrigger, SelectionTriggerFactory, SelectionTriggerOptions, SpatialInputAction, SpatialInputActionService, SpatialQueryModifier, SpatialSearchService };