"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryParseArbitraryCs = exports.getMapSize = exports.getUnitOfMeasure = exports.getUnits = exports.getUnitsOfMeasure = void 0;
var i18n_1 = require("../api/i18n");
var common_1 = require("../api/common");
var string_1 = require("./string");
var mUnits = [
    { name: "Unknown", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_UNKNOWN", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_UNKNOWN", locale); }, unitsPerMeter: 1.0, metersPerUnit: 1.0 },
    { name: "Inches", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_INCHES", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_INCHES", locale); }, unitsPerMeter: 39.370079, metersPerUnit: 0.0254 },
    { name: "Feet", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_FEET", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_FEET", locale); }, unitsPerMeter: 3.2808, metersPerUnit: 0.3048 },
    { name: "Yards", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_YARDS", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_YARDS", locale); }, unitsPerMeter: 1.0936133, metersPerUnit: 0.9144 },
    { name: "Miles", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_MILES", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_MILES", locale); }, unitsPerMeter: 0.00062137, metersPerUnit: 1609.344 },
    { name: "Nautical Miles", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_NAUT_MILES", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_NAUT_MILES", locale); }, unitsPerMeter: 0.000539956803, metersPerUnit: 1852 },
    { name: "Millimeters", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_MILLIMETERS", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_MILLIMETERS", locale); }, unitsPerMeter: 1000.0, metersPerUnit: 0.001 },
    { name: "Centimeters", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_CENTIMETERS", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_CENTIMETERS", locale); }, unitsPerMeter: 100.0, metersPerUnit: 0.01 },
    { name: "Meters", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_METERS", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_METERS", locale); }, unitsPerMeter: 1.0, metersPerUnit: 1.0 },
    { name: "Kilometers", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_KILOMETERS", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_KILOMETERS", locale); }, unitsPerMeter: 0.001, metersPerUnit: 1000.0 },
    { name: "Degrees", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_DEGREES", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_DEGREES", locale); }, unitsPerMeter: 0.000009044, metersPerUnit: 111061.75033 },
    { name: "Decimal Degrees", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_DEC_DEGREES", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_DEC_DEGREES", locale); }, unitsPerMeter: 0.000009044, metersPerUnit: 111061.75033 },
    { name: "Degrees Minutes Seconds", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_DMS", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_DMS", locale); }, unitsPerMeter: 0.000009044, metersPerUnit: 111061.75033 },
    { name: "Pixels", localizedName: function (locale) { return (0, i18n_1.tr)("UNIT_PIXELS", locale); }, abbreviation: function (locale) { return (0, i18n_1.tr)("UNIT_ABBR_PIXELS", locale); }, unitsPerMeter: 1.0, metersPerUnit: 1.0 }
];
/**
 * Gets all available units of measure
 * @since 0.12.2
 */
function getUnitsOfMeasure() {
    return [
        common_1.UnitOfMeasure.Centimeters,
        common_1.UnitOfMeasure.DecimalDegrees,
        common_1.UnitOfMeasure.Degrees,
        common_1.UnitOfMeasure.DMS,
        common_1.UnitOfMeasure.Feet,
        common_1.UnitOfMeasure.Inches,
        common_1.UnitOfMeasure.Kilometers,
        common_1.UnitOfMeasure.Meters,
        common_1.UnitOfMeasure.Miles,
        common_1.UnitOfMeasure.Millimeters,
        common_1.UnitOfMeasure.NauticalMiles,
        common_1.UnitOfMeasure.Pixels,
        common_1.UnitOfMeasure.Unknown,
        common_1.UnitOfMeasure.Yards
    ];
}
exports.getUnitsOfMeasure = getUnitsOfMeasure;
/**
 * @deprecated Use getUnitsOfMeasure() instead
 */
