Allow strings to be used wherever projections are needed

This commit is contained in:
Tom Payne
2013-03-06 18:48:53 +01:00
parent afcbec469a
commit eaa17758bd
8 changed files with 45 additions and 30 deletions

View File

@@ -11,7 +11,7 @@
@exportObjectLiteralProperty ol.View2DOptions.center ol.Coordinate|undefined
@exportObjectLiteralProperty ol.View2DOptions.maxResolution number|undefined
@exportObjectLiteralProperty ol.View2DOptions.numZoomLevels number|undefined
@exportObjectLiteralProperty ol.View2DOptions.projection ol.Projection|string|undefined
@exportObjectLiteralProperty ol.View2DOptions.projection ol.ProjectionLike
@exportObjectLiteralProperty ol.View2DOptions.resolution number|undefined
@exportObjectLiteralProperty ol.View2DOptions.resolutions Array.<number>|undefined
@exportObjectLiteralProperty ol.View2DOptions.rotation number|undefined
@@ -61,7 +61,7 @@
@exportObjectLiteral ol.control.MousePositionOptions
@exportObjectLiteralProperty ol.control.MousePositionOptions.coordinateFormat ol.CoordinateFormatType|undefined
@exportObjectLiteralProperty ol.control.MousePositionOptions.map ol.Map|undefined
@exportObjectLiteralProperty ol.control.MousePositionOptions.projection ol.Projection|undefined
@exportObjectLiteralProperty ol.control.MousePositionOptions.projection ol.ProjectionLike
@exportObjectLiteralProperty ol.control.MousePositionOptions.target Element|undefined
@exportObjectLiteralProperty ol.control.MousePositionOptions.undefinedHTML string|undefined
@@ -103,7 +103,7 @@
@exportObjectLiteral ol.source.DebugTileSourceOptions
@exportObjectLiteralProperty ol.source.DebugTileSourceOptions.extent ol.Extent|undefined
@exportObjectLiteralProperty ol.source.DebugTileSourceOptions.projection ol.Projection|undefined
@exportObjectLiteralProperty ol.source.DebugTileSourceOptions.projection ol.ProjectionLike
@exportObjectLiteralProperty ol.source.DebugTileSourceOptions.tileGrid ol.tilegrid.TileGrid|undefined
@exportObjectLiteral ol.source.SingleImageWMSOptions
@@ -111,7 +111,7 @@
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.crossOrigin null|string|undefined
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.extent ol.Extent|undefined
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.params Object.<string,*>
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.projection ol.Projection|undefined
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.projection ol.ProjectionLike
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.resolutions Array.<number>|undefined
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.url string|undefined
@@ -128,7 +128,7 @@
@exportObjectLiteralProperty ol.source.StaticImageOptions.extent ol.Extent|undefined
@exportObjectLiteralProperty ol.source.StaticImageOptions.imageExtent ol.Extent|undefined
@exportObjectLiteralProperty ol.source.StaticImageOptions.imageSize ol.Size|undefined
@exportObjectLiteralProperty ol.source.StaticImageOptions.projection ol.Projection|undefined
@exportObjectLiteralProperty ol.source.StaticImageOptions.projection ol.ProjectionLike
@exportObjectLiteralProperty ol.source.StaticImageOptions.url string|undefined
@exportObjectLiteral ol.source.TiledWMSOptions
@@ -138,7 +138,7 @@
@exportObjectLiteralProperty ol.source.TiledWMSOptions.extent ol.Extent|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.tileGrid ol.tilegrid.TileGrid|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.maxZoom number|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.projection ol.Projection|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.projection ol.ProjectionLike
@exportObjectLiteralProperty ol.source.TiledWMSOptions.url string|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.urls Array.<string>|undefined

View File

