[OpenLayers-Commits] r10948 - in trunk/openlayers: lib/OpenLayers/Control tests/Control

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Sat Dec 4 08:51:11 EST 2010


Author: ahocevar
Date: 2010-12-04 05:51:11 -0800 (Sat, 04 Dec 2010)
New Revision: 10948

Modified:
   trunk/openlayers/lib/OpenLayers/Control/WMSGetFeatureInfo.js
   trunk/openlayers/tests/Control/WMSGetFeatureInfo.html
Log:
Make WMSGetFeature control respect layer projection if it equals the map projection. r=bartvde (closes #2918)


Modified: trunk/openlayers/lib/OpenLayers/Control/WMSGetFeatureInfo.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/WMSGetFeatureInfo.js	2010-12-04 13:44:26 UTC (rev 10947)
+++ trunk/openlayers/lib/OpenLayers/Control/WMSGetFeatureInfo.js	2010-12-04 13:51:11 UTC (rev 10948)
@@ -345,28 +345,36 @@
             layerNames = layerNames.concat(layers[i].params.LAYERS);
             styleNames = styleNames.concat(this.getStyleNames(layers[i]));
         }
+        var firstLayer = layers[0];
+        // use the firstLayer's projection if it matches the map projection -
+        // this assumes that all layers will be available in this projection
+        var projection = this.map.getProjection();
+        var layerProj = firstLayer.projection;
+        if (layerProj && layerProj.equals(this.map.getProjectionObject())) {
+            projection = layerProj.getCode();
+        }
         var params = OpenLayers.Util.extend({
             service: "WMS",
-            version: layers[0].params.VERSION,
+            version: firstLayer.params.VERSION,
             request: "GetFeatureInfo",
             layers: layerNames,
             query_layers: layerNames,
             styles: styleNames,
             bbox: this.map.getExtent().toBBOX(null,
-                layers[0].reverseAxisOrder()),
+                firstLayer.reverseAxisOrder()),
             feature_count: this.maxFeatures,
             height: this.map.getSize().h,
             width: this.map.getSize().w,
             format: format,
             info_format: this.infoFormat
-        }, (parseFloat(layers[0].params.VERSION) >= 1.3) ?
+        }, (parseFloat(firstLayer.params.VERSION) >= 1.3) ?
             {
-                crs: this.map.getProjection(),
+                crs: projection,
                 i: clickPosition.x,
                 j: clickPosition.y
             } :
             {
-                srs: this.map.getProjection(),
+                srs: projection,
                 x: clickPosition.x,
                 y: clickPosition.y
             }

Modified: trunk/openlayers/tests/Control/WMSGetFeatureInfo.html
===================================================================
--- trunk/openlayers/tests/Control/WMSGetFeatureInfo.html	2010-12-04 13:44:26 UTC (rev 10947)
+++ trunk/openlayers/tests/Control/WMSGetFeatureInfo.html	2010-12-04 13:51:11 UTC (rev 10948)
@@ -451,7 +451,38 @@
         t.eq(count, 2, "We expect 2 requests to go off");
         map.destroy();
     }
+    
+    function test_GetFeatureInfo_buildWMSOptions(t) {
+        t.plan(3);
+        
+        var map = new OpenLayers.Map("map", {
+            getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));},
+            projection: "EPSG:900913"
+        });
+        var a = new OpenLayers.Layer.WMS("dummy", "http://localhost/wms", {
+            layers: "a"
+        }, {projection: "EPSG:3857"});
+        var b = new OpenLayers.Layer.WMS("dummy", "http://localhost/wms", {
+            layers: "b"
+        });
+        var c = new OpenLayers.Layer.WMS("dummy", "http://localhost/wms", {
+            layers: "c"
+        }, {projection: "EPSG:4326"});
+        map.addLayers([a, b, c]);
+        var gfi = new OpenLayers.Control.WMSGetFeatureInfo();
+        map.addControl(gfi);
+        gfi.activate();
 
+        var options = gfi.buildWMSOptions("http://localhost/wms", [a], {xy: {x: 50, y: 50}}, "text/html");
+        t.eq(options.params.SRS, "EPSG:3857", "layer projection used if provided and equal map projection");
+
+        options = gfi.buildWMSOptions("http://localhost/wms", [b], {xy: {x: 50, y: 50}}, "text/html");
+        t.eq(options.params.SRS, "EPSG:900913", "map projection used if layer has no projection configured");
+
+        options = gfi.buildWMSOptions("http://localhost/wms", [b], {xy: {x: 50, y: 50}}, "text/html");
+        t.eq(options.params.SRS, "EPSG:900913", "map projection used if layer configured with an incompatible projection");
+    }
+
     function test_GetFeatureInfo_WMS13(t) {
         t.plan(4);
         var map = new OpenLayers.Map("map", {



More information about the Commits mailing list