forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCesium3DTileStyleEngine.js
82 lines (70 loc) · 2.84 KB
/
Cesium3DTileStyleEngine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
define([
'../Core/defined',
'../Core/defineProperties'
], function(
defined,
defineProperties) {
'use strict';
/**
* @private
*/
function Cesium3DTileStyleEngine() {
this._style = undefined; // The style provided by the user
this._styleDirty = false; // true when the style is reassigned
this._lastStyleTime = 0; // The "time" when the last style was assigned
}
defineProperties(Cesium3DTileStyleEngine.prototype, {
style : {
get : function() {
return this._style;
},
set : function(value) {
this._style = value;
this._styleDirty = true;
}
}
});
Cesium3DTileStyleEngine.prototype.makeDirty = function() {
this._styleDirty = true;
};
Cesium3DTileStyleEngine.prototype.applyStyle = function(tileset, frameState) {
if (!tileset.ready) {
return;
}
if (defined(this._style) && !this._style.ready) {
return;
}
var styleDirty = this._styleDirty;
if (frameState.passes.render) {
// Don't reset until the color pass, e.g., for mouse-over picking
this._styleDirty = false;
}
if (styleDirty) {
// Increase "time", so the style is applied to all visible tiles
++this._lastStyleTime;
}
var lastStyleTime = this._lastStyleTime;
var statistics = tileset._statistics;
// If a new style was assigned, loop through all the visible tiles; otherwise, loop through
// only the tiles that are newly visible, i.e., they are visible this frame, but were not
// visible last frame. In many cases, the newly selected tiles list will be short or empty.
var tiles = styleDirty ? tileset._selectedTiles : tileset._selectedTilesToStyle;
// PERFORMANCE_IDEA: does mouse-over picking basically trash this? We need to style on
// pick, for example, because a feature's show may be false.
var length = tiles.length;
for (var i = 0; i < length; ++i) {
var tile = tiles[i];
if (tile.selected && (tile.lastStyleTime !== lastStyleTime)) {
// Apply the style to this tile if it wasn't already applied because:
// 1) the user assigned a new style to the tileset
// 2) this tile is now visible, but it wasn't visible when the style was first assigned
var content = tile.content;
tile.lastStyleTime = lastStyleTime;
content.applyStyle(this._style);
statistics.numberOfFeaturesStyled += content.featuresLength;
++statistics.numberOfTilesStyled;
}
}
};
return Cesium3DTileStyleEngine;
});