cesium学习笔记

806 阅读1分钟

cesium点击拾取坐标

    var scene = viewer.scene;
    var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

    //设置鼠标左键单击回调事件
    handler.setInputAction(function (e) {
      //首先移除之前添加的点
      viewer.entities.removeAll();
      //获取点击位置笛卡尔坐标
      var position = scene.pickPosition(e.position);

      //将笛卡尔坐标转化为经纬度坐标
      var cartographic = Cesium.Cartographic.fromCartesian(position);
      var longitude = Cesium.Math.toDegrees(cartographic.longitude);
      var latitude = Cesium.Math.toDegrees(cartographic.latitude);
      var height = cartographic.height;
      if (height < 0) {
        height = 0;
      }

      //创建弹出框信息
      var entity = new Cesium.Entity({
        name: "位置信息",
        description: createDescription(Cesium, [longitude, latitude, height.toFixed(4)])
      });
      viewer.selectedEntity = entity;

      //在点击位置添加对应点
      viewer.entities.add(new Cesium.Entity({
        point: new Cesium.PointGraphics({
          color: new Cesium.Color(1, 1, 0),
          pixelSize: 10,
          outlineColor: new Cesium.Color(0, 1, 1),
          disableDepthTestDistance:50000  // 添加的点位不被地形遮挡
        }),
        position: Cesium.Cartesian3.fromDegrees(longitude, latitude, height + 0.5)
      }));
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

    //创建描述位置的对话框
    function createDescription(Cesium, properties) {
      var simpleStyleIdentifiers = ['经度', '纬度', '高度'];
      var html = '';
      for (var key in properties) {
        if (properties.hasOwnProperty(key)) {
          if (simpleStyleIdentifiers.indexOf(key) !== -1) {
            continue;
          }
          var value = properties[key];
          if (Cesium.defined(value) && value !== '') {
            html += '<tr><td>' + simpleStyleIdentifiers[key] + '</td><td>' + value + '</td></tr>';
          }
        }
      }
      if (html.length > 0) {
        html = '<table class="zebra"><tbody>' + html + '</tbody></table>';
      }
      return html;
    }

cesium设置环境光

让整个场景更亮

  • 设置之前:

image.png

  • 设置之后:

image.png

    var scene = viewer.scene;
    scene.shadowMap.darkness = 1.275;
    scene.skyAtmosphere.brightnessShift=0.4;
    scene.debugShowFramesPerSecond = true;
    scene.hdrEnabled = false;
    scene.sun.show = false;
    // 设置环境光的强度
    scene.lightSource.ambientLightColor = new Cesium.Color(0.98, 0.98, 0.99, 1);
    var position1 = new Cesium.Cartesian3.fromDegrees(116.261209157595,  39.3042238956531, 320);
    var targetPosition1 = new Cesium.Cartesian3.fromDegrees(116.261209157595, 39.3042238956531,430);
    var dirLightOptions = {
        targetPosition: targetPosition1,
        color: new Cesium.Color(1.0, 1.1, 1.3, 1),
        //长条形景观的数据(数据的纹理没有使用烘焙纹理,可以通过光线来制造明暗,排除烘焙的干扰)
        intensity: 0.25
    };
    directionalLight_1 = new Cesium.DirectionalLight(position1, dirLightOptions);
    scene.addLightSource(directionalLight_1);

tiles的概念

High-resolution imagery like the first two layers used above is too large to fit into memory or often even a single disk, so imagery is divided into smaller images, called tiles, that can be streamed to a client as needed based on the view.

操作各种格式的地图底图

参考:sandcastle.cesium.com/?src=Imager…