/** EPSG codes for commonly used projections */
export var EpsgCode;
(function (EpsgCode) {
    /** Pseudo-Mercator */
    EpsgCode[EpsgCode["Google"] = 3857] = "Google";
    /** World Geodetic System 1984 */
    EpsgCode[EpsgCode["Wgs84"] = 4326] = "Wgs84";
    /** New Zealand Transverse Mercator */
    EpsgCode[EpsgCode["Nztm2000"] = 2193] = "Nztm2000";
    /** Chatham Islands Transverse Mercator */
    EpsgCode[EpsgCode["Citm2000"] = 3793] = "Citm2000";
})(EpsgCode || (EpsgCode = {}));
const EpsgText = {
    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 {
    constructor(code) {
        Object.defineProperty(this, "code", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        this.code = code;
        if (Epsg.Codes.has(code))
            throw new Error(`Duplicate EPSG code created: ${code}`);
        Epsg.Codes.set(this.code, this);
        EpsgText[code] = code;
    }
    /**  */
    toString() {
        return this.code.toString();
    }
    /** Override JSON output to output just the EpsgCode */
    toJSON() {
        return this.code;
    }
    /**
     * Convert a EPSG code into "EPSG:<code>""
     * @example "EPSG:2193"
     */
    toEpsgString() {
        return `EPSG:${this.code}`;
    }
    /**
     * convert a EPSG code into a URN
     * @example "urn:ogc:def:crs:EPSG::2193"
     */
    toUrn() {
        return `urn:ogc:def:crs:EPSG::${this.code}`;
    }
    /**
     * Get the EPSG instance for a specified code,
     *
     * throws a exception if the code is not recognized
     *
     * @param code
     */
    static get(code) {
        const epsg = Epsg.Codes.get(code);
        if (epsg == null)
            throw new Error(`Invalid EPSG:${code}`);
        return epsg;
    }
    /**
     * Try to find a corresponding epsg code for a number
     * @param code
     */
    static tryGet(code) {
        if (code == null)
            return;
        return Epsg.Codes.get(code);
    }
    /** parse a string returning the raw EpsgCode **/
    static parseCode(text) {
        if (text.startsWith('urn:'))
            return EpsgText[text.slice(text.lastIndexOf(':') + 1)];
        if (text.startsWith('https://'))
            return EpsgText[text.slice(text.lastIndexOf('/') + 1)];
        return EpsgText[text.replace(/[\W_]/g, '').toLowerCase()] ?? null;
    }
    static parse(text) {
        const code = Epsg.parseCode(text);
        if (code == null)
            return null;
        return Epsg.get(code);
    }
}
Object.defineProperty(Epsg, "Codes", {
    enumerable: true,
    configurable: true,
    writable: true,
    value: new Map()
});
Object.defineProperty(Epsg, "Google", {
    enumerable: true,
    configurable: true,
    writable: true,
    value: new Epsg(EpsgCode.Google)
});
Object.defineProperty(Epsg, "Wgs84", {
    enumerable: true,
    configurable: true,
    writable: true,
    value: new Epsg(EpsgCode.Wgs84)
});
Object.defineProperty(Epsg, "Nztm2000", {
    enumerable: true,
    configurable: true,
    writable: true,
    value: new Epsg(EpsgCode.Nztm2000)
});
Object.defineProperty(Epsg, "Citm2000", {
    enumerable: true,
    configurable: true,
    writable: true,
    value: new Epsg(EpsgCode.Citm2000)
});
//# sourceMappingURL=epsg.js.map