TerrainExaggeration.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Cartesian3 from "./Cartesian3.js";
  2. /**
  3. * @private
  4. */
  5. const TerrainExaggeration = {};
  6. /**
  7. * Scales a height relative to an offset.
  8. *
  9. * @param {number} height The height.
  10. * @param {number} scale A scalar used to exaggerate the terrain. If the value is 1.0 there will be no effect.
  11. * @param {number} relativeHeight The height relative to which terrain is exaggerated. If the value is 0.0 terrain will be exaggerated relative to the ellipsoid surface.
  12. */
  13. TerrainExaggeration.getHeight = function (height, scale, relativeHeight) {
  14. return (height - relativeHeight) * scale + relativeHeight;
  15. };
  16. const scratchCartographic = new Cartesian3();
  17. /**
  18. * Scales a position by exaggeration.
  19. */
  20. TerrainExaggeration.getPosition = function (
  21. position,
  22. ellipsoid,
  23. terrainExaggeration,
  24. terrainExaggerationRelativeHeight,
  25. result
  26. ) {
  27. const cartographic = ellipsoid.cartesianToCartographic(
  28. position,
  29. scratchCartographic
  30. );
  31. const newHeight = TerrainExaggeration.getHeight(
  32. cartographic.height,
  33. terrainExaggeration,
  34. terrainExaggerationRelativeHeight
  35. );
  36. return Cartesian3.fromRadians(
  37. cartographic.longitude,
  38. cartographic.latitude,
  39. newHeight,
  40. ellipsoid,
  41. result
  42. );
  43. };
  44. export default TerrainExaggeration;