Fix #7304: Re-calculate the resolution when the WMS source is reprojected
This commit is contained in:
@@ -10,6 +10,7 @@ goog.require('ol.events.EventType');
|
|||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.obj');
|
goog.require('ol.obj');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
|
goog.require('ol.reproj');
|
||||||
goog.require('ol.source.Image');
|
goog.require('ol.source.Image');
|
||||||
goog.require('ol.source.WMSServerType');
|
goog.require('ol.source.WMSServerType');
|
||||||
goog.require('ol.string');
|
goog.require('ol.string');
|
||||||
@@ -136,6 +137,13 @@ ol.source.ImageWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolut
|
|||||||
if (this.url_ === undefined) {
|
if (this.url_ === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
var projectionObj = ol.proj.get(projection);
|
||||||
|
var sourceProjectionObj = this.getProjection();
|
||||||
|
|
||||||
|
if (sourceProjectionObj && sourceProjectionObj !== projectionObj) {
|
||||||
|
resolution = ol.reproj.calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, resolution);
|
||||||
|
coordinate = ol.proj.transform(coordinate, projectionObj, sourceProjectionObj);
|
||||||
|
}
|
||||||
|
|
||||||
var extent = ol.extent.getForViewAndSize(
|
var extent = ol.extent.getForViewAndSize(
|
||||||
coordinate, resolution, 0,
|
coordinate, resolution, 0,
|
||||||
@@ -158,7 +166,7 @@ ol.source.ImageWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolut
|
|||||||
|
|
||||||
return this.getRequestUrl_(
|
return this.getRequestUrl_(
|
||||||
extent, ol.source.ImageWMS.GETFEATUREINFO_IMAGE_SIZE_,
|
extent, ol.source.ImageWMS.GETFEATUREINFO_IMAGE_SIZE_,
|
||||||
1, ol.proj.get(projection), baseParams);
|
1, sourceProjectionObj || projectionObj, baseParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ goog.require('ol.extent');
|
|||||||
goog.require('ol.obj');
|
goog.require('ol.obj');
|
||||||
goog.require('ol.math');
|
goog.require('ol.math');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
|
goog.require('ol.reproj');
|
||||||
goog.require('ol.size');
|
goog.require('ol.size');
|
||||||
goog.require('ol.source.TileImage');
|
goog.require('ol.source.TileImage');
|
||||||
goog.require('ol.source.WMSServerType');
|
goog.require('ol.source.WMSServerType');
|
||||||
@@ -117,14 +118,14 @@ ol.inherits(ol.source.TileWMS, ol.source.TileImage);
|
|||||||
*/
|
*/
|
||||||
ol.source.TileWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, projection, params) {
|
ol.source.TileWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, projection, params) {
|
||||||
var projectionObj = ol.proj.get(projection);
|
var projectionObj = ol.proj.get(projection);
|
||||||
|
var sourceProjectionObj = this.getProjection();
|
||||||
|
|
||||||
var tileGrid = this.getTileGrid();
|
var tileGrid = this.getTileGrid();
|
||||||
if (!tileGrid) {
|
if (!tileGrid) {
|
||||||
tileGrid = this.getTileGridForProjection(projectionObj);
|
tileGrid = this.getTileGridForProjection(projectionObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
var tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
var tileCoord = tileGrid.getTileCoordForCoordAndResolution(coordinate, resolution);
|
||||||
coordinate, resolution);
|
|
||||||
|
|
||||||
if (tileGrid.getResolutions().length <= tileCoord[0]) {
|
if (tileGrid.getResolutions().length <= tileCoord[0]) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -132,14 +133,19 @@ ol.source.TileWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resoluti
|
|||||||
|
|
||||||
var tileResolution = tileGrid.getResolution(tileCoord[0]);
|
var tileResolution = tileGrid.getResolution(tileCoord[0]);
|
||||||
var tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent_);
|
var tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tmpExtent_);
|
||||||
var tileSize = ol.size.toSize(
|
var tileSize = ol.size.toSize(tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
|
||||||
tileGrid.getTileSize(tileCoord[0]), this.tmpSize);
|
|
||||||
|
|
||||||
var gutter = this.gutter_;
|
var gutter = this.gutter_;
|
||||||
if (gutter !== 0) {
|
if (gutter !== 0) {
|
||||||
tileSize = ol.size.buffer(tileSize, gutter, this.tmpSize);
|
tileSize = ol.size.buffer(tileSize, gutter, this.tmpSize);
|
||||||
tileExtent = ol.extent.buffer(tileExtent,
|
tileExtent = ol.extent.buffer(tileExtent, tileResolution * gutter, tileExtent);
|
||||||
tileResolution * gutter, tileExtent);
|
}
|
||||||
|
|
||||||
|
if (sourceProjectionObj && sourceProjectionObj !== projectionObj) {
|
||||||
|
tileResolution = ol.reproj.calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, tileResolution);
|
||||||
|
tileExtent = ol.proj.transformExtent(tileExtent, projectionObj, sourceProjectionObj);
|
||||||
|
coordinate = ol.proj.transform(coordinate, projectionObj, sourceProjectionObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
var baseParams = {
|
var baseParams = {
|
||||||
@@ -159,7 +165,7 @@ ol.source.TileWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resoluti
|
|||||||
baseParams[this.v13_ ? 'J' : 'Y'] = y;
|
baseParams[this.v13_ ? 'J' : 'Y'] = y;
|
||||||
|
|
||||||
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
|
return this.getRequestUrl_(tileCoord, tileSize, tileExtent,
|
||||||
1, projectionObj, baseParams);
|
1, sourceProjectionObj || projectionObj, baseParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ goog.require('ol.proj');
|
|||||||
|
|
||||||
describe('ol.source.ImageWMS', function() {
|
describe('ol.source.ImageWMS', function() {
|
||||||
|
|
||||||
var extent, pixelRatio, options, projection, resolution;
|
var extent, pixelRatio, options, optionsReproj, projection, resolution;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
extent = [10, 20, 30, 40];
|
extent = [10, 20, 30, 40];
|
||||||
pixelRatio = 1;
|
pixelRatio = 1;
|
||||||
@@ -19,6 +19,14 @@ describe('ol.source.ImageWMS', function() {
|
|||||||
ratio: 1,
|
ratio: 1,
|
||||||
url: 'http://example.com/wms'
|
url: 'http://example.com/wms'
|
||||||
};
|
};
|
||||||
|
optionsReproj = {
|
||||||
|
params: {
|
||||||
|
'LAYERS': 'layer'
|
||||||
|
},
|
||||||
|
ratio: 1,
|
||||||
|
url: 'http://example.com/wms',
|
||||||
|
projection: 'EPSG:3857'
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getImage', function() {
|
describe('#getImage', function() {
|
||||||
@@ -223,7 +231,7 @@ describe('ol.source.ImageWMS', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getGetFeatureInfo', function() {
|
describe('#getGetFeatureInfoUrl', function() {
|
||||||
|
|
||||||
it('returns the expected GetFeatureInfo URL', function() {
|
it('returns the expected GetFeatureInfo URL', function() {
|
||||||
var source = new ol.source.ImageWMS(options);
|
var source = new ol.source.ImageWMS(options);
|
||||||
@@ -253,6 +261,34 @@ describe('ol.source.ImageWMS', function() {
|
|||||||
expect(uri.hash.replace('#', '')).to.be.empty();
|
expect(uri.hash.replace('#', '')).to.be.empty();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns the expected GetFeatureInfo URL when source\'s projection is different from the parameter', function() {
|
||||||
|
var source = new ol.source.ImageWMS(optionsReproj);
|
||||||
|
var url = source.getGetFeatureInfoUrl(
|
||||||
|
[20, 30], resolution, projection,
|
||||||
|
{INFO_FORMAT: 'text/plain'});
|
||||||
|
var uri = new URL(url);
|
||||||
|
expect(uri.protocol).to.be('http:');
|
||||||
|
expect(uri.hostname).to.be('example.com');
|
||||||
|
expect(uri.pathname).to.be('/wms');
|
||||||
|
var queryData = uri.searchParams;
|
||||||
|
expect(queryData.get('BBOX')).to.be('1577259.402312431,2854419.4299513334,2875520.229418512,4152680.2570574144');
|
||||||
|
expect(queryData.get('CRS')).to.be('EPSG:3857');
|
||||||
|
expect(queryData.get('FORMAT')).to.be('image/png');
|
||||||
|
expect(queryData.get('HEIGHT')).to.be('101');
|
||||||
|
expect(queryData.get('I')).to.be('50');
|
||||||
|
expect(queryData.get('J')).to.be('50');
|
||||||
|
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(null);
|
||||||
|
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('101');
|
||||||
|
expect(uri.hash.replace('#', '')).to.be.empty();
|
||||||
|
});
|
||||||
|
|
||||||
it('sets the QUERY_LAYERS param as expected', function() {
|
it('sets the QUERY_LAYERS param as expected', function() {
|
||||||
var source = new ol.source.ImageWMS(options);
|
var source = new ol.source.ImageWMS(options);
|
||||||
var url = source.getGetFeatureInfoUrl(
|
var url = source.getGetFeatureInfoUrl(
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ goog.require('ol.tilegrid.TileGrid');
|
|||||||
|
|
||||||
describe('ol.source.TileWMS', function() {
|
describe('ol.source.TileWMS', function() {
|
||||||
|
|
||||||
var options;
|
var options, optionsReproj;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
options = {
|
options = {
|
||||||
params: {
|
params: {
|
||||||
@@ -17,6 +17,13 @@ describe('ol.source.TileWMS', function() {
|
|||||||
},
|
},
|
||||||
url: 'http://example.com/wms'
|
url: 'http://example.com/wms'
|
||||||
};
|
};
|
||||||
|
optionsReproj = {
|
||||||
|
params: {
|
||||||
|
'LAYERS': 'layer'
|
||||||
|
},
|
||||||
|
url: 'http://example.com/wms',
|
||||||
|
projection: 'EPSG:4326'
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('constructor', function() {
|
describe('constructor', function() {
|
||||||
@@ -193,7 +200,7 @@ describe('ol.source.TileWMS', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getGetFeatureInfo', function() {
|
describe('#getGetFeatureInfoUrl', function() {
|
||||||
|
|
||||||
it('returns the expected GetFeatureInfo URL', function() {
|
it('returns the expected GetFeatureInfo URL', function() {
|
||||||
var source = new ol.source.TileWMS(options);
|
var source = new ol.source.TileWMS(options);
|
||||||
@@ -229,6 +236,36 @@ describe('ol.source.TileWMS', function() {
|
|||||||
expect(uri.hash.replace('#', '')).to.be.empty();
|
expect(uri.hash.replace('#', '')).to.be.empty();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns the expected GetFeatureInfo URL when source\'s projection is different from the parameter', function() {
|
||||||
|
var source = new ol.source.TileWMS(optionsReproj);
|
||||||
|
source.pixelRatio_ = 1;
|
||||||
|
var url = source.getGetFeatureInfoUrl(
|
||||||
|
[-7000000, -12000000],
|
||||||
|
19567.87924100512, ol.proj.get('EPSG:3857'),
|
||||||
|
{INFO_FORMAT: 'text/plain'});
|
||||||
|
var uri = new URL(url);
|
||||||
|
expect(uri.protocol).to.be('http:');
|
||||||
|
expect(uri.hostname).to.be('example.com');
|
||||||
|
expect(uri.pathname).to.be('/wms');
|
||||||
|
var queryData = uri.searchParams;
|
||||||
|
expect(queryData.get('BBOX')).to.be('-79.17133464081945,-90,-66.51326044311186,-45');
|
||||||
|
expect(queryData.get('CRS')).to.be('EPSG:4326');
|
||||||
|
expect(queryData.get('FORMAT')).to.be('image/png');
|
||||||
|
expect(queryData.get('HEIGHT')).to.be('256');
|
||||||
|
expect(queryData.get('I')).to.be('517');
|
||||||
|
expect(queryData.get('J')).to.be('117');
|
||||||
|
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(null);
|
||||||
|
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.hash.replace('#', '')).to.be.empty();
|
||||||
|
});
|
||||||
|
|
||||||
it('sets the QUERY_LAYERS param as expected', function() {
|
it('sets the QUERY_LAYERS param as expected', function() {
|
||||||
var source = new ol.source.TileWMS(options);
|
var source = new ol.source.TileWMS(options);
|
||||||
source.pixelRatio_ = 1;
|
source.pixelRatio_ = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user