Replace proj/Units enum with typedef

This commit is contained in:
Maximilian Krög
2022-07-17 00:36:18 +02:00
parent 361f1ab837
commit 7ac61fdc70
14 changed files with 52 additions and 93 deletions
+5 -5
View File
@@ -6,13 +6,13 @@ import {METERS_PER_UNIT} from './Units.js';
/**
* @typedef {Object} Options
* @property {string} code The SRS identifier code, e.g. `EPSG:4326`.
* @property {import("./Units.js").default|string} [units] Units. Required unless a
* @property {import("./Units.js").Units} [units] Units. Required unless a
* proj4 projection is defined for `code`.
* @property {import("../extent.js").Extent} [extent] The validity extent for the SRS.
* @property {string} [axisOrientation='enu'] The axis orientation as specified in Proj4.
* @property {boolean} [global=false] Whether the projection is valid for the whole globe.
* @property {number} [metersPerUnit] The meters per unit for the SRS.
* If not provided, the `units` are used to get the meters per unit from the {@link module:ol/proj/Units~METERS_PER_UNIT}
* If not provided, the `units` are used to get the meters per unit from the {@link METERS_PER_UNIT}
* lookup table.
* @property {import("../extent.js").Extent} [worldExtent] The world extent for the SRS.
* @property {function(number, import("../coordinate.js").Coordinate):number} [getPointResolution]
@@ -65,9 +65,9 @@ class Projection {
* `this.extent_` and `this.worldExtent_` must be configured properly for each
* tile.
* @private
* @type {import("./Units.js").default}
* @type {import("./Units.js").Units}
*/
this.units_ = /** @type {import("./Units.js").default} */ (options.units);
this.units_ = /** @type {import("./Units.js").Units} */ (options.units);
/**
* Validity extent of the projection in projected coordinates. For projections
@@ -153,7 +153,7 @@ class Projection {
/**
* Get the units of this projection.
* @return {import("./Units.js").default} Units.
* @return {import("./Units.js").Units} Units.
* @api
*/
getUnits() {
+25 -55
View File
@@ -3,58 +3,20 @@
*/
/**
* Projection units: `'degrees'`, `'ft'`, `'m'`, `'pixels'`, `'tile-pixels'` or
* `'us-ft'`.
* @enum {string}
* @typedef {'radians' | 'degrees' | 'ft' | 'm' | 'pixels' | 'tile-pixels' | 'us-ft'} Units
* Projection units.
*/
const Units = {
/**
* Radians
* @api
*/
RADIANS: 'radians',
/**
* Degrees
* @api
*/
DEGREES: 'degrees',
/**
* Feet
* @api
*/
FEET: 'ft',
/**
* Meters
* @api
*/
METERS: 'm',
/**
* Pixels
* @api
*/
PIXELS: 'pixels',
/**
* Tile Pixels
* @api
*/
TILE_PIXELS: 'tile-pixels',
/**
* US Feet
* @api
*/
USFEET: 'us-ft',
};
/**
* See http://duff.ess.washington.edu/data/raster/drg/docs/geotiff.txt
* @type {Object<number, Units>}
*/
const unitByCode = {
'9001': Units.METERS,
'9002': Units.FEET,
'9003': Units.USFEET,
'9101': Units.RADIANS,
'9102': Units.DEGREES,
'9001': 'm',
'9002': 'ft',
'9003': 'us-ft',
'9101': 'radians',
'9102': 'degrees',
};
/**
@@ -65,18 +27,26 @@ export function fromCode(code) {
return unitByCode[code];
}
/**
* @typedef {Object} MetersPerUnitLookup
* @property {number} radians Radians
* @property {number} degrees Degrees
* @property {number} ft Feet
* @property {number} m Meters
* @property {number} us-ft US feet
*/
/**
* Meters per unit lookup table.
* @const
* @type {Object<Units, number>}
* @type {MetersPerUnitLookup}
* @api
*/
export const METERS_PER_UNIT = {};
// use the radius of the Normal sphere
METERS_PER_UNIT[Units.RADIANS] = 6370997 / (2 * Math.PI);
METERS_PER_UNIT[Units.DEGREES] = (2 * Math.PI * 6370997) / 360;
METERS_PER_UNIT[Units.FEET] = 0.3048;
METERS_PER_UNIT[Units.METERS] = 1;
METERS_PER_UNIT[Units.USFEET] = 1200 / 3937;
export default Units;
export const METERS_PER_UNIT = {
// use the radius of the Normal sphere
'radians': 6370997 / (2 * Math.PI),
'degrees': (2 * Math.PI * 6370997) / 360,
'ft': 0.3048,
'm': 1,
'us-ft': 1200 / 3937,
};
+1 -2
View File
@@ -2,7 +2,6 @@
* @module ol/proj/epsg3857
*/
import Projection from './Projection.js';
import Units from './Units.js';
/**
* Radius of WGS84 sphere
@@ -48,7 +47,7 @@ class EPSG3857Projection extends Projection {
constructor(code) {
super({
code: code,
units: Units.METERS,
units: 'm',
extent: EXTENT,
global: true,
worldExtent: WORLD_EXTENT,
+1 -2
View File
@@ -2,7 +2,6 @@
* @module ol/proj/epsg4326
*/
import Projection from './Projection.js';
import Units from './Units.js';
/**
* Semi-major radius of the WGS84 ellipsoid.
@@ -42,7 +41,7 @@ class EPSG4326Projection extends Projection {
constructor(code, opt_axisOrientation) {
super({
code: code,
units: Units.DEGREES,
units: 'degrees',
extent: EXTENT,
axisOrientation: opt_axisOrientation,
global: true,
+1 -2
View File
@@ -2,7 +2,6 @@
* @module ol/proj/proj4
*/
import Projection from './Projection.js';
import Units from './Units.js';
import {
addCoordinateTransforms,
addEquivalentProjections,
@@ -33,7 +32,7 @@ export function register(proj4) {
const def = proj4.defs(code);
let units = def.units;
if (!units && def.projName === 'longlat') {
units = Units.DEGREES;
units = 'degrees';
}
addProjection(
new Projection({