123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import Color from "../Core/Color.js";
- import defined from "../Core/defined.js";
- import JulianDate from "../Core/JulianDate.js";
- import CesiumMath from "../Core/Math.js";
- function Cesium3DTilesetHeatmap(tilePropertyName) {
-
- this.tilePropertyName = tilePropertyName;
-
- this._minimum = Number.MAX_VALUE;
- this._maximum = -Number.MAX_VALUE;
-
- this._previousMinimum = Number.MAX_VALUE;
- this._previousMaximum = -Number.MAX_VALUE;
-
-
- this._referenceMinimum = {};
- this._referenceMaximum = {};
- }
- function getHeatmapValue(tileValue, tilePropertyName) {
- var value;
- if (tilePropertyName === "_loadTimestamp") {
- value = JulianDate.toDate(tileValue).getTime();
- } else {
- value = tileValue;
- }
- return value;
- }
- Cesium3DTilesetHeatmap.prototype.setReferenceMinimumMaximum = function (
- minimum,
- maximum,
- tilePropertyName
- ) {
- this._referenceMinimum[tilePropertyName] = getHeatmapValue(
- minimum,
- tilePropertyName
- );
- this._referenceMaximum[tilePropertyName] = getHeatmapValue(
- maximum,
- tilePropertyName
- );
- };
- function getHeatmapValueAndUpdateMinimumMaximum(heatmap, tile) {
- var tilePropertyName = heatmap.tilePropertyName;
- if (defined(tilePropertyName)) {
- var heatmapValue = getHeatmapValue(
- tile[tilePropertyName],
- tilePropertyName
- );
- if (!defined(heatmapValue)) {
- heatmap.tilePropertyName = undefined;
- return heatmapValue;
- }
- heatmap._maximum = Math.max(heatmapValue, heatmap._maximum);
- heatmap._minimum = Math.min(heatmapValue, heatmap._minimum);
- return heatmapValue;
- }
- }
- var heatmapColors = [
- new Color(0.1, 0.1, 0.1, 1),
- new Color(0.153, 0.278, 0.878, 1),
- new Color(0.827, 0.231, 0.49, 1),
- new Color(0.827, 0.188, 0.22, 1),
- new Color(1.0, 0.592, 0.259, 1),
- new Color(1.0, 0.843, 0.0, 1),
- ];
- Cesium3DTilesetHeatmap.prototype.colorize = function (tile, frameState) {
- var tilePropertyName = this.tilePropertyName;
- if (
- !defined(tilePropertyName) ||
- !tile.contentAvailable ||
- tile._selectedFrame !== frameState.frameNumber
- ) {
- return;
- }
- var heatmapValue = getHeatmapValueAndUpdateMinimumMaximum(this, tile);
- var minimum = this._previousMinimum;
- var maximum = this._previousMaximum;
- if (minimum === Number.MAX_VALUE || maximum === -Number.MAX_VALUE) {
- return;
- }
-
- var shiftedMax = maximum - minimum + CesiumMath.EPSILON7;
- var shiftedValue = CesiumMath.clamp(heatmapValue - minimum, 0.0, shiftedMax);
-
- var zeroToOne = shiftedValue / shiftedMax;
- var lastIndex = heatmapColors.length - 1.0;
- var colorPosition = zeroToOne * lastIndex;
-
- var colorPositionFloor = Math.floor(colorPosition);
- var colorPositionCeil = Math.ceil(colorPosition);
- var t = colorPosition - colorPositionFloor;
- var colorZero = heatmapColors[colorPositionFloor];
- var colorOne = heatmapColors[colorPositionCeil];
-
- var finalColor = Color.clone(Color.WHITE);
- finalColor.red = CesiumMath.lerp(colorZero.red, colorOne.red, t);
- finalColor.green = CesiumMath.lerp(colorZero.green, colorOne.green, t);
- finalColor.blue = CesiumMath.lerp(colorZero.blue, colorOne.blue, t);
- tile._debugColor = finalColor;
- };
- Cesium3DTilesetHeatmap.prototype.resetMinimumMaximum = function () {
-
- var tilePropertyName = this.tilePropertyName;
- if (defined(tilePropertyName)) {
- var referenceMinimum = this._referenceMinimum[tilePropertyName];
- var referenceMaximum = this._referenceMaximum[tilePropertyName];
- var useReference = defined(referenceMinimum) && defined(referenceMaximum);
- this._previousMinimum = useReference ? referenceMinimum : this._minimum;
- this._previousMaximum = useReference ? referenceMaximum : this._maximum;
- this._minimum = Number.MAX_VALUE;
- this._maximum = -Number.MAX_VALUE;
- }
- };
- export default Cesium3DTilesetHeatmap;
|