首页 / 浏览问题 / WebGIS / 问题详情
webgl Cesium未定义属性
8EXP 2021年04月29日

参照颜色设置 (supermap.com.cn)例子使用Cesium.knockout属性,报错Cesium没有knockout属性。"TypeError: Cannot read property 'knockout' of undefined"。

1个回答

您好,方便贴一下代码嘛?
1,504EXP 2021年04月29日
mounted() {

    let imageryLayers = this.$globe.imageryLayers;

    window.Cesium.knockout.track(this.viewModel);

    var toolbar = document.getElementById('toolbar');

    window.Cesium.knockout.applyBindings(this.viewModel, toolbar);

    this.subscribeLayerParameter('brightness')

    this.subscribeLayerParameter('alpha')

    imageryLayers.layerAdded.addEventListener(this.updateViewModel);

    imageryLayers.layerRemoved.addEventListener(this.updateViewModel);

    imageryLayers.layerMoved.addEventListener(this.updateViewModel);

    this.updateViewModel();

  },

  methods: {

    subscribeLayerParameter(name){

      window.Cesium.knockout.getObservable(this.viewModel, name).subscribe(

        function(newValue) {

          if (this.$globe.imageryLayers.length > 1) {

            var layer = this.$globe.imageryLayers.get(1);

            layer[name] = newValue;

          }

        }

      );

    },

    updateViewModel(){

      if (this.$globe.imageryLayers.length > 1) {

        var layer = this.$globe.imageryLayers.get(1);

        this.viewModel.brightness = layer.brightness;

        this.viewModel.alpha = layer.alpha;

      }

    }

  }
您好,我在我这边测试是没有这样的报错的,您使用一下Cesium的其他接口看是否是您的Cesium没有引入
...