From 9f19569144b6905e917584f4292e48831e515631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 11 Jul 2014 22:18:01 +0200 Subject: [PATCH] Add a worldExtent to ol.proj.Projection --- externs/olx.js | 10 +++++++++- src/ol/proj/epsg3857projection.js | 10 +++++++++- src/ol/proj/epsg4326projection.js | 3 ++- src/ol/proj/proj.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index ad1c275762..7d4331fb97 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -293,7 +293,8 @@ olx.OverlayOptions.prototype.insertFirst; * units: (ol.proj.Units|string), * extent: (ol.Extent|undefined), * axisOrientation: (string|undefined), - * global: (boolean|undefined)}} + * global: (boolean|undefined), + * worldExtent: (ol.Extent|undefined)}} * @api */ olx.ProjectionOptions; @@ -334,6 +335,13 @@ olx.ProjectionOptions.prototype.axisOrientation; olx.ProjectionOptions.prototype.global; +/** + * The world extent for the SRS. + * @type {ol.Extent|undefined} + */ +olx.ProjectionOptions.prototype.worldExtent; + + /** * Object literal with config options for the view. * @typedef {{center: (ol.Coordinate|undefined), diff --git a/src/ol/proj/epsg3857projection.js b/src/ol/proj/epsg3857projection.js index 1baae0cd3f..3186b43a3c 100644 --- a/src/ol/proj/epsg3857projection.js +++ b/src/ol/proj/epsg3857projection.js @@ -23,7 +23,8 @@ ol.proj.EPSG3857_ = function(code) { code: code, units: ol.proj.Units.METERS, extent: ol.proj.EPSG3857.EXTENT, - global: true + global: true, + worldExtent: ol.proj.EPSG3857.WORLD_EXTENT }); }; goog.inherits(ol.proj.EPSG3857_, ol.proj.Projection); @@ -61,6 +62,13 @@ ol.proj.EPSG3857.EXTENT = [ ]; +/** + * @const + * @type {ol.Extent} + */ +ol.proj.EPSG3857.WORLD_EXTENT = [-180, -85, 180, 85]; + + /** * Lists several projection codes with the same meaning as EPSG:3857. * diff --git a/src/ol/proj/epsg4326projection.js b/src/ol/proj/epsg4326projection.js index a2f2c01008..09fb570d87 100644 --- a/src/ol/proj/epsg4326projection.js +++ b/src/ol/proj/epsg4326projection.js @@ -26,7 +26,8 @@ ol.proj.EPSG4326_ = function(code, opt_axisOrientation) { units: ol.proj.Units.DEGREES, extent: ol.proj.EPSG4326.EXTENT, axisOrientation: opt_axisOrientation, - global: true + global: true, + worldExtent: ol.proj.EPSG4326.EXTENT }); }; goog.inherits(ol.proj.EPSG4326_, ol.proj.Projection); diff --git a/src/ol/proj/proj.js b/src/ol/proj/proj.js index 0c03273469..d7fbf15ff9 100644 --- a/src/ol/proj/proj.js +++ b/src/ol/proj/proj.js @@ -86,6 +86,13 @@ ol.proj.Projection = function(options) { */ this.extent_ = goog.isDef(options.extent) ? options.extent : null; + /** + * @private + * @type {ol.Extent} + */ + this.worldExtent_ = goog.isDef(options.worldExtent) ? + options.worldExtent : null; + /** * @private * @type {string} @@ -148,6 +155,16 @@ ol.proj.Projection.prototype.getMetersPerUnit = function() { }; +/** + * Get the world extent for this projection. + * @return {ol.Extent} Extent. + * @api + */ +ol.proj.Projection.prototype.getWorldExtent = function() { + return this.worldExtent_; +}; + + /** * Get the axis orientation of this projection. * Example values are: @@ -198,6 +215,17 @@ ol.proj.Projection.prototype.setExtent = function(extent) { }; +/** + * Set the world extent for this projection. + * @param {ol.Extent} worldExtent World extent + * [minlon, minlat, maxlon, maxlat]. + * @api + */ +ol.proj.Projection.prototype.setWorldExtent = function(worldExtent) { + this.worldExtent_ = worldExtent; +}; + + /** * Get the resolution of the point in degrees. For projections with degrees as * the unit this will simply return the provided resolution. For other