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

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Apr 5 02:52:46 EDT 2011


Author: bartvde
Date: 2011-04-04 23:52:42 -0700 (Mon, 04 Apr 2011)
New Revision: 11875

Modified:
   trunk/openlayers/lib/OpenLayers/Control/WMSGetFeatureInfo.js
   trunk/openlayers/tests/Control/WMSGetFeatureInfo.html
Log:
WMSGetFeatureInfo control: relate features to url, thanks erilem for the extensive amount of reviews you have done for OL 2.11, r=erilem (closes #2883)

Modified: trunk/openlayers/lib/OpenLayers/Control/WMSGetFeatureInfo.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/WMSGetFeatureInfo.js	2011-04-05 06:35:49 UTC (rev 11874)
+++ trunk/openlayers/lib/OpenLayers/Control/WMSGetFeatureInfo.js	2011-04-05 06:52:42 UTC (rev 11875)
@@ -55,6 +55,14 @@
      */
     clickCallback: "click",
     
+    /** APIProperty: output
+     *  {String} Either "features" or "object". When triggering a 
+     *      getfeatureinfo request should we pass on an array of features
+     *      or an object with with a "features" property and other properties
+     *      (such as the url of the WMS). Default is "features".
+     */
+    output: "features",
+    
     /**
      * Property: layers
      * {Array(<OpenLayers.Layer.WMS>)} The layers to query for feature info.
@@ -387,7 +395,7 @@
             url: url,
             params: OpenLayers.Util.upperCaseObject(params),
             callback: function(request) {
-                this.handleResponse(clickPosition, request);
+                this.handleResponse(clickPosition, request, url);
             },
             scope: this
         };
@@ -487,7 +495,9 @@
      * request - {XMLHttpRequest} The request object
      * xy - {<OpenLayers.Pixel>} The position on the map where the
      *     mouse event occurred.
-     * features - {Array(<OpenLayers.Feature.Vector>)}
+     * features - {Array(<OpenLayers.Feature.Vector>)} or
+     *     {Array({Object}) when output is "object". The object has a url and a
+     *     features property which contains an array of features.
      */
     triggerGetFeatureInfo: function(request, xy, features) {
         this.events.triggerEvent("getfeatureinfo", {
@@ -509,8 +519,9 @@
      * xy - {<OpenLayers.Pixel>} The position on the map where the
      *     mouse event occurred.
      * request - {XMLHttpRequest} The request object.
+     * url - {String} The url which was used for this request.
      */
-    handleResponse: function(xy, request) {
+    handleResponse: function(xy, request, url) {
         
         var doc = request.responseXML;
         if(!doc || !doc.documentElement) {
@@ -521,7 +532,13 @@
             this.triggerGetFeatureInfo(request, xy, features);
         } else {
             this._requestCount++;
+            if (this.output === "object") {
+                this._features = (this._features || []).concat(
+                    {url: url, features: features}
+                );
+            } else {
             this._features = (this._features || []).concat(features);
+            }
             if (this._requestCount === this._numRequests) {
                 this.triggerGetFeatureInfo(request, xy, this._features.concat()); 
                 delete this._features;

Modified: trunk/openlayers/tests/Control/WMSGetFeatureInfo.html
===================================================================
--- trunk/openlayers/tests/Control/WMSGetFeatureInfo.html	2011-04-05 06:35:49 UTC (rev 11874)
+++ trunk/openlayers/tests/Control/WMSGetFeatureInfo.html	2011-04-05 06:52:42 UTC (rev 11875)
@@ -115,6 +115,61 @@
         control.getInfoForHover({xy: {x: 50, y: 50}});
     }
 
+    function test_getfeatureinfo_event(t) {
+
+        t.plan(5);
+
+        var text =
+            '<?xml version="1.0" encoding="UTF-8" ?>' +
+            '<FeatureInfoResponse>' +
+            '  <FIELDS OBJECTID="1188" HECTARES="1819.734" ZONENR="5854" NULZONES=" " AREA="18197340.1426" PERIMETER="19177.4073627" SHAPE="NULL" SE_ANNO_CAD_DATA="NULL" SHAPE.AREA="0" SHAPE.LEN="0"/>' +
+            '</FeatureInfoResponse>';
+
+        var map = new OpenLayers.Map('map');
+
+        var xy;
+        var url = "http://foo";
+
+        // mock up a control with output "object" and drillDown true
+        var control = new OpenLayers.Control.WMSGetFeatureInfo({
+            output: "object",
+            drillDown: true,
+            request: function(position) {},
+            eventListeners: {
+                getfeatureinfo: function(evt) {
+                    t.ok(evt.features[0].url === url, "features is an object with a property url when output is object");
+                    var features = evt.features[0].features;
+                    t.ok(features.length === 1, "features properties has a length of 1");
+                    t.ok(features[0] instanceof OpenLayers.Feature.Vector, "Feature array contains 1 feature");
+                }
+            }
+        });
+
+        // mock up a control with output "features" and drillDown true
+        var control2 = new OpenLayers.Control.WMSGetFeatureInfo({
+            autoActivate: true,
+            drillDown: true,
+            request: function(position) {},
+            eventListeners: {
+                getfeatureinfo: function(evt) {
+                    var features = evt.features;
+                    t.ok(features.length === 1, "features properties has a length of 1");
+                    t.ok(features[0] instanceof OpenLayers.Feature.Vector, "Feature array contains 1 feature");
+                }
+            }
+        });
+
+        map.addControls([control, control2]);
+        control.activate();
+
+        xy = {x: 50, y: 50};
+        control._requestCount = control2._requestCount = 0;
+        control._numRequests = control2._numRequests = 1;
+        control.handleResponse({xy: xy}, {responseText: text}, url);
+        control2.handleResponse({xy: xy}, {responseText: text}, url);
+        map.destroy();
+    }
+
     function test_beforegetfeatureinfo_event(t) {
         t.plan(2);
         var map = new OpenLayers.Map('map');



More information about the Commits mailing list