3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 function test_initialize(t) {
10 url: 'http://localhost/wms',
16 var control = new OpenLayers.Control.WMSGetFeatureInfo(options);
17 t.ok(control instanceof OpenLayers.Control.WMSGetFeatureInfo,
18 "new OpenLayers.Control.WMSGetFeatureInfo returns an instance");
19 t.eq(control.url, 'http://localhost/wms',
20 "constructor sets url correctly");
21 t.eq(control.layers, ["foo"],
24 t.ok(control.format instanceof OpenLayers.Format.WMSGetFeatureInfo, "format created");
25 t.eq(control.format.foo, "bar", "format options used")
28 function test_destroy(t) {
30 var map = new OpenLayers.Map("map");
31 var click = new OpenLayers.Control.WMSGetFeatureInfo({
32 url: 'http://localhost/wms',
36 var hover = new OpenLayers.Control.WMSGetFeatureInfo({
37 url: 'http://localhost/wms',
42 click.handler.deactivate = function() {
44 "control.deactivate calls deactivate on click handler");
46 hover.handler.deactivate = function() {
48 "control.deactivate calls deactivate on hover handler");
54 function test_click(t) {
56 var map = new OpenLayers.Map('map');
58 // mock up active control
59 var control = new OpenLayers.Control.WMSGetFeatureInfo();
60 map.addControl(control);
63 control.request = function(position) {
65 "x position is as expected");
67 "y position is as expected");
70 control.getInfoForClick({xy: {x: 50, y: 50}});
71 control.getInfoForHover({xy: {x: 50, y: 50}});
74 function test_activate(t) {
76 var map = new OpenLayers.Map("map");
77 var click = new OpenLayers.Control.WMSGetFeatureInfo({
78 url: 'http://localhost/wms',
80 featureNS: 'http://localhost/ns',
83 var hover = new OpenLayers.Control.WMSGetFeatureInfo({
84 url: 'http://localhost/wms',
86 featureNS: 'http://localhost/ns',
90 map.addControl(click);
91 map.addControl(hover);
92 t.ok(!click.handler.active,
93 "click handler is not active prior to activating control");
94 t.ok(!hover.handler.active,
95 "hover handler is not active prior to activating control");
98 t.ok(click.handler.active,
99 "click handler is active after activating control");
100 t.ok(hover.handler.active,
101 "hover handler is active after activating control");
104 function test_deactivate(t) {
106 var map = new OpenLayers.Map("map");
107 var click = new OpenLayers.Control.WMSGetFeatureInfo({
108 url: 'http://localhost/wms',
110 featureNS: 'http://localhost/ns',
113 var hover = new OpenLayers.Control.WMSGetFeatureInfo({
114 url: 'http://localhost/wms',
116 featureNS: 'http://localhost/ns',
119 map.addControl(click);
120 map.addControl(hover);
124 click.handler.deactivate = function() {
126 "control.deactivate calls deactivate on click handler");
127 OpenLayers.Handler.Click.prototype.deactivate.apply(this, arguments);
129 hover.handler.deactivate = function() {
131 "control.deactivate calls deactivate on hover handler");
132 OpenLayers.Handler.Hover.prototype.deactivate.apply(this, arguments);
138 // Verify that things work all right when we combine different types for the STYLES and LAYERS
139 // params in the WMS Layers involved
140 function test_mixedParams(t) {
142 var map = new OpenLayers.Map("map", {
143 getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));}
147 var a = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
152 var b = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
153 layers: ["a","b","c","d"],
154 styles: ["a","b","c","d"]
157 var c = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
158 layers: ["a","b","c","d"]
161 var d = new OpenLayers.Layer.WMS("dummy","http://localhost/wms", {
165 var click = new OpenLayers.Control.WMSGetFeatureInfo({
171 map.addControl(click);
174 var _request = OpenLayers.Request.GET;
175 OpenLayers.Request.GET = function(options) {
176 log.options = options;
179 click.getInfoForClick({xy: {x: 50, y: 50}});
180 OpenLayers.Request.GET = _request;
183 log.options && log.options.url,
184 "http://localhost/wms",
185 "url from first layer used"
188 log.options && log.options.params.styles.join(","),
189 "a,b,c,d,a,b,c,d,,,,,,,,",
190 "Styles merged correctly"
195 function test_urlMatches(t) {
199 var control = new OpenLayers.Control.WMSGetFeatureInfo({
200 url: "http://host/wms?one=1&two=2"
203 t.ok(!control.urlMatches("foo"), "doesn't match garbage");
204 t.ok(control.urlMatches("http://host:80/wms?two=2&one=1"), "matches equivalent url");
206 // give the control more urls to match from
207 control.layerUrls = ["http://a.host/wms", "http://b.host/wms"];
209 t.ok(control.urlMatches("http://host:80/wms?two=2&one=1"), "still matches equivalent url");
210 t.ok(control.urlMatches("http://a.host:80/wms"), "matches equivalent of first of layerUrls");
211 t.ok(control.urlMatches("http://b.host:80/wms"), "matches equivalent of second of layerUrls");
215 function test_layerUrls(t) {
218 var map = new OpenLayers.Map({
220 getExtent: function() {
221 return new OpenLayers.Bounds(-180,-90,180,90);
225 var a = new OpenLayers.Layer.WMS(
226 null, "http://a.mirror/wms", {layers: "a"}
228 var b = new OpenLayers.Layer.WMS(
229 null, "http://b.mirror/wms", {layers: "b"}
231 var c = new OpenLayers.Layer.WMS(
232 null, ["http://c.mirror/wms", "http://d.mirror/wms"], {layers: "c"}
235 var control = new OpenLayers.Control.WMSGetFeatureInfo({
236 url: "http://host/wms",
239 map.addControl(control);
244 var _request = OpenLayers.Request.GET;
245 OpenLayers.Request.GET = function(options) {
246 log.options = options;
249 // control url doesn't match layer urls, no request issued
251 control.getInfoForClick({xy: {x: 50, y: 50}});
252 t.ok(!log.options, "no url match, no request issued");
254 // give control a list of urls to match
256 control.layerUrls = ["http://a.mirror/wms", "http://b.mirror/wms"];
257 control.getInfoForClick({xy: {x: 50, y: 50}});
258 t.eq(log.options && log.options.url, "http://host/wms", "some match, request issued");
259 t.eq(log.options && log.options.params["query_layers"].join(","), "a,b", "selected layers queried");
261 // show that a layer can be matched if it has a urls array itself (first needs to be matched)
263 control.layerUrls = ["http://c.mirror/wms"];
264 control.getInfoForClick({xy: {x: 50, y: 50}});
265 t.eq(log.options && log.options.params["query_layers"].join(","), "c", "layer with urls array can be queried");
268 OpenLayers.Request.GET = _request;
276 <div id="map" style="width: 400px; height: 250px;"/>