Merge pull request #1547 from elemoine/gfi

Add getGetFeatureInfoUrl methods to ImageWMS and TileWMS sources
This commit is contained in:
Éric Lemoine
2014-01-20 05:22:40 -08:00
11 changed files with 495 additions and 194 deletions
+76 -15
View File
@@ -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();
});
});
});
+67
View File
@@ -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();
});
});
});