Function
Static Public Summary | ||
public |
get(crsUri: string): Projection | undefined Returns a stored Projection for a given URI, or undefined if no Projection is stored for that URI. |
|
public |
load(crsUri: string): Promise<Projection, Error> Returns a Promise that succeeds with an already stored Projection or, if not stored, that remotely loads the Projection (currently using http://epsg.io), stores it, and then succeeds with it. |
|
public |
set(crsUri: string, proj: string | Projection, options: Object): Projection |
Static Public
public get(crsUri: string): Projection | undefined source
import {get} from 'uriproj/'
Returns a stored Projection for a given URI, or undefined if no Projection is stored for that URI.
Params:
Name | Type | Attribute | Description |
crsUri | string | The CRS URI for which to return a Projection. |
Example:
// has to be stored previously via load() or set()
var proj = uriproj.get('http://www.opengis.net/def/crs/EPSG/0/27700')
var [longitude, latitude] = [-1.54, 55.5]
var [easting,northing] = proj.forward([longitude, latitude])
public load(crsUri: string): Promise<Projection, Error> source
import {load} from 'uriproj/'
Returns a Promise that succeeds with an already stored Projection or, if not stored, that remotely loads the Projection (currently using http://epsg.io), stores it, and then succeeds with it.
Params:
Name | Type | Attribute | Description |
crsUri | string | The CRS URI for which to return a projection. |
Return:
Promise<Projection, Error> | A Promise object succeeding with a Projection object, and failing with an Error object in case of network or PROJ.4 parsing problems. |
Example:
uriproj.load('http://www.opengis.net/def/crs/EPSG/0/27700').then(proj => {
var [longitude, latitude] = [-1.54, 55.5]
var [easting,northing] = proj.forward([longitude, latitude])
})
var uris = [
'http://www.opengis.net/def/crs/EPSG/0/27700',
'http://www.opengis.net/def/crs/EPSG/0/7376',
'http://www.opengis.net/def/crs/EPSG/0/7375']
Promise.all(uris.map(uriproj.load)).then(projs => {
// all projections are loaded and stored now
// get the first projection
var proj1 = projs[0]
// or:
var proj1 = uriproj.get(uris[0])
})
public set(crsUri: string, proj: string | Projection, options: Object): Projection source
import {set} from 'uriproj/'
Params:
Name | Type | Attribute | Description |
crsUri | string | The CRS URI for which to store the projection. |
|
proj | string | Projection | A proj4 string or a Projection object. |
|
options | Object |
|
Options object. |
options.reverseAxes | boolean |
|
If proj is a proj4 string, whether to reverse the projection axes. |
Throw:
If crsUri or proj is missing, or if a PROJ.4 string cannot be parsed by proj4js. |
Example:
var uri = 'http://www.opengis.net/def/crs/EPSG/0/27700'
var proj4 = '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 ' +
'+ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs'
uriproj.set(uri, proj4)
var uri = 'http://www.opengis.net/def/crs/EPSG/0/27700'
var proj = {
forward: ([lon,lat]) => [..., ...],
inverse: ([x,y]) => [..., ...]
}
uriproj.set(uri, proj)