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.

In your manifest.json:

"components": [{
"name": "MyComponent",
"references": [{
"name": "coordinateTransformer",
"providing": "coordinatetransformer.CoordinateTransformer"
}]
}]

In your code (MyComponent.ts):

import { InjectedReference } from "apprt-core/InjectedReference";
import { CoordinateTransformer } from "coordinatetransformer/CoordinateTransformer";
import { Geometry } from "esri/geometry";

export default class MyComponent {
private coordinateTransformer: InjectedReference<CoordinateTransformer>;
async transformToWGS84(geometry: Geometry): Promise<Geometry> {
const wgs84Code = 4326;
const transformedGeometry =
await this.coordinateTransformer!.transform(geometry, wgs84Code);
return transformedGeometry;
}
}
interface CoordinateTransformer {
    getProjection(srsCode: any): undefined | Projection;
    getProjections(): Promise<Projection[]>;
    transform<G extends BaseGeometry>(
        geometry: G,
        targetSRS: any,
        coordinateModificationCallback?: CoordinateModificationCallback,
    ): Promise<G>;
    transformExtent(
        extent: Extent,
        scale: number,
        targetSRS: any,
    ): Promise<Extent>;
}

Methods

  • Function to retrieve projection metadata for an EPSG code.

    Parameters

    • srsCode: any

      SRS code, i.e. "4326"

    Returns undefined | Projection

    resolving to a metadata object describing a projection.

  • Returns a list of metadata objects for available projections.

    Returns Promise<Projection[]>

    a list of all available projections.

  • Transforms a geometry or an array of geometries.

    Type Parameters

    • G extends BaseGeometry

    Parameters

    • geometry: G

      input geometry (may also be an array of geometries)

    • targetSRS: any

      target code for transformation

    • OptionalcoordinateModificationCallback: CoordinateModificationCallback

      can be used to pre-process point coordinates before transformation

    Returns Promise<G>

    the transformed geometry (if input was an array, output will be an array of transformed geometries)

  • Dedicated function to transform an extent based on center and scale.

    Parameters

    • extent: Extent

      input extent, which center is used

    • scale: number

      target scale for transformation

    • targetSRS: any

      SRS for transformation

    Returns Promise<Extent>

    the transformed extent