Cesium中遇到 materialProperty.getType is not a function
需求描述为使用callbackProperty不断更新纹理,于是我写下了如下代码
this._rectangle = this._viewer.entities.add({rectangle: {show: this._show,coordinates: Cesium.Rectangle.fromDegrees(this._positions[0], this._positions[1],this._positions[2],this._positions[3]),heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,material: new Cesium.CallbackProperty(() => {return new Cesium.ImageMaterialProperty({image: this._dataMap.get(this._dataKey),//是一个map根据type获取iamgecolor: Cesium.Color.WHITE.withAlpha(1.0)}) }, true),}})
于是就报错了,正确的代码应为
this._rectangle = this._viewer.entities.add({rectangle: {show: this._show,coordinates: Cesium.Rectangle.fromDegrees(this._positions[0], this._positions[1],this._positions[2],this._positions[3]),heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,material: new Cesium.ImageMaterialProperty({image: new Cesium.CallbackProperty(() => {return this._dataMap.get(this._dataKey)}, true),color: Cesium.Color.WHITE.withAlpha(1.0)})}})
可以看到应该先创建ImageMaterialProperty,再创建callbackProperty,但是cesium文档并没有说明,但是可以看到,image的类型是Property,而material类型是MaterialProperty,难道是因为这个?但是他们都属于Property啊