Merge pull request #290 from bbinet/projection_stuff
Add a getMetersPerUnit instance method to ol.Projection class
This commit is contained in:
@@ -33,6 +33,16 @@ ol.ProjectionUnits = {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const {Object.<ol.ProjectionUnits, number>} Meters per unit lookup table.
|
||||
*/
|
||||
ol.METERS_PER_UNIT = {};
|
||||
ol.METERS_PER_UNIT[ol.ProjectionUnits.DEGREES] =
|
||||
2 * Math.PI * ol.sphere.NORMAL.radius / 360;
|
||||
ol.METERS_PER_UNIT[ol.ProjectionUnits.FEET] = 0.3048;
|
||||
ol.METERS_PER_UNIT[ol.ProjectionUnits.METERS] = 1;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
@@ -109,6 +119,14 @@ ol.Projection.prototype.getUnits = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Meters.
|
||||
*/
|
||||
ol.Projection.prototype.getMetersPerUnit = function() {
|
||||
return ol.METERS_PER_UNIT[this.units_];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string} Axis orientation.
|
||||
*/
|
||||
|
||||
@@ -221,7 +221,6 @@ describe('ol.projection', function() {
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('ol.projection.getTransformFromCodes()', function() {
|
||||
|
||||
it('returns a function', function() {
|
||||
@@ -321,6 +320,15 @@ describe('ol.projection', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('ol.Projection.prototype.getMetersPerUnit()', function() {
|
||||
|
||||
it('returns value in meters', function() {
|
||||
var epsg4326 = ol.projection.getFromCode('EPSG:4326');
|
||||
expect(epsg4326.getMetersPerUnit()).toEqual(111194.87428468118);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.array');
|
||||
|
||||
Reference in New Issue
Block a user