Cesium3DTileStyleEngine.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. this._style = value;
  17. this._styleDirty = true;
  18. },
  19. },
  20. });
  21. Cesium3DTileStyleEngine.prototype.makeDirty = function () {
  22. this._styleDirty = true;
  23. };
  24. Cesium3DTileStyleEngine.prototype.applyStyle = function (tileset, passOptions) {
  25. if (!tileset.ready) {
  26. return;
  27. }
  28. if (defined(this._style) && !this._style.ready) {
  29. return;
  30. }
  31. var styleDirty = this._styleDirty;
  32. if (passOptions.isRender) {
  33. // Don't reset until the render pass
  34. this._styleDirty = false;
  35. }
  36. if (styleDirty) {
  37. // Increase "time", so the style is applied to all visible tiles
  38. ++this._lastStyleTime;
  39. }
  40. var lastStyleTime = this._lastStyleTime;
  41. var statistics = tileset._statistics;
  42. // If a new style was assigned, loop through all the visible tiles; otherwise, loop through
  43. // only the tiles that are newly visible, i.e., they are visible this frame, but were not
  44. // visible last frame. In many cases, the newly selected tiles list will be short or empty.
  45. var tiles = styleDirty
  46. ? tileset._selectedTiles
  47. : tileset._selectedTilesToStyle;
  48. // PERFORMANCE_IDEA: does mouse-over picking basically trash this? We need to style on
  49. // pick, for example, because a feature's show may be false.
  50. var length = tiles.length;
  51. for (var i = 0; i < length; ++i) {
  52. var tile = tiles[i];
  53. if (tile.lastStyleTime !== lastStyleTime) {
  54. // Apply the style to this tile if it wasn't already applied because:
  55. // 1) the user assigned a new style to the tileset
  56. // 2) this tile is now visible, but it wasn't visible when the style was first assigned
  57. var content = tile.content;
  58. tile.lastStyleTime = lastStyleTime;
  59. content.applyStyle(this._style);
  60. statistics.numberOfFeaturesStyled += content.featuresLength;
  61. ++statistics.numberOfTilesStyled;
  62. }
  63. }
  64. };
  65. export default Cesium3DTileStyleEngine;