Implementing GetFeatureInfo for WMS

This commit is contained in:
ahocevar
2013-07-31 12:10:02 +02:00
parent f333acc183
commit 4dd148a731
4 changed files with 142 additions and 0 deletions
+38
View File
@@ -1,8 +1,11 @@
goog.provide('ol.source.SingleImageWMS');
goog.require('goog.asserts');
goog.require('goog.uri.utils');
goog.require('ol.Image');
goog.require('ol.ImageUrlFunction');
goog.require('ol.extent');
goog.require('ol.source.FeatureInfoSource');
goog.require('ol.source.ImageSource');
goog.require('ol.source.wms');
@@ -11,6 +14,7 @@ goog.require('ol.source.wms');
/**
* @constructor
* @extends {ol.source.ImageSource}
* @implements {ol.source.FeatureInfoSource}
* @param {ol.source.SingleImageWMSOptions} options Options.
*/
ol.source.SingleImageWMS = function(options) {
@@ -28,6 +32,13 @@ ol.source.SingleImageWMS = function(options) {
imageUrlFunction: imageUrlFunction
});
/**
* @private
* @type {ol.source.WMSGetFeatureInfoOptions}
*/
this.getFeatureInfoOptions_ = goog.isDef(options.getFeatureInfoOptions) ?
options.getFeatureInfoOptions : {};
/**
* @private
* @type {ol.Image}
@@ -68,3 +79,30 @@ ol.source.SingleImageWMS.prototype.getImage =
this.image_ = this.createImage(extent, resolution, size, projection);
return this.image_;
};
/**
* @inheritDoc
*/
ol.source.SingleImageWMS.prototype.getFeatureInfoForPixel =
function(pixel, map, success, opt_error) {
var view2D = map.getView().getView2D(),
projection = view2D.getProjection(),
size = map.getSize(),
bottomLeft = map.getCoordinateFromPixel([0, size[1]]),
topRight = map.getCoordinateFromPixel([size[0], 0]),
extent = [bottomLeft[0], topRight[0], bottomLeft[1], topRight[1]],
x = pixel[0],
y = pixel[1],
url = this.imageUrlFunction(extent, size, projection);
goog.asserts.assert(goog.isDef(url),
'ol.source.SingleImageWMS#imageUrlFunction does not return a url');
// TODO: X, Y is for WMS 1.1 and I, J for 1.3 - without a closure url
// function this could be set conditionally.
url = goog.uri.utils.appendParamsFromMap(url, {
'X': x, 'I': x,
'Y': y, 'J': y
});
ol.source.wms.getFeatureInfo(url, this.getFeatureInfoOptions_, success,
opt_error);
};