import { Geometry } from '@arcgis/core/geometry'; import SpatialReference from '@arcgis/core/geometry/SpatialReference'; import Extent from '@arcgis/core/geometry/Extent'; import BaseGeometry from '@arcgis/core/geometry/Geometry'; /** Helper type to represent an item or an array of items. */ type Items = T | T[]; /** Represents a point with x and y coordinates. */ interface Coordinates { /** The x coordinate. */ x: number; /** The y coordinate. */ y: number; } /** * Specifies a spatial reference system. * * @example Sample for different input variants * * ```ts * const wgs84String = "EPSG:4326"; * const wgs84Wkid = 4326; * * import SpatialReference from "@arcgis/core/geometry/SpatialReference"; * const wgs84 = new SpatialReference({wkid:4326}); * ``` */ type SrsParam = number | string | SpatialReference; /** * Represents a projection used by the coordinate transformer. * * @example * * ```json * { * "title" : "WGS84", * "srsCode" : "EPSG:4326", * "wkid": 4326, * "units" : "degree" * } * ``` */ interface Projection { /** The srs code. */ srsCode: string; /** A human readable title for this projection. */ title: string; /** The well known id associated with this projection (if available). */ wkid?: number | undefined; /** This projection mapped to a SpatialReference object. */ spatialReference: SpatialReference; /** The units used by this projection. */ units: string; } /** * A callback that may provide modified point coordinates. * * @param c The input coordinates. * @returns New coordinates or undefined if the input should remain unmodified. */ type CoordinateModificationCallback = (input: Readonly) => Coordinates | undefined; /** * A CoordinateTransformer transforms Esri geometries from one coordinate reference system to another. * Additionally it can be used to retrieve a list of available coordinate reference systems. * * Use `coordinatetransformer.CoordinateTransformer` to inject an instance of this service into your components. * * @example Use in own bundle * * In your manifest.json: * * ```json * "components": [{ * "name": "MyComponent", * "references": [{ * "name": "coordinateTransformer", * "providing": "coordinatetransformer.CoordinateTransformer" * }] * }] * ``` * * In your code (MyComponent.ts): * * ```ts * import { InjectedReference } from "apprt-core/InjectedReference"; * import { CoordinateTransformer } from "coordinatetransformer/CoordinateTransformer"; * import { Geometry } from "@arcgis/core/geometry"; * * export default class MyComponent { * private coordinateTransformer: InjectedReference; * async transformToWGS84(geometry: Geometry): Promise { * const wgs84Code = 4326; * const transformedGeometry = * await this.coordinateTransformer!.transform(geometry, wgs84Code); * return transformedGeometry; * } * } * ``` */ interface CoordinateTransformer { /** * Transforms a geometry or an array of geometries. * * @param geometry input geometry (may also be an array of geometries) * @param targetSRS target code for transformation * @param coordinateModificationCallback * can be used to pre-process point coordinates before transformation * @returns the transformed geometry * (if input was an array, output will be an array of transformed geometries) */ transform(geometry: G, targetSRS: SrsParam, coordinateModificationCallback?: CoordinateModificationCallback): Promise; transform(geometry: G[], targetSRS: SrsParam, coordinateModificationCallback?: CoordinateModificationCallback): Promise; transform(geometry: Items, targetSRS: SrsParam, coordinateModificationCallback?: CoordinateModificationCallback): Promise>; /** * Dedicated function to transform an extent based on center and scale. * * @param extent input extent, which center is used * @param scale target scale for transformation * @param targetSRS SRS for transformation * @returns the transformed extent */ transformExtent(extent: Extent, scale: number, targetSRS: SrsParam): Promise; /** * Function to retrieve projection metadata for an EPSG code. * * @param srsCode SRS code, i.e. "4326" * @returns resolving to a metadata object describing a projection. */ getProjection(srsCode: SrsParam): Projection | undefined; /** * Returns a list of metadata objects for available projections. * * @returns a list of all available projections. */ getProjections(): Promise; } export type { CoordinateModificationCallback, CoordinateTransformer, Coordinates, Items, Projection, SrsParam };