Skip to content

Commit

Permalink
Fix 2D Skeleton example thanks to @shunter 's higher order function t…
Browse files Browse the repository at this point in the history
…utorial.
  • Loading branch information
bagnell committed May 17, 2012
1 parent 505cec5 commit 02e377e
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions Source/Scene/BingMapsTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,16 @@ define([
this._requestTemplate();
}

function deferredQueueContains(deferredQueue, tile) {
//for a given tile, if we have an element with the same tile in the queue, return the element.
function findInDeferredQueue(deferredQueue, tile) {
for ( var i = 0, len = deferredQueue.length; i < len; ++i) {
var t = deferredQueue[i].tile;
var element = deferredQueue[i];
var t = element.tile;
if (t.zoom === tile.zoom && t.x === tile.x && t.y === tile.y) {
return true;
return element;
}
}
return false;
return undefined;
}

/**
Expand Down Expand Up @@ -339,17 +341,39 @@ define([
};

if (typeof this._url === 'undefined') {
if (!deferredQueueContains(this._deferredQueue, tile)) {
var existingElement = findInDeferredQueue(this._deferredQueue, tile);
if (typeof existingElement === 'undefined') {
this._deferredQueue.push(element);
return image;
}

return image;
//add the callbacks to the existing element so both are called
existingElement.onload = combineFunctions(existingElement.onload, onload);
existingElement.onerror = combineFunctions(existingElement.onerror, onerror);
existingElement.oninvalid = combineFunctions(existingElement.oninvalid, oninvalid);
return existingElement.image;
}

this._loadImage(element);
return image;
};

function combineFunctions(a, b) {
if (typeof a !== 'function' && typeof b !== 'function') {
return undefined;
}
if (typeof a !== 'function' && typeof b === 'function') {
return b;
}
if (typeof a === 'function' && typeof b !== 'function') {
return a;
}
return function() {
a();
b();
};
}

BingMapsTileProvider.prototype._loadImage = function(element) {
var tile = element.tile;
var lat = CesiumMath.toDegrees((tile.extent.north + tile.extent.south) * 0.5);
Expand Down

3 comments on commit 02e377e

@pjcozzi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this change is needed. Right now, scenes are completely separate. They will remain this way for the foreseeable future until the WebGL shared contexts extension is finished, implemented, and widely available. I'd rather see a fix in the Skeleton2D example where a separate BingMapsTileProvider is used for each scene just like a separate CentralBody primitive and night lights images are used. Otherwise, we have an inconsistent API where users don't know what is shared among scenes and what is not.

Bigger picture, some types like cartesians and matrices, can, of course, be used among multiple scenes, and perhaps we need to document that at some point.

@bagnell
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning here was that a tile provider should return the right image no matter who requests it, but I'll change the example to be consistent.

@pjcozzi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Please sign in to comment.