import Collection from '@arcgis/core/core/Collection'; import Graphic from '@arcgis/core/Graphic'; import esriSymbol from '@arcgis/core/symbols/Symbol'; import { ViewMode, MapWidgetModel } from 'map-widget/api'; export { ViewMode } from 'map-widget/api'; /** * Represents a highlight on a map. * Instances of this type can only be obtained through a {@link Highlighter}. */ interface Highlight { /** * Returns `true` if the highlight is still being displayed (i.e. it has not been removed yet). */ active(): boolean; /** * Removes the highlight. * * Does nothing if the highlight is no longer active. */ remove(): void; /** * Gets the graphic instances that are currently being displayed for this highlight. * NOTE: This may return `undefined` also if active is true. * This can happen if the highlight is rendered asynchronously. * Currently there is no way to wait for the graphics. * You need to poll this method until it returns a value. */ getGraphics(): Graphic[] | undefined; } /** * Type of the geometry as used in the ESRI API. Possible values are * * - point * - polyline * - polygon * - point-3d * - polyline-3d * - polygon-3d */ type GeometryType = string; /** * Properties for default symbols. * Properties must contain all properties required by * [@arcgis/core/Symbol](https://developers.arcgis.com/javascript/latest/api-reference/esri-symbols-Symbol.html) * and its derived classes. */ type SymbolProperties = Record; /** * Configuration of the highlight bundle. * Key: type of geometry. * Value: properties for the geometry type. */ type HighlightBundleConfig = Record; /** * Options used when highlighting an object. */ interface HighlightOptions { /** * Timeout in milliseconds. * The highlight is automatically removed if this value is greater than 0. */ timeout?: number; } /** * Graphic properties supported by the highlighter. */ interface HighlightGraphic extends Partial { /** * The given three dimensional symbol will be used to create the highlight if * the view is in "3D" mode at the time of creation. */ symbol3D?: esriSymbol; /** * Template for maptips. * * Requires maptip bundle. */ maptipTemplate?: any; } /** * The Highlighter class can be used to create highlights on a MapWidgetModel. * You should use either the {@link HighlightService} or the {@link HighlighterFactory} to * obtain an instance of this type: * * The {@link HighlightService} provides a Highlighter instance that operates on the default MapWidgetModel. * This should be sufficient for most use cases. * * The {@link HighlighterFactory} can create Highlighter instances for custom MapWidgetModel instances. * This can be useful, for example, to support multiple map views. */ interface Highlighter { /** * This function must be called to release resources used by this object when it is no longer needed. */ destroy(): void; /** * Returns the default symbol for the given geometry. * * @param geometryType The geometry type to highlight (as used in the esri API). * @param viewmode The viewmode must be either "2D" (the default) or "3D". * The function will fall back to 2D symbols if 3D symbols are requested but unavailable. */ getDefaultSymbol(geometryType: GeometryType, viewmode?: ViewMode): SymbolProperties | undefined; /** * Highlights the given object. The returned object represents the new highlight on the map. * Calling the {@link Highlight.remove} function on that object will manually remove the highlight. * * @param graphicObject * The object to be highlighted. This can be either an esri `Graphic` object, * a plain javascript `Object`, or an `Array` of such objects. * * If plain objects are passed to this function, they will be used as templates * to create a new Graphic object for each of them. * * The object *must* have a valid geometry. All other properties are optional. A default * symbol will be chosen if not specified. * * Use the optional `symbol3D` property to specify a 3D symbol. If the map widget is * in 3D mode at the time the highlight is created, the 3D symbol will be used to * render the highlight. * * @param options Additional highlight options. * @returns A new Highlight instance. Returns `undefined` if the given graphics * are not of type `object`. */ highlight(graphicObject: Partial | Partial[], options?: HighlightOptions): Highlight; /** * Removes all existing highlights. */ clear(): void; } /** * This service provides a {@link Highlighter} instance that operates on the * default MapWidgetModel. The service can be injected via `"highlights.HighlightService"`. */ interface HighlightService { /** * Creates a {@link Highlighter} instance. */ createInstance(): Highlighter; /** * Destroys a {@link Highlighter} instance. */ destroyInstance(instance: Highlighter): void; } /** * Resolves a graphics collection for the given mapWidgetModel. */ type GraphicsCollectionResolver = (mapWidgetModel: any) => Collection | undefined; /** * Options used to create {@link Highlighter} instances by a {@link HighlighterFactory}. */ interface HighlighterFactoryOptions { /** * A callback providing a collection to which the highlight graphics are added. * The callback will be invoked whenever the model's view changes (e.g. when switching from 2D to 3D). * * In practice, this function should return the graphics collection of a graphics layer (or equivalent). * The highlights created by this bundle will be added to (and removed from) that collection. * * The default implementation resolves to `mapWidgetModel.view.graphics`. */ graphicsCollectionResolver?: GraphicsCollectionResolver; } /** * Factory to create new {@link Highlighter} instances. * It can be injected as a component via `"highlights.HighlighterFactory"`. */ interface HighlighterFactory { /** * Returns a new {@link Highlighter} instance for the given map widget model. * * @param mapWidgetModel The map widget model on which highlights should be drawn. * @param options additional options * * @example highlighter for mapwidget model * ```ts * // inject factory as `highlights.HighlighterFactory` * // inject model as `map-widget.MapWidgetModel` * const highlighter = factory.forMapWidgetModel(model); * highlighter.highlight(graphic); * // later clean up * highlighter.destroy(); * ``` * * @example highlighter using custom collection * ```ts * const graphicsLayer = new GraphicsLayer(); * const graphics = graphicsLayer.graphics; * const highlighter = factory.forMapWidgetModel(model, { graphicsCollectionResolver: (model) => graphics }); * // now highlights are added to the custom GraphicsLayer. * ``` */ forMapWidgetModel(mapWidgetModel: MapWidgetModel, options?: HighlighterFactoryOptions): Highlighter; } export type { GeometryType, GraphicsCollectionResolver, Highlight, HighlightBundleConfig, HighlightGraphic, HighlightOptions, HighlightService, Highlighter, HighlighterFactory, HighlighterFactoryOptions, SymbolProperties };