WMSGetFeatureInfo: add an event when no queryable layers are found, r=crschmidt (closes #2744)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10670 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -149,6 +149,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* beforegetfeatureinfo - Triggered before the request is sent.
|
||||
* The event object has an *xy* property with the position of the
|
||||
* mouse click or hover event that triggers the request.
|
||||
* nogetfeatureinfo - no queryable layers were found.
|
||||
* getfeatureinfo - Triggered when a GetFeatureInfo response is received.
|
||||
* The event object has a *text* property with the body of the
|
||||
* response (String), a *features* property with an array of the
|
||||
@@ -159,7 +160,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* layers, *text* and *request* will only contain the response body
|
||||
* and request object of the last request.
|
||||
*/
|
||||
EVENT_TYPES: ["beforegetfeatureinfo", "getfeatureinfo"],
|
||||
EVENT_TYPES: ["beforegetfeatureinfo", "nogetfeatureinfo", "getfeatureinfo"],
|
||||
|
||||
/**
|
||||
* Constructor: <OpenLayers.Control.WMSGetFeatureInfo>
|
||||
@@ -424,6 +425,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
request: function(clickPosition, options) {
|
||||
var layers = this.findLayers();
|
||||
if(layers.length == 0) {
|
||||
this.events.triggerEvent("nogetfeatureinfo");
|
||||
// Reset the cursor.
|
||||
OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait");
|
||||
return;
|
||||
|
||||
@@ -146,6 +146,26 @@
|
||||
control.getInfoForHover({xy: xy});
|
||||
}
|
||||
|
||||
function test_nogetfeatureinfo_event(t) {
|
||||
t.plan(1);
|
||||
var map = new OpenLayers.Map('map');
|
||||
// mock up active control
|
||||
var control = new OpenLayers.Control.WMSGetFeatureInfo({
|
||||
eventListeners: {
|
||||
nogetfeatureinfo: function(evt) {
|
||||
t.ok((evt.type == "nogetfeatureinfo"), "nogetfeatureinfo listener gets called when there are no queryable layers");
|
||||
}
|
||||
}
|
||||
});
|
||||
map.addControl(control);
|
||||
control.activate();
|
||||
|
||||
// 1 test
|
||||
mode = "click";
|
||||
xy = {x: 50, y: 50};
|
||||
control.getInfoForClick({xy: xy});
|
||||
}
|
||||
|
||||
function test_activate(t) {
|
||||
t.plan(4);
|
||||
var map = new OpenLayers.Map("map");
|
||||
|
||||
Reference in New Issue
Block a user