Allow strings to be used wherever projections are needed
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)}}
|
||||
|
||||
@@ -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)}}
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user