自学内容网 自学内容网

Cesium-地球材质-高程

1. 创建viewer

创建viewer并添加地形

const viewer = new Cesium.Viewer("cesiumContainer", {
  terrain: Cesium.Terrain.fromWorldTerrain({
    requestVertexNormals: true, //Needed to visualize slope
  }),
});

2. 创建canvas色条

添加getColorRamp方法,创建canvas,按比例添加颜色值

const elevationRamp = [0.0, 0.045, 0.1, 0.15, 0.37, 0.54, 1.0];
const slopeRamp = [0.0, 0.29, 0.5, Math.sqrt(2) / 2, 0.87, 0.91, 1.0];
const aspectRamp = [0.0, 0.2, 0.4, 0.6, 0.8, 0.9, 1.0];
function getColorRamp(selectedShading) {
  const ramp = document.createElement("canvas");
  ramp.width = 100;
  ramp.height = 1;
  const ctx = ramp.getContext("2d");

  let values;
  if (selectedShading === "elevation") {
    values = elevationRamp;
  } else if (selectedShading === "slope") {
    values = slopeRamp;
  } else if (selectedShading === "aspect") {
    values = aspectRamp;
  }

  const grd = ctx.createLinearGradient(0, 0, 100, 0);
  grd.addColorStop(values[0], "#000000"); //black
  grd.addColorStop(values[1], "#2747E0"); //blue
  grd.addColorStop(values[2], "#D33B7D"); //pink
  grd.addColorStop(values[3], "#D33038"); //red
  grd.addColorStop(values[4], "#FF9742"); //orange
  grd.addColorStop(values[5], "#ffd700"); //yellow
  grd.addColorStop(values[6], "#ffffff"); //white

  ctx.fillStyle = grd;
  ctx.fillRect(0, 0, 100, 1);

  return ramp;
}

3. 创建材质

使用Cesium.Material.fromType方法创建材质

const minHeight = -414.0; // approximate dead sea elevation
const maxHeight = 8777.0; // approximate everest elevation

const material = Cesium.Material.fromType("ElevationRamp",{
  image:getColorRamp('elevation'),
  minimumHeight:minHeight,
  maximumHeight:maxHeight
});

把材质附加到地球上

viewer.scene.globe.material = material;

链接地址

https://sandcastle.cesium.com/#c=jVVZbxs3EP4rhPoQGVCovQ/JNoo6TvuQA4iD9CHKA707kohwlxuSK9kt9N8zJFdHXEGoHqjlcL6Pwzkr2WpDNhy2oMgNaWFL7kDzvqFfnGy8GFV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fLHnMRB+didHs9Rf3/QIV0j/6Iw02wZ6u2Dm/feSGl9HqK2/NII6V4ZOoF808


原文地址:https://blog.csdn.net/d312697510/article/details/144293574

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!