Skip to content

Commit

Permalink
For WMS 1.3, use CRS rather than SRS for coordinate system
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgrant committed Jan 9, 2017
1 parent fb84c84 commit 7a6ba78
Show file tree
Hide file tree
Showing 2 changed files with 272 additions and 3 deletions.
14 changes: 13 additions & 1 deletion Source/Scene/WebMapServiceImageryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,19 @@ define([
}

setParameter('layers', options.layers);
setParameter('srs', options.tilingScheme instanceof WebMercatorTilingScheme ? 'EPSG:3857' : 'EPSG:4326');

// Use SRS or CRS based on the WMS version.
if (parseFloat(parameters.version) >= 1.3) {
// Use CRS with 1.3.0 and going forward.
// For GeographicTilingScheme, use CRS:84 vice EPSG:4326 to specify lon, lat (x, y) ordering for
// bbox requests.
setParameter('crs', options.tilingScheme instanceof WebMercatorTilingScheme ? 'EPSG:3857' : 'CRS:84');
}
else {
// SRS for WMS 1.1.0 or 1.1.1.
setParameter('srs', options.tilingScheme instanceof WebMercatorTilingScheme ? 'EPSG:3857' : 'EPSG:4326');
}

setParameter('bbox', '{westProjected},{southProjected},{eastProjected},{northProjected}');
setParameter('width', '{width}');
setParameter('height', '{height}');
Expand Down
261 changes: 259 additions & 2 deletions Specs/Scene/WebMapServiceImageryProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ defineSuite([
layers : 'someLayer',
parameters : {
something : 'foo',
another : false
another : false,
version: '1.3.0'
}
});

Expand All @@ -126,6 +127,10 @@ defineSuite([
var params = queryToObject(uri.query);
expect(params.something).toEqual('foo');
expect(params.another).toEqual('false');
expect(params.version).toEqual('1.3.0');

// Don't need to actually load image, but satisfy the request.
deferred.resolve(true);
});

provider.requestImage(0, 0, 0);
Expand Down Expand Up @@ -172,6 +177,9 @@ defineSuite([
spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
var questionMarkCount = url.match(/\?/g).length;
expect(questionMarkCount).toEqual(1);

// Don't need to actually load image, but satisfy the request.
deferred.resolve(true);
});

provider.requestImage(0, 0, 0);
Expand All @@ -194,6 +202,9 @@ defineSuite([
expect(questionMarkCount).toEqual(1);

expect(url).not.toContain('&&');

// Don't need to actually load image, but satisfy the request.
deferred.resolve(true);
});

provider.requestImage(0, 0, 0);
Expand All @@ -218,6 +229,35 @@ defineSuite([
var uri = new Uri(url);
var params = queryToObject(uri.query);
expect(params.foo).toEqual('bar');

// Don't need to actually load image, but satisfy the request.
deferred.resolve(true);
});

provider.requestImage(0, 0, 0);

expect(loadImage.createImage).toHaveBeenCalled();
});
});

