@@ -200,14 +200,16 @@ define([
200
200
this . _requestTemplate ( ) ;
201
201
}
202
202
203
- function deferredQueueContains ( deferredQueue , tile ) {
203
+ //for a given tile, if we have an element with the same tile in the queue, return the element.
204
+ function findInDeferredQueue ( deferredQueue , tile ) {
204
205
for ( var i = 0 , len = deferredQueue . length ; i < len ; ++ i ) {
205
- var t = deferredQueue [ i ] . tile ;
206
+ var element = deferredQueue [ i ] ;
207
+ var t = element . tile ;
206
208
if ( t . zoom === tile . zoom && t . x === tile . x && t . y === tile . y ) {
207
- return true ;
209
+ return element ;
208
210
}
209
211
}
210
- return false ;
212
+ return undefined ;
211
213
}
212
214
213
215
/**
@@ -339,17 +341,39 @@ define([
339
341
} ;
340
342
341
343
if ( typeof this . _url === 'undefined' ) {
342
- if ( ! deferredQueueContains ( this . _deferredQueue , tile ) ) {
344
+ var existingElement = findInDeferredQueue ( this . _deferredQueue , tile ) ;
345
+ if ( typeof existingElement === 'undefined' ) {
343
346
this . _deferredQueue . push ( element ) ;
347
+ return image ;
344
348
}
345
349
346
- return image ;
350
+ //add the callbacks to the existing element so both are called
351
+ existingElement . onload = combineFunctions ( existingElement . onload , onload ) ;
352
+ existingElement . onerror = combineFunctions ( existingElement . onerror , onerror ) ;
353
+ existingElement . oninvalid = combineFunctions ( existingElement . oninvalid , oninvalid ) ;
354
+ return existingElement . image ;
347
355
}
348
356
349
357
this . _loadImage ( element ) ;
350
358
return image ;
351
359
} ;
352
360
361
+ function combineFunctions ( a , b ) {
362
+ if ( typeof a !== 'function' && typeof b !== 'function' ) {
363
+ return undefined ;
364
+ }
365
+ if ( typeof a !== 'function' && typeof b === 'function' ) {
366
+ return b ;
367
+ }
368
+ if ( typeof a === 'function' && typeof b !== 'function' ) {
369
+ return a ;
370
+ }
371
+ return function ( ) {
372
+ a ( ) ;
373
+ b ( ) ;
374
+ } ;
375
+ }
376
+
353
377
BingMapsTileProvider . prototype . _loadImage = function ( element ) {
354
378
var tile = element . tile ;
355
379
var lat = CesiumMath . toDegrees ( ( tile . extent . north + tile . extent . south ) * 0.5 ) ;
0 commit comments