Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TileMapServiceImageryProvider defaults can cause the browser to hang. #8448

Merged
29 changes: 4 additions & 25 deletions Source/Scene/TileMapServiceImageryProvider.js
Original file line number Diff line number Diff line change
@@ -262,31 +262,10 @@ import UrlTemplateImageryProvider from './UrlTemplateImageryProvider.js';
};

TileMapServiceImageryProvider.prototype._metadataFailure = function(error) {
// Can't load XML, still allow options and defaults
var options = this._options;
var fileExtension = defaultValue(options.fileExtension, 'png');
var tileWidth = defaultValue(options.tileWidth, 256);
var tileHeight = defaultValue(options.tileHeight, 256);
var minimumLevel = defaultValue(options.minimumLevel, 0);
var maximumLevel = options.maximumLevel;
var tilingScheme = defined(options.tilingScheme) ? options.tilingScheme : new WebMercatorTilingScheme({ellipsoid : options.ellipsoid});
var rectangle = defaultValue(options.rectangle, tilingScheme.rectangle);

var templateResource = this._tmsResource.getDerivedResource({
url : '{z}/{x}/{reverseY}.' + fileExtension
});

this._deferred.resolve({
url : templateResource,
tilingScheme : tilingScheme,
rectangle : rectangle,
tileWidth : tileWidth,
tileHeight : tileHeight,
minimumLevel : minimumLevel,
maximumLevel : maximumLevel,
tileDiscardPolicy : options.tileDiscardPolicy,
credit : options.credit
});
// Can't load XML, reject the ready promise.
var message = 'An error occurred while accessing ' + this._xmlResource.url + '. Error: ' + error;
TileProviderError.handleError(error, this, this._errorEvent, message, undefined, undefined, undefined, null);
this._deferred.reject(new RuntimeError(message));
};

export default TileMapServiceImageryProvider;
445 changes: 228 additions & 217 deletions Specs/Scene/TileMapServiceImageryProviderSpec.js
Original file line number Diff line number Diff line change
@@ -19,6 +19,44 @@ import { when } from '../../Source/Cesium.js';

describe('Scene/TileMapServiceImageryProvider', function() {

var validSampleXmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title>NE2_HR_LC_SR_W_DR_recolored.tif</Title>' +
' <Abstract></Abstract>' +
' <SRS>EPSG:4326</SRS>' +
' <BoundingBox miny="-90.00000000000000" minx="-180.00000000000000" maxy="90.00000000000000"' +
' maxx="180.00000000000000"/>' +
' <Origin y="-90.00000000000000" x="-180.00000000000000"/>' +
' <TileFormat width="256" height="256" mime-type="image/jpg" extension="jpg"/>' +
' <TileSets profile="geodetic">' +
' <TileSet href="0" units-per-pixel="0.70312500000000" order="0"/>' +
' <TileSet href="1" units-per-pixel="0.35156250000000" order="1"/>' +
' <TileSet href="2" units-per-pixel="0.17578125000000" order="2"/>' +
' </TileSets>' +
'</TileMap>';

function patchRequestScheduler(xmlResponseString) {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
// We can't resolve the promise immediately, because then the error would be raised
// before we could subscribe to it. This a problem particular to tests.
setTimeout(function() {
var parser = new DOMParser();
var xml = parser.parseFromString(xmlResponseString, 'text/xml');
deferred.resolve(xml);
}, 1);
};
}

function patchRequestSchedulerToRejectRequest() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
// We can't resolve the promise immediately, because then the error would be raised
// before we could subscribe to it. This a problem particular to tests.
setTimeout(function() {
deferred.reject(new Error('whoops; rejecting xhr request'));
}, 1);
};
}

