Simplify meters per unit handling

This commit is contained in:
Andreas Hocevar
2016-01-06 13:46:29 +01:00
parent 607d8ad154
commit 24f8cba0a1
5 changed files with 37 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ goog.provide('ol.proj.EPSG4326');
goog.require('ol.proj');
goog.require('ol.proj.Projection');
goog.require('ol.proj.Units');
goog.require('ol.sphere.WGS84');
@@ -27,6 +28,7 @@ ol.proj.EPSG4326_ = function(code, opt_axisOrientation) {
extent: ol.proj.EPSG4326.EXTENT,
axisOrientation: opt_axisOrientation,
global: true,
metersPerUnit: ol.proj.EPSG4326.METERS_PER_UNIT,
worldExtent: ol.proj.EPSG4326.EXTENT
});
};
@@ -50,6 +52,13 @@ ol.proj.EPSG4326_.prototype.getPointResolution = function(resolution, point) {
ol.proj.EPSG4326.EXTENT = [-180, -90, 180, 90];
/**
* @const
* @type {number}
*/
ol.proj.EPSG4326.METERS_PER_UNIT = Math.PI * ol.sphere.WGS84.radius / 180;
/**
* Projections equal to EPSG:4326.
*

View File

@@ -143,6 +143,12 @@ ol.proj.Projection = function(options) {
*/
this.defaultTileGrid_ = null;
/**
* @private
* @type {number|undefined}
*/
this.metersPerUnit_ = options.metersPerUnit;
var projections = ol.proj.projections_;
var code = options.code;
goog.asserts.assert(code !== undefined,
@@ -155,16 +161,11 @@ ol.proj.Projection = function(options) {
if (def.axis !== undefined && options.axisOrientation === undefined) {
this.axisOrientation_ = def.axis;
}
if (options.metersPerUnit === undefined) {
this.metersPerUnit_ = def.to_meter;
}
if (options.units === undefined) {
var units = def.units;
if (def.to_meter !== undefined) {
if (units === undefined ||
ol.proj.METERS_PER_UNIT[units] === undefined) {
units = def.to_meter.toString();
ol.proj.METERS_PER_UNIT[units] = def.to_meter;
}
}
this.units_ = units;
this.units_ = def.units;
}
var currentCode, currentDef, currentProj, proj4Transform;
for (currentCode in projections) {
@@ -227,12 +228,13 @@ ol.proj.Projection.prototype.getUnits = function() {
/**
* Get the amount of meters per unit of this projection. If the projection is
* not configured with a units identifier, the return is `undefined`.
* not configured with `metersPerUnit` or a units identifier, the return is
* `undefined`.
* @return {number|undefined} Meters.
* @api stable
*/
ol.proj.Projection.prototype.getMetersPerUnit = function() {
return ol.proj.METERS_PER_UNIT[this.units_];
return this.metersPerUnit_ || ol.proj.METERS_PER_UNIT[this.units_];
};