diff --git a/src/objectliterals.exports b/src/objectliterals.exports index f94f2d9076..dd1ae0d5f8 100644 --- a/src/objectliterals.exports +++ b/src/objectliterals.exports @@ -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.|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. -@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.projection ol.Projection|undefined +@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.projection ol.ProjectionLike @exportObjectLiteralProperty ol.source.SingleImageWMSOptions.resolutions Array.|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.|undefined diff --git a/src/ol/control/mousepositioncontrol.js b/src/ol/control/mousepositioncontrol.js index fc736fe5a2..aa0b1f39a9 100644 --- a/src/ol/control/mousepositioncontrol.js +++ b/src/ol/control/mousepositioncontrol.js @@ -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 { diff --git a/src/ol/projection.js b/src/ol/projection.js index 512444c766..e3d5e22ee2 100644 --- a/src/ol/projection.js +++ b/src/ol/projection.js @@ -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; diff --git a/src/ol/source/imagesource.js b/src/ol/source/imagesource.js index 70c980afb2..b96973af8b 100644 --- a/src/ol/source/imagesource.js +++ b/src/ol/source/imagesource.js @@ -16,7 +16,7 @@ goog.require('ol.source.Source'); * @typedef {{attributions: (Array.|undefined), * crossOrigin: (null|string|undefined), * extent: (null|ol.Extent|undefined), - * projection: (ol.Projection|undefined), + * projection: ol.ProjectionLike, * resolutions: (Array.|undefined), * imageUrlFunction: (ol.ImageUrlFunctionType| * undefined)}} diff --git a/src/ol/source/imagetilesource.js b/src/ol/source/imagetilesource.js index b9fd30f9ea..646c5ec18a 100644 --- a/src/ol/source/imagetilesource.js +++ b/src/ol/source/imagetilesource.js @@ -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)}} */ diff --git a/src/ol/source/source.js b/src/ol/source/source.js index 2bc657b57c..8245f26e69 100644 --- a/src/ol/source/source.js +++ b/src/ol/source/source.js @@ -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.|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 diff --git a/src/ol/source/staticimagesource.js b/src/ol/source/staticimagesource.js index b1d15bcbe0..d788e20fa5 100644 --- a/src/ol/source/staticimagesource.js +++ b/src/ol/source/staticimagesource.js @@ -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, diff --git a/src/ol/source/tilesource.js b/src/ol/source/tilesource.js index 92bd61caf3..9244a53e7b 100644 --- a/src/ol/source/tilesource.js +++ b/src/ol/source/tilesource.js @@ -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.|undefined), * extent: (ol.Extent|undefined), * opaque: (boolean|undefined), - * projection: (ol.Projection|undefined), + * projection: ol.ProjectionLike, * tileGrid: (ol.tilegrid.TileGrid|undefined)}} */ ol.source.TileSourceOptions;