我在使用EditHandler来编辑一个自定义的矩形区域,但是进入编辑模式之后,默认是多边形的编辑状态,我想使用new Cesium.EditHandler文档中提到的 changedEvt : Event 成员来做编辑对象的监听,满足矩形编辑的逻辑,拖动对角点,其他点同步变化的状态。请问有好的方法吗?
if (!that.editHandler) {
that.editHandler = new Cesium.EditHandler(that.myMap.viewer, entity);
that.editHandler.changedEvt.addEventListener((updatedPositions) => {
console.log('Entity updated:', entity);
console.log('Updated positions:', updatedPositions);
// 假设控制点顺序为:[leftTop, rightBottom, rightTop, leftBottom]
if (updatedPositions.length >= 2) {
let leftTop = updatedPositions[0];
let rightBottom = updatedPositions[1];
// 计算新的矩形坐标
let rightTop = new Cesium.Cartesian3(rightBottom.x, leftTop.y, leftTop.z);
let leftBottom = new Cesium.Cartesian3(leftTop.x, rightBottom.y, leftTop.z);
// 更新实体的控制点
let newHierarchy = new Cesium.PolygonHierarchy([
leftTop, rightTop, rightBottom, leftBottom, leftTop
]);
entity.polygon.hierarchy = newHierarchy;
console.log('Updated rectangle positions:', newHierarchy.positions);
}
})
// 是否允许编辑高度
that.editHandler.isEditZ = false;
that.editHandler.activate();
}