Skip to content
This repository

New OpenLayers.Projection.defaults property #219

Merged
merged 9 commits into from about 2 years ago

5 participants

Andreas Hocevar Tim Schaub Frédéric Junod Antoine Abt Éric Lemoine
Andreas Hocevar
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.

and others added some commits February 15, 2012
Andreas Hocevar 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
Frédéric Junod If sphericalMercator, use default values from Projection.defaults a40ae7e
Frédéric Junod Simplify parent call (don't use intermediate array) cd3ffa2
Frédéric Junod Don't compute limit if it's not needed 147b32b
Andreas Hocevar Merge pull request #3 from fredj/proj-defaults
Proj defaults
1b57783
Andreas Hocevar 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
Tim Schaub
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.

Andreas Hocevar
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?

Andreas Hocevar
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.

Frédéric Junod
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)

Andreas Hocevar ahocevar merged commit 2fe882f into from February 16, 2012
Andreas Hocevar ahocevar closed this February 16, 2012
Antoine Abt tonio commented on the diff February 16, 2012
lib/OpenLayers/Layer/XYZ.js
((5 lines not shown))
74  
-            options = OpenLayers.Util.extend({
75  
-                maxExtent: new OpenLayers.Bounds(
76  
-                    -128 * 156543.03390625,
77  
-                    -128 * 156543.03390625,
78  
-                    128 * 156543.03390625,
79  
-                    128 * 156543.03390625
80  
-                ),
81  
-                maxResolution: 156543.03390625,
82  
-                numZoomLevels: 19,
83  
-                units: "m",
84  
-                projection: "EPSG:900913"
85  
-            }, options);
  73
+        options = options || {};
  74
