Merge pull request #1547 from elemoine/gfi
Add getGetFeatureInfoUrl methods to ImageWMS and TileWMS sources
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
|
||||
<div class="span4">
|
||||
<h4 id="title">GetFeatureInfo example</h4>
|
||||
<p id="shortdesc">Example of a WMS layer and a vector layer, both configured to provide feature information on click.</p>
|
||||
<p id="shortdesc">This example shows how to trigger WMS GetFeatureInfo requests on click for a WMS image layer.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="getfeatureinfo.js" target="_blank">getfeatureinfo.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
42
examples/getfeatureinfo.js
Normal file
42
examples/getfeatureinfo.js
Normal file
@@ -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 =
|
||||
'<iframe seamless src="' + url + '"></iframe>';
|
||||
}
|
||||
});
|
||||
@@ -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('');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
@@ -1,3 +0,0 @@
|
||||
@exportSymbol ol.source.WMSGetFeatureInfoMethod
|
||||
@exportProperty ol.source.WMSGetFeatureInfoMethod.IFRAME
|
||||
@exportProperty ol.source.WMSGetFeatureInfoMethod.XHR_GET
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ 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];
|
||||
@@ -20,6 +18,8 @@ describe('ol.source.ImageWMS', function() {
|
||||
};
|
||||
});
|
||||
|
||||
describe('#getImage', function() {
|
||||
|
||||
it('returns the expected image URL', function() {
|
||||
var source = new ol.source.ImageWMS(options);
|
||||
var image = source.getImage(extent, resolution, pixelRatio, projection);
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user