Add export for ol.proj.METERS_PER_UNIT

This commit is contained in:
Bart van den Eijnden
2014-01-30 10:19:26 +01:00
parent 61ed9a106c
commit 1ada9dfea5
5 changed files with 15 additions and 10 deletions

View File

@@ -18,3 +18,5 @@
@exportSymbol ol.proj.configureProj4jsProjection @exportSymbol ol.proj.configureProj4jsProjection
@exportSymbol ol.proj.common.add @exportSymbol ol.proj.common.add
@exportSymbol ol.proj.METERS_PER_UNIT

View File

@@ -1,4 +1,5 @@
goog.provide('ol.proj'); goog.provide('ol.proj');
goog.provide('ol.proj.METERS_PER_UNIT');
goog.provide('ol.proj.Projection'); goog.provide('ol.proj.Projection');
goog.provide('ol.proj.ProjectionLike'); goog.provide('ol.proj.ProjectionLike');
goog.provide('ol.proj.Units'); goog.provide('ol.proj.Units');
@@ -51,11 +52,10 @@ ol.proj.Units = {
* @const * @const
* @type {Object.<ol.proj.Units, number>} * @type {Object.<ol.proj.Units, number>}
*/ */
ol.METERS_PER_UNIT = {}; ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES] =
ol.METERS_PER_UNIT[ol.proj.Units.DEGREES] =
2 * Math.PI * ol.sphere.NORMAL.radius / 360; 2 * Math.PI * ol.sphere.NORMAL.radius / 360;
ol.METERS_PER_UNIT[ol.proj.Units.FEET] = 0.3048; ol.proj.METERS_PER_UNIT[ol.proj.Units.FEET] = 0.3048;
ol.METERS_PER_UNIT[ol.proj.Units.METERS] = 1; ol.proj.METERS_PER_UNIT[ol.proj.Units.METERS] = 1;
@@ -153,7 +153,7 @@ ol.proj.Projection.prototype.getUnits = function() {
* @return {number|undefined} Meters. * @return {number|undefined} Meters.
*/ */
ol.proj.Projection.prototype.getMetersPerUnit = function() { ol.proj.Projection.prototype.getMetersPerUnit = function() {
return ol.METERS_PER_UNIT[this.units_]; return ol.proj.METERS_PER_UNIT[this.units_];
}; };
@@ -240,7 +240,7 @@ goog.inherits(ol.Proj4jsProjection_, ol.proj.Projection);
ol.Proj4jsProjection_.prototype.getMetersPerUnit = function() { ol.Proj4jsProjection_.prototype.getMetersPerUnit = function() {
var metersPerUnit = this.proj4jsProj_.to_meter; var metersPerUnit = this.proj4jsProj_.to_meter;
if (!goog.isDef(metersPerUnit)) { if (!goog.isDef(metersPerUnit)) {
metersPerUnit = ol.METERS_PER_UNIT[this.units_]; metersPerUnit = ol.proj.METERS_PER_UNIT[this.units_];
} }
return metersPerUnit; return metersPerUnit;
}; };

View File

@@ -7,6 +7,7 @@ goog.require('ol.TileCoord');
goog.require('ol.TileRange'); goog.require('ol.TileRange');
goog.require('ol.array'); goog.require('ol.array');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.proj.METERS_PER_UNIT');
goog.require('ol.proj.Projection'); goog.require('ol.proj.Projection');
goog.require('ol.proj.Units'); goog.require('ol.proj.Units');
@@ -417,7 +418,7 @@ ol.tilegrid.createForProjection =
function(projection, opt_maxZoom, opt_tileSize) { function(projection, opt_maxZoom, opt_tileSize) {
var projectionExtent = projection.getExtent(); var projectionExtent = projection.getExtent();
var size = goog.isNull(projectionExtent) ? var size = goog.isNull(projectionExtent) ?
360 * ol.METERS_PER_UNIT[ol.proj.Units.DEGREES] / 360 * ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES] /
projection.getMetersPerUnit() : projection.getMetersPerUnit() :
Math.max(projectionExtent[2] - projectionExtent[0], Math.max(projectionExtent[2] - projectionExtent[0],
projectionExtent[3] - projectionExtent[1]); projectionExtent[3] - projectionExtent[1]);

View File

@@ -16,6 +16,7 @@ goog.require('ol.View');
goog.require('ol.coordinate'); goog.require('ol.coordinate');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.proj'); goog.require('ol.proj');
goog.require('ol.proj.METERS_PER_UNIT');
goog.require('ol.proj.Projection'); goog.require('ol.proj.Projection');
goog.require('ol.proj.Units'); goog.require('ol.proj.Units');
@@ -544,8 +545,8 @@ ol.View2D.createResolutionConstraint_ = function(options) {
.getExtent(); .getExtent();
var size = goog.isNull(projectionExtent) ? var size = goog.isNull(projectionExtent) ?
// use an extent that can fit the whole world if need be // use an extent that can fit the whole world if need be
360 * ol.METERS_PER_UNIT[ol.proj.Units.DEGREES] / 360 * ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES] /
ol.METERS_PER_UNIT[projection.getUnits()] : ol.proj.METERS_PER_UNIT[projection.getUnits()] :
Math.max(projectionExtent[2] - projectionExtent[0], Math.max(projectionExtent[2] - projectionExtent[0],
projectionExtent[3] - projectionExtent[1]); projectionExtent[3] - projectionExtent[1]);
maxResolution = size / ol.DEFAULT_TILE_SIZE; maxResolution = size / ol.DEFAULT_TILE_SIZE;

View File

@@ -196,7 +196,7 @@ describe('ol.tilegrid.TileGrid', function() {
var grid = ol.tilegrid.createForProjection(projection); var grid = ol.tilegrid.createForProjection(projection);
var resolutions = grid.getResolutions(); var resolutions = grid.getResolutions();
expect(resolutions[5]).to.be( expect(resolutions[5]).to.be(
360 * ol.METERS_PER_UNIT[ol.proj.Units.DEGREES] / 360 * ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES] /
ol.DEFAULT_TILE_SIZE / Math.pow(2, 5)); ol.DEFAULT_TILE_SIZE / Math.pow(2, 5));
}); });
@@ -645,6 +645,7 @@ describe('ol.tilegrid.TileGrid', function() {
goog.require('ol.Coordinate'); goog.require('ol.Coordinate');
goog.require('ol.TileCoord'); goog.require('ol.TileCoord');
goog.require('ol.proj'); goog.require('ol.proj');
goog.require('ol.proj.METERS_PER_UNIT');
goog.require('ol.proj.Projection'); goog.require('ol.proj.Projection');
goog.require('ol.proj.Units'); goog.require('ol.proj.Units');
goog.require('ol.tilegrid.TileGrid'); goog.require('ol.tilegrid.TileGrid');