/** EPSG codes for commonly used projections */ export enum EpsgCode { /** Pseudo WebMercator */ Google = 3857 , Wgs84 = 4326 , /** New Zealand transverse mercator */ Nztm2000 = 2193 , /** Chatham Islands transverse mercator */ Citm2000 = 3793 } const EPSGTextMap = { google : EpsgCode . Google , epsg3857 : EpsgCode . Google , [ EpsgCode . Google ] : EpsgCode . Google , globalmercator : EpsgCode . Google , wgs84 : EpsgCode . Wgs84 , epsg4326 : EpsgCode . Wgs84 , [ EpsgCode . Wgs84 ] : EpsgCode . Wgs84 , nztm : EpsgCode . Nztm2000 , epsg2193 : EpsgCode . Nztm2000 , [ EpsgCode . Nztm2000 ] : EpsgCode . Nztm2000 , nztm2000 : EpsgCode . Nztm2000 , citm : EpsgCode . Citm2000 , epsg3793 : EpsgCode . Citm2000 , [ EpsgCode . Citm2000 ] : EpsgCode . Citm2000 , citm2000 : EpsgCode . Citm2000 , } ; export class Epsg { static Codes = new Map < number , Epsg > ( ) ; static Google = new Epsg ( EpsgCode . Google ) ; static Wgs84 = new Epsg ( EpsgCode . Wgs84 ) ; static Nztm2000 = new Epsg ( EpsgCode . Nztm2000 ) ; static Citm2000 = new Epsg ( EpsgCode . Citm2000 ) ; code : EpsgCode ; constructor ( code ) { this . code = code ; if ( Epsg . Codes . has ( code ) ) throw new Error ( `Duplicate EPSG code created: ${ code }` ) ; Epsg . Codes . set ( this . code , this ) ; } /**  */ toString ( ) { return this . code . toString ( ) ; } /** Override JSON output to output just the EpsgCode */ toJSON ( ) { return this . code ; } example toEpsgString ( ) { return `EPSG:${ this . code }` ; } example toUrn ( ) { return `urn:ogc:def:crs:EPSG::${ this . code }` ; } param code public static get ( code ) { const epsg = Epsg . Codes . get ( code ) ; if ( epsg == null ) throw new Error ( `Invalid EPSG:${ code }` ) ; return epsg ; } param code public static tryGet ( code ? ) { if ( code == null ) return ; return Epsg . Codes . get ( code ) ; } /** parse a string returning the raw EpsgCode **/ public static parseCode ( text ) { if ( text . startsWith ( 'urn:' ) ) return EPSGTextMap [ text . slice ( text . lastIndexOf ( ':' ) + 1 ) ] ; if ( text . startsWith ( 'https://' ) ) return EPSGTextMap [ text . slice ( text . lastIndexOf ( '/' ) + 1 ) ] ; return EPSGTextMap [ text . replace ( /[\W_]/g , '' ) . toLowerCase ( ) ] ?? null ; } public static parse ( text ) { const code = Epsg . parseCode ( text ) ; if ( code == null ) return null ; return Epsg . get ( code ) ; } }