@@ -41,9 +41,9 @@ ol.control.MousePosition = function(opt_options) {
/**
* @private
* @type {ol.Projection|undefined}
* @type {ol.Projection}
*/
this.projection_ = options.projection;
this.projection_ = ol.projection.get(options.projection);
/**
* @private
@@ -168,7 +168,7 @@ ol.control.MousePosition.prototype.updateHTML_ = function(pixel) {
var html = this.undefinedHTML_;
if (!goog.isNull(pixel)) {
if (this.renderedProjection_ != this.mapProjection_) {
if (goog.isDef(this.projection_)) {
if (!goog.isNull(this.projection_)) {
this.transform_ = ol.projection.getTransform(
this.mapProjection_, this.projection_);
} else {

View File

@@ -1,4 +1,5 @@
goog.provide('ol.Projection');
goog.provide('ol.ProjectionLike');
goog.provide('ol.ProjectionUnits');
goog.provide('ol.projection');
@@ -23,6 +24,12 @@ ol.ENABLE_PROJ4JS = true;
ol.HAVE_PROJ4JS = ol.ENABLE_PROJ4JS && typeof Proj4js == 'object';
/**
* @typedef {ol.Projection|string|undefined}
*/
ol.ProjectionLike;
/**
* @enum {string}
*/
@@ -422,20 +429,29 @@ ol.projection.removeTransform = function(source, destination) {
/**
* @param {string} code Code which is a combination of authority and identifier
* such as “EPSG:4326”.
* @param {ol.ProjectionLike} projectionLike Either a code string which is a
* combination of authority and identifier such as “EPSG:4326”, or an
* existing projection object, or undefined.
* @return {ol.Projection} Projection.
*/
ol.projection.get = function(code) {
var projection = ol.projection.projections_[code];
if (ol.HAVE_PROJ4JS && !goog.isDef(projection)) {
projection = ol.projection.getProj4jsProjectionFromCode_({
code: code,
extent: null
});
}
if (!goog.isDef(projection)) {
goog.asserts.assert(goog.isDef(projection));
ol.projection.get = function(projectionLike) {
var projection;
if (projectionLike instanceof ol.Projection) {
projection = projectionLike;
} else if (goog.isString(projectionLike)) {
var code = projectionLike;
projection = ol.projection.projections_[code];
if (ol.HAVE_PROJ4JS && !goog.isDef(projection)) {
projection = ol.projection.getProj4jsProjectionFromCode_({
code: code,
extent: null
});
}
if (!goog.isDef(projection)) {
goog.asserts.assert(goog.isDef(projection));
projection = null;
}
} else {
projection = null;
}
return projection;

View File

@@ -16,7 +16,7 @@ goog.require('ol.source.Source');
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
* crossOrigin: (null|string|undefined),
* extent: (null|ol.Extent|undefined),
* projection: (ol.Projection|undefined),
* projection: ol.ProjectionLike,
* resolutions: (Array.<number>|undefined),
* imageUrlFunction: (ol.ImageUrlFunctionType|
* undefined)}}

View File

@@ -18,7 +18,7 @@ goog.require('ol.tilegrid.TileGrid');
* crossOrigin: (null|string|undefined),
* extent: (ol.Extent|undefined),
* opaque: (boolean|undefined),
* projection: (ol.Projection|undefined),
* projection: ol.ProjectionLike,
* tileGrid: (ol.tilegrid.TileGrid|undefined),
* tileUrlFunction: (ol.TileUrlFunctionType|undefined)}}
*/

View File

@@ -5,13 +5,13 @@ goog.require('goog.events.EventType');
goog.require('goog.functions');
goog.require('ol.Attribution');
goog.require('ol.Extent');
goog.require('ol.Projection');
goog.require('ol.projection');
/**
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
* extent: (ol.Extent|undefined),
* projection: (ol.Projection|undefined)}}
* projection: ol.ProjectionLike}}
*/
ol.source.SourceOptions;
@@ -30,8 +30,7 @@ ol.source.Source = function(sourceOptions) {
* @private
* @type {ol.Projection}
*/
this.projection_ = goog.isDef(sourceOptions.projection) ?
sourceOptions.projection : null;
this.projection_ = ol.projection.get(sourceOptions.projection);
/**
* @private

View File

@@ -2,6 +2,7 @@ goog.provide('ol.source.StaticImage');
goog.require('ol.Image');
goog.require('ol.ImageUrlFunctionType');
goog.require('ol.projection');
goog.require('ol.source.ImageSource');
@@ -19,7 +20,7 @@ ol.source.StaticImage = function(options) {
var imageExtent = options.imageExtent;
var imageSize = options.imageSize;
var imageResolution = imageExtent.getHeight() / imageSize.height;
var projection = goog.isDef(options.projection) ? options.projection : null;
var projection = ol.projection.get(options.projection);
goog.base(this, {
attributions: options.attributions,

View File

@@ -4,7 +4,6 @@ goog.provide('ol.source.TileSourceOptions');
goog.require('goog.functions');
goog.require('ol.Attribution');
goog.require('ol.Extent');
goog.require('ol.Projection');
goog.require('ol.Tile');
goog.require('ol.TileCoord');
goog.require('ol.TileRange');
@@ -16,7 +15,7 @@ goog.require('ol.tilegrid.TileGrid');
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
* extent: (ol.Extent|undefined),
* opaque: (boolean|undefined),
* projection: (ol.Projection|undefined),
* projection: ol.ProjectionLike,
* tileGrid: (ol.tilegrid.TileGrid|undefined)}}
*/
ol.source.TileSourceOptions;