Allow getMetersPerUnit to work without units identifier (see #814)
This commit is contained in:
@@ -76,6 +76,12 @@ Proj4js.Proj.prototype.units;
|
||||
Proj4js.Proj.prototype.srsCode;
|
||||
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
Proj4js.Proj.prototype.to_meter;
|
||||
|
||||
|
||||
/**
|
||||
* @nosideeffects
|
||||
* @param {Proj4js.Proj} source
|
||||
|
||||
@@ -143,7 +143,15 @@ ol.Projection.prototype.getUnits = function() {
|
||||
* @return {number} Meters.
|
||||
*/
|
||||
ol.Projection.prototype.getMetersPerUnit = function() {
|
||||
return ol.METERS_PER_UNIT[this.units_];
|
||||
var metersPerUnit;
|
||||
if (!goog.isNull(this.units_)) {
|
||||
metersPerUnit = ol.METERS_PER_UNIT[this.units_];
|
||||
} else {
|
||||
if (this instanceof ol.Proj4jsProjection_) {
|
||||
metersPerUnit = this.getProj4jsProj().to_meter;
|
||||
}
|
||||
}
|
||||
return metersPerUnit;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -313,11 +313,31 @@ describe('ol.proj', function() {
|
||||
|
||||
describe('ol.Projection.prototype.getMetersPerUnit()', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
Proj4js.defs['EPSG:26782'] =
|
||||
'+proj=lcc +lat_1=29.3 +lat_2=30.7 +lat_0=28.66666666666667 ' +
|
||||
'+lon_0=-91.33333333333333 +x_0=609601.2192024384 +y_0=0 ' +
|
||||
'+ellps=clrk66 +datum=NAD27 +to_meter=0.3048006096012192 +no_defs';
|
||||
ol.proj.configureProj4jsProjection({
|
||||
code: 'EPSG:26782'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
ol.proj.proj4jsProjections_ = {};
|
||||
delete Proj4js.defs['EPSG:26782'];
|
||||
});
|
||||
|
||||
it('returns value in meters', function() {
|
||||
var epsg4326 = ol.proj.get('EPSG:4326');
|
||||
expect(epsg4326.getMetersPerUnit()).to.eql(111194.87428468118);
|
||||
});
|
||||
|
||||
it('works for proj4js projections without units', function() {
|
||||
var epsg26782 = ol.proj.get('EPSG:26782');
|
||||
expect(epsg26782.getMetersPerUnit()).to.eql(0.3048006096012192);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.proj.configureProj4jsProjection()', function() {
|
||||
|
||||
Reference in New Issue
Block a user