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)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11875 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -55,6 +55,14 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
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 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
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 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* 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 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* 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 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
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;
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user