@@ -17,6 +17,7 @@ define([
17
17
'../Core/getStringFromTypedArray' ,
18
18
'../Core/Intersect' ,
19
19
'../Core/joinUrls' ,
20
+ '../Core/JulianDate' ,
20
21
'../Core/loadArrayBuffer' ,
21
22
'../Core/Matrix3' ,
22
23
'../Core/Matrix4' ,
@@ -60,6 +61,7 @@ define([
60
61
getStringFromTypedArray ,
61
62
Intersect ,
62
63
joinUrls ,
64
+ JulianDate ,
63
65
loadArrayBuffer ,
64
66
Matrix3 ,
65
67
Matrix4 ,
@@ -268,6 +270,30 @@ define([
268
270
*/
269
271
this . replacementNode = undefined ;
270
272
273
+ var expire = header . expire ;
274
+ var expireDuration ;
275
+ var expireDate ;
276
+ if ( defined ( expire ) ) {
277
+ expireDuration = expire . duration ;
278
+ if ( defined ( expire . date ) ) {
279
+ expireDate = JulianDate . fromIso8601 ( expire . date ) ;
280
+ }
281
+ }
282
+
283
+ /**
284
+ * The time in seconds after the tile's content is ready when the content expires and new content is requested.
285
+ *
286
+ * @type {Number }
287
+ */
288
+ this . expireDuration = expireDuration ;
289
+
290
+ /**
291
+ * The date when the content expires and new content is requested.
292
+ *
293
+ * @type {JulianDate }
294
+ */
295
+ this . expireDate = expireDate ;
296
+
271
297
// Members that are updated every frame for tree traversal and rendering optimizations:
272
298
273
299
/**
@@ -449,6 +475,21 @@ define([
449
475
}
450
476
} ,
451
477
478
+ /**
479
+ * Determines if the tile's content is expired. <code>true</code> if tile's
480
+ * content is expired; otherwise, <code>false</code>.
481
+ *
482
+ * @memberof Cesium3DTile.prototype
483
+ *
484
+ * @type {Boolean }
485
+ * @readonly
486
+ */
487
+ contentExpired : {
488
+ get : function ( ) {
489
+ return this . _contentState === Cesium3DTileContentState . EXPIRED ;
490
+ }
491
+ } ,
492
+
452
493
/**
453
494
* Gets the promise that will be resolved when the tile's content is ready to process.
454
495
* This happens after the content is downloaded but before the content is ready
@@ -490,6 +531,32 @@ define([
490
531
}
491
532
} ) ;
492
533
534
+ var scratchJulianDate = new JulianDate ( ) ;
535
+
536
+ function updateExpiration ( tile ) {
537
+ if ( defined ( tile . expireDate ) && tile . contentReady && ! tile . hasEmptyContent ) {
538
+ var now = JulianDate . now ( scratchJulianDate ) ;
539
+ if ( JulianDate . lessThan ( tile . expireDate , now ) ) {
540
+ tile . _contentState = Cesium3DTileContentState . EXPIRED ;
541
+ }
542
+ }
543
+ }
544
+
545
+ function updateExpireDate ( tile ) {
546
+ if ( defined ( tile . expireDuration ) ) {
547
+ var expireDurationDate = JulianDate . now ( scratchJulianDate ) ;
548
+ JulianDate . addSeconds ( expireDurationDate , tile . expireDuration , expireDurationDate ) ;
549
+
550
+ if ( defined ( tile . expireDate ) ) {
551
+ if ( JulianDate . lessThan ( tile . expireDate , expireDurationDate ) ) {
552
+ JulianDate . clone ( expireDurationDate , tile . expireDate ) ;
553
+ }
554
+ } else {
555
+ tile . expireDate = JulianDate . clone ( expireDurationDate ) ;
556
+ }
557
+ }
558
+ }
559
+
493
560
/**
494
561
* Requests the tile's content.
495
562
* <p>
@@ -509,9 +576,16 @@ define([
509
576
return false ;
510
577
}
511
578
579
+ var url = this . _contentUrl ;
580
+ if ( defined ( this . expireDate ) ) {
581
+ // Append a query parameter of the tile expiration date to prevent caching
582
+ var timestampQuery = '?expired=' + this . expireDate . toString ( ) ;
583
+ url = joinUrls ( url , timestampQuery , false ) ;
584
+ }
585
+
512
586
var distance = this . distanceToCamera ;
513
587
var promise = RequestScheduler . schedule ( new Request ( {
514
- url : this . _contentUrl ,
588
+ url : url ,
515
589
server : this . _requestServer ,
516
590
requestFunction : loadArrayBuffer ,
517
591
type : RequestType . TILES3D ,
@@ -530,6 +604,10 @@ define([
530
604
if ( that . isDestroyed ( ) ) {
531
605
return when . reject ( 'tileset is destroyed' ) ;
532
606
}
607
+
608
+ // Destroy expired content to make way for the new content
609
+ that . _content = that . _content && that . _content . destroy ( ) ;
610
+
533
611
var uint8Array = new Uint8Array ( arrayBuffer ) ;
534
612
var magic = getMagic ( uint8Array ) ;
535
613
var contentFactory = Cesium3DTileContentFactory [ magic ] ;
@@ -549,6 +627,7 @@ define([
549
627
that . _contentReadyToProcessPromise . resolve ( content ) ;
550
628
551
629
content . readyPromise . then ( function ( content ) {
630
+ updateExpireDate ( that ) ;
552
631
that . _contentState = Cesium3DTileContentState . READY ;
553
632
that . _contentReadyPromise . resolve ( content ) ;
554
633
} ) . otherwise ( function ( error ) {
@@ -861,6 +940,7 @@ define([
861
940
*/
862
941
Cesium3DTile . prototype . update = function ( tileset , frameState ) {
863
942
applyDebugSettings ( this , tileset , frameState ) ;
943
+ updateExpiration ( this ) ;
864
944
this . _content . update ( tileset , frameState ) ;
865
945
this . _transformDirty = false ;
866
946
} ;
0 commit comments