Merge pull request #2582 from elemoine/wmsgfi

Support for "Stateless GetFeatureInfo"
This commit is contained in:
Éric Lemoine
2014-08-21 18:07:39 +02:00
7 changed files with 132 additions and 72 deletions

View File

@@ -87,18 +87,6 @@ ol.source.ImageWMS = function(opt_options) {
*/
this.imageSize_ = [0, 0];
/**
* @private
* @type {ol.proj.Projection}
*/
this.renderedProjection_ = null;
/**
* @private
* @type {number}
*/
this.renderedResolution_ = NaN;
/**
* @private
* @type {number}
@@ -115,13 +103,21 @@ ol.source.ImageWMS = function(opt_options) {
goog.inherits(ol.source.ImageWMS, ol.source.Image);
/**
* @const
* @type {ol.Size}
* @private
*/
ol.source.ImageWMS.GETFEATUREINFO_IMAGE_SIZE_ = [101, 101];
/**
* Return the GetFeatureInfo URL for the passed coordinate, resolution, and
* projection. Return `undefined` if the GetFeatureInfo URL cannot be
* constructed.
* @param {ol.Coordinate} coordinate Coordinate.
* @param {number} resolution Resolution.
* @param {ol.proj.Projection} projection Projection.
* @param {ol.proj.ProjectionLike} projection Projection.
* @param {!Object} params GetFeatureInfo params. `INFO_FORMAT` at least should
* be provided. If `QUERY_LAYERS` is not provided then the layers specified
* in the `LAYERS` parameter will be used. `VERSION` should not be
@@ -134,22 +130,13 @@ ol.source.ImageWMS.prototype.getGetFeatureInfoUrl =
goog.asserts.assert(!('VERSION' in params));
if (!goog.isDef(this.url_) || goog.isNull(this.image_)) {
if (!goog.isDef(this.url_)) {
return undefined;
}
goog.asserts.assert(this.imageSize_[0] !== 0 &&
this.imageSize_[1] !== 0);
goog.asserts.assert(!isNaN(this.renderedResolution_));
goog.asserts.assert(!goog.isNull(this.renderedProjection_));
if (resolution != this.renderedResolution_ ||
!ol.proj.equivalent(projection, this.renderedProjection_)) {
return undefined;
}
var extent = this.image_.getExtent();
var pixelRatio = this.image_.getPixelRatio();
var extent = ol.extent.getForViewAndSize(
coordinate, resolution, 0,
ol.source.ImageWMS.GETFEATUREINFO_IMAGE_SIZE_);
var baseParams = {
'SERVICE': 'WMS',
@@ -161,15 +148,14 @@ ol.source.ImageWMS.prototype.getGetFeatureInfoUrl =
};
goog.object.extend(baseParams, this.params_, params);
var imageResolution = resolution / pixelRatio;
var x = Math.floor((coordinate[0] - extent[0]) / imageResolution);
var y = Math.floor((extent[3] - coordinate[1]) / imageResolution);
var x = Math.floor((coordinate[0] - extent[0]) / resolution);
var y = Math.floor((extent[3] - coordinate[1]) / resolution);
goog.object.set(baseParams, this.v13_ ? 'I' : 'X', x);
goog.object.set(baseParams, this.v13_ ? 'J' : 'Y', y);
return this.getRequestUrl_(extent, this.imageSize_, pixelRatio, projection,
baseParams);
return this.getRequestUrl_(
extent, ol.source.ImageWMS.GETFEATUREINFO_IMAGE_SIZE_,
1, ol.proj.get(projection), baseParams);
};
@@ -251,8 +237,6 @@ ol.source.ImageWMS.prototype.getImage =
this.image_ = new ol.Image(extent, resolution, pixelRatio,
this.getAttributions(), url, this.crossOrigin_);
this.renderedProjection_ = projection;
this.renderedResolution_ = resolution;
this.renderedRevision_ = this.getRevision();
return this.image_;

View File

@@ -73,12 +73,6 @@ ol.source.TileWMS = function(opt_options) {
*/
this.params_ = params;
/**
* @private
* @type {number}
*/
this.pixelRatio_ = NaN;
/**
* @private
* @type {boolean}
@@ -136,11 +130,6 @@ ol.source.TileWMS.prototype.getGetFeatureInfoUrl =
goog.asserts.assert(!('VERSION' in params));
var pixelRatio = this.pixelRatio_;
if (isNaN(this.pixelRatio_)) {
return undefined;
}
var projectionObj = ol.proj.get(projection);
var tileGrid = this.getTileGrid();
@@ -165,9 +154,6 @@ ol.source.TileWMS.prototype.getGetFeatureInfoUrl =
tileExtent = ol.extent.buffer(tileExtent,
tileResolution * gutter, tileExtent);
}
if (pixelRatio != 1) {
tileSize = (tileSize * pixelRatio + 0.5) | 0;
}
var baseParams = {
'SERVICE': 'WMS',
@@ -179,16 +165,14 @@ ol.source.TileWMS.prototype.getGetFeatureInfoUrl =
};
goog.object.extend(baseParams, this.params_, params);
var x = Math.floor((coordinate[0] - tileExtent[0]) /
(tileResolution / pixelRatio));
var y = Math.floor((tileExtent[3] - coordinate[1]) /
(tileResolution / pixelRatio));
var x = Math.floor((coordinate[0] - tileExtent[0]) / tileResolution);
var y = Math.floor((tileExtent[3] - coordinate[1]) / tileResolution);
goog.object.set(baseParams, this.v13_ ? 'I' : 'X', x);
goog.object.set(baseParams, this.v13_ ? 'J' : 'Y', y);
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
pixelRatio, projectionObj, baseParams);
1, projectionObj, baseParams);
};
@@ -409,8 +393,6 @@ ol.source.TileWMS.prototype.tileUrlFunction_ =
};
goog.object.extend(baseParams, this.params_);
this.pixelRatio_ = pixelRatio;
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
pixelRatio, projection, baseParams);
};