vue3.0 添加entity polygon hierarchy属性使用回调函数CallbackProperty报错
var PolygonPrimitive = (function () {
function _(hierarchy) {
this.options = {
polygon: {
show: true,
hierarchy: [],
material: Cesium.Color.CORNFLOWERBLUE
}
};
this.hierarchy = hierarchy;
this._init();
}
_.prototype._init = function () {
var _self = this;
var _update = function () {
return _self.hierarchy;
};
//实时更新polygon.hierarchy
this.options.polygon.hierarchy = new Cesium.CallbackProperty(_update, false);
const viewer = window.earth
viewer.entities.add(this.options);
};
return _;
})();
export { PolygonPrimitive }
调试到源码 是在cesium 添加Polygon的时候出错了 PolygonGeometry.js中 var outerPositions = polygonHierarchy.positions;这个出错了。排查了下原因是因为polygon = new PolygonPrimitive(points) 这样传入的类型有问题,不是一个PolygonHierarchy类型,没有positions属性,而是一个三维坐标的数组,所以在传入的时候需要进行格式强制转换 polygon = new PolygonPrimitive(new Cesium.PolygonHierarchy(points)),但是polyline的话是可以直接传入坐标
之后还发现个奇怪的事,在vue中需要强制转换,在原生js中直接传入是可以的polygon = new PolygonPrimitive(points) 没有深究了