diff --git a/old/examples/getfeatureinfo.html b/examples/getfeatureinfo.html
similarity index 93%
rename from old/examples/getfeatureinfo.html
rename to examples/getfeatureinfo.html
index 16446f0cfd..8d4b054528 100644
--- a/old/examples/getfeatureinfo.html
+++ b/examples/getfeatureinfo.html
@@ -32,7 +32,7 @@
GetFeatureInfo example
-
Example of a WMS layer and a vector layer, both configured to provide feature information on click.
+
This example shows how to trigger WMS GetFeatureInfo requests on click for a WMS image layer.
diff --git a/examples/getfeatureinfo.js b/examples/getfeatureinfo.js
new file mode 100644
index 0000000000..42e7468074
--- /dev/null
+++ b/examples/getfeatureinfo.js
@@ -0,0 +1,42 @@
+goog.require('ol.Map');
+goog.require('ol.RendererHint');
+goog.require('ol.View2D');
+goog.require('ol.layer.Tile');
+goog.require('ol.source.TileWMS');
+
+
+var wmsSource = new ol.source.TileWMS({
+ url: 'http://demo.opengeo.org/geoserver/wms',
+ params: {'LAYERS': 'ne:ne'}
+});
+
+var wmsLayer = new ol.layer.Tile({
+ source: wmsSource
+});
+
+var view = new ol.View2D({
+ center: [0, 0],
+ zoom: 1
+});
+
+var viewProjection = /** @type {ol.proj.Projection} */
+ (view.getProjection());
+
+var map = new ol.Map({
+ layers: [wmsLayer],
+ renderer: ol.RendererHint.CANVAS,
+ target: 'map',
+ view: view
+});
+
+map.on('singleclick', function(evt) {
+ document.getElementById('info').innerHTML = '';
+ var viewResolution = /** @type {number} */ (view.getResolution());
+ var url = wmsSource.getGetFeatureInfoUrl(
+ evt.getCoordinate(), viewResolution, viewProjection,
+ {'INFO_FORMAT': 'text/html'});
+ if (url) {
+ document.getElementById('info').innerHTML =
+ '
';
+ }
+});
diff --git a/old/examples/getfeatureinfo.js b/old/examples/getfeatureinfo.js
deleted file mode 100644
index ae7258d6cb..0000000000
--- a/old/examples/getfeatureinfo.js
+++ /dev/null
@@ -1,56 +0,0 @@
-goog.require('ol.Map');
-goog.require('ol.RendererHint');
-goog.require('ol.View2D');
-goog.require('ol.layer.Tile');
-goog.require('ol.layer.Vector');
-goog.require('ol.parser.GeoJSON');
-goog.require('ol.source.TileWMS');
-goog.require('ol.source.Vector');
-goog.require('ol.style.Stroke');
-goog.require('ol.style.Style');
-
-
-var wms = new ol.layer.Tile({
- source: new ol.source.TileWMS({
- url: 'http://demo.opengeo.org/geoserver/wms',
- params: {'LAYERS': 'ne:ne'}
- })
-});
-
-var vector = new ol.layer.Vector({
- source: new ol.source.Vector({
- parser: new ol.parser.GeoJSON(),
- url: 'data/countries.geojson'
- }),
- style: new ol.style.Style({
- symbolizers: [
- new ol.style.Stroke({
- color: '#33cc66',
- width: 2
- })
- ]
- }),
- transformFeatureInfo: function(features) {
- return features.length > 0 ?
- features[0].getId() + ': ' + features[0].get('name') : ' ';
- }
-});
-
-var map = new ol.Map({
- layers: [wms, vector],
- renderer: ol.RendererHint.CANVAS,
- target: 'map',
- view: new ol.View2D({
- center: [0, 0],
- zoom: 1
- })
-});
-
-map.on('singleclick', function(evt) {
- map.getFeatureInfo({
- pixel: evt.getPixel(),
- success: function(featureInfoByLayer) {
- document.getElementById('info').innerHTML = featureInfoByLayer.join('');
- }
- });
-});
diff --git a/old/src/ol/source/featureinfosource.js b/old/src/ol/source/featureinfosource.js
deleted file mode 100644
index 61f4d116ec..0000000000
--- a/old/src/ol/source/featureinfosource.js
+++ /dev/null
@@ -1,19 +0,0 @@
-goog.provide('ol.source.FeatureInfoSource');
-
-
-
-/**
- * @interface
- * @todo stability experimental
- */
-ol.source.FeatureInfoSource = function() {};
-
-
-/**
- * @param {ol.Pixel} pixel Pixel.
- * @param {ol.Map} map The map that the pixel belongs to.
- * @param {function(string)} success Callback with feature info.
- * @param {function()=} opt_error Optional error callback.
- */
-ol.source.FeatureInfoSource.prototype.getFeatureInfoForPixel =
- goog.abstractMethod;
diff --git a/old/src/ol/source/wmssource.exports b/old/src/ol/source/wmssource.exports
deleted file mode 100644
index ec75424b4f..0000000000
--- a/old/src/ol/source/wmssource.exports
+++ /dev/null
@@ -1,3 +0,0 @@
-@exportSymbol ol.source.WMSGetFeatureInfoMethod
-@exportProperty ol.source.WMSGetFeatureInfoMethod.IFRAME
-@exportProperty ol.source.WMSGetFeatureInfoMethod.XHR_GET
diff --git a/src/ol/source/imagewmssource.exports b/src/ol/source/imagewmssource.exports
index acb2495587..eb78668cdf 100644
--- a/src/ol/source/imagewmssource.exports
+++ b/src/ol/source/imagewmssource.exports
@@ -1,4 +1,5 @@
@exportSymbol ol.source.ImageWMS
+@exportProperty ol.source.ImageWMS.prototype.getGetFeatureInfoUrl
@exportProperty ol.source.ImageWMS.prototype.getParams
@exportProperty ol.source.ImageWMS.prototype.setUrl
@exportProperty ol.source.ImageWMS.prototype.updateParams
diff --git a/src/ol/source/imagewmssource.js b/src/ol/source/imagewmssource.js
index 82a7c2348e..0e48cd1bcd 100644
--- a/src/ol/source/imagewmssource.js
+++ b/src/ol/source/imagewmssource.js
@@ -1,3 +1,5 @@
+// FIXME cannot be shared between maps with different projections
+
goog.provide('ol.source.ImageWMS');
goog.require('goog.asserts');
@@ -6,6 +8,7 @@ goog.require('goog.string');
goog.require('goog.uri.utils');
goog.require('ol.Image');
goog.require('ol.extent');
+goog.require('ol.proj');
goog.require('ol.source.Image');
goog.require('ol.source.wms');
goog.require('ol.source.wms.ServerType');
@@ -74,6 +77,24 @@ ol.source.ImageWMS = function(opt_options) {
*/
this.image_ = null;
+ /**
+ * @private
+ * @type {ol.Size}
+ */
+ this.imageSize_ = [0, 0];
+
+ /**
+ * @private
+ * @type {ol.proj.Projection}
+ */
+ this.renderedProjection_ = null;
+
+ /**
+ * @private
+ * @type {number}
+ */
+ this.renderedResolution_ = NaN;
+
/**
* @private
* @type {number}
@@ -90,6 +111,63 @@ ol.source.ImageWMS = function(opt_options) {
goog.inherits(ol.source.ImageWMS, ol.source.Image);
+/**
+ * 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 {!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
+ * specified here.
+ * @return {string|undefined} GetFeatureInfo URL.
+ */
+ol.source.ImageWMS.prototype.getGetFeatureInfoUrl =
+ function(coordinate, resolution, projection, params) {
+
+ goog.asserts.assert(!('VERSION' in params));
+
+ if (!goog.isDef(this.url_) || goog.isNull(this.image_)) {
+ 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 baseParams = {
+ 'SERVICE': 'WMS',
+ 'VERSION': ol.source.wms.DEFAULT_VERSION,
+ 'REQUEST': 'GetFeatureInfo',
+ 'FORMAT': 'image/png',
+ 'TRANSPARENT': true,
+ 'QUERY_LAYERS': goog.object.get(this.params_, 'LAYERS')
+ };
+ 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);
+ 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);
+};
+
+
/**
* Get the user-provided params, i.e. those passed to the constructor through
* the "params" option, and possibly updated using the updateParams method.
@@ -134,6 +212,62 @@ ol.source.ImageWMS.prototype.getImage =
};
goog.object.extend(params, this.params_);
+ extent = extent.slice();
+ var centerX = (extent[0] + extent[2]) / 2;
+ var centerY = (extent[1] + extent[3]) / 2;
+ if (this.ratio_ != 1) {
+ var halfWidth = this.ratio_ * (extent[2] - extent[0]) / 2;
+ var halfHeight = this.ratio_ * (extent[3] - extent[1]) / 2;
+ extent[0] = centerX - halfWidth;
+ extent[1] = centerY - halfHeight;
+ extent[2] = centerX + halfWidth;
+ extent[3] = centerY + halfHeight;
+ }
+
+ var imageResolution = resolution / pixelRatio;
+
+ // Compute an integer width and height.
+ var width = Math.ceil((extent[2] - extent[0]) / imageResolution);
+ var height = Math.ceil((extent[3] - extent[1]) / imageResolution);
+
+ // Modify the extent to match the integer width and height.
+ extent[0] = centerX - imageResolution * width / 2;
+ extent[2] = centerX + imageResolution * width / 2;
+ extent[1] = centerY - imageResolution * height / 2;
+ extent[3] = centerY + imageResolution * height / 2;
+
+ this.imageSize_[0] = width;
+ this.imageSize_[1] = height;
+
+ var url = this.getRequestUrl_(extent, this.imageSize_, pixelRatio,
+ projection, params);
+
+ 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_;
+
+};
+
+
+/**
+ * @param {ol.Extent} extent Extent.
+ * @param {ol.Size} size Size.
+ * @param {number} pixelRatio Pixel ratio.
+ * @param {ol.proj.Projection} projection Projection.
+ * @param {Object} params Params.
+ * @return {string} Request URL.
+ * @private
+ */
+ol.source.ImageWMS.prototype.getRequestUrl_ =
+ function(extent, size, pixelRatio, projection, params) {
+
+ goog.asserts.assert(goog.isDef(this.url_));
+
params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode();
if (!('STYLES' in this.params_)) {
@@ -158,31 +292,8 @@ ol.source.ImageWMS.prototype.getImage =
}
}
- extent = extent.slice();
- var centerX = (extent[0] + extent[2]) / 2;
- var centerY = (extent[1] + extent[3]) / 2;
- if (this.ratio_ != 1) {
- var halfWidth = this.ratio_ * (extent[2] - extent[0]) / 2;
- var halfHeight = this.ratio_ * (extent[3] - extent[1]) / 2;
- extent[0] = centerX - halfWidth;
- extent[1] = centerY - halfHeight;
- extent[2] = centerX + halfWidth;
- extent[3] = centerY + halfHeight;
- }
-
- var imageResolution = resolution / pixelRatio;
-
- // Compute an integer width and height.
- var width = Math.ceil((extent[2] - extent[0]) / imageResolution);
- goog.object.set(params, 'WIDTH', width);
- var height = Math.ceil((extent[3] - extent[1]) / imageResolution);
- goog.object.set(params, 'HEIGHT', height);
-
- // Modify the extent to match the integer width and height.
- extent[0] = centerX - imageResolution * width / 2;
- extent[2] = centerX + imageResolution * width / 2;
- extent[1] = centerY - imageResolution * height / 2;
- extent[3] = centerY + imageResolution * height / 2;
+ goog.object.set(params, 'WIDTH', size[0]);
+ goog.object.set(params, 'HEIGHT', size[1]);
var axisOrientation = projection.getAxisOrientation();
var bbox;
@@ -193,13 +304,7 @@ ol.source.ImageWMS.prototype.getImage =
}
goog.object.set(params, 'BBOX', bbox.join(','));
- var url = goog.uri.utils.appendParamsFromMap(this.url_, params);
-
- this.image_ = new ol.Image(extent, resolution, pixelRatio,
- this.getAttributions(), url, this.crossOrigin_);
- this.renderedRevision_ = this.getRevision();
- return this.image_;
-
+ return goog.uri.utils.appendParamsFromMap(this.url_, params);
};
diff --git a/src/ol/source/tilewmssource.exports b/src/ol/source/tilewmssource.exports
index e9049c25f3..9da9856159 100644
--- a/src/ol/source/tilewmssource.exports
+++ b/src/ol/source/tilewmssource.exports
@@ -1,3 +1,4 @@
@exportSymbol ol.source.TileWMS
+@exportProperty ol.source.TileWMS.prototype.getGetFeatureInfoUrl
@exportProperty ol.source.TileWMS.prototype.getParams
@exportProperty ol.source.TileWMS.prototype.updateParams
diff --git a/src/ol/source/tilewmssource.js b/src/ol/source/tilewmssource.js
index bcabf10712..f9b565d426 100644
--- a/src/ol/source/tilewmssource.js
+++ b/src/ol/source/tilewmssource.js
@@ -1,5 +1,6 @@
// FIXME add minZoom support
// FIXME add date line wrap (tile coord transform)
+// FIXME cannot be shared between maps with different projections
goog.provide('ol.source.TileWMS');
@@ -67,6 +68,12 @@ ol.source.TileWMS = function(opt_options) {
*/
this.params_ = params;
+ /**
+ * @private
+ * @type {number}
+ */
+ this.pixelRatio_ = NaN;
+
/**
* @private
* @type {boolean}
@@ -104,6 +111,79 @@ ol.source.TileWMS = function(opt_options) {
goog.inherits(ol.source.TileWMS, ol.source.TileImage);
+/**
+ * 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 {!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
+ * specified here.
+ * @return {string|undefined} GetFeatureInfo URL.
+ */
+ol.source.TileWMS.prototype.getGetFeatureInfoUrl =
+ function(coordinate, resolution, projection, params) {
+
+ goog.asserts.assert(!('VERSION' in params));
+
+ var pixelRatio = this.pixelRatio_;
+ if (isNaN(this.pixelRatio_)) {
+ return undefined;
+ }
+
+ var tileGrid = this.getTileGrid();
+ if (goog.isNull(tileGrid)) {
+ tileGrid = this.getTileGridForProjection(projection);
+ }
+
+ var tileCoord = tileGrid.getTileCoordForCoordAndResolution(
+ coordinate, resolution);
+
+ if (tileGrid.getResolutions().length <= tileCoord.z) {
+ return undefined;
+ }
+
+ var tileResolution = tileGrid.getResolution(tileCoord.z);
+ var tileExtent = tileGrid.getTileCoordExtent(
+ tileCoord, this.tmpExtent_);
+ var tileSize = tileGrid.getTileSize(tileCoord.z);
+
+ var gutter = this.gutter_;
+ if (gutter !== 0) {
+ tileSize += 2 * gutter;
+ tileExtent = ol.extent.buffer(tileExtent,
+ tileResolution * gutter, tileExtent);
+ }
+ if (pixelRatio != 1) {
+ tileSize = (tileSize * pixelRatio + 0.5) | 0;
+ }
+
+ var baseParams = {
+ 'SERVICE': 'WMS',
+ 'VERSION': ol.source.wms.DEFAULT_VERSION,
+ 'REQUEST': 'GetFeatureInfo',
+ 'FORMAT': 'image/png',
+ 'TRANSPARENT': true,
+ 'QUERY_LAYERS': goog.object.get(this.params_, 'LAYERS')
+ };
+ 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));
+
+ 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, projection, baseParams);
+};
+
+
/**
* @inheritDoc
*/
@@ -131,6 +211,76 @@ ol.source.TileWMS.prototype.getParams = function() {
};
+/**
+ * @param {ol.TileCoord} tileCoord Tile coordinate.
+ * @param {number} tileSize Tile size.
+ * @param {ol.Extent} tileExtent Tile extent.
+ * @param {number} pixelRatio Pixel ratio.
+ * @param {ol.proj.Projection} projection Projection.
+ * @param {Object} params Params.
+ * @return {string|undefined} Request URL.
+ * @private
+ */
+ol.source.TileWMS.prototype.getRequestUrl_ =
+ function(tileCoord, tileSize, tileExtent,
+ pixelRatio, projection, params) {
+
+ var urls = this.urls_;
+ if (!goog.isDef(urls) || goog.array.isEmpty(urls)) {
+ return undefined;
+ }
+
+ goog.object.set(params, 'WIDTH', tileSize);
+ goog.object.set(params, 'HEIGHT', tileSize);
+
+ params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode();
+
+ if (!('STYLES' in this.params_)) {
+ goog.object.set(params, 'STYLES', new String(''));
+ }
+
+ if (pixelRatio != 1) {
+ switch (this.serverType_) {
+ case ol.source.wms.ServerType.GEOSERVER:
+ var dpi = (90 * pixelRatio + 0.5) | 0;
+ goog.object.set(params, 'FORMAT_OPTIONS', 'dpi:' + dpi);
+ break;
+ case ol.source.wms.ServerType.MAPSERVER:
+ goog.object.set(params, 'MAP_RESOLUTION', 90 * pixelRatio);
+ break;
+ case ol.source.wms.ServerType.QGIS:
+ goog.object.set(params, 'DPI', 90 * pixelRatio);
+ break;
+ default:
+ goog.asserts.fail();
+ break;
+ }
+ }
+
+ var axisOrientation = projection.getAxisOrientation();
+ var bbox = tileExtent;
+ if (this.v13_ && axisOrientation.substr(0, 2) == 'ne') {
+ var tmp;
+ tmp = tileExtent[0];
+ bbox[0] = tileExtent[1];
+ bbox[1] = tmp;
+ tmp = tileExtent[2];
+ bbox[2] = tileExtent[3];
+ bbox[3] = tmp;
+ }
+ goog.object.set(params, 'BBOX', bbox.join(','));
+
+ var url;
+ if (urls.length == 1) {
+ url = urls[0];
+ } else {
+ var index = goog.math.modulo(tileCoord.hash(), this.urls_.length);
+ url = urls[index];
+ }
+ return goog.uri.utils.appendParamsFromMap(url, params);
+};
+
+
/**
* @param {number} z Z.
* @param {number} pixelRatio Pixel ratio.
@@ -165,17 +315,12 @@ ol.source.TileWMS.prototype.resetCoordKeyPrefix_ = function() {
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
- * @private
* @return {string|undefined} Tile URL.
+ * @private
*/
ol.source.TileWMS.prototype.tileUrlFunction_ =
function(tileCoord, pixelRatio, projection) {
- var urls = this.urls_;
- if (!goog.isDef(urls) || goog.array.isEmpty(urls)) {
- return undefined;
- }
-
var tileGrid = this.getTileGrid();
if (goog.isNull(tileGrid)) {
tileGrid = this.getTileGridForProjection(projection);
@@ -185,80 +330,37 @@ ol.source.TileWMS.prototype.tileUrlFunction_ =
return undefined;
}
- var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
+ var tileResolution = tileGrid.getResolution(tileCoord.z);
+ var tileExtent = tileGrid.getTileCoordExtent(
+ tileCoord, this.tmpExtent_);
+ var tileSize = tileGrid.getTileSize(tileCoord.z);
- var params = {
+ var gutter = this.gutter_;
+ if (gutter !== 0) {
+ tileSize += 2 * gutter;
+ tileExtent = ol.extent.buffer(tileExtent,
+ tileResolution * gutter, tileExtent);
+ }
+ if (pixelRatio != 1) {
+ tileSize = (tileSize * pixelRatio + 0.5) | 0;
+ }
+
+ var baseParams = {
'SERVICE': 'WMS',
'VERSION': ol.source.wms.DEFAULT_VERSION,
'REQUEST': 'GetMap',
'FORMAT': 'image/png',
'TRANSPARENT': true
};
- goog.object.extend(params, this.params_);
+ goog.object.extend(baseParams, this.params_);
- var tileResolution = tileGrid.getResolution(tileCoord.z);
if (pixelRatio != 1 && (!this.hidpi_ || !goog.isDef(this.serverType_))) {
pixelRatio = 1;
}
- var tileSize = tileGrid.getTileSize(tileCoord.z);
- var gutter = this.gutter_;
- if (gutter !== 0) {
- tileSize += 2 * gutter;
- tileExtent =
- ol.extent.buffer(tileExtent, tileResolution * gutter, this.tmpExtent_);
- }
- if (pixelRatio != 1) {
- tileSize = (tileSize * pixelRatio + 0.5) | 0;
- }
- goog.object.set(params, 'WIDTH', tileSize);
- goog.object.set(params, 'HEIGHT', tileSize);
-
- params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode();
-
- if (!('STYLES' in this.params_)) {
- goog.object.set(params, 'STYLES', new String(''));
- }
-
- if (pixelRatio != 1) {
- switch (this.serverType_) {
- case ol.source.wms.ServerType.GEOSERVER:
- var dpi = (90 * pixelRatio + 0.5) | 0;
- goog.object.set(params, 'FORMAT_OPTIONS', 'dpi:' + dpi);
- break;
- case ol.source.wms.ServerType.MAPSERVER:
- goog.object.set(params, 'MAP_RESOLUTION', 90 * pixelRatio);
- break;
- case ol.source.wms.ServerType.QGIS:
- goog.object.set(params, 'DPI', 90 * pixelRatio);
- break;
- default:
- goog.asserts.fail();
- break;
- }
- }
-
- var axisOrientation = projection.getAxisOrientation();
- var bbox;
- if (this.v13_ && axisOrientation.substr(0, 2) == 'ne') {
- bbox = this.tmpExtent_;
- bbox[0] = tileExtent[1];
- bbox[1] = tileExtent[0];
- bbox[2] = tileExtent[3];
- bbox[3] = tileExtent[2];
- } else {
- bbox = tileExtent;
- }
- goog.object.set(params, 'BBOX', bbox.join(','));
-
- var url;
- if (urls.length == 1) {
- url = urls[0];
- } else {
- var index = goog.math.modulo(tileCoord.hash(), this.urls_.length);
- url = urls[index];
- }
- return goog.uri.utils.appendParamsFromMap(url, params);
+ this.pixelRatio_ = pixelRatio;
+ return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
+ pixelRatio, projection, baseParams);
};
diff --git a/test/spec/ol/source/imagewmssource.test.js b/test/spec/ol/source/imagewmssource.test.js
index 18aa4848b8..88585008f0 100644
--- a/test/spec/ol/source/imagewmssource.test.js
+++ b/test/spec/ol/source/imagewmssource.test.js
@@ -3,22 +3,22 @@ goog.provide('ol.test.source.ImageWMS');
describe('ol.source.ImageWMS', function() {
- describe('#getImage', function() {
+ var extent, pixelRatio, options, projection, resolution;
+ beforeEach(function() {
+ extent = [10, 20, 30, 40];
+ pixelRatio = 1;
+ projection = ol.proj.get('EPSG:4326');
+ resolution = 0.1;
+ options = {
+ params: {
+ 'LAYERS': 'layer'
+ },
+ ratio: 1,
+ url: 'http://example.com/wms'
+ };
+ });
- var extent, pixelRatio, options, projection, resolution;
- beforeEach(function() {
- extent = [10, 20, 30, 40];
- pixelRatio = 1;
- projection = ol.proj.get('EPSG:4326');
- resolution = 0.1;
- options = {
- params: {
- 'LAYERS': 'layer'
- },
- ratio: 1,
- url: 'http://example.com/wms'
- };
- });
+ describe('#getImage', function() {
it('returns the expected image URL', function() {
var source = new ol.source.ImageWMS(options);
@@ -136,6 +136,67 @@ describe('ol.source.ImageWMS', function() {
});
+ describe('#getGetFeatureInfo', function() {
+
+ it('returns the expected GetFeatureInfo URL', function() {
+ var source = new ol.source.ImageWMS(options);
+ source.getImage(extent, resolution, pixelRatio, projection);
+ var url = source.getGetFeatureInfoUrl(
+ [20, 30], resolution, projection,
+ {INFO_FORMAT: 'text/plain'});
+ var uri = new goog.Uri(url);
+ expect(uri.getScheme()).to.be('http');
+ expect(uri.getDomain()).to.be('example.com');
+ expect(uri.getPath()).to.be('/wms');
+ var queryData = uri.getQueryData();
+ expect(queryData.get('BBOX')).to.be('20,10,40,30');
+ expect(queryData.get('CRS')).to.be('EPSG:4326');
+ expect(queryData.get('FORMAT')).to.be('image/png');
+ expect(queryData.get('HEIGHT')).to.be('200');
+ expect(queryData.get('I')).to.be('100');
+ expect(queryData.get('J')).to.be('100');
+ expect(queryData.get('LAYERS')).to.be('layer');
+ expect(queryData.get('QUERY_LAYERS')).to.be('layer');
+ expect(queryData.get('REQUEST')).to.be('GetFeatureInfo');
+ expect(queryData.get('SERVICE')).to.be('WMS');
+ expect(queryData.get('SRS')).to.be(undefined);
+ expect(queryData.get('STYLES')).to.be('');
+ expect(queryData.get('TRANSPARENT')).to.be('true');
+ expect(queryData.get('VERSION')).to.be('1.3.0');
+ expect(queryData.get('WIDTH')).to.be('200');
+ expect(uri.getFragment()).to.be.empty();
+ });
+
+ it('sets the QUERY_LAYERS param as expected', function() {
+ var source = new ol.source.ImageWMS(options);
+ source.getImage(extent, resolution, pixelRatio, projection);
+ var url = source.getGetFeatureInfoUrl(
+ [20, 30], resolution, projection,
+ {INFO_FORMAT: 'text/plain', QUERY_LAYERS: 'foo,bar'});
+ var uri = new goog.Uri(url);
+ expect(uri.getScheme()).to.be('http');
+ expect(uri.getDomain()).to.be('example.com');
+ expect(uri.getPath()).to.be('/wms');
+ var queryData = uri.getQueryData();
+ expect(queryData.get('BBOX')).to.be('20,10,40,30');
+ expect(queryData.get('CRS')).to.be('EPSG:4326');
+ expect(queryData.get('FORMAT')).to.be('image/png');
+ expect(queryData.get('HEIGHT')).to.be('200');
+ expect(queryData.get('I')).to.be('100');
+ expect(queryData.get('J')).to.be('100');
+ expect(queryData.get('LAYERS')).to.be('layer');
+ expect(queryData.get('QUERY_LAYERS')).to.be('foo,bar');
+ expect(queryData.get('REQUEST')).to.be('GetFeatureInfo');
+ expect(queryData.get('SERVICE')).to.be('WMS');
+ expect(queryData.get('SRS')).to.be(undefined);
+ expect(queryData.get('STYLES')).to.be('');
+ expect(queryData.get('TRANSPARENT')).to.be('true');
+ expect(queryData.get('VERSION')).to.be('1.3.0');
+ expect(queryData.get('WIDTH')).to.be('200');
+ expect(uri.getFragment()).to.be.empty();
+ });
+ });
+
});
diff --git a/test/spec/ol/source/tilewmssource.test.js b/test/spec/ol/source/tilewmssource.test.js
index ecdc587cc4..c7b192b641 100644
--- a/test/spec/ol/source/tilewmssource.test.js
+++ b/test/spec/ol/source/tilewmssource.test.js
@@ -104,6 +104,73 @@ describe('ol.source.TileWMS', function() {
});
+ describe('#getGetFeatureInfo', function() {
+
+ it('returns the expected GetFeatureInfo URL', function() {
+ var source = new ol.source.TileWMS(options);
+ source.pixelRatio_ = 1;
+ var url = source.getGetFeatureInfoUrl(
+ [-7000000, -12000000],
+ 19567.87924100512, ol.proj.get('EPSG:3857'),
+ {INFO_FORMAT: 'text/plain'});
+ var uri = new goog.Uri(url);
+ expect(uri.getScheme()).to.be('http');
+ expect(uri.getDomain()).to.be('example.com');
+ expect(uri.getPath()).to.be('/wms');
+ var queryData = uri.getQueryData();
+ expect(queryData.get('BBOX')).to.be(
+ '-10018754.171394622,-15028131.257091932,' +
+ '-5009377.085697311,-10018754.17139462');
+ expect(queryData.get('CRS')).to.be('EPSG:3857');
+ expect(queryData.get('FORMAT')).to.be('image/png');
+ expect(queryData.get('HEIGHT')).to.be('256');
+ expect(queryData.get('I')).to.be('154');
+ expect(queryData.get('J')).to.be('101');
+ expect(queryData.get('LAYERS')).to.be('layer');
+ expect(queryData.get('QUERY_LAYERS')).to.be('layer');
+ expect(queryData.get('REQUEST')).to.be('GetFeatureInfo');
+ expect(queryData.get('SERVICE')).to.be('WMS');
+ expect(queryData.get('SRS')).to.be(undefined);
+ expect(queryData.get('STYLES')).to.be('');
+ expect(queryData.get('TRANSPARENT')).to.be('true');
+ expect(queryData.get('VERSION')).to.be('1.3.0');
+ expect(queryData.get('WIDTH')).to.be('256');
+ expect(uri.getFragment()).to.be.empty();
+ });
+
+ it('sets the QUERY_LAYERS param as expected', function() {
+ var source = new ol.source.TileWMS(options);
+ source.pixelRatio_ = 1;
+ var url = source.getGetFeatureInfoUrl(
+ [-7000000, -12000000],
+ 19567.87924100512, ol.proj.get('EPSG:3857'),
+ {INFO_FORMAT: 'text/plain', QUERY_LAYERS: 'foo,bar'});
+ var uri = new goog.Uri(url);
+ expect(uri.getScheme()).to.be('http');
+ expect(uri.getDomain()).to.be('example.com');
+ expect(uri.getPath()).to.be('/wms');
+ var queryData = uri.getQueryData();
+ expect(queryData.get('BBOX')).to.be(
+ '-10018754.171394622,-15028131.257091932,' +
+ '-5009377.085697311,-10018754.17139462');
+ expect(queryData.get('CRS')).to.be('EPSG:3857');
+ expect(queryData.get('FORMAT')).to.be('image/png');
+ expect(queryData.get('HEIGHT')).to.be('256');
+ expect(queryData.get('I')).to.be('154');
+ expect(queryData.get('J')).to.be('101');
+ expect(queryData.get('LAYERS')).to.be('layer');
+ expect(queryData.get('QUERY_LAYERS')).to.be('foo,bar');
+ expect(queryData.get('REQUEST')).to.be('GetFeatureInfo');
+ expect(queryData.get('SERVICE')).to.be('WMS');
+ expect(queryData.get('SRS')).to.be(undefined);
+ expect(queryData.get('STYLES')).to.be('');
+ expect(queryData.get('TRANSPARENT')).to.be('true');
+ expect(queryData.get('VERSION')).to.be('1.3.0');
+ expect(queryData.get('WIDTH')).to.be('256');
+ expect(uri.getFragment()).to.be.empty();
+ expect(uri.getFragment()).to.be.empty();
+ });
+ });
});