Skip to content

Commit

Permalink
Merge pull request CesiumGS#1409 from andre-nunes/minLevel
Browse files Browse the repository at this point in the history
OpenStreetMapImageryProvider can now make use of minimum level
  • Loading branch information
kring committed Jan 31, 2014
2 parents 6f752e4 + f67455d commit 8dce8af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Beta Releases
* `TileMapServiceImageryProvider` can now handle casing differences in tilemapresource.xml.
* Added `Quaternion.fastSlerp` and `Quaternion.fastSquad`.
* Upgraded Tween.js to version r12.
* `OpenStreetMapImageryProvider` now supports imagery with a minimum level.

### b24 - 2014-01-06

Expand Down
14 changes: 13 additions & 1 deletion Source/Scene/OpenStreetMapImageryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ define([
* @param {String} [description.fileExtension='png'] The file extension for images on the server.
* @param {Object} [description.proxy] A proxy to use for requests. This object is expected to have a getURL function which returns the proxied URL.
* @param {Extent} [description.extent=Extent.MAX_VALUE] The extent of the layer.
* @param {Number} [description.minimumLevel=0] The minimum level-of-detail supported by the imagery provider.
* @param {Number} [description.maximumLevel=18] The maximum level-of-detail supported by the imagery provider.
* @param {Credit|String} [description.credit='MapQuest, Open Street Map and contributors, CC-BY-SA'] A credit for the data source, which is displayed on the canvas.
*
Expand Down Expand Up @@ -70,10 +71,21 @@ define([
this._tileWidth = 256;
this._tileHeight = 256;

this._minimumLevel = defaultValue(description.minimumLevel, 0);
this._maximumLevel = defaultValue(description.maximumLevel, 18);

this._extent = defaultValue(description.extent, this._tilingScheme.getExtent());

// Check the number of tiles at the minimum level. If it's more than four,
// try requesting the lower levels anyway, because starting at the higher minimum
// level will cause too many tiles to be downloaded and rendered.
var swTile = this._tilingScheme.positionToTileXY(this._extent.getSouthwest(), this._minimumLevel);
var neTile = this._tilingScheme.positionToTileXY(this._extent.getNortheast(), this._minimumLevel);
var tileCount = (Math.abs(neTile.x - swTile.x) + 1) * (Math.abs(neTile.y - swTile.y) + 1);
if (tileCount > 4) {
throw new DeveloperError('Too many tiles at the minimum level');
}

this._errorEvent = new Event();

this._ready = true;
Expand Down Expand Up @@ -197,7 +209,7 @@ define([
}
//>>includeEnd('debug');

return 0;
return this._minimumLevel;
};

/**
Expand Down
8 changes: 8 additions & 0 deletions Specs/Scene/OpenStreetMapImageryProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ defineSuite([
expect(provider.getMaximumLevel()).toEqual(5);
});

it('uses minimumLevel passed to constructor', function() {
var provider = new OpenStreetMapImageryProvider({
url : 'made/up/osm/server',
minimumLevel : 0
});
expect(provider.getMinimumLevel()).toEqual(0);
});

it('raises error event when image cannot be loaded', function() {
var provider = new OpenStreetMapImageryProvider({
url : 'made/up/osm/server'
Expand Down

0 comments on commit 8dce8af

Please sign in to comment.