function getUnits() {
    return [
        [common_1.UnitOfMeasure.Centimeters, "Centimeters"],
        [common_1.UnitOfMeasure.DecimalDegrees, "Decimal Degrees"],
        [common_1.UnitOfMeasure.Degrees, "Degrees"],
        [common_1.UnitOfMeasure.DMS, "Degrees Minutes Seconds"],
        [common_1.UnitOfMeasure.Feet, "Feet"],
        [common_1.UnitOfMeasure.Inches, "Inches"],
        [common_1.UnitOfMeasure.Kilometers, "Kilometers"],
        [common_1.UnitOfMeasure.Meters, "Meters"],
        [common_1.UnitOfMeasure.Miles, "Miles"],
        [common_1.UnitOfMeasure.Millimeters, "Millimeters"],
        [common_1.UnitOfMeasure.NauticalMiles, "Nautical Miles"],
        [common_1.UnitOfMeasure.Pixels, "Pixels"],
        [common_1.UnitOfMeasure.Unknown, "Unknown"],
        [common_1.UnitOfMeasure.Yards, "Yards"]
    ];
}
exports.getUnits = getUnits;
function getUnitOfMeasure(unit) {
    var u = mUnits[unit];
    return u || mUnits[0]; //The unknown unit
}
exports.getUnitOfMeasure = getUnitOfMeasure;
/**
 * Utility function to compute the physical map size based on the given display size and various display settings
 *
 * @since 0.11
 * @export
 * @param {[number, number]} displaySize
 * @param {number} metersPerUnit
 * @param {UnitOfMeasure} units
 * @param {number} [resolution]
 * @param {number} [precision]
 * @returns {[number, number]}
 */
function getMapSize(displaySize, metersPerUnit, units, resolution, precision) {
    var width = displaySize[0], height = displaySize[1];
    var gw = width;
    var gh = height;
    var uom = getUnitOfMeasure(units);
    if (resolution && units != common_1.UnitOfMeasure.Pixels) {
        gw = resolution * width;
        gh = resolution * height;
        if (units != common_1.UnitOfMeasure.Unknown) {
            gw = uom.unitsPerMeter * gw * metersPerUnit;
            gh = uom.unitsPerMeter * gh * metersPerUnit;
        }
        var prec = precision || 2;
        if (prec >= 0) {
            var factor = Math.pow(10, prec);
            gw = Math.round(gw * factor) / factor;
            gh = Math.round(gh * factor) / factor;
        }
    }
    return [gw, gh];
}
exports.getMapSize = getMapSize;
/**
 * Attempts to be parse unit information for the given mentor CS code
 *
 * @param csCode
 * @since 0.14.3
 * @returns
 */
function tryParseArbitraryCs(csCode) {
    if (!(0, string_1.strIsNullOrEmpty)(csCode) && (0, string_1.strStartsWith)(csCode, "XY-")) {
        // We'll only cover arbitrary CSes that are clearly mappable to our UOM set
        var suffix = csCode.substring(3);
        switch (suffix) {
            case "M":
                return { code: csCode, units: common_1.UnitOfMeasure.Meters };
            case "FT":
                return { code: csCode, units: common_1.UnitOfMeasure.Feet };
            case "IN":
                return { code: csCode, units: common_1.UnitOfMeasure.Inches };
            case "CM":
                return { code: csCode, units: common_1.UnitOfMeasure.Centimeters };
            case "KM":
                return { code: csCode, units: common_1.UnitOfMeasure.Kilometers };
            case "YD":
                return { code: csCode, units: common_1.UnitOfMeasure.Yards };
            case "MM":
                return { code: csCode, units: common_1.UnitOfMeasure.Millimeters };
            case "MI":
                return { code: csCode, units: common_1.UnitOfMeasure.Miles };
            case "NM":
                return { code: csCode, units: common_1.UnitOfMeasure.NauticalMiles };
            case "PX": //Not supported by MapGuide, but our own defn to support static images
                return { code: csCode, units: common_1.UnitOfMeasure.Pixels };
        }
    }
    return undefined;
}
exports.tryParseArbitraryCs = tryParseArbitraryCs;
//# sourceMappingURL=units.js.map