Added WMSGetFeatureInfo control. Thanks dwins for the patch. I made the
following modifications:
* WMSGetFeatureInfo class was contained twice in WMSGetFeatureInfo.js.
Removed one.
* Fixed @requires
* Added vendorParams option (with test) to allow for e.g. adding custom
params like RADIUS
* Changed the clickPosition key in the getfeatureinfo event parameter
to xy to comply with other event parameters in OpenLayers
* Modified concatenation of layerNames and styleNames as proposed in my
previous comment
* Made a separate handleResponse function from the previously closured
callback function and added xy to the scope
* Fixed some ND comments, especially removed links (<..>) from object
types that cannot be linked (e.g. {String})
* Inserted line breaks where lines exceeded 80 chars
* Fixed test for format option, because this is now formats and has a
different type
* Fixed tests in the example (this is no US census data)
* added ProxyHost and absolute WMS url to the example
* removed custom format from the click handler in the example so users
can also see the simpler instantiation with the default formats
r=me (closes #2007)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9159 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
182
examples/getfeatureinfo-control.html
Normal file
182
examples/getfeatureinfo-control.html
Normal file
@@ -0,0 +1,182 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenLayers WMS Feature Info Example (GeoServer)</title>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
|
||||
<link rel="stylesheet" href="style.css" type="text/css" />
|
||||
<style type="text/css">
|
||||
ul, li { padding-left: 0px; margin-left: 0px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="title">Feature Info Example</h1>
|
||||
|
||||
<div id="tags"></div>
|
||||
|
||||
<p id="shortdesc">
|
||||
Demonstrates the WMSGetFeatureInfo control for fetching information about a position from WMS.
|
||||
</p>
|
||||
|
||||
<a id="permalink" href="">Permalink</a><br />
|
||||
|
||||
<div style="float:right;width:28%">
|
||||
<h1 style="font-size:1.3em;">South Africa</h1>
|
||||
<p style="font-size:.8em;">Click on the map to get feature info.</p>
|
||||
<div id="nodeList">
|
||||
</div>
|
||||
</div>
|
||||
<div id="map" class="smallmap"></div>
|
||||
|
||||
<script defer="defer" type="text/javascript">
|
||||
OpenLayers.ProxyHost = "/dev/examples/proxy.cgi?url=";
|
||||
var map = new OpenLayers.Map('map', {
|
||||
maxExtent: new OpenLayers.Bounds(16.154,-34.953,33.327,-22.193)
|
||||
});
|
||||
|
||||
var roads = new OpenLayers.Layer.WMS("Roads",
|
||||
"http://geo.openplans.org/geoserver/wms",
|
||||
{'layers': 'za:za_roads', transparent: true, format: 'image/png'},
|
||||
{isBaseLayer: true}
|
||||
);
|
||||
|
||||
var natural = new OpenLayers.Layer.WMS("Natural Features",
|
||||
"http://geo.openplans.org/geoserver/wms",
|
||||
{'layers': 'za:za_natural', transparent: true, format: 'image/png'},
|
||||
{isBaseLayer: false}
|
||||
);
|
||||
|
||||
var points = new OpenLayers.Layer.WMS("Points of Interest",
|
||||
"http://geo.openplans.org/geoserver/wms",
|
||||
{'layers': 'za:za_points', transparent: true, format: 'image/png'},
|
||||
{isBaseLayer: false}
|
||||
);
|
||||
|
||||
var vegetation = new OpenLayers.Layer.WMS("Vegetation",
|
||||
"http://geo.openplans.org/geoserver/wms",
|
||||
{'layers': 'za:za_vegetation', transparent: true, format: 'image/png'},
|
||||
{isBaseLayer: false}
|
||||
);
|
||||
|
||||
var highlightLayer = new OpenLayers.Layer.Vector("Highlighted Features", {
|
||||
displayInLayerSwitcher: false,
|
||||
isBaseLayer: false,
|
||||
styleMap: new OpenLayers.StyleMap({
|
||||
"default": new OpenLayers.Style({
|
||||
fillColor: "#0000BB",
|
||||
strokeColor: "#000099"
|
||||
})
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
var infoControls = {
|
||||
click: new OpenLayers.Control.WMSGetFeatureInfo('http://geo.openplans.org/geoserver/wms', {
|
||||
title: 'Identify features by clicking',
|
||||
layers: [vegetation],
|
||||
queryVisible: true
|
||||
}),
|
||||
hover: new OpenLayers.Control.WMSGetFeatureInfo('http://geo.openplans.org/geoserver/wms', {
|
||||
title: 'Identify features by clicking',
|
||||
layers: [vegetation],
|
||||
hover: true,
|
||||
// defining a custom format here
|
||||
formats: {'application/vnd.ogc.gml': new OpenLayers.Format.GML({
|
||||
typeName: 'vegetation',
|
||||
featureNS: 'http://opengeo.org/za'
|
||||
})},
|
||||
queryVisible: true
|
||||
})
|
||||
}
|
||||
|
||||
map.addLayers([roads, natural, points, vegetation, highlightLayer]);
|
||||
for (var i in infoControls) {
|
||||
infoControls[i].events.register("getfeatureinfo", this, showInfo);
|
||||
map.addControl(infoControls[i]);
|
||||
}
|
||||
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
|
||||
infoControls.click.activate();
|
||||
map.zoomToMaxExtent();
|
||||
|
||||
function showInfo(evt) {
|
||||
if (evt.features && evt.features.length) {
|
||||
highlightLayer.destroyFeatures();
|
||||
highlightLayer.addFeatures(evt.features);
|
||||
highlightLayer.redraw();
|
||||
} else {
|
||||
$('nodeList').innerHTML = evt.text;
|
||||
}
|
||||
}
|
||||
|
||||
function toggleControl(element) {
|
||||
for (var key in infoControls) {
|
||||
var control = infoControls[key];
|
||||
if (element.value == key && element.checked) {
|
||||
control.activate();
|
||||
} else {
|
||||
control.deactivate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toggleFormat(element) {
|
||||
for (var key in infoControls) {
|
||||
var control = infoControls[key];
|
||||
control.infoFormat = element.value;
|
||||
}
|
||||
}
|
||||
|
||||
function toggleLayers(element) {
|
||||
for (var key in infoControls) {
|
||||
var control = infoControls[key];
|
||||
if (element.value == 'Specified') {
|
||||
control.layers = [vegetation];
|
||||
} else {
|
||||
control.layers = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// function toggle(key
|
||||
</script>
|
||||
<div id="docs">
|
||||
</div>
|
||||
<ul id="control">
|
||||
<li>
|
||||
<input type="radio" name="controlType" value="click" id="click"
|
||||
onclick="toggleControl(this);" checked="checked" />
|
||||
<label for="click">Click</label>
|
||||
</li>
|
||||
<li>
|
||||
<input type="radio" name="controlType" value="hover" id="hover"
|
||||
onclick="toggleControl(this);" />
|
||||
<label for="hover">Hover</label>
|
||||
</li>
|
||||
</ul>
|
||||
<ul id="format">
|
||||
<li>
|
||||
<input type="radio" name="formatType" value="text/html" id="html"
|
||||
onclick="toggleFormat(this);" checked="checked" />
|
||||
<label for="html">Show HTML Description</label>
|
||||
</li>
|
||||
<li>
|
||||
<input type="radio" name="formatType" value="application/vnd.ogc.gml" id="highlight"
|
||||
onclick="toggleFormat(this);" />
|
||||
<label for="highlight">Highlight Feature on Map</label>
|
||||
</li>
|
||||
</ul>
|
||||
<ul id="layers">
|
||||
<li>
|
||||
<input type="radio" name="layerSelection" value="Specified" id="Specified"
|
||||
onclick="toggleLayers(this);" checked="checked" />
|
||||
<label for="html">Get Vegetation info</label>
|
||||
</li>
|
||||
<li>
|
||||
<input type="radio" name="layerSelection" value="Auto" id="Auto"
|
||||
onclick="toggleLayers(this);" />
|
||||
<label for="">Get info for visible layers</label>
|
||||
</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
@@ -163,6 +163,7 @@
|
||||
"OpenLayers/Control/SelectFeature.js",
|
||||
"OpenLayers/Control/NavigationHistory.js",
|
||||
"OpenLayers/Control/Measure.js",
|
||||
"OpenLayers/Control/WMSGetFeatureInfo.js",
|
||||
"OpenLayers/Geometry.js",
|
||||
"OpenLayers/Geometry/Rectangle.js",
|
||||
"OpenLayers/Geometry/Collection.js",
|
||||
|
||||
363
lib/OpenLayers/Control/WMSGetFeatureInfo.js
Normal file
363
lib/OpenLayers/Control/WMSGetFeatureInfo.js
Normal file
@@ -0,0 +1,363 @@
|
||||
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
|
||||
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||
* full text of the license. */
|
||||
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Control.js
|
||||
* @requires OpenLayers/Handler/Click.js
|
||||
* @requires OpenLayers/Handler/Hover.js
|
||||
* @requires OpenLayers/Request.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Control.WMSGetFeatureInfo
|
||||
* The WMSGetFeatureInfo control uses a WMS query to get information about a point on the map. The
|
||||
* information may be in a display-friendly format such as HTML, or a machine-friendly format such
|
||||
* as GML, depending on the server's capabilities and the client's configuration. This control
|
||||
* handles click or hover events, attempts to parse the results using an OpenLayers.Format, and
|
||||
* fires a 'getfeatureinfo' event with the click position, the raw body of the response, and an
|
||||
* array of features if it successfully read the response.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Control>
|
||||
*/
|
||||
OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
/**
|
||||
* APIProperty: hover
|
||||
* {Boolean} Send WMS request on mouse moves. This will cause the
|
||||
* "hoverfeature" and "outfeature" events to be triggered.
|
||||
* Default is false.
|
||||
*/
|
||||
hover: false,
|
||||
|
||||
/**
|
||||
* APIProperty: maxFeatures
|
||||
* {Integer} maximum number of features to return from a WMS query. This
|
||||
* has the same effect as the feature_count parameter on WMS GetFeatureInfo
|
||||
* requests. Will be ignored for box selections.
|
||||
*/
|
||||
maxFeatures: 10,
|
||||
|
||||
/**
|
||||
* Property: layers
|
||||
* {<Array(OpenLayers.Layer.WMS>} The Layer objects for which to find
|
||||
* feature info. If omitted, search all WMS layers from the map whose url
|
||||
* is the same as the one in this control's configuration. See the
|
||||
* <queryVisible> property
|
||||
*/
|
||||
layers: null,
|
||||
|
||||
/**
|
||||
* Property: queryVisible
|
||||
* {Boolean} If true, filter out hidden layers when searching the map for
|
||||
* layers to query. If an explicit layers parameter is set, then this does
|
||||
* nothing.
|
||||
*/
|
||||
queryVisible: false,
|
||||
|
||||
/**
|
||||
* Property: url
|
||||
* {String} The URL of the WMS service to use.
|
||||
*/
|
||||
url: null,
|
||||
|
||||
/**
|
||||
* Property: infoFormat
|
||||
* {String} The mimetype to request from the server
|
||||
*/
|
||||
infoFormat: 'text/html',
|
||||
|
||||
/**
|
||||
* Property: vendorParams
|
||||
* {Object} Additional parameters that will be added to the request, for
|
||||
* WMS implementations that support them. This could e.g. look like
|
||||
* (start code)
|
||||
* {
|
||||
* radius: 5
|
||||
* }
|
||||
* (end)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Property: formats
|
||||
* An object mapping from mime-types to OL Format objects to use when
|
||||
* parsing GFI responses. The default mapping is
|
||||
* (start code)
|
||||
* {
|
||||
* 'application/vnd.ogc.gml': new OpenLayers.Format.WMSGetFeatureInfo()
|
||||
* }
|
||||
* (end)
|
||||
* An object provided here will extend the default mapping.
|
||||
*/
|
||||
formats: null,
|
||||
|
||||
/**
|
||||
* APIProperty: handlerOptions
|
||||
* {Object} Additional options for the handlers used by this control, e.g.
|
||||
* (start code)
|
||||
* {
|
||||
* "click": {delay: 100},
|
||||
* "hover": {delay: 300}
|
||||
* }
|
||||
* (end)
|
||||
*/
|
||||
handlerOptions: null,
|
||||
|
||||
/**
|
||||
* Property: handler
|
||||
* {Object} Reference to the <OpenLayers.Handler> for this control
|
||||
*/
|
||||
handler: null,
|
||||
|
||||
/**
|
||||
* Property: hoverRequest
|
||||
* {<OpenLayers.Request>} contains the currently running hover request
|
||||
* (if any).
|
||||
*/
|
||||
hoverRequest: null,
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
*
|
||||
* Supported event types:
|
||||
* - *getfeatureinfo* Triggered when a GetFeatureInfo response is received.
|
||||
* The event object has a text property with:
|
||||
* text: a string containing the body of the response,
|
||||
* features: an array of the parsed features, if parsing succeeded.
|
||||
* xy: the position of the mouse click or hover event that
|
||||
* triggered the request
|
||||
*/
|
||||
EVENT_TYPES: ["getfeatureinfo"],
|
||||
|
||||
/**
|
||||
* Constructor: <OpenLayers.Control.SelectFeature>
|
||||
*
|
||||
* Parameters:
|
||||
* url - {String}
|
||||
* options - {Object}
|
||||
*/
|
||||
initialize: function(url, options) {
|
||||
// concatenate events specific to vector with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.WMSGetFeatureInfo.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
|
||||
options = options || {};
|
||||
options.handlerOptions = options.handlerOptions || {};
|
||||
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
this.url = url;
|
||||
this.layers = options.layers;
|
||||
|
||||
this.formats = OpenLayers.Util.extend({
|
||||
'application/vnd.ogc.gml': new OpenLayers.Format.WMSGetFeatureInfo()
|
||||
}, options.formats);
|
||||
|
||||
|
||||
if (this.hover) {
|
||||
this.handler = new OpenLayers.Handler.Hover(
|
||||
this, {
|
||||
'move': this.cancelHover,
|
||||
'pause': this.getInfoForHover
|
||||
},
|
||||
OpenLayers.Util.extend(this.handlerOptions.hover || {}, {
|
||||
'delay': 250
|
||||
}));
|
||||
} else {
|
||||
this.handler = new OpenLayers.Handler.Click(this,
|
||||
{click: this.getInfoForClick}, this.handlerOptions.click || {});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: activate
|
||||
* Activates the control.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} The control was effectively activated.
|
||||
*/
|
||||
activate: function () {
|
||||
if (!this.active) {
|
||||
this.handler.activate();
|
||||
}
|
||||
return OpenLayers.Control.prototype.activate.apply(
|
||||
this, arguments
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: deactivate
|
||||
* Deactivates the control.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} The control was effectively deactivated.
|
||||
*/
|
||||
deactivate: function () {
|
||||
return OpenLayers.Control.prototype.deactivate.apply(
|
||||
this, arguments
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getInfoForClick
|
||||
* Called on click
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {<OpenLayers.Event>}
|
||||
*/
|
||||
getInfoForClick: function(evt) {
|
||||
// Set the cursor to "wait" to tell the user we're working on their
|
||||
// click.
|
||||
OpenLayers.Element.addClass(this.map.div, "olCursorWait");
|
||||
this.request(evt.xy, {});
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getInfoForHover
|
||||
* Pause callback for the hover handler
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Object}
|
||||
*/
|
||||
getInfoForHover: function(evt) {
|
||||
this.request(evt.xy, {hover: true});
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: cancelHover
|
||||
* Cancel callback for the hover handler
|
||||
*/
|
||||
cancelHover: function() {
|
||||
if (this.hoverRequest) {
|
||||
this.hoverRequest.abort();
|
||||
this.hoverRequest = null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: findLayers
|
||||
* Internal method to get the layers, independent of whether we are
|
||||
* inspecting the map or using a client-provided array
|
||||
*/
|
||||
findLayers: function() {
|
||||
if (this.layers) return this.layers;
|
||||
|
||||
var layers = [];
|
||||
|
||||
for (var i = 0, len = this.map.layers.length; i < len; i++) {
|
||||
var mapLayer = this.map.layers[i];
|
||||
if (mapLayer instanceof OpenLayers.Layer.WMS
|
||||
&& mapLayer.url === this.url
|
||||
&& (!this.queryVisible || mapLayer.getVisibility())) {
|
||||
|
||||
layers.push(mapLayer);
|
||||
}
|
||||
}
|
||||
|
||||
return layers;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: request
|
||||
* Sends a GetFeatureInfo request to the WMS
|
||||
*
|
||||
* Parameters:
|
||||
* clickPosition - The position on the map where the mouse event occurred
|
||||
* options - {Object} additional options for this method.
|
||||
*
|
||||
* Valid options:
|
||||
* - *hover* {Boolean} true if we do the request for the hover handler
|
||||
*/
|
||||
request: function(clickPosition, options) {
|
||||
options = options || {};
|
||||
var layerNames = [];
|
||||
var styleNames = [];
|
||||
|
||||
var layers = this.findLayers();
|
||||
|
||||
for (var i = 0, len = layers.length; i < len; i++) {
|
||||
layerNames = layerNames.concat(layers[i].params.LAYERS);
|
||||
// in the event of a WMS layer bundling multiple layers but not
|
||||
// specifying styles,we need the same number of commas to specify
|
||||
// the default style for each of the layers. We can't just leave it
|
||||
// blank as we may be including other layers that do specify styles.
|
||||
styleNames = styleNames.concat(layers[i].params.STYLES ||
|
||||
layers[i].params.LAYERS.replace(/[^,]/g,""));
|
||||
}
|
||||
|
||||
var wmsOptions = {
|
||||
url: this.url,
|
||||
params: OpenLayers.Util.applyDefaults({
|
||||
service: "WMS",
|
||||
version: "1.1.0",
|
||||
request: 'getfeatureinfo',
|
||||
layers: layerNames,
|
||||
query_layers: layerNames,
|
||||
styles: styleNames,
|
||||
bbox: this.map.getExtent().toBBOX(),
|
||||
srs: this.map.getProjection(),
|
||||
feature_count: this.maxFeatures,
|
||||
x: clickPosition.x,
|
||||
y: clickPosition.y,
|
||||
height: this.map.getSize().h,
|
||||
width: this.map.getSize().w,
|
||||
info_format: this.infoFormat
|
||||
}, this.vendorParams),
|
||||
callback: this.handleResponse,
|
||||
scope: OpenLayers.Util.extend({
|
||||
xy: clickPosition
|
||||
}, this)
|
||||
};
|
||||
|
||||
var response = OpenLayers.Request.GET(wmsOptions);
|
||||
|
||||
if (options.hover === true) {
|
||||
this.hoverRequest = response.priv;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: handleResponse
|
||||
* Handler for the GetFeatureInfo response. Will be called in an extended
|
||||
* scope of this instance plus an xy property with the click position.
|
||||
*
|
||||
* Parameters:
|
||||
* response - {Object}
|
||||
*/
|
||||
handleResponse: function(response) {
|
||||
var features;
|
||||
var fmt = this.formats[
|
||||
response.getResponseHeader("Content-type").split(";")[0]
|
||||
];
|
||||
if (fmt) {
|
||||
features = fmt.read(response.responseXml ||
|
||||
response.responseText);
|
||||
}
|
||||
|
||||
this.events.triggerEvent("getfeatureinfo", {
|
||||
text: response.responseText,
|
||||
features: features,
|
||||
xy: this.xy
|
||||
});
|
||||
|
||||
// Reset the cursor.
|
||||
OpenLayers.Element.removeClass(this.map.div, "olCursorWait");
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: setMap
|
||||
* Set the map property for the control.
|
||||
*
|
||||
* Parameters:
|
||||
* map - {<OpenLayers.Map>}
|
||||
*/
|
||||
setMap: function(map) {
|
||||
this.handler.setMap(map);
|
||||
OpenLayers.Control.prototype.setMap.apply(this, arguments);
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Control.WMSGetFeatureInfo"
|
||||
});
|
||||
293
tests/Control/WMSGetFeatureInfo.html
Normal file
293
tests/Control/WMSGetFeatureInfo.html
Normal file
@@ -0,0 +1,293 @@
|
||||
<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: 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();
|
||||
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();
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width: 400px; height: 250px;"/>
|
||||
</body>
|
||||
</html>
|
||||
@@ -33,6 +33,7 @@
|
||||
<li>Control/SelectFeature.html</li>
|
||||
<li>Control/Snapping.html</li>
|
||||
<li>Control/Split.html</li>
|
||||
<li>Control/WMSGetFeatureInfo.html</li>
|
||||
<li>Events.html</li>
|
||||
<li>Extras.html</li>
|
||||
<li>Feature.html</li>
|
||||
|
||||
Reference in New Issue
Block a user