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