Permalink
Browse files

Merge pull request #562 from AnalyticalGraphicsInc/TileCoordinatesIma…

…geryProvider

Tile coordinates imagery provider
  • Loading branch information...
2 parents 4b38e03 + de99401 commit 5ac6bde9ed559f92cacdca2cce6653d17c7a9e00 @pjcozzi pjcozzi committed Mar 13, 2013
@@ -161,6 +161,9 @@
Cesium.Math.toRadians(39.75))
}),
1.0);
+ addAdditionalLayerOption(
+ 'Tile Coordinates',
+ new Cesium.TileCoordinatesImageryProvider(), 1.0, false);
}
function addBaseLayerOption(name, imageryProvider) {
@@ -175,9 +178,10 @@
baseLayers.push(layer);
}
- function addAdditionalLayerOption(name, imageryProvider, alpha) {
+ function addAdditionalLayerOption(name, imageryProvider, alpha, show) {
var layer = imageryLayerCollection.addImageryProvider(imageryProvider);
layer.alpha = Cesium.defaultValue(alpha, 0.5);
+ layer.show = Cesium.defaultValue(show, true);
layer.name = name;
}
View
@@ -10,7 +10,8 @@ Beta Releases
*
* Added `BoundingSphere.fromCornerPoints`.
* Added `fromArray` and `distance` functions to `Cartesian2`, `Cartesian3`, and `Cartesian4`.
-* Added `DynamicPath.resolution` property for setting the maximum step size, in seconds, to take when sampling a position for path visualization.
+* Added `DynamicPath.resolution` property for setting the maximum step size, in seconds, to take when sampling a position for path visualization.
+* Added `TileCoordinatesImageryProvider` that renders imagery with tile X, Y, Level coordinates on the surface of the globe. This is mostly useful for debugging.
### b14 - 2013-03-01
@@ -0,0 +1,193 @@
+/*global define*/
+define([
+ '../Core/defaultValue',
+ '../Core/Color',
+ '../Core/Event',
+ './GeographicTilingScheme'
+ ], function(
+ defaultValue,
+ Color,
+ Event,
+ GeographicTilingScheme) {
+ "use strict";
+
+ /**
+ * An {@link ImageryProvider} that draws a box around every rendered tile in the tiling scheme, and draws
+ * a label inside it indicating the X, Y, Level coordinates of the tile. This is mostly useful for
+ * debugging terrain and imagery rendering problems.
+ *
+ * @alias TileCoordinatesImageryProvider
+ * @constructor
+ *
+ * @param {TilingScheme} [description.tilingScheme=new GeographicTilingScheme()] The tiling scheme for which to draw tiles.
+ * @param {Color} [description.color=Color.YELLOW] The color to draw the tile box and label.
+ * @param {Number} [description.tileWidth=256] The width of the tile for level-of-detail selection purposes.
+ * @param {Number} [description.tileHeight=256] The height of the tile for level-of-detail selection purposes.
+ */
+ var TileCoordinatesImageryProvider = function TileCoordinatesImageryProvider(description) {
+ description = defaultValue(description, {});
+
+ this._tilingScheme = defaultValue(description.tilingScheme, new GeographicTilingScheme());
+ this._color = defaultValue(description.color, Color.YELLOW);
+ this._errorEvent = new Event();
+ this._tileWidth = defaultValue(description.tileWidth, 256);
+ this._tileHeight = defaultValue(description.tileHeight, 256);
+ };
+
+ /**
+ * Gets the width of each tile, in pixels. This function should
+ * not be called before {@link BingMapsImageryProvider#isReady} returns true.
+ *
+ * @memberof TileCoordinatesImageryProvider
+ *
+ * @returns {Number} The width.
+ *
+ * @exception {DeveloperError} <code>getTileWidth</code> must not be called before the imagery provider is ready.
+ */
+ TileCoordinatesImageryProvider.prototype.getTileWidth = function() {
+ return this._tileWidth;
+ };
+
+ /**
+ * Gets the height of each tile, in pixels. This function should
+ * not be called before {@link BingMapsImageryProvider#isReady} returns true.
+ *
+ * @memberof TileCoordinatesImageryProvider
+ *
+ * @returns {Number} The height.
+ */
+ TileCoordinatesImageryProvider.prototype.getTileHeight = function() {
+ return this._tileHeight;
+ };
+
+ /**
+ * Gets the maximum level-of-detail that can be requested. This function should
+ * not be called before {@link BingMapsImageryProvider#isReady} returns true.
+ *
+ * @memberof TileCoordinatesImageryProvider
+ *
+ * @returns {Number} The maximum level.
+ */
+ TileCoordinatesImageryProvider.prototype.getMaximumLevel = function() {
+ return undefined;
+ };
+
+ /**
+ * Gets the tiling scheme used by this provider. This function should
+ * not be called before {@link BingMapsImageryProvider#isReady} returns true.
+ *
+ * @memberof TileCoordinatesImageryProvider
+ *
+ * @returns {TilingScheme} The tiling scheme.
+ * @see WebMercatorTilingScheme
+ * @see GeographicTilingScheme
+ */
+ TileCoordinatesImageryProvider.prototype.getTilingScheme = function() {
+ return this._tilingScheme;
+ };
+
+ /**
+ * Gets the extent, in radians, of the imagery provided by this instance. This function should
+ * not be called before {@link BingMapsImageryProvider#isReady} returns true.
+ *
+ * @memberof TileCoordinatesImageryProvider
+ *
+ * @returns {Extent} The extent.
+ */
+ TileCoordinatesImageryProvider.prototype.getExtent = function() {
+ return this._tilingScheme.getExtent();
+ };
+
+ /**
+ * Gets the tile discard policy. If not undefined, the discard policy is responsible
+ * for filtering out "missing" tiles via its shouldDiscardImage function. If this function
+ * returns undefined, no tiles are filtered. This function should
+ * not be called before {@link BingMapsImageryProvider#isReady} returns true.
+ *
+ * @memberof TileCoordinatesImageryProvider
+ *
+ * @returns {TileDiscardPolicy} The discard policy.
+ *
+ * @see DiscardMissingTileImagePolicy
+ * @see NeverTileDiscardPolicy
+ */
+ TileCoordinatesImageryProvider.prototype.getTileDiscardPolicy = function() {
+ return undefined;
+ };
+
+ /**
+ * Gets an event that is raised when the imagery provider encounters an asynchronous error. By subscribing
+ * to the event, you will be notified of the error and can potentially recover from it. Event listeners
+ * are passed an instance of {@link TileProviderError}.
+ *
+ * @memberof TileCoordinatesImageryProvider
+ *
+ * @returns {Event} The event.
+ */
+ TileCoordinatesImageryProvider.prototype.getErrorEvent = function() {
+ return this._errorEvent;
+ };
+
+ /**
+ * Gets a value indicating whether or not the provider is ready for use.
+ *
+ * @memberof TileCoordinatesImageryProvider
+ *
+ * @returns {Boolean} True if the provider is ready to use; otherwise, false.
+ */
+ TileCoordinatesImageryProvider.prototype.isReady = function() {
+ return true;
+ };
+
+ /**
+ * Requests the image for a given tile. This function should
+ * not be called before {@link BingMapsImageryProvider#isReady} returns true.
+ *
+ * @memberof TileCoordinatesImageryProvider
+ *
+ * @param {Number} x The tile X coordinate.
+ * @param {Number} y The tile Y coordinate.
+ * @param {Number} level The tile level.
+ *
+ * @returns {Promise} A promise for the image that will resolve when the image is available, or
+ * undefined if there are too many active requests to the server, and the request
+ * should be retried later. The resolved image may be either an
+ * Image or a Canvas DOM object.
+ */
+ TileCoordinatesImageryProvider.prototype.requestImage = function(x, y, level) {
+ var canvas = document.createElement('canvas');
+ canvas.width = 256;
+ canvas.height = 256;
+ var context = canvas.getContext('2d');
+
+ var cssColor = this._color.toCssColorString();
+
+ context.strokeStyle = cssColor;
+ context.lineWidth = 2;
+ context.strokeRect(1, 1, 255, 255);
+
+ var label = 'L' + level + 'X' + x + 'Y' + y;
+ context.font = 'bold 25px Arial';
+ context.textAlign = 'center';
+ context.fillStyle = 'black';
+ context.fillText(label, 127, 127);
+ context.fillStyle = cssColor;
+ context.fillText(label, 124, 124);
+
+ return canvas;
+ };
+
+ /**
+ * Gets the logo to display when this imagery provider is active. Typically this is used to credit
+ * the source of the imagery. This function should not be called before {@link BingMapsImageryProvider#isReady} returns true.
+ *
+ * @memberof TileCoordinatesImageryProvider
+ *
+ * @returns {Image|Canvas} A canvas or image containing the log to display, or undefined if there is no logo.
+ */
+ TileCoordinatesImageryProvider.prototype.getLogo = function() {
+ return undefined;
+ };
+
+ return TileCoordinatesImageryProvider;
+});
@@ -0,0 +1,82 @@
+/*global defineSuite*/
+defineSuite([
+ 'Scene/TileCoordinatesImageryProvider',
+ 'Scene/GeographicTilingScheme',
+ 'Scene/ImageryProvider',
+ 'Scene/WebMercatorTilingScheme',
+ 'ThirdParty/when'
+ ], function(
+ TileCoordinatesImageryProvider,
+ GeographicTilingScheme,
+ ImageryProvider,
+ WebMercatorTilingScheme,
+ when) {
+ "use strict";
+ /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/
+
+ it('conforms to ImageryProvider interface', function() {
+ expect(TileCoordinatesImageryProvider).toConformToInterface(ImageryProvider);
+ });
+
+ it('can provide a root tile', function() {
+ var provider = new TileCoordinatesImageryProvider();
+
+ waitsFor(function() {
+ return provider.isReady();
+ }, 'imagery provider to become ready');
+
+ var tile000Image;
+
+ runs(function() {
+ expect(provider.getTileWidth()).toEqual(256);
+ expect(provider.getTileHeight()).toEqual(256);
+ expect(provider.getMaximumLevel()).toBeUndefined();
+ expect(provider.getTilingScheme()).toBeInstanceOf(GeographicTilingScheme);
+ expect(provider.getTileDiscardPolicy()).toBeUndefined();
+ expect(provider.getExtent()).toEqual(new GeographicTilingScheme().getExtent());
+
+ when(provider.requestImage(0, 0, 0), function(image) {
+ tile000Image = image;
+ });
+ });
+
+ waitsFor(function() {
+ return typeof tile000Image !== 'undefined';
+ }, 'requested tile to be loaded');
+
+ runs(function() {
+ expect(tile000Image).toBeDefined();
+ });
+ });
+
+ it('uses alternate tiling scheme if provided', function() {
+ var tilingScheme = new WebMercatorTilingScheme();
+ var provider = new TileCoordinatesImageryProvider({
+ tilingScheme : tilingScheme
+ });
+
+ waitsFor(function() {
+ return provider.isReady();
+ }, 'imagery provider to become ready');
+
+ runs(function() {
+ expect(provider.getTilingScheme()).toBe(tilingScheme);
+ });
+ });
+
+ it('uses tile width and height if provided', function() {
+ var provider = new TileCoordinatesImageryProvider({
+ tileWidth : 123,
+ tileHeight : 456
+ });
+
+ waitsFor(function() {
+ return provider.isReady();
+ }, 'imagery provider to become ready');
+
+ runs(function() {
+ expect(provider.getTileWidth()).toEqual(123);
+ expect(provider.getTileHeight()).toEqual(456);
+ });
+ });
+});

0 comments on commit 5ac6bde

Please sign in to comment.