import Point from '@arcgis/core/geometry/Point'; import Graphic from '@arcgis/core/Graphic'; import Layer from '@arcgis/core/layers/Layer'; import Sublayer from '@arcgis/core/layers/support/Sublayer'; import { MapWidgetModel } from 'map-widget/api'; import { Store } from 'store-api/api'; /** * Properties of a popup template. */ type PopupTemplateProperties = __esri.PopupTemplateProperties; /** * Definition of a popup template. */ type PopupTemplateDefinition = PopupTemplateProperties & { popupType?: string; customActions?: string[]; }; /** * Result returned when the template could not be resolved. */ interface UnknownPopupTemplate { /** * Fixed value 'unknown'. */ location: "unknown"; /** * Result is undefined. */ popupTemplate: undefined; /** * Result is undefined. */ layer: undefined; /** * Result is undefined. */ sublayer: undefined; } /** * Resolved PopupTemplate. */ interface ResolvedPopupTemplate { /** * Location where the template has been resolved from. */ location: "store" | "layer" | "sublayer"; /** * The resolved template. */ popupTemplate: PopupTemplateDefinition; /** * The layer, if the template has been resolved from a layer. */ layer?: Layer; /** * The Sublayer, if the template has been resolved from a sublayer. */ sublayer?: Sublayer; } /** * Properties checked on a store to resolve a popup template. */ interface StorePopupProperties { /** * Is the popup enabled? */ popupEnabled?: boolean; /** * The popup definition. */ popupTemplate?: PopupTemplateDefinition; /** * An layer id, which may have a popup definition. */ layerId?: string; } /** * Represents a store instance and the properties used by this bundle. */ type StoreInstance = Store & StorePopupProperties & { /** * For backwards compat the implementation will check for masterStore property. */ masterStore?: StoreInstance; }; /** * Parameters used to resolve Popup templates from stores or layers. */ interface PopupTemplateResolverParams { /** * Id of the store. */ storeId?: string; /** * Store. */ store?: StoreInstance; /** * Id of the layer. */ layerId?: string; /** * Optional MapWidgetModel, by default the global model is used. */ mapWidgetModel?: MapWidgetModel; /** * Stops resolving for templates at store level. */ resolveOnLayer?: boolean; } /** * Resolves popup templates for layers or stores. * * Use `popups.PopupTemplateResolver` as service name in your `manifest.json` * to get an PopupTemplateResolver instance. */ interface PopupTemplateResolver { /** * Resolves popup template for store or layer. * * Note that the source layer is required on a graphic (`.layer` property) if domain values should be resolved, * even if a popup template is resolved from a store. * * The popup template resolver returns the additional `layer` property if the original layer could be found, * which will point to the layer where the feature originates from. * * @example Resolve for store * ```ts * const { popupTemplate } = await resolver.resolvePopupTemplate({store: store}); * ``` * @example Resolve for storeId * ```ts * const { popupTemplate } = await resolver.resolvePopupTemplate({storeId: "my-store"}); * ``` * @example Resolve for layerId * ```ts * const { popupTemplate } = await resolver.resolvePopupTemplate({layerId: "countries"}); * ``` * @example Resolve for sub layerId * ```ts * const { popupTemplate } = await resolver.resolvePopupTemplate({layerId: "countries/2"}); * ``` */ resolvePopupTemplate(params: PopupTemplateResolverParams): Promise; } /** * Context provided to the {@link Action#trigger} method. * * The context contains all features in the popup and the selected one. */ interface ActionContext { /** * Array of all Graphic objects in the popup */ features: Graphic[]; /** * The currently selected Graphic of the popup. */ selectedFeature: Graphic; /** * The Point where the popup is positioned. */ location: Point; /** * Backreference to triggered action. */ action: Action; } /** * Methods which have to be implemented by Actions. */ interface ActionMethods { /** * Returns true, if the action is visible for a certain feature. * If this method is not provided, the default value is `true`. * * @param feature The feature. */ isVisibleForFeature?(feature: Graphic): boolean; /** * Triggers the action. * @param context Context of the action. */ trigger(context: ActionContext): void | Promise; } /** * Actions which can be executed in Popups. * * @see [@arcgis/core/support/actions/ActionBase](https://developers.arcgis.com/javascript/latest/api-reference/esri-support-actions-ActionBase.html) */ type Action = __esri.ActionButtonProperties & __esri.ActionToggleProperties & Required> & ActionMethods; /** * Factory for creating Actions. */ interface ActionFactory { /** * @returns A list action IDs supported by this factory. */ getTypes(): string[] | Promise; /** * Creates an {@link Action} instance. * * The returned action must either be an object of type {@link Action} * or an instance of a class derived from the class `popups/Action`. * * @example * ActionFactory returning a properties object * ```ts * export class TweetActionFactory implements ActionFactory { * createAction(type: string): Action | undefined { * return { * id: "tweetablePopups.action.tweet", * type: "button", * title: "Tweet Feature", * className: "esri-icon-share2", * trigger(context) { * // Code to be performed, when the action is triggered, * // for example if someone clicks the link that is displayed in the popup. * * const features = context.features; // All features that are hit by clicking on the map. * const selectedFeature = context.selectedFeature; // The selected and visible feature in the popup. * const location = context.location; // The point position where the popup is opened on the map. * * // Tweet it: for example selectedFeature.attributes.description ... * } * }; * } * getTypes(): string[] | Promise { * return ["tweet"]; * } * } * ``` * * @example * ActionFactory returning an instance from a class extending `popups/Action` * * ```ts * export class MyCustomAction extends Action { * trigger(context: ActionContext) { * // Do something when action is clicked * } * } * * export class MyCustomActionFactory implements ActionFactory { * getTypes(): string[] | Promise { * return ["mycustomaction"]; * } * createAction(type: string): Action | undefined { * return new MyCustomAction({ * id: type, * title: "customAction" * }); * } * } * ``` * * @param type Type ID of action to be created. * @returns action instance or undefined, if no Action could be created for this type. */ createAction(type: string): Action | undefined; } /** * Factory for creating {@link PopupDefinition} instances. */ interface PopupDefinitionFactory { /** * @returns List of popup types supported by this factory. */ getTypes(): string[] | Promise; /** * Creates a {@link PopupDefinition}. * * @param name Name of the popup. */ createPopupDefinition(name: string): PopupDefinition | undefined | Promise; } /** * Encapsulates the creation and lifecycle of PopupTemplates. */ interface PopupDefinition { /** * Provides a PopupTemplate (definition) for a layer. * Function is triggered by the custom popup engine to resolve PopupTemplate information as soon as a layer is * registered inside a map. * * @param layer Instance for which the popup template should be created. * @returns The resolved template, see https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html. */ resolvePopupTemplate(layer: Layer): PopupTemplateDefinition | undefined; /** * Provides a PopupTemplate (definition) for a store. * Function is triggered by the custom popup engine to resolve PopupTemplate information as soon as a store is * registered in the system. * * @param store Instance for which the popup template should be created. * @param storeProperties Additional information about the store instance. * @returns The resolved template, see https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html. */ resolvePopupTemplateForStore?(store: Store, storeProperties: Record): PopupTemplateDefinition | undefined | Promise; /** * Hook to cleanup resources cached for a given popuptemplate or layer. * * Function is triggered by the custom popup engine if a layer is removed from the map. * * @param layerOrStore instance (either {@link Layer} or {@link StoreInstance} * for which the popup template was created. */ cleanupPopupTemplate?(layerOrStore: Layer | Store): void; } export type { Action, ActionContext, ActionFactory, ActionMethods, PopupDefinition, PopupDefinitionFactory, PopupTemplateDefinition, PopupTemplateProperties, PopupTemplateResolver, PopupTemplateResolverParams, ResolvedPopupTemplate, StoreInstance, StorePopupProperties, UnknownPopupTemplate };