Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

S3MLayerCache.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const { Cesium } = DC.Namespace
  2. function S3MLayerCache() {
  3. this._list = new Cesium.DoublyLinkedList();
  4. this._sentinel = this._list.add();
  5. this._trimTiles = false;
  6. }
  7. S3MLayerCache.prototype.reset = function() {
  8. this._list.splice(this._list.tail, this._sentinel);
  9. };
  10. S3MLayerCache.prototype.touch = function(tile) {
  11. let node = tile.cacheNode;
  12. if (Cesium.defined(node)) {
  13. this._list.splice(this._sentinel, node);
  14. }
  15. };
  16. S3MLayerCache.prototype.add = function(tile) {
  17. if (!Cesium.defined(tile.cacheNode)) {
  18. tile.cacheNode = this._list.add(tile);
  19. }
  20. };
  21. S3MLayerCache.prototype.unloadTile = function(layer, tile, unloadCallback) {
  22. let node = tile.cacheNode;
  23. if (!Cesium.defined(node)) {
  24. return;
  25. }
  26. this._list.remove(node);
  27. tile.cacheNode = undefined;
  28. unloadCallback(layer, tile);
  29. };
  30. S3MLayerCache.prototype.unloadTiles = function(layer, unloadCallback) {
  31. let trimTiles = this._trimTiles;
  32. this._trimTiles = false;
  33. let list = this._list;
  34. let maximumMemoryUsageInBytes = layer.maximumMemoryUsage * 1024 * 1024;
  35. let sentinel = this._sentinel;
  36. let node = list.head;
  37. while (node && (node !== sentinel) && ((layer.totalMemoryUsageInBytes > maximumMemoryUsageInBytes) || trimTiles)) {
  38. let tile = node.item;
  39. node = node.next;
  40. this.unloadTile(layer, tile, unloadCallback);
  41. }
  42. };
  43. S3MLayerCache.prototype.trim = function() {
  44. this._trimTiles = true;
  45. };
  46. export default S3MLayerCache;