Merge pull request #872 from marcjansen/wmsgfi-api
WMSGetFeatureInfo API enhancements
This commit is contained in:
@@ -15,10 +15,10 @@
|
||||
/**
|
||||
* 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
|
||||
* 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:
|
||||
@@ -49,23 +49,25 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
maxFeatures: 10,
|
||||
|
||||
/** APIProperty: clickCallback
|
||||
* {String} The click callback to register in the
|
||||
* {<OpenLayers.Handler.Click>} object created when the hover
|
||||
* option is set to false. Default is "click".
|
||||
/**
|
||||
* APIProperty: clickCallback
|
||||
* {String} The click callback to register in the
|
||||
* {<OpenLayers.Handler.Click>} object created when the hover
|
||||
* option is set to false. Default is "click".
|
||||
*/
|
||||
clickCallback: "click",
|
||||
|
||||
/** APIProperty: output
|
||||
* {String} Either "features" or "object". When triggering a
|
||||
* getfeatureinfo request should we pass on an array of features
|
||||
* or an object with with a "features" property and other properties
|
||||
* (such as the url of the WMS). Default is "features".
|
||||
|
||||
/**
|
||||
* APIProperty: output
|
||||
* {String} Either "features" or "object". When triggering a getfeatureinfo
|
||||
* request should we pass on an array of features or an object with with
|
||||
* a "features" property and other properties (such as the url of the
|
||||
* WMS). Default is "features".
|
||||
*/
|
||||
output: "features",
|
||||
|
||||
|
||||
/**
|
||||
* Property: layers
|
||||
* APIProperty: layers
|
||||
* {Array(<OpenLayers.Layer.WMS>)} The layers to query for feature info.
|
||||
* If omitted, all map WMS layers with a url that matches this <url> or
|
||||
* <layerUrls> will be considered.
|
||||
@@ -73,21 +75,21 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
layers: null,
|
||||
|
||||
/**
|
||||
* Property: queryVisible
|
||||
* APIProperty: queryVisible
|
||||
* {Boolean} If true, filter out hidden layers when searching the map for
|
||||
* layers to query. Default is false.
|
||||
*/
|
||||
queryVisible: false,
|
||||
|
||||
/**
|
||||
* Property: url
|
||||
* APIProperty: url
|
||||
* {String} The URL of the WMS service to use. If not provided, the url
|
||||
* of the first eligible layer will be used.
|
||||
*/
|
||||
url: null,
|
||||
|
||||
|
||||
/**
|
||||
* Property: layerUrls
|
||||
* APIProperty: layerUrls
|
||||
* {Array(String)} Optional list of urls for layers that should be queried.
|
||||
* This can be used when the layer url differs from the url used for
|
||||
* making GetFeatureInfo requests (in the case of a layer using cached
|
||||
@@ -96,18 +98,18 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
layerUrls: null,
|
||||
|
||||
/**
|
||||
* Property: infoFormat
|
||||
* {String} The mimetype to request from the server. If you are using
|
||||
* drillDown mode and have multiple servers that do not share a common
|
||||
* infoFormat, you can override the control's infoFormat by providing an
|
||||
* INFO_FORMAT parameter in your <OpenLayers.Layer.WMS> instance(s).
|
||||
* APIProperty: infoFormat
|
||||
* {String} The mimetype to request from the server. If you are using
|
||||
* drillDown mode and have multiple servers that do not share a common
|
||||
* infoFormat, you can override the control's infoFormat by providing an
|
||||
* INFO_FORMAT parameter in your <OpenLayers.Layer.WMS> instance(s).
|
||||
*/
|
||||
infoFormat: 'text/html',
|
||||
|
||||
|
||||
/**
|
||||
* Property: vendorParams
|
||||
* APIProperty: vendorParams
|
||||
* {Object} Additional parameters that will be added to the request, for
|
||||
* WMS implementations that support them. This could e.g. look like
|
||||
* WMS implementations that support them. This could e.g. look like
|
||||
* (start code)
|
||||
* {
|
||||
* radius: 5
|
||||
@@ -115,16 +117,16 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* (end)
|
||||
*/
|
||||
vendorParams: {},
|
||||
|
||||
|
||||
/**
|
||||
* Property: format
|
||||
* APIProperty: format
|
||||
* {<OpenLayers.Format>} A format for parsing GetFeatureInfo responses.
|
||||
* Default is <OpenLayers.Format.WMSGetFeatureInfo>.
|
||||
*/
|
||||
format: null,
|
||||
|
||||
|
||||
/**
|
||||
* Property: formatOptions
|
||||
* APIProperty: formatOptions
|
||||
* {Object} Optional properties to set on the format (if one is not provided
|
||||
* in the <format> property.
|
||||
*/
|
||||
@@ -140,21 +142,21 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* }
|
||||
* (end)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 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,
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* APIProperty: events
|
||||
* {<OpenLayers.Events>} Events instance for listeners and triggering
|
||||
* control specific events.
|
||||
@@ -166,7 +168,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
*
|
||||
* Supported event types (in addition to those from <OpenLayers.Control.events>):
|
||||
* beforegetfeatureinfo - Triggered before the request is sent.
|
||||
* The event object has an *xy* property with the position of the
|
||||
* 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.
|
||||
@@ -184,20 +186,20 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Constructor: <OpenLayers.Control.WMSGetFeatureInfo>
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object}
|
||||
* options - {Object}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
options.handlerOptions = options.handlerOptions || {};
|
||||
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
|
||||
|
||||
if(!this.format) {
|
||||
this.format = new OpenLayers.Format.WMSGetFeatureInfo(
|
||||
options.formatOptions
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if(this.drillDown === true) {
|
||||
this.hover = false;
|
||||
}
|
||||
@@ -220,11 +222,11 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getInfoForClick
|
||||
* Method: getInfoForClick
|
||||
* Called on click
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {<OpenLayers.Event>}
|
||||
* evt - {<OpenLayers.Event>}
|
||||
*/
|
||||
getInfoForClick: function(evt) {
|
||||
this.events.triggerEvent("beforegetfeatureinfo", {xy: evt.xy});
|
||||
@@ -233,7 +235,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
|
||||
this.request(evt.xy, {});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Method: getInfoForHover
|
||||
* Pause callback for the hover handler
|
||||
@@ -284,7 +286,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
}
|
||||
return layers;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Method: urlMatches
|
||||
* Test to see if the provided url matches either the control <url> or one
|
||||
@@ -383,7 +385,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Method: getStyleNames
|
||||
* Gets the STYLES parameter for the layer. Make sure the STYLES parameter
|
||||
* matches the LAYERS parameter
|
||||
*
|
||||
*
|
||||
* Parameters:
|
||||
* layer - {<OpenLayers.Layer.WMS>}
|
||||
*
|
||||
@@ -411,12 +413,12 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
/**
|
||||
* Method: request
|
||||
* Sends a GetFeatureInfo request to the WMS
|
||||
*
|
||||
*
|
||||
* Parameters:
|
||||
* clickPosition - {<OpenLayers.Pixel>} 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
|
||||
*/
|
||||
@@ -428,13 +430,13 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
options = options || {};
|
||||
if(this.drillDown === false) {
|
||||
var wmsOptions = this.buildWMSOptions(this.url, layers,
|
||||
clickPosition, layers[0].params.FORMAT);
|
||||
clickPosition, layers[0].params.FORMAT);
|
||||
var request = OpenLayers.Request.GET(wmsOptions);
|
||||
|
||||
|
||||
if (options.hover === true) {
|
||||
this.hoverRequest = request;
|
||||
}
|
||||
@@ -458,9 +460,9 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
var layers;
|
||||
for (var url in services) {
|
||||
layers = services[url];
|
||||
var wmsOptions = this.buildWMSOptions(url, layers,
|
||||
var wmsOptions = this.buildWMSOptions(url, layers,
|
||||
clickPosition, layers[0].params.FORMAT);
|
||||
OpenLayers.Request.GET(wmsOptions);
|
||||
OpenLayers.Request.GET(wmsOptions);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -488,11 +490,11 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
// Reset the cursor.
|
||||
OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait");
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Method: handleResponse
|
||||
* Handler for the GetFeatureInfo response.
|
||||
*
|
||||
*
|
||||
* Parameters:
|
||||
* xy - {<OpenLayers.Pixel>} The position on the map where the
|
||||
* mouse event occurred.
|
||||
@@ -500,7 +502,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* url - {String} The url which was used for this request.
|
||||
*/
|
||||
handleResponse: function(xy, request, url) {
|
||||
|
||||
|
||||
var doc = request.responseXML;
|
||||
if(!doc || !doc.documentElement) {
|
||||
doc = request.responseText;
|
||||
@@ -518,7 +520,7 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
this._features = (this._features || []).concat(features);
|
||||
}
|
||||
if (this._requestCount === this._numRequests) {
|
||||
this.triggerGetFeatureInfo(request, xy, this._features.concat());
|
||||
this.triggerGetFeatureInfo(request, xy, this._features.concat());
|
||||
delete this._features;
|
||||
delete this._requestCount;
|
||||
delete this._numRequests;
|
||||
|
||||
Reference in New Issue
Block a user