+        if (options.sphericalMercator || this.sphericalMercator) {
  75
+            options.projection = new OpenLayers.Projection('EPSG:900913');
  76
+            options.numZoomLevels = 19;
1
Antoine Abt Collaborator
tonio added a note February 16, 2012

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
Frédéric Junod fredj referenced this pull request from a commit February 16, 2012
Commit has since been removed from the repository and is no longer available.
Frédéric Junod
Owner

@tonio please try 5d79b68

Antoine Abt
Collaborator

@fredj Works for me, and looks good!

Thanks, please merge.

Éric Lemoine
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

Showing 9 unique commits by 2 authors.

Feb 15, 2012
Andreas Hocevar 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
Frédéric Junod If sphericalMercator, use default values from Projection.defaults a40ae7e
Frédéric Junod Simplify parent call (don't use intermediate array) cd3ffa2
Frédéric Junod Don't compute limit if it's not needed 147b32b
Andreas Hocevar Merge pull request #3 from fredj/proj-defaults
Proj defaults
1b57783
Andreas Hocevar 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
Andreas Hocevar Calculating maxResolution instead of having it in defaults. 262e2d5
Feb 16, 2012
Frédéric Junod Use OpenLayers.Projection.defaults values. 1cc8770
Andreas Hocevar Merge pull request #4 from fredj/proj-defaults
Proj defaults: update examples
79bab72
This page is out of date. Refresh to see the latest.
7  examples/canvas.js
@@ -5,12 +5,7 @@ function init() {
5 5
     map = new OpenLayers.Map({
6 6
         div: "map",
7 7
         projection: new OpenLayers.Projection("EPSG:900913"),
8  
-        displayProjection: new OpenLayers.Projection("EPSG:4326"),
9  
-        units: "m",
10  
-        maxResolution: 156543.0339,
11  
-        maxExtent: new OpenLayers.Bounds(
12  
-            -20037508, -20037508, 20037508, 20037508
13  
-        )
  8
+        displayProjection: new OpenLayers.Projection("EPSG:4326")
14 9
     });
15 10
 
16 11
     var g = new OpenLayers.Layer.Google("Google Layer", {
4  examples/clientzoom.js
@@ -5,10 +5,6 @@ function init() {
5 5
     map = new OpenLayers.Map({
6 6
         div: "map",
7 7
         projection: "EPSG:900913",
8  
-        units: "m",
9  
-        maxExtent: new OpenLayers.Bounds(
10  
-            -20037508.34, -20037508.34, 20037508.34, 20037508.34
11  
-        ),
12 8
         controls: [],
13 9
         fractionalZoom: true
14 10
     });
5  examples/mobile-base.js
@@ -41,12 +41,7 @@ var init = function (onSelectFeatureFunction) {
41 41
         div: "map",
42 42
         theme: null,
43 43
         projection: sm,
44  
-        units: "m",
45 44
         numZoomLevels: 18,
46  
-        maxResolution: 156543.0339,
47  
-        maxExtent: new OpenLayers.Bounds(
48  
-            -20037508.34, -20037508.34, 20037508.34, 20037508.34
49  
-        ),
50 45
         controls: [
51 46
             new OpenLayers.Control.Attribution(),
52 47
             new OpenLayers.Control.TouchNavigation({
5  examples/mobile-drawing.js
@@ -41,12 +41,7 @@ function init() {
41 41
     map = new OpenLayers.Map({
42 42
         div: 'map',
43 43
         projection: 'EPSG:900913',
44  
-        units: 'm',
45 44
         numZoomLevels: 18,
46  
-        maxResolution: 156543.0339,
47  
-        maxExtent: new OpenLayers.Bounds(
48  
-            -20037508.34, -20037508.34, 20037508.34, 20037508.34
49  
-        ),
50 45
         controls: [
51 46
             new OpenLayers.Control.TouchNavigation({
52 47
                 dragPanOptions: {
5  examples/mobile-navigation.js
@@ -5,12 +5,7 @@ function init() {
5 5
         div: "map",
6 6
         theme: null,
7 7
         projection: new OpenLayers.Projection("EPSG:900913"),
8  
-        units: "m",
9 8
         numZoomLevels: 18,
10  
-        maxResolution: 156543.0339,
11  
-        maxExtent: new OpenLayers.Bounds(
12  
-            -20037508.34, -20037508.34, 20037508.34, 20037508.34
13  
-        ),
14 9
         controls: [
15 10
             new OpenLayers.Control.TouchNavigation({
16 11
                 dragPanOptions: {
7  examples/osm-google.js
@@ -3,12 +3,7 @@ var map;
3 3
 function init() {
4 4
     map = new OpenLayers.Map({
5 5
         div: "map",
6  
-        projection: new OpenLayers.Projection("EPSG:900913"),
7  
-        units: "m",
8  
-        maxResolution: 156543.0339,
9  
-        maxExtent: new OpenLayers.Bounds(
10  
-            -20037508, -20037508, 20037508, 20037508.34
11  
-        )
  6
+        projection: new OpenLayers.Projection("EPSG:900913")
12 7
     });
13 8
     
14 9
     var osm = new OpenLayers.Layer.OSM();            
3  examples/overviewmap.html
@@ -91,8 +91,7 @@ <h1 id="title">Overview Map</h1>
91 91
             maxExtent: new OpenLayers.Bounds(-8242894.927728, 4965204.031195,
92 92
                     -8227290.161511, 4994963.723637), 
93 93
             maxResolution: 116.24879860156216,
94  
-            projection: "EPSG:900913",
95  
-            units: "m"
  94
+            projection: "EPSG:900913"
96 95
         };
97 96
 
98 97
         var map2 = new OpenLayers.Map('map2', mapOptions);
10  examples/spherical-mercator.html
@@ -12,7 +12,10 @@
12 12
     <link rel="stylesheet" href="style.css" type="text/css">
13 13
     <style type="text/css">
14 14
         .olControlAttribution { 
15  
-            bottom: 0px 
  15
+            bottom: 0px;
  16
+            left: 2px;
  17
+            right: inherit;
  18
+            width: 400px;
16 19
         }
17 20
         #map {
18 21
             height: 512px;
@@ -42,10 +45,7 @@ <h1 id="title">OpenLayers Spherical Mercator Example</h1>
42 45
         div: "map",
43 46
         projection: "EPSG:900913",
44 47
         displayProjection: "EPSG:4326",
45  
-        units: "m",
46  
-        numZoomLevels: 18,
47  
-        maxResolution: 156543.0339,
48  
-        maxExtent: [-20037508, -20037508, 20037508, 20037508],
  48
+        numZoomLevels: 18
49 49
     });
50 50
 
51 51
     // create Google Mercator layers
6  examples/sundials-spherical-mercator.html
@@ -31,11 +31,7 @@
31 31
         function init(){
32 32
             var options = {
33 33
                 projection: new OpenLayers.Projection("EPSG:900913"),
34  
-                displayProjection: new OpenLayers.Projection("EPSG:4326"),
35  
-                units: "m",
36  
-                maxResolution: 156543.0339,
37  
-                maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
38  
-                                                 20037508.34, 20037508.34)
  34
+                displayProjection: new OpenLayers.Projection("EPSG:4326")
39 35
             };
40 36
             map = new OpenLayers.Map('map', options);
41 37
             var mapnik = new OpenLayers.Layer.OSM("OpenStreetMap (Mapnik)");
3  examples/wfs-protocol-transactions.js
@@ -38,9 +38,6 @@ function init() {
38 38
     map = new OpenLayers.Map('map', {
39 39
         projection: new OpenLayers.Projection("EPSG:900913"),
40 40
         displayProjection: new OpenLayers.Projection("EPSG:4326"),
41  
-        units: "m",
42  
-        maxResolution: 20037508.34 / 128,
43  
-        maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508),
44 41
         restrictedExtent: extent,
45 42
         controls: [
46 43
             new OpenLayers.Control.PanZoom(),
7  examples/wfs-reprojection.js
@@ -7,12 +7,7 @@ function init() {
7 7
     var mercator = new OpenLayers.Projection("EPSG:900913");
8 8
 
9 9
     map = new OpenLayers.Map('map', {
10  
-        projection: mercator,
11  
-        units: "m",
12  
-        maxResolution: 156543.0339,
13  
-        maxExtent: new OpenLayers.Bounds(
14  
-            -20037508, -20037508, 20037508, 20037508
15  
-        )
  10
+        projection: mercator
16 11
     });
17 12
 
18 13
     var g = new OpenLayers.Layer.Google("Google Layer", {
7  examples/wmts-capabilities.js
@@ -47,12 +47,7 @@ function init() {
47 47
     
48 48
     map = new OpenLayers.Map({
49 49
         div: "map",
50  
-        projection: "EPSG:900913",
51  
-        units: "m",
52  
-        maxExtent: new OpenLayers.Bounds(
53  
-            -20037508.34, -20037508.34, 20037508.34, 20037508.34
54  
-        ),
55  
-        maxResolution: 156543.0339
  50
+        projection: "EPSG:900913"
56 51
     });    
57 52
     
58 53
     var osm = new OpenLayers.Layer.OSM();
7  examples/wmts-getfeatureinfo.js
@@ -5,12 +5,7 @@ function init() {
5 5
     
6 6
     map = new OpenLayers.Map({
7 7
         div: "map",
8  
-        projection: "EPSG:900913",
9  
-        units: "m",
10  
-        maxExtent: new OpenLayers.Bounds(
11  
-            -20037508.34, -20037508.34, 20037508.34, 20037508.34
12  
-        ),
13  
-        maxResolution: 156543.0339
  8
+        projection: "EPSG:900913"
14 9
     });    
15 10
     
16 11
     var osm = new OpenLayers.Layer.OSM();
7  examples/wmts.js
@@ -4,12 +4,7 @@ function init() {
4 4
     
5 5
     map = new OpenLayers.Map({
6 6
         div: "map",
7  
-        projection: "EPSG:900913",
8  
-        units: "m",
9  
-        maxExtent: new OpenLayers.Bounds(
10  
-            -20037508.34, -20037508.34, 20037508.34, 20037508.34
11  
-        ),
12  
-        maxResolution: 156543.0339
  7
+        projection: "EPSG:900913"
13 8
     });    
14 9
     
15 10
     var osm = new OpenLayers.Layer.OSM();
33  lib/OpenLayers/Layer.js
@@ -255,8 +255,8 @@ OpenLayers.Layer = OpenLayers.Class({
255 255
      * APIProperty: maxResolution
256 256
      * {Float} Default max is 360 deg / 256 px, which corresponds to
257 257
      *     zoom level 0 on gmaps.  Specify a different value in the layer 
258  
-     *     options if you are not using a geographic projection and 
259  
-     *     displaying the whole world.
  258
+     *     options if you are not using the default <OpenLayers.Map.tileSize>
  259
+     *     and displaying the whole world.
260 260
      */
261 261
     maxResolution: null,
262 262
 
@@ -473,8 +473,18 @@ OpenLayers.Layer = OpenLayers.Class({
473 473
             this.options = {};
474 474
         }
475 475
         
476  
-        // allow array for extents
477 476
         if (newOptions) {
  477
+            // make sure this.projection references a projection object
  478
+            if(typeof newOptions.projection == "string") {
  479
+                newOptions.projection = new OpenLayers.Projection(newOptions.projection);
  480
+            }
  481
+            if (newOptions.projection) {
  482
+                // get maxResolution, units and maxExtent from projection defaults if
  483
+                // they are not defined already
  484
+                OpenLayers.Util.applyDefaults(newOptions,
  485
+                    OpenLayers.Projection.defaults[newOptions.projection.getCode()]);
  486
+            }
  487
+            // allow array for extents
478 488
             if (newOptions.maxExtent && !(newOptions.maxExtent instanceof OpenLayers.Bounds)) {
479 489
                 newOptions.maxExtent = new OpenLayers.Bounds(newOptions.maxExtent);
480 490
             }
@@ -488,12 +498,7 @@ OpenLayers.Layer = OpenLayers.Class({
488 498
 
489 499
         // add new options to this
490 500
         OpenLayers.Util.extend(this, newOptions);
491  
-
492  
-        // make sure this.projection references a projection object
493  
-        if(typeof this.projection == "string") {
494  
-            this.projection = new OpenLayers.Projection(this.projection);
495  
-        }
496  
-
  501
+        
497 502
         // get the units from the projection, if we have a projection
498 503
         // and it it has units
499 504
         if(this.projection && this.projection.getUnits()) {
@@ -885,6 +890,16 @@ OpenLayers.Layer = OpenLayers.Class({
885 890
                 props.resolutions = this.resolutionsFromScales(props.scales);
886 891
             }
887 892
             if(props.resolutions == null) {
  893
+                var maxExtent = this.maxExtent;
  894
+                if (!props.maxResolution && maxExtent) {
  895
+                    // maxResolution for default grid sets assumes that at zoom
  896
+                    // level zero, the whole world fits on one tile.
  897
+                    var tileSize = this.tileSize || this.map.getTileSize();
  898
+                    props.maxResolution = Math.max(
  899
+                        maxExtent.getWidth() / tileSize.w,
  900
+                        maxExtent.getHeight() / tileSize.h
  901
+                    );
  902
+                }
888 903
                 props.resolutions = this.calculateResolutions(props);
889 904
             }
890 905
         }
16  lib/OpenLayers/Layer/Google/v3.js
@@ -30,29 +30,13 @@ OpenLayers.Layer.Google.v3 = {
30 30
      * 
31 31
      * (code)
32 32
      * {
33  
-     *     maxExtent: new OpenLayers.Bounds(
34  
-     *         -128 * 156543.03390625,
35  
-     *         -128 * 156543.03390625,
36  
-     *         128 * 156543.03390625,
37  
-     *         128 * 156543.03390625
38  
-     *     ),
39 33
      *     sphericalMercator: true,
40  
-     *     maxResolution: 156543.03390625,
41  
-     *     units: "m",
42 34
      *     projection: "EPSG:900913"
43 35
      * }
44 36
      * (end)
45 37
      */
46 38
     DEFAULTS: {
47  
-        maxExtent: new OpenLayers.Bounds(
48  
-            -128 * 156543.03390625,
49  
-            -128 * 156543.03390625,
50  
-            128 * 156543.03390625,
51  
-            128 * 156543.03390625
52  
-        ),
53 39
         sphericalMercator: true,
54  
-        maxResolution: 156543.03390625,
55  
-        units: "m",
56 40
         projection: "EPSG:900913"
57 41
     },
58 42
 
11  lib/OpenLayers/Layer/WMS.js
@@ -56,9 +56,11 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
56 56
      * Property: yx
57 57
      * {Object} Keys in this object are EPSG codes for which the axis order
58 58
      *     is to be reversed (yx instead of xy, LatLon instead of LonLat), with
59  
-     *     true as value. This is only relevant for WMS versions >= 1.3.0.
  59
+     *     true as value. This is only relevant for WMS versions >= 1.3.0, and
  60
+     *     only if yx is not set in <OpenLayers.Projection.defaults> for the
  61
+     *     used projection.
60 62
      */
61  
-    yx: {'EPSG:4326': true},
  63
+    yx: {},
62 64
     
63 65
     /**
64 66
      * Constructor: OpenLayers.Layer.WMS
@@ -173,8 +175,9 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
173 175
      * {Boolean} true if the axis order is reversed, false otherwise.
174 176
      */
175 177
     reverseAxisOrder: function() {
176  
-        return (parseFloat(this.params.VERSION) >= 1.3 && 
177  
-            !!this.yx[this.map.getProjectionObject().getCode()]);
  178
+        var projCode = this.projection.getCode();
  179
+        return parseFloat(this.params.VERSION) >= 1.3 && 
  180
+            !!(this.yx[projCode] || OpenLayers.Projection.defaults[projCode].yx);
178 181
     },
179 182
     
180 183
     /**
31  lib/OpenLayers/Layer/XYZ.js
@@ -70,24 +70,14 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, {
70 70
      * options - {Object} Hashtable of extra options to tag onto the layer
71 71
      */
72 72
     initialize: function(name, url, options) {
73  
-        if (options && options.sphericalMercator || this.sphericalMercator) {
74  
-            options = OpenLayers.Util.extend({
75  
-                maxExtent: new OpenLayers.Bounds(
76  
-                    -128 * 156543.03390625,
77  
-                    -128 * 156543.03390625,
78  
-                    128 * 156543.03390625,
79  
-                    128 * 156543.03390625
80  
-                ),
81  
-                maxResolution: 156543.03390625,
82  
-                numZoomLevels: 19,
83  
-                units: "m",
84  
-                projection: "EPSG:900913"
85  
-            }, options);
  73
+        options = options || {};
  74
+        if (options.sphericalMercator || this.sphericalMercator) {
  75
+            options.projection = new OpenLayers.Projection('EPSG:900913');
  76
+            options.numZoomLevels = 19;
86 77
         }
87  
-        url = url || this.url;
88  
-        name = name || this.name;
89  
-        var newArguments = [name, url, {}, options];
90  
-        OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
  78
+        OpenLayers.Layer.Grid.prototype.initialize.apply(this, [
  79
+            name || this.name, url || this.url, {}, options
  80
+        ]);
91 81
     },
92 82
     
93 83
     /**
@@ -157,10 +147,9 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, {
157 147
             OpenLayers.Util.indexOf(resolutions, res) :
158 148
             this.getServerZoom() + this.zoomOffset;
159 149
 
160  
-        var limit = Math.pow(2, z);
161  
-        if (this.wrapDateLine)
162  
-        {
163  
-           x = ((x % limit) + limit) % limit;
  150
+        if (this.wrapDateLine) {
  151
+            var limit = Math.pow(2, z);
  152
+            x = ((x % limit) + limit) % limit;
164 153
         }
165 154
 
166 155
         return {'x': x, 'y': y, 'z': z};
30  lib/OpenLayers/Map.js
@@ -8,6 +8,7 @@
8 8
  * @requires OpenLayers/Util.js
9 9
  * @requires OpenLayers/Events.js
10 10
  * @requires OpenLayers/Tween.js
  11
+ * @requires OpenLayers/Projection.js
11 12
  */
12 13
 
13 14
 /**
@@ -248,17 +249,19 @@ OpenLayers.Map = OpenLayers.Class({
248 249
     /**
249 250
      * APIProperty: projection
250 251
      * {String} Set in the map options to override the default projection 
251  
-     *          string this map - also set maxExtent, maxResolution, and 
252  
-     *          units if appropriate.  Default is "EPSG:4326".
  252
+     *          string this map. When using a projection other than EPSG:4326
  253
+     *          (CRS:84, Geographic) or EPSG:3857 (EPSG:900913, Web Mercator),
  254
+     *          also set maxExtent and maxResolution.  Default is "EPSG:4326".
253 255
      */
254 256
     projection: "EPSG:4326",    
255 257
         
256 258
     /**
257 259
      * APIProperty: units
258  
-     * {String} The map units.  Defaults to 'degrees'.  Possible values are
259  
-     *          'degrees' (or 'dd'), 'm', 'ft', 'km', 'mi', 'inches'.
  260
+     * {String} The map units.  Possible values are 'degrees' (or 'dd'), 'm', 
  261
+     *     'ft', 'km', 'mi', 'inches'.  Only required if the projection default
  262
+     *     should be overridden.
260 263
      */
261  
-    units: 'degrees',
  264
+    units: null,
262 265
 
263 266
     /**
264 267
      * APIProperty: resolutions
@@ -271,12 +274,10 @@ OpenLayers.Map = OpenLayers.Class({
271 274
 
272 275
     /**
273 276
      * APIProperty: maxResolution
274  
-     * {Float} Default max is 360 deg / 256 px, which corresponds to
275  
-     *          zoom level 0 on gmaps.  Specify a different value in the map 
276  
-     *          options if you are not using a geographic projection and 
277  
-     *          displaying the whole world.
  277
+     * {Float} Required if you are not displaying the whole world on a tile
  278
+     * with the size specified in <tileSize>.
278 279
      */
279  
-    maxResolution: 1.40625,
  280
+    maxResolution: null,
280 281
 
281 282
     /**
282 283
      * APIProperty: minResolution
@@ -342,7 +343,8 @@ OpenLayers.Map = OpenLayers.Class({
342 343
     
343 344
     /** 
344 345
      * APIProperty: displayProjection
345  
-     * {<OpenLayers.Projection>} Requires proj4js support.Projection used by
  346
+     * {<OpenLayers.Projection>} Requires proj4js support for projections other
  347
+     *     than EPSG:4326 or EPSG:900913/EPSG:3857. Projection used by
346 348
      *     several controls to display data to user. If this property is set,
347 349
      *     it will be set on any control which has a null displayProjection
348 350
      *     property at the time the control is added to the map. 
@@ -471,8 +473,6 @@ OpenLayers.Map = OpenLayers.Class({
471 473
         this.tileSize = new OpenLayers.Size(OpenLayers.Map.TILE_WIDTH,
472 474
                                             OpenLayers.Map.TILE_HEIGHT);
473 475
         
474  
-        this.maxExtent = new OpenLayers.Bounds(-180, -90, 180, 90);
475  
-        
476 476
         this.paddingForPopups = new OpenLayers.Bounds(15, 15, 15, 15);
477 477
 
478 478
         this.theme = OpenLayers._getScriptLocation() + 
@@ -481,6 +481,10 @@ OpenLayers.Map = OpenLayers.Class({
481 481
         // now override default options 
482 482
         OpenLayers.Util.extend(this, options);
483 483
         
  484
+        var projCode = this.projection instanceof OpenLayers.Projection ?
  485
+            this.projection.projCode : this.projection;
  486
+        OpenLayers.Util.applyDefaults(this, OpenLayers.Projection.defaults[projCode]);
  487
+        
484 488
         // allow extents to be arrays
485 489
         if (this.maxExtent && !(this.maxExtent instanceof OpenLayers.Bounds)) {
486 490
             this.maxExtent = new OpenLayers.Bounds(this.maxExtent);
78  lib/OpenLayers/Projection.js
@@ -142,7 +142,7 @@ OpenLayers.Projection = OpenLayers.Class({
142 142
 
143 143
 /**
144 144
  * Property: transforms
145  
- * Transforms is an object, with from properties, each of which may
  145
+ * {Object} Transforms is an object, with from properties, each of which may
146 146
  * have a to property. This allows you to define projections without 
147 147
  * requiring support for proj4js to be included.
148 148
  *
@@ -163,6 +163,30 @@ OpenLayers.Projection = OpenLayers.Class({
163 163
 OpenLayers.Projection.transforms = {};
164 164
 
165 165
 /**
  166
+ * APIProperty: defaults
  167
+ * {Object} Defaults for the SRS codes known to OpenLayers (currently
  168
+ * EPSG:4326, CRS:84, urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857,
  169
+ * EPSG:102113 and EPSG:102100). Keys are the SRS code, values are units,
  170
+ * maxExtent (the validity extent for the SRS) and yx (true if this SRS is
  171
+ * known to have a reverse axis order).
  172
+ */
  173
+OpenLayers.Projection.defaults = {
  174
+    "EPSG:4326": {
  175
+        units: "degrees",
  176
+        maxExtent: [-180, -90, 180, 90],
  177
+        yx: true
  178
+    },
  179
+    "CRS:84": {
  180
+        units: "degrees",
  181
+        maxExtent: [-180, -90, 180, 90]
  182
+    },
  183
+    "EPSG:900913": {
  184
+        units: "m",
  185
+        maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34]
  186
+    }
  187
+};
  188
+
  189
+/**
166 190
  * APIMethod: addTransform
167 191
  * Set a custom transform method between two projections.  Use this method in
168 192
  *     cases where the proj4js lib is not available or where custom projections
@@ -176,6 +200,12 @@ OpenLayers.Projection.transforms = {};
176 200
  *     in place.  The original point should be modified.
177 201
  */
178 202
 OpenLayers.Projection.addTransform = function(from, to, method) {
  203
+    if (method === OpenLayers.Projection.nullTransform) {
  204
+        var defaults = OpenLayers.Projection.defaults[from];
  205
+        if (defaults && !OpenLayers.Projection.defaults[to]) {
  206
+            OpenLayers.Projection.defaults[to] = defaults;
  207
+        }
  208
+    }
179 209
     if(!OpenLayers.Projection.transforms[from]) {
180 210
         OpenLayers.Projection.transforms[from] = {};
181 211
     }
@@ -235,12 +265,15 @@ OpenLayers.Projection.nullTransform = function(point) {
235 265
 };
236 266
 
237 267
 /**
238  
- * Note: Transforms for web mercator <-> EPSG:4326
  268
+ * Note: Transforms for web mercator <-> geographic
239 269
  * OpenLayers recognizes EPSG:3857, EPSG:900913, EPSG:102113 and EPSG:102100.
240 270
  * OpenLayers originally started referring to EPSG:900913 as web mercator.
241 271
  * The EPSG has declared EPSG:3857 to be web mercator.
242 272
  * ArcGIS 10 recognizes the EPSG:3857, EPSG:102113, and EPSG:102100 as
243  
- * 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
  273
+ * 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.
  274
+ * For geographic, OpenLayers recognizes EPSG:4326, CRS:84 and
  275
+ * urn:ogc:def:crs:EPSG:6.6:4326. OpenLayers also knows about the reverse axis
  276
+ * order for EPSG:4326. 
244 277
  */
245 278
 (function() {
246 279
 
@@ -258,22 +291,31 @@ OpenLayers.Projection.nullTransform = function(point) {
258 291
         return xy;
259 292
     }
260 293
 
261  
-    // list of equivalent codes for web mercator
262  
-    var codes = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"];
263  
-
264  
-    var add = OpenLayers.Projection.addTransform;
265  
-    var same = OpenLayers.Projection.nullTransform;
266  
-
267  
-    var i, len, code, other, j;
268  
-    for (i=0, len=codes.length; i<len; ++i) {
269  
-        code = codes[i];
270  
-        add("EPSG:4326", code, forwardMercator);
271  
-        add(code, "EPSG:4326", inverseMercator);
272  
-        for (j=i+1; j<len; ++j) {
273  
-            other = codes[j];
274  
-            add(code, other, same);
275  
-            add(other, code, same);
  294
+    function map(base, codes) {
  295
+        var add = OpenLayers.Projection.addTransform;
  296
+        var same = OpenLayers.Projection.nullTransform;
  297
+        var i, len, code, other, j;
  298
+        for (i=0, len=codes.length; i<len; ++i) {
  299
+            code = codes[i];
  300
+            add(base, code, forwardMercator);
  301
+            add(code, base, inverseMercator);
  302
+            for (j=i+1; j<len; ++j) {
  303
+                other = codes[j];
  304
+                add(code, other, same);
  305
+                add(other, code, same);
  306
+            }
276 307
         }
277 308
     }
  309
+    
  310
+    // list of equivalent codes for web mercator
  311
+    var mercator = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"],
  312
+        geographic = ["CRS:84", "urn:ogc:def:crs:EPSG:6.6:4326", "EPSG:4326"],
  313
+        i;
  314
+    for (i=mercator.length-1; i>=0; --i) {
  315
+        map(mercator[i], geographic);
  316
+    }
  317
+    for (i=geographic.length-1; i>=0; --i) {
  318
+        map(geographic[i], mercator);
  319
+    }
278 320
 
279 321
 })();
13  tests/Control/WMSGetFeatureInfo.html
@@ -291,18 +291,18 @@
291 291
         t.plan(5);
292 292
         var map = new OpenLayers.Map("map", {
293 293
             getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));}
294  
-            }
295  
-        );
  294
+        });
  295
+        var geographic = new OpenLayers.Projection("EPSG:4326");
296 296
 
297 297
         var a = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
298 298
             layers: "a,b,c,d",
299 299
             styles: "a,b,c,d"
300  
-        });
  300
+        }, {projection: geographic});
301 301
 
302 302
         var b = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
303 303
             layers: ["a","b","c","d"],
304 304
             styles: ["a","b","c","d"]
305  
-        });
  305
+        }, {projection: geographic});
306 306
 
307 307
         var c = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
308 308
             layers: ["a","b","c","d"]
@@ -310,13 +310,13 @@
310 310
 
311 311
         var d = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
312 312
             layers: "a,b,c,d"
313  
-        });
  313
+        }, {projection: geographic});
314 314
 
315 315
         var click = new OpenLayers.Control.WMSGetFeatureInfo({
316 316
             featureType: 'type',
317 317
             featureNS: 'ns',
318 318
             layers: [a, b, c, d]
319  
-        });
  319
+        }, {projection: geographic});
320 320
 
321 321
         map.addControl(click);
322 322
 
@@ -399,6 +399,7 @@
399 399
         var c = new OpenLayers.Layer.WMS(
400 400
             null, ["http://c.mirror/wms", "http://d.mirror/wms"], {layers: "c"}
401 401
         );
  402
+        map.addLayers([a, b, c]);
402 403
 
403 404
         var control = new OpenLayers.Control.WMSGetFeatureInfo({
404 405
             url: "http://host/wms",
4  tests/Layer.html
@@ -268,10 +268,10 @@
268 268
         map.destroy();
269 269
 
270 270
         map = new OpenLayers.Map("map");
271  
-        layer = new OpenLayers.Layer("test", {projection: "EPSG:4326"});
  271
+        layer = new OpenLayers.Layer("test", {projection: "unknown"});
272 272
         map.addLayer(layer);
273 273
         t.eq(layer.alwaysInRange, true,
274  
-             "alwaysInRange true if only get projection.");
  274
+             "alwaysInRange true if unknown projection is set.");
275 275
         map.destroy();
276 276
 
277 277
         map = new OpenLayers.Map("map");
4  tests/Layer/TMS.html
@@ -178,7 +178,7 @@
178 178
         
179 179
         var map = new OpenLayers.Map({
180 180
             div: "map",
181  
-            maxResolution: OpenLayers.Map.prototype.maxResolution / Math.pow(2, offset)
  181
+            maxResolution: OpenLayers.Projection.defaults["EPSG:4326"].maxResolution / Math.pow(2, offset)
182 182
         });
183 183
         var layer = new OpenLayers.Layer.TMS("TMS", "", {
184 184
             layername: "basic",
@@ -200,7 +200,7 @@
200 200
         
201 201
         var map = new OpenLayers.Map({
202 202
             div: "map",
203  
-            maxResolution: OpenLayers.Map.prototype.maxResolution / Math.pow(2, offset)
  203
+            maxResolution: OpenLayers.Projection.defaults["EPSG:4326"].maxResolution / Math.pow(2, offset)
204 204
         });
205 205
         var layer = new OpenLayers.Layer.TMS("TMS", "", {
206 206
             layername: "basic",
1  tests/Layer/WMS.html
@@ -388,6 +388,7 @@
388 388
         var map = new OpenLayers.Map({
389 389
             div: "map",
390 390
             maxExtent: new OpenLayers.Bounds(-185, -95, 185, 95),
  391
+            maxResolution: 1.40625,
391 392
             layers: [dummy, unconstrained, constrained],
392 393
             center: new OpenLayers.LonLat(0, 0),
393 394
             zoom: 1
6  tests/Layer/WMTS.html
@@ -136,7 +136,8 @@
136 136
                     layer: "world",
137 137
                     style: "blue_marble",
138 138
                     matrixSet: "arcgis_online",
139  
-                    tileSize: new OpenLayers.Size(512, 512),            
  139
+                    tileSize: new OpenLayers.Size(512, 512),  
  140
+                    maxResolution: 1.40625,          
140 141
                     requestEncoding: "REST"            
141 142
                 });
142 143
                 map.addLayer(layer1);
@@ -156,7 +157,8 @@
156 157
                     layer: "world",
157 158
                     style: "blue_marble",
158 159
                     matrixSet: "arcgis_online",
159  
-                    tileSize: new OpenLayers.Size(512, 512),            
  160
+                    tileSize: new OpenLayers.Size(512, 512),       
  161
+                    maxResolution: 1.40625,     
160 162
                     requestEncoding: "REST"            
161 163
                 });                                
162 164
                 map.addLayer(layer1);
4  tests/Layer/XYZ.html
@@ -195,7 +195,7 @@
195 195
         
196 196
         var map = new OpenLayers.Map({
197 197
             div: "map",
198  
-            maxResolution: OpenLayers.Map.prototype.maxResolution / Math.pow(2, offset)
  198
+            maxResolution: 1.40625 / Math.pow(2, offset)
199 199
         });
200 200
         var layer = new OpenLayers.Layer.XYZ(name, url, {zoomOffset: offset});
201 201
         map.addLayer(layer);
@@ -211,7 +211,7 @@
211 211
         
212 212
         var map = new OpenLayers.Map({
213 213
             div: "map",
214  
-            maxResolution: OpenLayers.Map.prototype.maxResolution / Math.pow(2, offset)
  214
+            maxResolution: 1.40625 / Math.pow(2, offset)
215 215
         });
216 216
         var layer = new OpenLayers.Layer.XYZ(name, url, {zoomOffset: offset});
217 217
         map.addLayer(layer);
4  tests/Protocol/WFS.html
@@ -302,7 +302,7 @@
302 302
     function test_fromWMSLayer(t) {
303 303
         t.plan(9);
304 304
         var map = new OpenLayers.Map("map", {
305  
-            projection: "EPSG:1234"
  305
+            projection: "CRS:84"
306 306
         });
307 307
         var layer = new OpenLayers.Layer.WMS("foo", "htttp://foo/ows",
308 308
             {layers: "topp:states"}
@@ -312,7 +312,7 @@
312 312
         t.eq(protocol.url, "htttp://foo/ows", "url taken from wms layer");
313 313
         t.eq(protocol.featurePrefix, "topp", "feature prefix correctly extracted");
314 314
         t.eq(protocol.featureType, "states", "typeName correctly extracted");
315  
-        t.eq(protocol.srsName, "EPSG:1234", "srsName set correctly");
  315
+        t.eq(protocol.srsName, "CRS:84", "srsName set correctly");
316 316
         t.eq(protocol.version, "1.1.0", "version set correctly");
317 317
         t.eq(protocol.format.geometryName, null, "format's geometryName set to null");
318 318
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.