it('defaults WMS version to 1.1.1', function() {

var provider = new WebMapServiceImageryProvider({
url : 'made/up/wms/server?foo=bar',
layers : 'someLayer'
});

return pollToPromise(function() {
return provider.ready;
}).then(function() {
spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {

var uri = new Uri(url);
var params = queryToObject(uri.query);
expect(params.version).toEqual('1.1.1');

// Don't need to actually load image, but satisfy the request.
deferred.resolve(true);
});

provider.requestImage(0, 0, 0);
Expand Down Expand Up @@ -256,7 +296,7 @@ defineSuite([
});
});

it('requestImage requests tiles with SRS EPSG:3857 when tiling scheme is WebMercatorTilingScheme', function() {
it('requestImage requests tiles with SRS EPSG:3857 when tiling scheme is WebMercatorTilingScheme, WMS 1.1.1', function() {
var tilingScheme = new WebMercatorTilingScheme();
var provider = new WebMapServiceImageryProvider({
url : 'made/up/wms/server',
Expand All @@ -281,6 +321,219 @@ defineSuite([
var params = queryToObject(uri.query);

expect(params.srs).toEqual('EPSG:3857');
expect(params.version).toEqual('1.1.1');

var rect = tilingScheme.tileXYToNativeRectangle(0, 0, 0);
expect(params.bbox).toEqual(rect.west + ',' + rect.south + ',' + rect.east + ',' + rect.north);

loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred);
});

return provider.requestImage(0, 0, 0).then(function(image) {
expect(loadImage.createImage).toHaveBeenCalled();
expect(image).toBeInstanceOf(Image);
});
});
});

it('requestImage requests tiles with CRS EPSG:3857 when tiling scheme is WebMercatorTilingScheme, WMS 1.3.0', function() {
var tilingScheme = new WebMercatorTilingScheme();
var provider = new WebMapServiceImageryProvider({
url : 'made/up/wms/server',
layers : 'someLayer',
tilingScheme : tilingScheme,
parameters: {
version: '1.3.0'
}
});

expect(provider.url).toEqual('made/up/wms/server');
expect(provider.layers).toEqual('someLayer');

return pollToPromise(function() {
return provider.ready;
}).then(function() {
expect(provider.tileWidth).toEqual(256);
expect(provider.tileHeight).toEqual(256);
expect(provider.maximumLevel).toBeUndefined();
expect(provider.tilingScheme).toBeInstanceOf(WebMercatorTilingScheme);
expect(provider.rectangle).toEqual(new WebMercatorTilingScheme().rectangle);

spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
var uri = new Uri(url);
var params = queryToObject(uri.query);

expect(params.crs).toEqual('EPSG:3857');
expect(params.version).toEqual('1.3.0');

var rect = tilingScheme.tileXYToNativeRectangle(0, 0, 0);
expect(params.bbox).toEqual(rect.west + ',' + rect.south + ',' + rect.east + ',' + rect.north);

loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred);
});

return provider.requestImage(0, 0, 0).then(function(image) {
expect(loadImage.createImage).toHaveBeenCalled();
expect(image).toBeInstanceOf(Image);
});
});
});

it('requestImage requests tiles with SRS EPSG:4326 when tiling scheme is GeographicTilingScheme, WMS 1.1.1', function() {
var tilingScheme = new GeographicTilingScheme();
var provider = new WebMapServiceImageryProvider({
url : 'made/up/wms/server',
layers : 'someLayer',
tilingScheme : tilingScheme
});

expect(provider.url).toEqual('made/up/wms/server');
expect(provider.layers).toEqual('someLayer');

return pollToPromise(function() {
return provider.ready;
}).then(function() {
expect(provider.tileWidth).toEqual(256);
expect(provider.tileHeight).toEqual(256);
expect(provider.maximumLevel).toBeUndefined();
expect(provider.tilingScheme).toBeInstanceOf(GeographicTilingScheme);
expect(provider.rectangle).toEqual(new GeographicTilingScheme().rectangle);

spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
var uri = new Uri(url);
var params = queryToObject(uri.query);

expect(params.srs).toEqual('EPSG:4326');
expect(params.version).toEqual('1.1.1');

var rect = tilingScheme.tileXYToNativeRectangle(0, 0, 0);
expect(params.bbox).toEqual(rect.west + ',' + rect.south + ',' + rect.east + ',' + rect.north);

loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred);
});

return provider.requestImage(0, 0, 0).then(function(image) {
expect(loadImage.createImage).toHaveBeenCalled();
expect(image).toBeInstanceOf(Image);
});
});
});

it('requestImage requests tiles with SRS EPSG:4326 when tiling scheme is GeographicTilingScheme, WMS 1.1.0', function() {
var tilingScheme = new GeographicTilingScheme();
var provider = new WebMapServiceImageryProvider({
url : 'made/up/wms/server',
layers : 'someLayer',
tilingScheme : tilingScheme,
parameters: {
version: '1.1.0'
}
});

expect(provider.url).toEqual('made/up/wms/server');
expect(provider.layers).toEqual('someLayer');

return pollToPromise(function() {
return provider.ready;
}).then(function() {
expect(provider.tileWidth).toEqual(256);
expect(provider.tileHeight).toEqual(256);
expect(provider.maximumLevel).toBeUndefined();
expect(provider.tilingScheme).toBeInstanceOf(GeographicTilingScheme);
expect(provider.rectangle).toEqual(new GeographicTilingScheme().rectangle);

spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
var uri = new Uri(url);
var params = queryToObject(uri.query);

expect(params.srs).toEqual('EPSG:4326');
expect(params.version).toEqual('1.1.0');

var rect = tilingScheme.tileXYToNativeRectangle(0, 0, 0);
expect(params.bbox).toEqual(rect.west + ',' + rect.south + ',' + rect.east + ',' + rect.north);

loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred);
});

return provider.requestImage(0, 0, 0).then(function(image) {
expect(loadImage.createImage).toHaveBeenCalled();
expect(image).toBeInstanceOf(Image);
});
});
});

