init
This commit is contained in:
89
src/Obj/ModelController/EditParticle.js
Normal file
89
src/Obj/ModelController/EditParticle.js
Normal file
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* @description 平移旋转粒子效果(未完成)
|
||||
*/
|
||||
import Event from '../../Event'
|
||||
class EditParticle {
|
||||
constructor(sdk, model) {
|
||||
this.sdk = sdk
|
||||
this.model = model
|
||||
|
||||
let handlerGE = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
|
||||
this.MapEvent = new Event(this.sdk)
|
||||
|
||||
// 获取双击的实体
|
||||
const entity = model;
|
||||
if (!entity) return;
|
||||
|
||||
let diff = []; // 记录选中实体与鼠标位置信息的差异
|
||||
let type = null; // 记录选中的实体类型
|
||||
let positions = null; // 记录选中实体的位置信息
|
||||
let newPosition = null; // 记录鼠标移动的位置
|
||||
const position = changeToThree(event.position); // 获取鼠标双击点的位置,并转为世界坐标
|
||||
// 根据选中的实体类型获取位置信息
|
||||
if (entity.polygon) {
|
||||
if (!entity.polygon.hierarchy?._value) return;
|
||||
type = "polygon";
|
||||
positions = entity.polygon.hierarchy._value.positions;
|
||||
} else if (entity.polyline) {
|
||||
if (!entity.polyline.positions?._value) return;
|
||||
type = "polyline"
|
||||
positions = entity.polyline.positions._value;
|
||||
};
|
||||
// 记录选中实体与鼠标位置信息的差异
|
||||
positions.forEach(item => {
|
||||
diff.push({
|
||||
x: item.x - position.x,
|
||||
y: item.y - position.y,
|
||||
z: item.z - position.z,
|
||||
});
|
||||
});
|
||||
|
||||
// 鼠标移动开始移动实体
|
||||
handlerGE.setInputAction(event => {
|
||||
// 获取移动点的位置,且将格式转为世界坐标
|
||||
const movePosition = changeToThree(event.endPosition);
|
||||
// 根据鼠标位置以及选中实体与鼠标位置信息的差异计算出移动后的实体位置
|
||||
newPosition = diff.map(item => ({
|
||||
x: item.x + movePosition.x,
|
||||
y: item.y + movePosition.y,
|
||||
z: item.z + movePosition.z,
|
||||
}));
|
||||
if (type === "polygon") {
|
||||
// 动态改变面的位置信息
|
||||
entity.polygon.hierarchy = new Cesium.CallbackProperty(function () {
|
||||
return new Cesium.PolygonHierarchy(newPosition);
|
||||
}, false);
|
||||
// 动态改变面边框的位置信息
|
||||
entity.polygon.positions = new Cesium.CallbackProperty(function () {
|
||||
return newPosition.concat([newPosition[0]]);
|
||||
}, false);
|
||||
} else if (type === "polyline") {
|
||||
// 动态改变面的位置信息
|
||||
entity.polygon.positions = new Cesium.CallbackProperty(function () {
|
||||
return newPosition;
|
||||
}, false);
|
||||
};
|
||||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
||||
|
||||
// 鼠标右键结束移动
|
||||
handlerGE.setInputAction(() => {
|
||||
// 根据选中的实体类型确认位置信息
|
||||
if (type === "polygon") {
|
||||
entity.polygon.hierarchy = newPosition;
|
||||
entity.polyline.positions = newPosition.concat([newPosition[0]]);
|
||||
} else if (type === "polyline") {
|
||||
entity.polyline.positions = newPosition;
|
||||
};
|
||||
// 初始化
|
||||
diff = [];
|
||||
type = null;
|
||||
positions = null;
|
||||
isMove = false;
|
||||
newPosition = null;
|
||||
// 清除鼠标移动监听和点击右键监听
|
||||
handlerGE.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
||||
handlerGE.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
||||
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
||||
}
|
||||
}
|
||||
export default EditParticle
|
||||
Reference in New Issue
Block a user