Class: Projection

ol/proj/Projection~Projection


import Projection from 'ol/proj/Projection';

Projection definition class. One of these is created for each projection supported in the application and stored in the module:ol/proj namespace. You can use these in applications, but this is not required, as API params and options use module:ol/proj~ProjectionLike which means the simple string code will suffice.

You can use module:ol/proj.get to retrieve the object for a particular projection.

The library includes definitions for EPSG:4326 and EPSG:3857, together with the following aliases:

If you use proj4js, aliases can be added using proj4.defs(). After all required projection definitions are added, call the module:ol/proj/proj4.register function.

new Projection(options)

Name Type Description
options

Projection options.

Name Type Description
code string

The SRS identifier code, e.g. EPSG:4326.

units module:ol/proj/Units | string

Units. Required unless a proj4 projection is defined for code.

extent module:ol/extent~Extent

The validity extent for the SRS.

axisOrientation string (defaults to 'enu')

The axis orientation as specified in Proj4.

global boolean (defaults to false)

Whether the projection is valid for the whole globe.

metersPerUnit number

The meters per unit for the SRS. If not provided, the units are used to get the meters per unit from the module:ol/proj/Units~METERS_PER_UNIT lookup table.

worldExtent module:ol/extent~Extent

The world extent for the SRS.

getPointResolution function

Function to determine resolution at a point. The function is called with a number view resolution and a Coordinate as arguments, and returns the number resolution in projection units at the passed coordinate. If this is undefined, the default getPointResolution() function will be used.

Methods

getAxisOrientation(){string}

Get the axis orientation of this projection. Example values are: enu - the default easting, northing, elevation. neu - northing, easting, up - useful for "lat/long" geographic coordinates, or south orientated transverse mercator. wnu - westing, northing, up - some planetary coordinate systems have "west positive" coordinate systems

Returns:
Axis orientation.

getCode(){string}

Get the code for this projection, e.g. 'EPSG:4326'.

Returns:
Code.

Get the validity extent for this projection.

Returns:
Extent.

getMetersPerUnit(){number|undefined}

Get the amount of meters per unit of this projection. If the projection is not configured with metersPerUnit or a units identifier, the return is undefined.

Returns:
Meters.

Get the units of this projection.

Returns:
Units.

Get the world extent for this projection.

Returns:
Extent.

isGlobal(){boolean}

Is this projection a global projection which spans the whole world?

Returns:
Whether the projection is global.

setExtent(extent)

Set the validity extent for this projection.

Name Type Description
extent module:ol/extent~Extent

Extent.

setGetPointResolution(func)

Set the getPointResolution function (see module:ol/proj.getPointResolution for this projection.

Name Type Description
func function

Function

setGlobal(global)

Set if the projection is a global projection which spans the whole world

Name Type Description
global boolean

Whether the projection is global.

setWorldExtent(worldExtent)

Set the world extent for this projection.

Name Type Description
worldExtent module:ol/extent~Extent

World extent [minlon, minlat, maxlon, maxlat].