Files
openlayers/tests/Control/WMSGetFeatureInfo.html
ahocevar bfc17248e9 Fixed styleNames creation for layers with mixed strings and arrays.
Thanks dwins for spotting this and the quick patch, which, btw, was 
perfect (i.e. with unit tests that show the problem). r=me (closes #2025)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@9161 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2009-04-01 15:39:58 +00:00

344 lines
12 KiB
HTML

<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_WMSGetFeatureInfo_constructor(t) {
t.plan(5);
var options = {
layers: 'ns:type',
featureNS: 'http://localhost/ns',
featureType: 'type'
};
var layer = "bar";
var control = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', 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.format.featureNS, 'http://localhost/ns', 'Feature namespace passed through properly');
t.eq(control.format.featureType, 'type', 'Feature type name passed through properly');
}
function test_Control_WMSGetFeatureInfo_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 hover = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', {
layers: 'ns:type',
featureNS: 'http://localhost/ns',
featureType: 'type',
hover: true
});
click.handler.deactivate = function() {
t.ok(true,
"control.deactivate calls deactivate on click handler");
}
hover.handler.deactivate = function() {
t.ok(true,
"control.deactivate calls deactivate on hover handler");
}
click.destroy();
hover.destroy();
}
function test_Control_WMSGetFeatureInfo_click(t) {
t.plan(4);
var map = new OpenLayers.Map('map');
// mock up active control
var control = new OpenLayers.Control.WMSGetFeatureInfo();
map.addControl(control);
control.activate();
control.request = function(position) {
t.eq(position.x, 50,
"x position is as expected");
t.eq(position.y, 50,
"y position is as expected");
}
control.getInfoForClick({xy: {x: 50, y: 50}});
control.getInfoForHover({xy: {x: 50, y: 50}});
}
function test_Control_WMSGetFeatureInfo_request(t) {
t.plan(1);
var map = new OpenLayers.Map('map', {
getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));}
});
var _request = OpenLayers.Request.GET;
OpenLayers.Request.GET = function(options) {
t.eq(options.params.RADIUS, 5, "vendor params passed correctly");
}
// mock up active control
var control = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms',{
vendorParams:{ RADIUS: 5}
});
map.addControl(control);
control.activate();
control.request({xy: {x: 50, y: 50}});
OpenLayers.Request.GET = _request;
}
function test_Control_WMSGetFeatureInfo_activate(t) {
t.plan(4);
var map = new OpenLayers.Map("map");
var click = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', {
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type'
});
var hover = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', {
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type',
hover: true
});
map.addControl(click);
map.addControl(hover);
t.ok(!click.handler.active,
"click handler is not active prior to activating control");
t.ok(!hover.handler.active,
"hover handler is not active prior to activating control");
click.activate();
hover.activate();
t.ok(click.handler.active,
"click handler is active after activating control");
t.ok(hover.handler.active,
"hover handler is active after activating control");
}
function test_Control_WMSGetFeatureInfo_deactivate(t) {
t.plan(2);
var map = new OpenLayers.Map("map");
var click = new OpenLayers.Control.WMSGetFeatureInfo("http://localhost/wms", {
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type'
});
var hover = new OpenLayers.Control.WMSGetFeatureInfo("http://localhost/wms", {
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type'
});
map.addControl(click);
map.addControl(hover);
click.activate();
hover.activate();
click.handler.deactivate = function() {
t.ok(true,
"control.deactivate calls deactivate on click handler");
OpenLayers.Handler.Click.prototype.deactivate.apply(this, arguments);
}
hover.handler.deactivate = function() {
t.ok(true,
"control.deactivate calls deactivate on hover handler");
OpenLayers.Handler.Hover.prototype.deactivate.apply(this, arguments);
}
click.deactivate();
hover.deactivate();
}
</script>
</head>
<body>
<div id="map" style="width: 400px; height: 250px;"/>
</body>
</html>
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_WMSGetFeatureInfo_constructor(t) {
t.plan(4);
var options = {
layers: 'ns:type',
formats: {"application/vnd.ogc.gml": "foo"}
};
var layer = "bar";
var control = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', 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.formats["application/vnd.ogc.gml"], "foo", 'Custom format passed through properly');
}
function test_Control_WMSGetFeatureInfo_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 hover = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', {
layers: 'ns:type',
featureNS: 'http://localhost/ns',
featureType: 'type',
hover: true
});
click.handler.deactivate = function() {
t.ok(true,
"control.deactivate calls deactivate on click handler");
}
hover.handler.deactivate = function() {
t.ok(true,
"control.deactivate calls deactivate on hover handler");
}
click.destroy();
hover.destroy();
}
function test_Control_WMSGetFeatureInfo_click(t) {
t.plan(4);
var map = new OpenLayers.Map('map');
// mock up active control
var control = new OpenLayers.Control.WMSGetFeatureInfo();
map.addControl(control);
control.activate();
control.request = function(position) {
t.eq(position.x, 50,
"x position is as expected");
t.eq(position.y, 50,
"y position is as expected");
}
control.getInfoForClick({xy: {x: 50, y: 50}});
control.getInfoForHover({xy: {x: 50, y: 50}});
}
function test_Control_WMSGetFeatureInfo_activate(t) {
t.plan(4);
var map = new OpenLayers.Map("map");
var click = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', {
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type'
});
var hover = new OpenLayers.Control.WMSGetFeatureInfo('http://localhost/wms', {
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type',
hover: true
});
map.addControl(click);
map.addControl(hover);
t.ok(!click.handler.active,
"click handler is not active prior to activating control");
t.ok(!hover.handler.active,
"hover handler is not active prior to activating control");
click.activate();
hover.activate();
t.ok(click.handler.active,
"click handler is active after activating control");
t.ok(hover.handler.active,
"hover handler is active after activating control");
}
function test_Control_WMSGetFeatureInfo_deactivate(t) {
t.plan(2);
var map = new OpenLayers.Map("map");
var click = new OpenLayers.Control.WMSGetFeatureInfo("http://localhost/wms", {
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type'
});
var hover = new OpenLayers.Control.WMSGetFeatureInfo("http://localhost/wms", {
featureType: 'type',
featureNS: 'http://localhost/ns',
layers: 'ns:type'
});
map.addControl(click);
map.addControl(hover);
click.activate();
hover.activate();
click.handler.deactivate = function() {
t.ok(true,
"control.deactivate calls deactivate on click handler");
OpenLayers.Handler.Click.prototype.deactivate.apply(this, arguments);
}
hover.handler.deactivate = function() {
t.ok(true,
"control.deactivate calls deactivate on hover handler");
OpenLayers.Handler.Hover.prototype.deactivate.apply(this, arguments);
}
click.deactivate();
hover.deactivate();
}
// 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);
var map = new OpenLayers.Map("map", {
getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));}
}
);
var a = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
layers: "a,b,c,d",
styles: "a,b,c,d"
});
var b = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
layers: ["a","b","c","d"],
styles: ["a","b","c","d"]
});
var c = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
layers: ["a","b","c","d"]
});
var d = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
layers: "a,b,c,d"
});
var click = new OpenLayers.Control.WMSGetFeatureInfo("http://localhost/wms", {
featureType: 'type',
featureNS: 'ns',
layers: [a, b, c, d]
});
map.addControl(click);
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"
);
};
click.activate();
click.getInfoForClick({xy: {x: 50, y: 50}});
OpenLayers.Request.GET = _request;
}
</script>
</head>
<body>
<div id="map" style="width: 400px; height: 250px;"/>
</body>
</html>