Touching up WMSGetFeatureInfo. Requests are now sent out with correct case on request parameter. Requests are only sent out if there are layers to query. The control has a single format with configurable options. Requests can be made in cases where layer url differs from control url. The control url property is optional. In cases where it is not provided, the url of the first eligible layer will be used. Tests pass and example works (for the first time) in IE as well.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9300 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-04-15 23:44:29 +00:00
parent cd815bc2a2
commit d54440b0e9
4 changed files with 354 additions and 179 deletions

View File

@@ -2,37 +2,40 @@
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_WMSGetFeatureInfo_constructor(t) {
t.plan(4);
function test_initialize(t) {
t.plan(5);
var options = {
layers: 'ns:type',
formats: {"application/vnd.ogc.gml": "foo"}
url: 'http://localhost/wms',
layers: ["foo"],
formatOptions: {
foo: "bar"
}
};
var layer = "bar";
var control = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', options);
var control = new OpenLayers.Control.WMSGetFeatureInfo(options);
t.ok(control instanceof OpenLayers.Control.WMSGetFeatureInfo,
"new OpenLayers.Control.WMSGetFeatureInfo returns an instance");
t.eq(control.url, 'http://localhost/wms',
"constructor sets url correctly");
t.eq(control.layers, "ns:type",
"constructor sets options correctly on feature handler"
t.eq(control.layers, ["foo"],
"constructor layers"
);
t.eq(control.formats["application/vnd.ogc.gml"], "foo", 'Custom format passed through properly');
t.ok(control.format instanceof OpenLayers.Format.WMSGetFeatureInfo, "format created");
t.eq(control.format.foo, "bar", "format options used")
}
function test_Control_WMSGetFeatureInfo_destroy(t) {
function test_destroy(t) {
t.plan(2);
var map = new OpenLayers.Map("map");
var click = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', {
layers: 'ns:type',
featureNS: 'http://localhost/ns',
featureType: 'type'
var click = new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost/wms',
layers: ["foo"]
});
var hover = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', {
layers: 'ns:type',
featureNS: 'http://localhost/ns',
featureType: 'type',
var hover = new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost/wms',
layers: ["foo"],
hover: true
});
@@ -48,7 +51,7 @@
hover.destroy();
}
function test_Control_WMSGetFeatureInfo_click(t) {
function test_click(t) {
t.plan(4);
var map = new OpenLayers.Map('map');
@@ -68,15 +71,17 @@
control.getInfoForHover({xy: {x: 50, y: 50}});
}
function test_Control_WMSGetFeatureInfo_activate(t) {
function test_activate(t) {
t.plan(4);
var map = new OpenLayers.Map("map");
var click = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', {
var click = new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost/wms',
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type'
});
var hover = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', {
var hover = new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost/wms',
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type',
@@ -96,15 +101,17 @@
"hover handler is active after activating control");
}
function test_Control_WMSGetFeatureInfo_deactivate(t) {
function test_deactivate(t) {
t.plan(2);
var map = new OpenLayers.Map("map");
var click = new OpenLayers.Control.WMSGetFeatureInfo("http://localhost/wms", {
var click = new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost/wms',
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type'
});
var hover = new OpenLayers.Control.WMSGetFeatureInfo("http://localhost/wms", {
var hover = new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost/wms',
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type'
@@ -130,8 +137,8 @@
// Verify that things work all right when we combine different types for the STYLES and LAYERS
// params in the WMS Layers involved
function test_Control_WMSGetFeatureInfo_MixedParams(t) {
t.plan(1);
function test_mixedParams(t) {
t.plan(2);
var map = new OpenLayers.Map("map", {
getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));}
}
@@ -155,7 +162,7 @@
layers: "a,b,c,d"
});
var click = new OpenLayers.Control.WMSGetFeatureInfo("http://localhost/wms", {
var click = new OpenLayers.Control.WMSGetFeatureInfo({
featureType: 'type',
featureNS: 'ns',
layers: [a, b, c, d]
@@ -163,17 +170,104 @@
map.addControl(click);
var log = {};
var _request = OpenLayers.Request.GET;
OpenLayers.Request.GET = function(options) {
t.eq(
options.params.styles.join(","), "a,b,c,d,a,b,c,d,,,,,,,,",
"Styles merged correctly"
);
log.options = options;
};
click.activate();
click.getInfoForClick({xy: {x: 50, y: 50}});
OpenLayers.Request.GET = _request;
t.eq(
log.options && log.options.url,
"http://localhost/wms",
"url from first layer used"
);
t.eq(
log.options && log.options.params.styles.join(","),
"a,b,c,d,a,b,c,d,,,,,,,,",
"Styles merged correctly"
);
}
function test_urlMatches(t) {
t.plan(5);
var control = new OpenLayers.Control.WMSGetFeatureInfo({
url: "http://host/wms?one=1&two=2"
});
t.ok(!control.urlMatches("foo"), "doesn't match garbage");
t.ok(control.urlMatches("http://host:80/wms?two=2&one=1"), "matches equivalent url");
// give the control more urls to match from
control.layerUrls = ["http://a.host/wms", "http://b.host/wms"];
t.ok(control.urlMatches("http://host:80/wms?two=2&one=1"), "still matches equivalent url");
t.ok(control.urlMatches("http://a.host:80/wms"), "matches equivalent of first of layerUrls");
t.ok(control.urlMatches("http://b.host:80/wms"), "matches equivalent of second of layerUrls");
}
function test_layerUrls(t) {
t.plan(4);
var map = new OpenLayers.Map({
div: "map",
getExtent: function() {
return new OpenLayers.Bounds(-180,-90,180,90);
}
});
var a = new OpenLayers.Layer.WMS(
null, "http://a.mirror/wms", {layers: "a"}
);
var b = new OpenLayers.Layer.WMS(
null, "http://b.mirror/wms", {layers: "b"}
);
var c = new OpenLayers.Layer.WMS(
null, ["http://c.mirror/wms", "http://d.mirror/wms"], {layers: "c"}
);
var control = new OpenLayers.Control.WMSGetFeatureInfo({
url: "http://host/wms",
layers: [a, b, c]
});
map.addControl(control);
control.activate();
// log calls to GET
var log;
var _request = OpenLayers.Request.GET;
OpenLayers.Request.GET = function(options) {
log.options = options;
};
// control url doesn't match layer urls, no request issued
log = {};
control.getInfoForClick({xy: {x: 50, y: 50}});
t.ok(!log.options, "no url match, no request issued");
// give control a list of urls to match
log = {};
control.layerUrls = ["http://a.mirror/wms", "http://b.mirror/wms"];
control.getInfoForClick({xy: {x: 50, y: 50}});
t.eq(log.options && log.options.url, "http://host/wms", "some match, request issued");
t.eq(log.options && log.options.params["query_layers"].join(","), "a,b", "selected layers queried");
// show that a layer can be matched if it has a urls array itself (first needs to be matched)
log = {};
control.layerUrls = ["http://c.mirror/wms"];
control.getInfoForClick({xy: {x: 50, y: 50}});
t.eq(log.options && log.options.params["query_layers"].join(","), "c", "layer with urls array can be queried");
// clean up
OpenLayers.Request.GET = _request;
map.destroy();
}
</script>