Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

New OpenLayers.Projection.defaults property #219

Merged
merged 9 commits into from

5 participants

@ahocevar
Owner

This allows us to simplify the map and layer configuration, because now the projection also defines defaults for maxExtent, maxResolution and units.

This change also adds transforms for SRS aliases for EPSG:4326 and centralizes axis order information in OpenLayers.Projection.defaults.

ahocevar and others added some commits
@ahocevar ahocevar New OpenLayers.Projection.defaults property.
This allows us to simplify the map and layer configuration, because now the projection also defines defaults for maxExtent, maxResolution and units.
This change also adds transforms for SRS aliases for EPSG:4326 and centralizes axis order information in OpenLayers.Projection.defaults.
11966d2
@fredj fredj If sphericalMercator, use default values from Projection.defaults a40ae7e
@fredj fredj Simplify parent call (don't use intermediate array) cd3ffa2
@fredj fredj Don't compute limit if it's not needed 147b32b
@ahocevar ahocevar Merge pull request #3 from fredj/proj-defaults
Proj defaults
1b57783
@ahocevar ahocevar Use the layer's projection.
In setMap, the layer gets the map's projection if it doesn't have its own. And since a layer can have a different SRS code than the map (but a compatible one, i.e. with OpenLayers.Projection.transforms[mapProj][layerProj] being OpenLayer.Projection.nullTransform), the axis order can be different.
2e423df
@tschaub
Owner

Thanks for working on this. The maxExtent and units properties make good sense. It's a little funny to force someone to describe the maxResolution of a projection. The convention we're using for defaults is to have a max resolution that is related to the maxExtent and tileSize. In my opinion, it would make more sense to calculate the maxResolution default rather than push another coupled value into the projection defaults.

@ahocevar
Owner

@tschaub Sounds good - so you mean a calculation based on the assumption that the validity extent's height matches the tile height at zoom level 0?

@ahocevar
Owner

I had tried this in addOptions, but there are too many ways to calculate resolutions when maxResolution is not set, so many tests failed with that. This is why the code ended up where it is now.

@fredj
Owner

Looks very good to me, please merge.
Thanks for working on this @ahocevar

(more example may be simplified but this can be done later)

@ahocevar ahocevar merged commit 2fe882f into openlayers:master
@tonio tonio commented on the diff
lib/OpenLayers/Layer/XYZ.js
((5 lines not shown))
- options = OpenLayers.Util.extend({
- maxExtent: new OpenLayers.Bounds(
- -128 * 156543.03390625,
- -128 * 156543.03390625,
- 128 * 156543.03390625,
- 128 * 156543.03390625
- ),
- maxResolution: 156543.03390625,
- numZoomLevels: 19,
- units: "m",
- projection: "EPSG:900913"
- }, options);
+ options = options || {};
+ if (options.sphericalMercator || this.sphericalMercator) {
+ options.projection = new OpenLayers.Projection('EPSG:900913');
+ options.numZoomLevels = 19;
@tonio Collaborator
tonio added a note

Previously, numZoomLevels were preserved.
It just break one of my app where I have a bigger number of zoom levels. I think it should be set only if it’s not already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fredj fredj referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@fredj
Owner

@tonio please try 5d79b68

@tonio
Collaborator

@fredj Works for me, and looks good!

Thanks, please merge.

@elemoine
Owner

@ahocevar This commit should have changed the TMS.html test file. This file still has

OpenLayers.Projection.defaults["EPSG:4326"].maxResolution

when setting maxResolution.

This makes me wonder how come this test passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 15, 2012
  1. @ahocevar

    New OpenLayers.Projection.defaults property.

    ahocevar authored
    This allows us to simplify the map and layer configuration, because now the projection also defines defaults for maxExtent, maxResolution and units.
    This change also adds transforms for SRS aliases for EPSG:4326 and centralizes axis order information in OpenLayers.Projection.defaults.
  2. @fredj
  3. @fredj
  4. @fredj
  5. @ahocevar

    Merge pull request #3 from fredj/proj-defaults

    ahocevar authored
    Proj defaults
  6. @ahocevar

    Use the layer's projection.

    ahocevar authored
    In setMap, the layer gets the map's projection if it doesn't have its own. And since a layer can have a different SRS code than the map (but a compatible one, i.e. with OpenLayers.Projection.transforms[mapProj][layerProj] being OpenLayer.Projection.nullTransform), the axis order can be different.
  7. @ahocevar
Commits on Feb 16, 2012
  1. @fredj
  2. @ahocevar

    Merge pull request #4 from fredj/proj-defaults

    ahocevar authored
    Proj defaults: update examples
This page is out of date. Refresh to see the latest.
View
7 examples/canvas.js
@@ -5,12 +5,7 @@ function init() {
map = new OpenLayers.Map({
div: "map",
projection: new OpenLayers.Projection("EPSG:900913"),
- displayProjection: new OpenLayers.Projection("EPSG:4326"),
- units: "m",
- maxResolution: 156543.0339,
- maxExtent: new OpenLayers.Bounds(
- -20037508, -20037508, 20037508, 20037508
- )
+ displayProjection: new OpenLayers.Projection("EPSG:4326")
});
var g = new OpenLayers.Layer.Google("Google Layer", {
View
4 examples/clientzoom.js
@@ -5,10 +5,6 @@ function init() {
map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
- units: "m",
- maxExtent: new OpenLayers.Bounds(
- -20037508.34, -20037508.34, 20037508.34, 20037508.34
- ),
controls: [],
fractionalZoom: true
});
View
5 examples/mobile-base.js
@@ -41,12 +41,7 @@ var init = function (onSelectFeatureFunction) {
div: "map",
theme: null,
projection: sm,
- units: "m",
numZoomLevels: 18,
- maxResolution: 156543.0339,
- maxExtent: new OpenLayers.Bounds(
- -20037508.34, -20037508.34, 20037508.34, 20037508.34
- ),
controls: [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.TouchNavigation({
View
5 examples/mobile-drawing.js
@@ -41,12 +41,7 @@ function init() {
map = new OpenLayers.Map({
div: 'map',
projection: 'EPSG:900913',
- units: 'm',
numZoomLevels: 18,
- maxResolution: 156543.0339,
- maxExtent: new OpenLayers.Bounds(
- -20037508.34, -20037508.34, 20037508.34, 20037508.34
- ),
controls: [
new OpenLayers.Control.TouchNavigation({
dragPanOptions: {
View
5 examples/mobile-navigation.js
@@ -5,12 +5,7 @@ function init() {
div: "map",
theme: null,
projection: new OpenLayers.Projection("EPSG:900913"),
- units: "m",
numZoomLevels: 18,
- maxResolution: 156543.0339,
- maxExtent: new OpenLayers.Bounds(
- -20037508.34, -20037508.34, 20037508.34, 20037508.34
- ),
controls: [
new OpenLayers.Control.TouchNavigation({
dragPanOptions: {
View
7 examples/osm-google.js
@@ -3,12 +3,7 @@ var map;
function init() {
map = new OpenLayers.Map({
div: "map",
- projection: new OpenLayers.Projection("EPSG:900913"),
- units: "m",
- maxResolution: 156543.0339,
- maxExtent: new OpenLayers.Bounds(
- -20037508, -20037508, 20037508, 20037508.34
- )
+ projection: new OpenLayers.Projection("EPSG:900913")
});
var osm = new OpenLayers.Layer.OSM();
View
3  examples/overviewmap.html
@@ -91,8 +91,7 @@ <h1 id="title">Overview Map</h1>
maxExtent: new OpenLayers.Bounds(-8242894.927728, 4965204.031195,
-8227290.161511, 4994963.723637),
maxResolution: 116.24879860156216,
- projection: "EPSG:900913",
- units: "m"
+ projection: "EPSG:900913"
};
var map2 = new OpenLayers.Map('map2', mapOptions);
View
10 examples/spherical-mercator.html
@@ -12,7 +12,10 @@
<link rel="stylesheet" href="style.css" type="text/css">
<style type="text/css">
.olControlAttribution {
- bottom: 0px
+ bottom: 0px;
+ left: 2px;
+ right: inherit;
+ width: 400px;
}
#map {
height: 512px;
@@ -42,10 +45,7 @@ <h1 id="title">OpenLayers Spherical Mercator Example</h1>
div: "map",
projection: "EPSG:900913",
displayProjection: "EPSG:4326",
- units: "m",
- numZoomLevels: 18,
- maxResolution: 156543.0339,
- maxExtent: [-20037508, -20037508, 20037508, 20037508],
+ numZoomLevels: 18
});
// create Google Mercator layers
View
6 examples/sundials-spherical-mercator.html
@@ -31,11 +31,7 @@
function init(){
var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
- displayProjection: new OpenLayers.Projection("EPSG:4326"),
- units: "m",
- maxResolution: 156543.0339,
- maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
- 20037508.34, 20037508.34)
+ displayProjection: new OpenLayers.Projection("EPSG:4326")
};
map = new OpenLayers.Map('map', options);
var mapnik = new OpenLayers.Layer.OSM("OpenStreetMap (Mapnik)");
View
3  examples/wfs-protocol-transactions.js
@@ -38,9 +38,6 @@ function init() {
map = new OpenLayers.Map('map', {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
- units: "m",
- maxResolution: 20037508.34 / 128,
- maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508),
restrictedExtent: extent,
controls: [
new OpenLayers.Control.PanZoom(),
View
7 examples/wfs-reprojection.js
@@ -7,12 +7,7 @@ function init() {
var mercator = new OpenLayers.Projection("EPSG:900913");
map = new OpenLayers.Map('map', {
- projection: mercator,
- units: "m",
- maxResolution: 156543.0339,
- maxExtent: new OpenLayers.Bounds(
- -20037508, -20037508, 20037508, 20037508
- )
+ projection: mercator
});
var g = new OpenLayers.Layer.Google("Google Layer", {
View
7 examples/wmts-capabilities.js
@@ -47,12 +47,7 @@ function init() {
map = new OpenLayers.Map({
div: "map",
- projection: "EPSG:900913",
- units: "m",
- maxExtent: new OpenLayers.Bounds(
- -20037508.34, -20037508.34, 20037508.34, 20037508.34
- ),
- maxResolution: 156543.0339
+ projection: "EPSG:900913"
});
var osm = new OpenLayers.Layer.OSM();
View
7 examples/wmts-getfeatureinfo.js
@@ -5,12 +5,7 @@ function init() {
map = new OpenLayers.Map({
div: "map",
- projection: "EPSG:900913",
- units: "m",
- maxExtent: new OpenLayers.Bounds(
- -20037508.34, -20037508.34, 20037508.34, 20037508.34
- ),
- maxResolution: 156543.0339
+ projection: "EPSG:900913"
});
var osm = new OpenLayers.Layer.OSM();
View
7 examples/wmts.js
@@ -4,12 +4,7 @@ function init() {
map = new OpenLayers.Map({
div: "map",
- projection: "EPSG:900913",
- units: "m",
- maxExtent: new OpenLayers.Bounds(
- -20037508.34, -20037508.34, 20037508.34, 20037508.34
- ),
- maxResolution: 156543.0339
+ projection: "EPSG:900913"
});
var osm = new OpenLayers.Layer.OSM();
View
33 lib/OpenLayers/Layer.js
@@ -255,8 +255,8 @@ OpenLayers.Layer = OpenLayers.Class({
* APIProperty: maxResolution
* {Float} Default max is 360 deg / 256 px, which corresponds to
* zoom level 0 on gmaps. Specify a different value in the layer
- * options if you are not using a geographic projection and
- * displaying the whole world.
+ * options if you are not using the default <OpenLayers.Map.tileSize>
+ * and displaying the whole world.
*/
maxResolution: null,
@@ -473,8 +473,18 @@ OpenLayers.Layer = OpenLayers.Class({
this.options = {};
}
- // allow array for extents
if (newOptions) {
+ // make sure this.projection references a projection object
+ if(typeof newOptions.projection == "string") {
+ newOptions.projection = new OpenLayers.Projection(newOptions.projection);
+ }
+ if (newOptions.projection) {
+ // get maxResolution, units and maxExtent from projection defaults if
+ // they are not defined already
+ OpenLayers.Util.applyDefaults(newOptions,
+ OpenLayers.Projection.defaults[newOptions.projection.getCode()]);
+ }
+ // allow array for extents
if (newOptions.maxExtent && !(newOptions.maxExtent instanceof OpenLayers.Bounds)) {
newOptions.maxExtent = new OpenLayers.Bounds(newOptions.maxExtent);
}
@@ -488,12 +498,7 @@ OpenLayers.Layer = OpenLayers.Class({
// add new options to this
OpenLayers.Util.extend(this, newOptions);
-
- // make sure this.projection references a projection object
- if(typeof this.projection == "string") {
- this.projection = new OpenLayers.Projection(this.projection);
- }
-
+
// get the units from the projection, if we have a projection
// and it it has units
if(this.projection && this.projection.getUnits()) {
@@ -885,6 +890,16 @@ OpenLayers.Layer = OpenLayers.Class({
props.resolutions = this.resolutionsFromScales(props.scales);
}
if(props.resolutions == null) {
+ var maxExtent = this.maxExtent;
+ if (!props.maxResolution && maxExtent) {
+ // maxResolution for default grid sets assumes that at zoom
+ // level zero, the whole world fits on one tile.
+ var tileSize = this.tileSize || this.map.getTileSize();
+ props.maxResolution = Math.max(
+ maxExtent.getWidth() / tileSize.w,
+ maxExtent.getHeight() / tileSize.h
+ );
+ }
props.resolutions = this.calculateResolutions(props);
}
}
View
16 lib/OpenLayers/Layer/Google/v3.js
@@ -30,29 +30,13 @@ OpenLayers.Layer.Google.v3 = {
*
* (code)
* {
- * maxExtent: new OpenLayers.Bounds(
- * -128 * 156543.03390625,
- * -128 * 156543.03390625,
- * 128 * 156543.03390625,
- * 128 * 156543.03390625
- * ),
* sphericalMercator: true,
- * maxResolution: 156543.03390625,
- * units: "m",
* projection: "EPSG:900913"
* }
* (end)
*/
DEFAULTS: {
- maxExtent: new OpenLayers.Bounds(
- -128 * 156543.03390625,
- -128 * 156543.03390625,
- 128 * 156543.03390625,
- 128 * 156543.03390625
- ),
sphericalMercator: true,
- maxResolution: 156543.03390625,
- units: "m",
projection: "EPSG:900913"
},
View
11 lib/OpenLayers/Layer/WMS.js
@@ -56,9 +56,11 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
* Property: yx
* {Object} Keys in this object are EPSG codes for which the axis order
* is to be reversed (yx instead of xy, LatLon instead of LonLat), with
- * true as value. This is only relevant for WMS versions >= 1.3.0.
+ * true as value. This is only relevant for WMS versions >= 1.3.0, and
+ * only if yx is not set in <OpenLayers.Projection.defaults> for the
+ * used projection.
*/
- yx: {'EPSG:4326': true},
+ yx: {},
/**
* Constructor: OpenLayers.Layer.WMS
@@ -173,8 +175,9 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
* {Boolean} true if the axis order is reversed, false otherwise.
*/
reverseAxisOrder: function() {
- return (parseFloat(this.params.VERSION) >= 1.3 &&
- !!this.yx[this.map.getProjectionObject().getCode()]);
+ var projCode = this.projection.getCode();
+ return parseFloat(this.params.VERSION) >= 1.3 &&
+ !!(this.yx[projCode] || OpenLayers.Projection.defaults[projCode].yx);
},
/**
View
31 lib/OpenLayers/Layer/XYZ.js
@@ -70,24 +70,14 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, {
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, url, options) {
- if (options && options.sphericalMercator || this.sphericalMercator) {
- options = OpenLayers.Util.extend({
- maxExtent: new OpenLayers.Bounds(
- -128 * 156543.03390625,
- -128 * 156543.03390625,
- 128 * 156543.03390625,
- 128 * 156543.03390625
- ),
- maxResolution: 156543.03390625,
- numZoomLevels: 19,
- units: "m",
- projection: "EPSG:900913"
- }, options);
+ options = options || {};
+ if (options.sphericalMercator || this.sphericalMercator) {
+ options.projection = new OpenLayers.Projection('EPSG:900913');
+ options.numZoomLevels = 19;
@tonio Collaborator
tonio added a note

Previously, numZoomLevels were preserved.
It just break one of my app where I have a bigger number of zoom levels. I think it should be set only if it’s not already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
- url = url || this.url;
- name = name || this.name;
- var newArguments = [name, url, {}, options];
- OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
+ OpenLayers.Layer.Grid.prototype.initialize.apply(this, [
+ name || this.name, url || this.url, {}, options
+ ]);
},
/**
@@ -157,10 +147,9 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, {
OpenLayers.Util.indexOf(resolutions, res) :
this.getServerZoom() + this.zoomOffset;
- var limit = Math.pow(2, z);
- if (this.wrapDateLine)
- {
- x = ((x % limit) + limit) % limit;
+ if (this.wrapDateLine) {
+ var limit = Math.pow(2, z);
+ x = ((x % limit) + limit) % limit;
}
return {'x': x, 'y': y, 'z': z};
View
30 lib/OpenLayers/Map.js
@@ -8,6 +8,7 @@
* @requires OpenLayers/Util.js
* @requires OpenLayers/Events.js
* @requires OpenLayers/Tween.js
+ * @requires OpenLayers/Projection.js
*/
/**
@@ -248,17 +249,19 @@ OpenLayers.Map = OpenLayers.Class({
/**
* APIProperty: projection
* {String} Set in the map options to override the default projection
- * string this map - also set maxExtent, maxResolution, and
- * units if appropriate. Default is "EPSG:4326".
+ * string this map. When using a projection other than EPSG:4326
+ * (CRS:84, Geographic) or EPSG:3857 (EPSG:900913, Web Mercator),
+ * also set maxExtent and maxResolution. Default is "EPSG:4326".
*/
projection: "EPSG:4326",
/**
* APIProperty: units
- * {String} The map units. Defaults to 'degrees'. Possible values are
- * 'degrees' (or 'dd'), 'm', 'ft', 'km', 'mi', 'inches'.
+ * {String} The map units. Possible values are 'degrees' (or 'dd'), 'm',
+ * 'ft', 'km', 'mi', 'inches'. Only required if the projection default
+ * should be overridden.
*/
- units: 'degrees',
+ units: null,
/**
* APIProperty: resolutions
@@ -271,12 +274,10 @@ OpenLayers.Map = OpenLayers.Class({
/**
* APIProperty: maxResolution
- * {Float} Default max is 360 deg / 256 px, which corresponds to
- * zoom level 0 on gmaps. Specify a different value in the map
- * options if you are not using a geographic projection and
- * displaying the whole world.
+ * {Float} Required if you are not displaying the whole world on a tile
+ * with the size specified in <tileSize>.
*/
- maxResolution: 1.40625,
+ maxResolution: null,
/**
* APIProperty: minResolution
@@ -342,7 +343,8 @@ OpenLayers.Map = OpenLayers.Class({
/**
* APIProperty: displayProjection
- * {<OpenLayers.Projection>} Requires proj4js support.Projection used by
+ * {<OpenLayers.Projection>} Requires proj4js support for projections other
+ * than EPSG:4326 or EPSG:900913/EPSG:3857. Projection used by
* several controls to display data to user. If this property is set,
* it will be set on any control which has a null displayProjection
* property at the time the control is added to the map.
@@ -471,8 +473,6 @@ OpenLayers.Map = OpenLayers.Class({
this.tileSize = new OpenLayers.Size(OpenLayers.Map.TILE_WIDTH,
OpenLayers.Map.TILE_HEIGHT);
- this.maxExtent = new OpenLayers.Bounds(-180, -90, 180, 90);
-
this.paddingForPopups = new OpenLayers.Bounds(15, 15, 15, 15);
this.theme = OpenLayers._getScriptLocation() +
@@ -481,6 +481,10 @@ OpenLayers.Map = OpenLayers.Class({
// now override default options
OpenLayers.Util.extend(this, options);
+ var projCode = this.projection instanceof OpenLayers.Projection ?
+ this.projection.projCode : this.projection;
+ OpenLayers.Util.applyDefaults(this, OpenLayers.Projection.defaults[projCode]);
+
// allow extents to be arrays
if (this.maxExtent && !(this.maxExtent instanceof OpenLayers.Bounds)) {
this.maxExtent = new OpenLayers.Bounds(this.maxExtent);
View
78 lib/OpenLayers/Projection.js
@@ -142,7 +142,7 @@ OpenLayers.Projection = OpenLayers.Class({
/**
* Property: transforms
- * Transforms is an object, with from properties, each of which may
+ * {Object} Transforms is an object, with from properties, each of which may
* have a to property. This allows you to define projections without
* requiring support for proj4js to be included.
*
@@ -163,6 +163,30 @@ OpenLayers.Projection = OpenLayers.Class({
OpenLayers.Projection.transforms = {};
/**
+ * APIProperty: defaults
+ * {Object} Defaults for the SRS codes known to OpenLayers (currently
+ * EPSG:4326, CRS:84, urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857,
+ * EPSG:102113 and EPSG:102100). Keys are the SRS code, values are units,
+ * maxExtent (the validity extent for the SRS) and yx (true if this SRS is
+ * known to have a reverse axis order).
+ */
+OpenLayers.Projection.defaults = {
+ "EPSG:4326": {
+ units: "degrees",
+ maxExtent: [-180, -90, 180, 90],
+ yx: true
+ },
+ "CRS:84": {
+ units: "degrees",
+ maxExtent: [-180, -90, 180, 90]
+ },
+ "EPSG:900913": {
+ units: "m",
+ maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34]
+ }
+};
+
+/**
* APIMethod: addTransform
* Set a custom transform method between two projections. Use this method in
* cases where the proj4js lib is not available or where custom projections
@@ -176,6 +200,12 @@ OpenLayers.Projection.transforms = {};
* in place. The original point should be modified.
*/
OpenLayers.Projection.addTransform = function(from, to, method) {
+ if (method === OpenLayers.Projection.nullTransform) {
+ var defaults = OpenLayers.Projection.defaults[from];
+ if (defaults && !OpenLayers.Projection.defaults[to]) {
+ OpenLayers.Projection.defaults[to] = defaults;
+ }
+ }
if(!OpenLayers.Projection.transforms[from]) {
OpenLayers.Projection.transforms[from] = {};
}
@@ -235,12 +265,15 @@ OpenLayers.Projection.nullTransform = function(point) {
};
/**
- * Note: Transforms for web mercator <-> EPSG:4326
+ * Note: Transforms for web mercator <-> geographic
* OpenLayers recognizes EPSG:3857, EPSG:900913, EPSG:102113 and EPSG:102100.
* OpenLayers originally started referring to EPSG:900913 as web mercator.
* The EPSG has declared EPSG:3857 to be web mercator.
* ArcGIS 10 recognizes the EPSG:3857, EPSG:102113, and EPSG:102100 as
- * equivalent. See http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/11/20/ArcGIS-Online-moving-to-Google-_2F00_-Bing-tiling-scheme_3A00_-What-does-this-mean-for-you_3F00_.aspx#12084
+ * equivalent. See http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/11/20/ArcGIS-Online-moving-to-Google-_2F00_-Bing-tiling-scheme_3A00_-What-does-this-mean-for-you_3F00_.aspx#12084.
+ * For geographic, OpenLayers recognizes EPSG:4326, CRS:84 and
+ * urn:ogc:def:crs:EPSG:6.6:4326. OpenLayers also knows about the reverse axis
+ * order for EPSG:4326.
*/
(function() {
@@ -258,22 +291,31 @@ OpenLayers.Projection.nullTransform = function(point) {
return xy;
}
- // list of equivalent codes for web mercator
- var codes = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"];
-
- var add = OpenLayers.Projection.addTransform;
- var same = OpenLayers.Projection.nullTransform;
-
- var i, len, code, other, j;
- for (i=0, len=codes.length; i<len; ++i) {
- code = codes[i];
- add("EPSG:4326", code, forwardMercator);
- add(code, "EPSG:4326", inverseMercator);
- for (j=i+1; j<len; ++j) {
- other = codes[j];
- add(code, other, same);
- add(other, code, same);
+ function map(base, codes) {
+ var add = OpenLayers.Projection.addTransform;
+ var same = OpenLayers.Projection.nullTransform;
+ var i, len, code, other, j;
+ for (i=0, len=codes.length; i<len; ++i) {
+ code = codes[i];
+ add(base, code, forwardMercator);
+ add(code, base, inverseMercator);
+ for (j=i+1; j<len; ++j) {
+ other = codes[j];
+ add(code, other, same);
+ add(other, code, same);
+ }
}
}
+
+ // list of equivalent codes for web mercator
+ var mercator = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"],
+ geographic = ["CRS:84", "urn:ogc:def:crs:EPSG:6.6:4326", "EPSG:4326"],
+ i;
+ for (i=mercator.length-1; i>=0; --i) {
+ map(mercator[i], geographic);
+ }
+ for (i=geographic.length-1; i>=0; --i) {
+ map(geographic[i], mercator);
+ }
})();
View
13 tests/Control/WMSGetFeatureInfo.html
@@ -291,18 +291,18 @@
t.plan(5);
var map = new OpenLayers.Map("map", {
getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));}
- }
- );
+ });
+ var geographic = new OpenLayers.Projection("EPSG:4326");
var a = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
layers: "a,b,c,d",
styles: "a,b,c,d"
- });
+ }, {projection: geographic});
var b = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
layers: ["a","b","c","d"],
styles: ["a","b","c","d"]
- });
+ }, {projection: geographic});
var c = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
layers: ["a","b","c","d"]
@@ -310,13 +310,13 @@
var d = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
layers: "a,b,c,d"
- });
+ }, {projection: geographic});
var click = new OpenLayers.Control.WMSGetFeatureInfo({
featureType: 'type',
featureNS: 'ns',
layers: [a, b, c, d]
- });
+ }, {projection: geographic});
map.addControl(click);
@@ -399,6 +399,7 @@
var c = new OpenLayers.Layer.WMS(
null, ["http://c.mirror/wms", "http://d.mirror/wms"], {layers: "c"}
);
+ map.addLayers([a, b, c]);
var control = new OpenLayers.Control.WMSGetFeatureInfo({
url: "http://host/wms",
View
4 tests/Layer.html
@@ -268,10 +268,10 @@
map.destroy();
map = new OpenLayers.Map("map");
- layer = new OpenLayers.Layer("test", {projection: "EPSG:4326"});
+ layer = new OpenLayers.Layer("test", {projection: "unknown"});
map.addLayer(layer);
t.eq(layer.alwaysInRange, true,
- "alwaysInRange true if only get projection.");
+ "alwaysInRange true if unknown projection is set.");
map.destroy();
map = new OpenLayers.Map("map");
View
4 tests/Layer/TMS.html
@@ -178,7 +178,7 @@
var map = new OpenLayers.Map({
div: "map",
- maxResolution: OpenLayers.Map.prototype.maxResolution / Math.pow(2, offset)
+ maxResolution: OpenLayers.Projection.defaults["EPSG:4326"].maxResolution / Math.pow(2, offset)
});
var layer = new OpenLayers.Layer.TMS("TMS", "", {
layername: "basic",
@@ -200,7 +200,7 @@
var map = new OpenLayers.Map({
div: "map",
- maxResolution: OpenLayers.Map.prototype.maxResolution / Math.pow(2, offset)
+ maxResolution: OpenLayers.Projection.defaults["EPSG:4326"].maxResolution / Math.pow(2, offset)
});
var layer = new OpenLayers.Layer.TMS("TMS", "", {
layername: "basic",
View
1  tests/Layer/WMS.html
@@ -388,6 +388,7 @@
var map = new OpenLayers.Map({
div: "map",
maxExtent: new OpenLayers.Bounds(-185, -95, 185, 95),
+ maxResolution: 1.40625,
layers: [dummy, unconstrained, constrained],
center: new OpenLayers.LonLat(0, 0),
zoom: 1
View
6 tests/Layer/WMTS.html
@@ -136,7 +136,8 @@
layer: "world",
style: "blue_marble",
matrixSet: "arcgis_online",
- tileSize: new OpenLayers.Size(512, 512),
+ tileSize: new OpenLayers.Size(512, 512),
+ maxResolution: 1.40625,
requestEncoding: "REST"
});
map.addLayer(layer1);
@@ -156,7 +157,8 @@
layer: "world",
style: "blue_marble",
matrixSet: "arcgis_online",
- tileSize: new OpenLayers.Size(512, 512),
+ tileSize: new OpenLayers.Size(512, 512),
+ maxResolution: 1.40625,
requestEncoding: "REST"
});
map.addLayer(layer1);
View
4 tests/Layer/XYZ.html
@@ -195,7 +195,7 @@
var map = new OpenLayers.Map({
div: "map",
- maxResolution: OpenLayers.Map.prototype.maxResolution / Math.pow(2, offset)
+ maxResolution: 1.40625 / Math.pow(2, offset)
});
var layer = new OpenLayers.Layer.XYZ(name, url, {zoomOffset: offset});
map.addLayer(layer);
@@ -211,7 +211,7 @@
var map = new OpenLayers.Map({
div: "map",
- maxResolution: OpenLayers.Map.prototype.maxResolution / Math.pow(2, offset)
+ maxResolution: 1.40625 / Math.pow(2, offset)
});
var layer = new OpenLayers.Layer.XYZ(name, url, {zoomOffset: offset});
map.addLayer(layer);
View
4 tests/Protocol/WFS.html
@@ -302,7 +302,7 @@
function test_fromWMSLayer(t) {
t.plan(9);
var map = new OpenLayers.Map("map", {
- projection: "EPSG:1234"
+ projection: "CRS:84"
});
var layer = new OpenLayers.Layer.WMS("foo", "htttp://foo/ows",
{layers: "topp:states"}
@@ -312,7 +312,7 @@
t.eq(protocol.url, "htttp://foo/ows", "url taken from wms layer");
t.eq(protocol.featurePrefix, "topp", "feature prefix correctly extracted");
t.eq(protocol.featureType, "states", "typeName correctly extracted");
- t.eq(protocol.srsName, "EPSG:1234", "srsName set correctly");
+ t.eq(protocol.srsName, "CRS:84", "srsName set correctly");
t.eq(protocol.version, "1.1.0", "version set correctly");
t.eq(protocol.format.geometryName, null, "format's geometryName set to null");
Something went wrong with that request. Please try again.