import { EventSource } from 'apprt-core/Events'; import { GeometryUnion } from '@arcgis/core/unionTypes'; import { PopupTemplateDefinition } from 'popups/api'; interface ActionItem { /** Arbitrary properties. */ readonly [key: string]: unknown; /** Some actions require an item geometry in order to work. */ readonly geometry?: GeometryUnion; } /** Shape of the `options` parameter passed to an action. */ interface ActionOptions { /** Arbitrary properties. */ readonly [key: string]: unknown; /** The items for which the action is triggered. */ readonly items?: readonly ActionItem[]; } /** * Options accepted by the HighlightAction. * The highlight action will create a new highlight for every item. * The items should have a geometry. */ interface HighlightActionOptions extends ActionOptions { /** * Custom symbol for highlighting (optional). * Use e.g. `highlight-symbol-point` to define a symbol for a point. */ readonly [key: string]: unknown; /** An array of objects with a geometry. */ readonly "items": readonly ActionItem[]; /** * The time in milliseconds until the drawn graphic will be removed from the * map again (optional). */ readonly "highlight-remove-timeout"?: number; } /** * Options accepted by the OpenPopupAction. * A popup will be opened for the specified item. */ interface OpenPopupActionOptions extends ActionOptions { /** An array of objects with a geometry. Only first is used. */ readonly "items": readonly ActionItem[]; /** A popupTemplate to use (optional). */ readonly "popupTemplate"?: PopupTemplateDefinition; /** A store which is used to find the popupTemplate (optional). */ readonly "source"?: any; /** * The time in milliseconds until the popup is hidden (optional). * Same property as HighlightAction. */ readonly "highlight-remove-timeout"?: number; } /** * Sets the view to the geometry of the items in the options' `items` property. * * @example * * ```ts * actionService.trigger(["zoomto"], { * items: [ * { * geometry: new Point({ * x: 7.5, * y: 52 * }) * } * ], * "zoomto-point-scale": 5000 * }); * ``` */ interface ZoomToActionOptions extends ActionOptions { /** * An array of objects with a geometry. * If multiple items are specified, then the union of their extents * will serve as the target geometry. */ readonly "items": readonly ActionItem[]; /** Specifies the scale to zoom to (optional). */ readonly "zoomto-scale"?: number; /** * Factor applied to the extent of a non-point input geometry (optional). * The expanded extent makes up the new zoom target geometry, * so for a factor > 1 you get more map context around the input geometry. */ readonly "zoomto-extent-expansion-factor"?: number; /** Specifies the scale to zoom to for points. */ readonly "zoomto-point-scale"?: number; /** Specifies additional animation options of the view.goTo method (optional). */ readonly "zoomto-animation-options"?: unknown; } /** This interface must be implemented by all components that provide `map-actions.Action`. */ interface Action { /** Unique id of this action. */ readonly id: string; /** * Actions are executed one by one. * This flag allows to run an action independently of all other actions. * */ readonly immediate?: boolean; /** `trigger()` is invoked with an array of items and arbitrary additional options. */ trigger(options?: ActionOptions): unknown | Promise; } interface ActionServiceEvents { "action-added": { readonly id: string; }; "action-removed": { readonly id: string; }; } /** * The ActionService provides access to `map-actions.Action` instances. * * An instance of this class can be referenced using the service name `map-actions.ActionService`. * The service can be used in different workflows to trigger the same functionality. * * The action service will emit events `action-added` and `action-removed` * when a new action is registered or an existing action is unregistered. * In both cases, an object `{id: "action-id"}` is passed to the event handler. */ interface ActionService extends EventSource { /** * Get currently available action ids. */ getActionIds(): string[]; /** * Checks if an action with the given ID exists. * * @param actionId ID of the action. */ hasAction(actionId: string): boolean; /** * Trigger the actions and return their response as a list of Promises. * * @param actionIds * List of action IDs to trigger. * To trigger all available actions pass a list with only one entry: `["*"]`. * @param options * Options to be passed to the actions. * This can, for example, include the items of a search result. * @returns List of Promises with the actions' result of their `trigger` methods. */ trigger(actionIds: readonly string[], options?: ActionOptions): Promise[]; } export type { Action, ActionItem, ActionOptions, ActionService, ActionServiceEvents, HighlightActionOptions, OpenPopupActionOptions, ZoomToActionOptions };