Cesium3DTileStyleEngine.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import defined from "../Core/defined.js";
  2. /**
  3. * @private
  4. */
  5. function Cesium3DTileStyleEngine() {
  6. this._style = undefined; // The style provided by the user
  7. this._styleDirty = false; // true when the style is reassigned
  8. this._lastStyleTime = 0; // The "time" when the last style was assigned
  9. }
  10. Object.defineProperties(Cesium3DTileStyleEngine.prototype, {
  11. style: {
  12. get: function () {
  13. return this._style;
  14. },
  15. set: function (value) {
  16. if (value === this._style) {
  17. return;
  18. }
  19. this._style = value;
  20. this._styleDirty = true;
  21. },
  22. },
  23. });
  24. Cesium3DTileStyleEngine.prototype.makeDirty = function () {
  25. this._styleDirty = true;
  26. };
  27. Cesium3DTileStyleEngine.prototype.resetDirty = function () {
  28. this._styleDirty = false;
  29. };
  30. Cesium3DTileStyleEngine.prototype.applyStyle = function (tileset) {
  31. if (!tileset.ready) {
  32. return;
  33. }
  34. if (defined(this._style) && !this._style.ready) {
  35. return;
  36. }
  37. const styleDirty = this._styleDirty;
  38. if (styleDirty) {
  39. // Increase "time", so the style is applied to all visible tiles
  40. ++this._lastStyleTime;
  41. }
  42. const lastStyleTime = this._lastStyleTime;
  43. const statistics = tileset._statistics;
  44. // If a new style was assigned, loop through all the visible tiles; otherwise, loop through
  45. // only the tiles that are newly visible, i.e., they are visible this frame, but were not
  46. // visible last frame. In many cases, the newly selected tiles list will be short or empty.
  47. const tiles = styleDirty
  48. ? tileset._selectedTiles
  49. : tileset._selectedTilesToStyle;
  50. // PERFORMANCE_IDEA: does mouse-over picking basically trash this? We need to style on
  51. // pick, for example, because a feature's show may be false.
  52. const length = tiles.length;
  53. for (let i = 0; i < length; ++i) {
  54. const tile = tiles[i];
  55. if (tile.lastStyleTime !== lastStyleTime) {
  56. // Apply the style to this tile if it wasn't already applied because:
  57. // 1) the user assigned a new style to the tileset
  58. // 2) this tile is now visible, but it wasn't visible when the style was first assigned
  59. const content = tile.content;
  60. tile.lastStyleTime = lastStyleTime;
  61. content.applyStyle(this._style);
  62. statistics.numberOfFeaturesStyled += content.featuresLength;
  63. ++statistics.numberOfTilesStyled;
  64. }
  65. }
  66. };
  67. export default Cesium3DTileStyleEngine;