beforeEach(function() {
RequestScheduler.clearForSpecs();
});
@@ -36,6 +74,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('resolves readyPromise', function() {
patchRequestScheduler(validSampleXmlString);
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server/'
});
@@ -47,6 +86,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('resolves readyPromise when promise url is used', function() {
patchRequestScheduler(validSampleXmlString);
var provider = new TileMapServiceImageryProvider({
url : when.resolve('made/up/tms/server/')
});
@@ -58,6 +98,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('resolves readyPromise with Resource', function() {
patchRequestScheduler(validSampleXmlString);
var resource = new Resource({
url : 'made/up/tms/server/'
});
@@ -86,29 +127,20 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('rejects readyPromise on error', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
// We can't resolve the promise immediately, because then the error would be raised
// before we could subscribe to it. This a problem particular to tests.
setTimeout(function() {
var parser = new DOMParser();
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <BoundingBox minx="-10.0" miny="-123.0" maxx="11.0" maxy="-110.0"/>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="foobar">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
}, 1);
};

var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <BoundingBox minx="-10.0" miny="-123.0" maxx="11.0" maxy="-110.0"/>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="foobar">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
patchRequestScheduler(xmlString);
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
});
@@ -122,28 +154,19 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('rejects readyPromise on invalid xml', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
// We can't resolve the promise immediately, because then the error would be raised
// before we could subscribe to it. This a problem particular to tests.
setTimeout(function() {
var parser = new DOMParser();
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="foobar">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
}, 1);
};

var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="foobar">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
patchRequestScheduler(xmlString);
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
});
@@ -165,6 +188,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('returns valid value for hasAlphaChannel', function() {
patchRequestScheduler(validSampleXmlString);
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server/'
});
@@ -177,6 +201,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('supports a slash at the end of the URL', function() {
patchRequestScheduler(validSampleXmlString);
var baseUrl = 'made/up/tms/server/';
var provider = new TileMapServiceImageryProvider({
url : baseUrl
@@ -200,6 +225,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('supports no slash at the endof the URL', function() {
patchRequestScheduler(validSampleXmlString);
var provider = new TileMapServiceImageryProvider({
url : 'http://made/up/tms/server'
});
@@ -222,6 +248,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('supports a query string at the end of the URL', function() {
patchRequestScheduler(validSampleXmlString);
var baseUrl = 'made/up/tms/server/';
var provider = new TileMapServiceImageryProvider({
url : baseUrl + '?a=some&b=query'
@@ -245,19 +272,18 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('requestImage returns a promise for an image and loads it for cross-origin use', function() {
patchRequestScheduler(validSampleXmlString);
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server/'
});

return pollToPromise(function() {
return provider.ready;
}).then(function() {
expect(provider.url).toEqual(getAbsoluteUri('made/up/tms/server/{z}/{x}/{reverseY}.png'));
// check some details about the tilemapresourcel.xml so we know we got parsed/configured properly
expect(provider.url).toEqual(getAbsoluteUri('made/up/tms/server/{z}/{x}/{reverseY}.jpg'));
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(Resource._Implementations, 'createImage').and.callFake(function(url, crossOrigin, deferred) {
// Just return any old image.
@@ -272,6 +298,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('when no credit is supplied, the provider has no logo', function() {
patchRequestScheduler(validSampleXmlString);
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
});
@@ -283,6 +310,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('turns the supplied credit into a logo', function() {
patchRequestScheduler(validSampleXmlString);
var providerWithCredit = new TileMapServiceImageryProvider({
url : 'made/up/gms/server',
credit : 'Thanks to our awesome made up source of this imagery!'
@@ -313,6 +341,8 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('rectangle passed to constructor does not affect tile numbering', function() {
patchRequestScheduler(validSampleXmlString);

var rectangle = new Rectangle(0.1, 0.2, 0.3, 0.4);
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server',
@@ -322,10 +352,12 @@ describe('Scene/TileMapServiceImageryProvider', function() {
return pollToPromise(function() {
return provider.ready;
}).then(function() {
// check some values coming from tilemapresource.xml
expect(provider.tileWidth).toEqual(256);
expect(provider.tileHeight).toEqual(256);
expect(provider.maximumLevel).toBeUndefined();
expect(provider.tilingScheme).toBeInstanceOf(WebMercatorTilingScheme);
expect(provider.maximumLevel).toEqual(2);
expect(provider.tilingScheme).toBeInstanceOf(GeographicTilingScheme);
// check our rectangle from the constructor is correctly used
expect(provider.rectangle.west).toEqualEpsilon(rectangle.west, CesiumMath.EPSILON14);
expect(provider.rectangle.east).toEqualEpsilon(rectangle.east, CesiumMath.EPSILON14);
expect(provider.rectangle.north).toEqualEpsilon(rectangle.north, CesiumMath.EPSILON14);
@@ -347,6 +379,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('uses maximumLevel passed to constructor', function() {
patchRequestScheduler(validSampleXmlString);
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server',
maximumLevel : 5
@@ -360,6 +393,7 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('raises error event when image cannot be loaded', function() {
patchRequestScheduler(validSampleXmlString);
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
});
@@ -409,24 +443,19 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('keeps the rectangle within the bounds allowed by the tiling scheme no matter what the tilemapresource.xml says.', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
var parser = new DOMParser();
var xmlString =
"<TileMap version='1.0.0' tilemapservice='http://tms.osgeo.org/1.0.0'>" +
' <Title>dnb_land_ocean_ice.2012.54000x27000_geo.tif</Title>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
" <BoundingBox miny='-88.0' minx='-185.0' maxy='88.0' maxx='185.0'/>" +
" <Origin y='-88.0' x='-180.00000000000000'/>" +
" <TileFormat width='256' height='256' mime-type='image/png' extension='png'/>" +
" <TileSets profile='mercator'>" +
" <TileSet href='8' units-per-pixel='611.49622617187504' order='8'/>" +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
};

var xmlString =
"<TileMap version='1.0.0' tilemapservice='http://tms.osgeo.org/1.0.0'>" +
' <Title>dnb_land_ocean_ice.2012.54000x27000_geo.tif</Title>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
" <BoundingBox miny='-88.0' minx='-185.0' maxy='88.0' maxx='185.0'/>" +
" <Origin y='-88.0' x='-180.00000000000000'/>" +
" <TileFormat width='256' height='256' mime-type='image/png' extension='png'/>" +
" <TileSets profile='mercator'>" +
" <TileSet href='8' units-per-pixel='611.49622617187504' order='8'/>" +
' </TileSets>' +
'</TileMap>';
patchRequestScheduler(xmlString);
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
});
@@ -446,24 +475,20 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('uses a minimum level if the tilemapresource.xml specifies one and it is reasonable', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
var parser = new DOMParser();
var xmlString =
"<TileMap version='1.0.0' tilemapservice='http://tms.osgeo.org/1.0.0'>" +
' <Title>dnb_land_ocean_ice.2012.54000x27000_geo.tif</Title>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
" <BoundingBox minx='-10.0' miny='5.0' maxx='-9.0' maxy='6.0'/>" +
" <Origin x='-88.0' y='-180.00000000000000'/>" +
" <TileFormat width='256' height='256' mime-type='image/png' extension='png'/>" +
" <TileSets profile='mercator'>" +
" <TileSet href='7' units-per-pixel='1222.99245234375008' order='7'/>" +
" <TileSet href='8' units-per-pixel='611.49622617187504' order='8'/>" +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
};
var xmlString =
"<TileMap version='1.0.0' tilemapservice='http://tms.osgeo.org/1.0.0'>" +
' <Title>dnb_land_ocean_ice.2012.54000x27000_geo.tif</Title>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
" <BoundingBox minx='-10.0' miny='5.0' maxx='-9.0' maxy='6.0'/>" +
" <Origin x='-88.0' y='-180.00000000000000'/>" +
" <TileFormat width='256' height='256' mime-type='image/png' extension='png'/>" +
" <TileSets profile='mercator'>" +
" <TileSet href='7' units-per-pixel='1222.99245234375008' order='7'/>" +
" <TileSet href='8' units-per-pixel='611.49622617187504' order='8'/>" +
' </TileSets>' +
'</TileMap>';
patchRequestScheduler(xmlString);

var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
@@ -478,24 +503,20 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('ignores the minimum level in the tilemapresource.xml if it is unreasonable', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
var parser = new DOMParser();
var xmlString =
"<TileMap version='1.0.0' tilemapservice='http://tms.osgeo.org/1.0.0'>" +
' <Title>dnb_land_ocean_ice.2012.54000x27000_geo.tif</Title>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
" <BoundingBox minx='-170.0' miny='-85.0' maxx='170.0' maxy='85.0'/>" +
" <Origin x='-88.0' y='-180.00000000000000'/>" +
" <TileFormat width='256' height='256' mime-type='image/png' extension='png'/>" +
" <TileSets profile='mercator'>" +
" <TileSet href='7' units-per-pixel='1222.99245234375008' order='7'/>" +
" <TileSet href='8' units-per-pixel='611.49622617187504' order='8'/>" +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
};
var xmlString =
"<TileMap version='1.0.0' tilemapservice='http://tms.osgeo.org/1.0.0'>" +
' <Title>dnb_land_ocean_ice.2012.54000x27000_geo.tif</Title>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
" <BoundingBox minx='-170.0' miny='-85.0' maxx='170.0' maxy='85.0'/>" +
" <Origin x='-88.0' y='-180.00000000000000'/>" +
" <TileFormat width='256' height='256' mime-type='image/png' extension='png'/>" +
" <TileSets profile='mercator'>" +
" <TileSet href='7' units-per-pixel='1222.99245234375008' order='7'/>" +
" <TileSet href='8' units-per-pixel='611.49622617187504' order='8'/>" +
' </TileSets>' +
'</TileMap>';
patchRequestScheduler(xmlString);

var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
@@ -510,24 +531,20 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('handles XML with casing differences', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
var parser = new DOMParser();
var xmlString =
"<Tilemap version='1.0.0' tilemapservice='http://tms.osgeo.org/1.0.0'>" +
' <Title>dnb_land_ocean_ice.2012.54000x27000_geo.tif</Title>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
" <boundingbox minx='-10.0' miny='5.0' maxx='-9.0' maxy='6.0'/>" +
" <Origin x='-88.0' y='-180.00000000000000'/>" +
" <Tileformat width='256' height='256' mime-type='image/png' extension='png'/>" +
" <TileSets profile='mercator'>" +
" <tiLeset href='7' units-per-pixel='1222.99245234375008' order='7'/>" +
" <tileset href='8' units-per-pixel='611.49622617187504' order='8'/>" +
' </TileSets>' +
'</Tilemap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
};
var xmlString =
"<Tilemap version='1.0.0' tilemapservice='http://tms.osgeo.org/1.0.0'>" +
' <Title>dnb_land_ocean_ice.2012.54000x27000_geo.tif</Title>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
" <boundingbox minx='-10.0' miny='5.0' maxx='-9.0' maxy='6.0'/>" +
" <Origin x='-88.0' y='-180.00000000000000'/>" +
" <Tileformat width='256' height='256' mime-type='image/png' extension='png'/>" +
" <TileSets profile='mercator'>" +
" <tiLeset href='7' units-per-pixel='1222.99245234375008' order='7'/>" +
" <tileset href='8' units-per-pixel='611.49622617187504' order='8'/>" +
' </TileSets>' +
'</Tilemap>';
patchRequestScheduler(xmlString);

var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
@@ -542,24 +559,20 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('supports the global-mercator profile with a non-flipped, mercator bounding box', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
var parser = new DOMParser();
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
' <BoundingBox minx="-11877789.66764229300000" miny="1707163.75952051670000" maxx="-4696205.45407573510000" maxy="7952627.07365330120000"/>' +
' <Origin x="-20037508.34278924400000" y="-20037508.34278924400000"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="global-mercator">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
};
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
' <BoundingBox minx="-11877789.66764229300000" miny="1707163.75952051670000" maxx="-4696205.45407573510000" maxy="7952627.07365330120000"/>' +
' <Origin x="-20037508.34278924400000" y="-20037508.34278924400000"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="global-mercator">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
patchRequestScheduler(xmlString);

var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
@@ -583,24 +596,20 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('supports the global-geodetic profile with a non-flipped, geographic bounding box', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
var parser = new DOMParser();
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <BoundingBox minx="-123.0" miny="-10.0" maxx="-110.0" maxy="11.0"/>' +
' <Origin x="-180.0" y="-90.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="global-geodetic">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
};
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <BoundingBox minx="-123.0" miny="-10.0" maxx="-110.0" maxy="11.0"/>' +
' <Origin x="-180.0" y="-90.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="global-geodetic">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
patchRequestScheduler(xmlString);

var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
@@ -623,24 +632,20 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('supports the old mercator profile with a flipped, geographic bounding box', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
var parser = new DOMParser();
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
' <BoundingBox minx="-10.0" miny="-123.0" maxx="11.0" maxy="-110.0"/>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="mercator">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
};
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:900913</SRS>' +
' <BoundingBox minx="-10.0" miny="-123.0" maxx="11.0" maxy="-110.0"/>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="mercator">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
patchRequestScheduler(xmlString);

var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server',
@@ -664,24 +669,20 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('supports the old geodetic profile with a flipped, geographic bounding box', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
var parser = new DOMParser();
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <BoundingBox minx="-10.0" miny="-123.0" maxx="11.0" maxy="-110.0"/>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="geodetic">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
};
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <BoundingBox minx="-10.0" miny="-123.0" maxx="11.0" maxy="-110.0"/>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="geodetic">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
patchRequestScheduler(xmlString);

var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server',
@@ -705,28 +706,20 @@ describe('Scene/TileMapServiceImageryProvider', function() {
});

it('raises an error if tilemapresource.xml specifies an unsupported profile', function() {
Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
// We can't resolve the promise immediately, because then the error would be raised
// before we could subscribe to it. This a problem particular to tests.
setTimeout(function() {
var parser = new DOMParser();
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <BoundingBox minx="-10.0" miny="-123.0" maxx="11.0" maxy="-110.0"/>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="foobar">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
var xml = parser.parseFromString(xmlString, 'text/xml');
deferred.resolve(xml);
}, 1);
};
var xmlString =
'<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">' +
' <Title/>' +
' <Abstract/>' +
' <SRS>EPSG:4326</SRS>' +
' <BoundingBox minx="-10.0" miny="-123.0" maxx="11.0" maxy="-110.0"/>' +
' <Origin x="-90.0" y="-180.0"/>' +
' <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>' +
' <TileSets profile="foobar">' +
' <TileSet href="2" units-per-pixel="39135.75848201024200" order="2"/>' +
' <TileSet href="3" units-per-pixel="19567.87924100512100" order="3"/>' +
' </TileSets>' +
'</TileMap>';
patchRequestScheduler(xmlString);

var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server'
@@ -744,4 +737,22 @@ describe('Scene/TileMapServiceImageryProvider', function() {
expect(errorRaised).toBe(true);
});
});

it('rejects readyPromise if the tilemapresource.xml request fails', function (done) {
patchRequestSchedulerToRejectRequest();
var provider = new TileMapServiceImageryProvider({
url : 'made/up/tms/server/',
maximumLevel : 10
});

return provider.readyPromise.then(function() {
// we don't want to resolve this promise because the tilemapresource.xml data is required!
// if we start assuming default values for the xml and combined those defaults with passed in options from the constructor.
// we can end up with unintended and unexpected configurations that can hang the browser.
done.fail('Should not resolve.');
}).otherwise(function(error) {
expect(error.message).toContain('An error occurred while accessing');
expect(error.message).toContain('/made/up/tms/server/tilemapresource.xml.');
});
});
});