Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | 1x 54x 53x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 1x 1x 52x 50x 50x 50x 1x 1x 1x 1x 1x 72x 72x 72x 72x 72x 68x 4x 4x 4x 4x 1x 1x 43x 1x 43x 1x 43x 43x | import Cartesian3 from "../Core/Cartesian3.js";
import Cartographic from "../Core/Cartographic.js";
import Check from "../Core/Check.js";
import defined from "../Core/defined.js";
import destroyObject from "../Core/destroyObject.js";
import Event from "../Core/Event.js";
import Iso8601 from "../Core/Iso8601.js";
import JulianDate from "../Core/JulianDate.js";
import CesiumMath from "../Core/Math.js";
import HeightReference, {
isHeightReferenceRelative,
} from "../Scene/HeightReference.js";
import Property from "./Property.js";
const scratchPosition = new Cartesian3();
/**
* @private
*/
function TerrainOffsetProperty(
scene,
positionProperty,
heightReferenceProperty,
extrudedHeightReferenceProperty,
) {
//>>includeStart('debug', pragmas.debug);
Check.defined("scene", scene);
Check.defined("positionProperty", positionProperty);
//>>includeEnd('debug');
this._scene = scene;
this._heightReference = heightReferenceProperty;
this._extrudedHeightReference = extrudedHeightReferenceProperty;
this._positionProperty = positionProperty;
this._position = new Cartesian3();
this._cartographicPosition = new Cartographic();
this._normal = new Cartesian3();
this._definitionChanged = new Event();
this._terrainHeight = 0;
this._removeCallbackFunc = undefined;
this._removeEventListener = undefined;
this._removeModeListener = undefined;
const that = this;
if (defined(scene.globe)) {
this._removeEventListener = scene.terrainProviderChanged.addEventListener(
function () {
that._updateClamping();
},
);
this._removeModeListener = scene.morphComplete.addEventListener(
function () {
that._updateClamping();
},
);
}
if (positionProperty.isConstant) {
const position = positionProperty.getValue(
Iso8601.MINIMUM_VALUE,
scratchPosition,
);
Eif (
!defined(position) ||
Cartesian3.equals(position, Cartesian3.ZERO) ||
!defined(scene.globe)
) {
return;
}
this._position = Cartesian3.clone(position, this._position);
this._updateClamping();
this._normal = scene.ellipsoid.geodeticSurfaceNormal(
position,
this._normal,
);
}
}
Object.defineProperties(TerrainOffsetProperty.prototype, {
/**
* Gets a value indicating if this property is constant.
* @memberof TerrainOffsetProperty.prototype
*
* @type {boolean}
* @readonly
*/
isConstant: {
get: function () {
return false;
},
},
/**
* Gets the event that is raised whenever the definition of this property changes.
* @memberof TerrainOffsetProperty.prototype
*
* @type {Event}
* @readonly
*/
definitionChanged: {
get: function () {
return this._definitionChanged;
},
},
});
/**
* @private
*/
TerrainOffsetProperty.prototype._updateClamping = function () {
if (defined(this._removeCallbackFunc)) {
this._removeCallbackFunc();
}
const scene = this._scene;
const position = this._position;
if (Cartesian3.equals(position, Cartesian3.ZERO)) {
this._terrainHeight = 0;
return;
}
const ellipsoid = scene.ellipsoid;
const cartographicPosition = ellipsoid.cartesianToCartographic(
position,
this._cartographicPosition,
);
const height = scene.getHeight(cartographicPosition, this._heightReference);
if (defined(height)) {
this._terrainHeight = height;
} else {
this._terrainHeight = 0;
}
const updateFunction = (clampedPosition) => {
this._terrainHeight = clampedPosition.height;
this.definitionChanged.raiseEvent();
};
this._removeCallbackFunc = scene.updateHeight(
cartographicPosition,
updateFunction,
this._heightReference,
);
};
const timeScratch = new JulianDate();
/**
* Gets the height relative to the terrain based on the positions.
*
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {Cartesian3} The offset
*/
TerrainOffsetProperty.prototype.getValue = function (time, result) {
Iif (!defined(time)) {
time = JulianDate.now(timeScratch);
}
const heightReference = Property.getValueOrDefault(
this._heightReference,
time,
HeightReference.NONE,
);
const extrudedHeightReference = Property.getValueOrDefault(
this._extrudedHeightReference,
time,
HeightReference.NONE,
);
Iif (
heightReference === HeightReference.NONE &&
!isHeightReferenceRelative(extrudedHeightReference)
) {
this._position = Cartesian3.clone(Cartesian3.ZERO, this._position);
return Cartesian3.clone(Cartesian3.ZERO, result);
}
if (this._positionProperty.isConstant) {
return Cartesian3.multiplyByScalar(
this._normal,
this._terrainHeight,
result,
);
}
const scene = this._scene;
const position = this._positionProperty.getValue(time, scratchPosition);
Eif (
!defined(position) ||
Cartesian3.equals(position, Cartesian3.ZERO) ||
!defined(scene.globe)
) {
return Cartesian3.clone(Cartesian3.ZERO, result);
}
if (
Cartesian3.equalsEpsilon(this._position, position, CesiumMath.EPSILON10)
) {
return Cartesian3.multiplyByScalar(
this._normal,
this._terrainHeight,
result,
);
}
this._position = Cartesian3.clone(position, this._position);
this._updateClamping();
const normal = scene.ellipsoid.geodeticSurfaceNormal(position, this._normal);
return Cartesian3.multiplyByScalar(normal, this._terrainHeight, result);
};
TerrainOffsetProperty.prototype.isDestroyed = function () {
return false;
};
TerrainOffsetProperty.prototype.destroy = function () {
if (defined(this._removeEventListener)) {
this._removeEventListener();
}
if (defined(this._removeModeListener)) {
this._removeModeListener();
}
Iif (defined(this._removeCallbackFunc)) {
this._removeCallbackFunc();
}
return destroyObject(this);
};
/**
* A function which creates one or more providers.
* @callback TerrainOffsetProperty.PositionFunction
* @param {JulianDate} time The clock time at which to retrieve the position
* @param {Cartesian3} result The result position
* @returns {Cartesian3} The position at which to do the terrain height check
*/
export default TerrainOffsetProperty;
|