it('requestImage requests tiles with CRS CRS:84 when tiling scheme is GeographicTilingScheme, WMS 1.3.0', function() {
var tilingScheme = new GeographicTilingScheme();
var provider = new WebMapServiceImageryProvider({
url : 'made/up/wms/server',
layers : 'someLayer',
tilingScheme : tilingScheme,
parameters: {
version: '1.3.0'
}
});

expect(provider.url).toEqual('made/up/wms/server');
expect(provider.layers).toEqual('someLayer');

return pollToPromise(function() {
return provider.ready;
}).then(function() {
expect(provider.tileWidth).toEqual(256);
expect(provider.tileHeight).toEqual(256);
expect(provider.maximumLevel).toBeUndefined();
expect(provider.tilingScheme).toBeInstanceOf(GeographicTilingScheme);
expect(provider.rectangle).toEqual(new GeographicTilingScheme().rectangle);

spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
var uri = new Uri(url);
var params = queryToObject(uri.query);

expect(params.crs).toEqual('CRS:84');
expect(params.version).toEqual('1.3.0');

var rect = tilingScheme.tileXYToNativeRectangle(0, 0, 0);
expect(params.bbox).toEqual(rect.west + ',' + rect.south + ',' + rect.east + ',' + rect.north);

loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred);
});

return provider.requestImage(0, 0, 0).then(function(image) {
expect(loadImage.createImage).toHaveBeenCalled();
expect(image).toBeInstanceOf(Image);
});
});
});

it('requestImage requests tiles with CRS CRS:84 when tiling scheme is GeographicTilingScheme, WMS 1.3.1', function() {
var tilingScheme = new GeographicTilingScheme();
var provider = new WebMapServiceImageryProvider({
url : 'made/up/wms/server',
layers : 'someLayer',
tilingScheme : tilingScheme,
parameters: {
version: '1.3.1'
}
});

expect(provider.url).toEqual('made/up/wms/server');
expect(provider.layers).toEqual('someLayer');

return pollToPromise(function() {
return provider.ready;
}).then(function() {
expect(provider.tileWidth).toEqual(256);
expect(provider.tileHeight).toEqual(256);
expect(provider.maximumLevel).toBeUndefined();
expect(provider.tilingScheme).toBeInstanceOf(GeographicTilingScheme);
expect(provider.rectangle).toEqual(new GeographicTilingScheme().rectangle);

spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
var uri = new Uri(url);
var params = queryToObject(uri.query);

expect(params.crs).toEqual('CRS:84');
expect(params.version).toEqual('1.3.1');

var rect = tilingScheme.tileXYToNativeRectangle(0, 0, 0);
expect(params.bbox).toEqual(rect.west + ',' + rect.south + ',' + rect.east + ',' + rect.north);
Expand Down Expand Up @@ -669,6 +922,8 @@ defineSuite([
enablePickFeatures : false
});

expect(provider.enablePickFeatures).toBe(false);

return pollToPromise(function() {
return provider.ready;
}).then(function() {
Expand All @@ -684,6 +939,7 @@ defineSuite([
});

provider.enablePickFeatures = false;
expect(provider.enablePickFeatures).toBe(false);

return pollToPromise(function() {
return provider.ready;
Expand All @@ -700,6 +956,7 @@ defineSuite([
});

provider.enablePickFeatures = true;
expect(provider.enablePickFeatures).toBe(true);

return pollToPromise(function() {
return provider.ready;
Expand Down

0 comments on commit 7a6ba78

Please sign in to comment.