// @ts-nocheck import type { Activeble, Clearable } from "../Common"; import type { ActionCallback } from "./Common"; import { ActionManager } from "./ActionManager"; abstract class BaseHelper implements Clearable, Activeble{ readonly id: string; readonly parent: ActionHelper; // 是否响应事件 protected answer: boolean = false; constructor(id: string, parent: ActionHelper) { this.id = id; this.parent = parent } /** * 清空所有相关回调 */ clear(): ActionHelper { this.deactive(); return this.parent; } /** * 开启事件响应 */ active(): ActionHelper { this.answer = true; return this.parent; } /** * 关闭事件响应 */ deactive(): ActionHelper { this.answer = false; return this.parent; } /** * 是否响应事件 */ isActived() { return this.answer; } } const DragIdTag = '_drag'; export class ActionHelper implements Clearable{ readonly simple: SimpleHelper; readonly drag: DragHelper; static dragTargetId: string | undefined = undefined; static dragSP: Cesium.Cartesian3 | undefined = undefined; static dragP: Cesium.Cartesian3 | undefined = undefined; static startDrag(targetId: string, position: Cesium.Cartesian3) { ActionHelper.dragTargetId = targetId; ActionHelper.dragSP = position; ActionHelper.dragP = position; } static onDrag(position: Cesium.Cartesian3) { ActionHelper.dragP = position; } static finishDrag() { ActionHelper.dragTargetId = undefined; ActionHelper.dragSP = undefined; } static isDraging() { return ActionHelper.dragTargetId != undefined; } constructor(id: string) { this.simple = new SimpleHelper(id, this); this.drag = new DragHelper(id + DragIdTag, this); } /** * 清空所有相关回调 */ clear(): ActionHelper { this.simple.clear(); this.drag.clear(); return this; } } class SimpleHelper extends BaseHelper { /** * 注册左键点击回调 */ onLeftTap(callback: ActionCallback): ActionHelper { ActionManager._addCallback(this.id, Cesium.ScreenSpaceEventType.LEFT_CLICK, callback); return this.parent; } /** * 移除左键点击回调 */ removeLeftTap() { ActionManager._removeCallback(this.id, Cesium.ScreenSpaceEventType.LEFT_CLICK); } /** * 注册右键点击回调 */ onRightTap(callback: ActionCallback): ActionHelper { ActionManager._addCallback(this.id, Cesium.ScreenSpaceEventType.RIGHT_CLICK, callback); return this.parent; } /** * 移除右键点击回调 */ removeRightTap() { ActionManager._removeCallback(this.id, Cesium.ScreenSpaceEventType.RIGHT_CLICK); } /** * 注册鼠标移动回调 */ onMove(callback: ActionCallback): ActionHelper { ActionManager._addCallback(this.id, Cesium.ScreenSpaceEventType.MOUSE_MOVE, callback); return this.parent; } /** * 移除鼠标移动回调 */ removeMove() { ActionManager._removeCallback(this.id, Cesium.ScreenSpaceEventType.MOUSE_MOVE); } clear(): ActionHelper { super.clear(); this.removeLeftTap(); this.removeRightTap(); this.removeMove(); return this.parent; } } class DragHelper extends BaseHelper { /** * 注册拖拽移动回调 */ onMove(callback: ActionCallback): ActionHelper { ActionManager._addCallback(this.id, Cesium.ScreenSpaceEventType.MOUSE_MOVE, callback); ActionManager._addCallback(this.id, Cesium.ScreenSpaceEventType.LEFT_DOWN, undefined); ActionManager._addCallback(this.id, Cesium.ScreenSpaceEventType.LEFT_UP, undefined); return this.parent; } /** * 注册拖拽开始回调 */ onStart(callback: ActionCallback): ActionHelper { ActionManager._addCallback(this.id, Cesium.ScreenSpaceEventType.LEFT_DOWN, callback); return this.parent; } /** * 注册拖拽结束回调 */ onEnd(callback: ActionCallback): ActionHelper { ActionManager._addCallback(this.id, Cesium.ScreenSpaceEventType.LEFT_UP, callback); return this.parent; } /** * 移除拖拽回调 */ removeDrag() { ActionManager._removeCallback(this.id, Cesium.ScreenSpaceEventType.MOUSE_MOVE); ActionManager._removeCallback(this.id, Cesium.ScreenSpaceEventType.LEFT_DOWN); ActionManager._removeCallback(this.id, Cesium.ScreenSpaceEventType.LEFT_UP); } clear(): ActionHelper { super.clear(); this.removeDrag(); return this.parent; } }