WMSGetFeatureInfo: add beforegetfeatureinfo event, p=fvanderbiest, r=me (closes #2127)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9569 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -131,6 +131,9 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* Constant: EVENT_TYPES
|
* Constant: EVENT_TYPES
|
||||||
*
|
*
|
||||||
* Supported event types (in addition to those from <OpenLayers.Control>):
|
* Supported event types (in addition to those from <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.
|
||||||
* getfeatureinfo - Triggered when a GetFeatureInfo response is received.
|
* getfeatureinfo - Triggered when a GetFeatureInfo response is received.
|
||||||
* The event object has a *text* property with the body of the
|
* The event object has a *text* property with the body of the
|
||||||
* response (String), a *features* property with an array of the
|
* response (String), a *features* property with an array of the
|
||||||
@@ -138,7 +141,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* click or hover event that triggered the request, and a *request*
|
* click or hover event that triggered the request, and a *request*
|
||||||
* property with the request itself.
|
* property with the request itself.
|
||||||
*/
|
*/
|
||||||
EVENT_TYPES: ["getfeatureinfo"],
|
EVENT_TYPES: ["beforegetfeatureinfo", "getfeatureinfo"],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: <OpenLayers.Control.WMSGetFeatureInfo>
|
* Constructor: <OpenLayers.Control.WMSGetFeatureInfo>
|
||||||
@@ -216,6 +219,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* evt - {<OpenLayers.Event>}
|
* evt - {<OpenLayers.Event>}
|
||||||
*/
|
*/
|
||||||
getInfoForClick: function(evt) {
|
getInfoForClick: function(evt) {
|
||||||
|
this.events.triggerEvent("beforegetfeatureinfo", {xy: evt.xy});
|
||||||
// Set the cursor to "wait" to tell the user we're working on their
|
// Set the cursor to "wait" to tell the user we're working on their
|
||||||
// click.
|
// click.
|
||||||
OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
|
OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
|
||||||
@@ -230,6 +234,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* evt - {Object}
|
* evt - {Object}
|
||||||
*/
|
*/
|
||||||
getInfoForHover: function(evt) {
|
getInfoForHover: function(evt) {
|
||||||
|
this.events.triggerEvent("beforegetfeatureinfo", {xy: evt.xy});
|
||||||
this.request(evt.xy, {hover: true});
|
this.request(evt.xy, {hover: true});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,37 @@
|
|||||||
control.getInfoForHover({xy: {x: 50, y: 50}});
|
control.getInfoForHover({xy: {x: 50, y: 50}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_beforegetfeatureinfo_event(t) {
|
||||||
|
t.plan(2);
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
|
||||||
|
var xy, mode;
|
||||||
|
|
||||||
|
// mock up active control
|
||||||
|
var control = new OpenLayers.Control.WMSGetFeatureInfo({
|
||||||
|
request: function(position) {},
|
||||||
|
eventListeners: {
|
||||||
|
beforegetfeatureinfo: function(evt) {
|
||||||
|
t.eq(evt.xy, xy,
|
||||||
|
"beforegetfeatureinfo listener gets " +
|
||||||
|
"expected xy (" + mode + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
map.addControl(control);
|
||||||
|
control.activate();
|
||||||
|
|
||||||
|
// 1 test
|
||||||
|
mode = "click";
|
||||||
|
xy = {x: 50, y: 50};
|
||||||
|
control.getInfoForClick({xy: xy});
|
||||||
|
|
||||||
|
// 1 test
|
||||||
|
mode = "hover";
|
||||||
|
xy = {x: 70, y: 70};
|
||||||
|
control.getInfoForHover({xy: xy});
|
||||||
|
}
|
||||||
|
|
||||||
function test_activate(t) {
|
function test_activate(t) {
|
||||||
t.plan(4);
|
t.plan(4);
|
||||||
var map = new OpenLayers.Map("map");
|
var map = new OpenLayers.Map("map");
|
||||||
|
|||||||
Reference in New Issue
Block a user