左键托画布
This commit is contained in:
parent
9edfdfa935
commit
49bfd7e346
@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import DraggableDialog from '../common/DraggableDialog.vue';
|
import DraggableDialog from '../common/DraggableDialog.vue';
|
||||||
import { onMounted, ref, watch } from 'vue';
|
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
||||||
import { JlGraphic } from 'src/jl-graphic';
|
import { JlGraphic } from 'src/jl-graphic';
|
||||||
import { Station } from 'src/graphics/station/Station';
|
import { Station } from 'src/graphics/station/Station';
|
||||||
import { useLineStore } from 'src/stores/line-store';
|
import { useLineStore } from 'src/stores/line-store';
|
||||||
@ -180,6 +180,14 @@ watch(
|
|||||||
);
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
lineStore.getLineApp().emit('options-update', {
|
||||||
|
mouseToolOptions: {
|
||||||
|
boxSelect: true,
|
||||||
|
viewportDrag: true,
|
||||||
|
viewportDragLeft: false,
|
||||||
|
wheelZoom: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
clearSelect();
|
clearSelect();
|
||||||
onReset();
|
onReset();
|
||||||
setAlartTextData.value.lineId = lineStore.lineId as unknown as string;
|
setAlartTextData.value.lineId = lineStore.lineId as unknown as string;
|
||||||
@ -242,4 +250,15 @@ function onReset() {
|
|||||||
};
|
};
|
||||||
selectGraphic = [];
|
selectGraphic = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
lineStore.getLineApp().emit('options-update', {
|
||||||
|
mouseToolOptions: {
|
||||||
|
boxSelect: false,
|
||||||
|
viewportDrag: true,
|
||||||
|
viewportDragLeft: true,
|
||||||
|
wheelZoom: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -97,7 +97,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import DraggableDialog from '../common/DraggableDialog.vue';
|
import DraggableDialog from '../common/DraggableDialog.vue';
|
||||||
import { onMounted, ref, watch } from 'vue';
|
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
||||||
import { JlGraphic } from 'src/jl-graphic';
|
import { JlGraphic } from 'src/jl-graphic';
|
||||||
import { Station } from 'src/graphics/station/Station';
|
import { Station } from 'src/graphics/station/Station';
|
||||||
import { useLineStore } from 'src/stores/line-store';
|
import { useLineStore } from 'src/stores/line-store';
|
||||||
@ -198,6 +198,14 @@ watch(
|
|||||||
);
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
lineStore.getLineApp().emit('options-update', {
|
||||||
|
mouseToolOptions: {
|
||||||
|
boxSelect: true,
|
||||||
|
viewportDrag: true,
|
||||||
|
viewportDragLeft: false,
|
||||||
|
wheelZoom: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
clearSelect();
|
clearSelect();
|
||||||
onReset();
|
onReset();
|
||||||
setAlartTextData.value.lineId = lineStore.lineId as unknown as string;
|
setAlartTextData.value.lineId = lineStore.lineId as unknown as string;
|
||||||
@ -266,4 +274,15 @@ function onReset() {
|
|||||||
};
|
};
|
||||||
selectGraphic = [];
|
selectGraphic = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
lineStore.getLineApp().emit('options-update', {
|
||||||
|
mouseToolOptions: {
|
||||||
|
boxSelect: false,
|
||||||
|
viewportDrag: true,
|
||||||
|
viewportDragLeft: true,
|
||||||
|
wheelZoom: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -152,8 +152,9 @@ export function initLineApp(lineId: number): IGraphicApp {
|
|||||||
Turnout.Type,
|
Turnout.Type,
|
||||||
],
|
],
|
||||||
mouseToolOptions: {
|
mouseToolOptions: {
|
||||||
boxSelect: true,
|
boxSelect: false,
|
||||||
viewportDrag: true,
|
viewportDrag: true,
|
||||||
|
viewportDragLeft: true,
|
||||||
wheelZoom: true,
|
wheelZoom: true,
|
||||||
},
|
},
|
||||||
dataLoader: lineAppDataLoader,
|
dataLoader: lineAppDataLoader,
|
||||||
|
@ -94,6 +94,7 @@ export function initLineNetApp(): IGraphicApp {
|
|||||||
mouseToolOptions: {
|
mouseToolOptions: {
|
||||||
boxSelect: false,
|
boxSelect: false,
|
||||||
viewportDrag: true,
|
viewportDrag: true,
|
||||||
|
viewportDragLeft: true,
|
||||||
wheelZoom: true,
|
wheelZoom: true,
|
||||||
},
|
},
|
||||||
dataLoader: lineNetAppDataLoader,
|
dataLoader: lineNetAppDataLoader,
|
||||||
|
@ -24,6 +24,10 @@ export interface IMouseToolOptions {
|
|||||||
* 是否启用视口拖拽(默认右键),默认启用
|
* 是否启用视口拖拽(默认右键),默认启用
|
||||||
*/
|
*/
|
||||||
viewportDrag?: boolean;
|
viewportDrag?: boolean;
|
||||||
|
/**
|
||||||
|
* 是否启用左键视口拖拽
|
||||||
|
*/
|
||||||
|
viewportDragLeft?: boolean;
|
||||||
/**
|
/**
|
||||||
* 是否启用鼠标滚轮缩放,默认启用
|
* 是否启用鼠标滚轮缩放,默认启用
|
||||||
*/
|
*/
|
||||||
@ -37,12 +41,14 @@ export interface IMouseToolOptions {
|
|||||||
class CompleteMouseToolOptions implements IMouseToolOptions {
|
class CompleteMouseToolOptions implements IMouseToolOptions {
|
||||||
boxSelect: boolean;
|
boxSelect: boolean;
|
||||||
viewportDrag: boolean;
|
viewportDrag: boolean;
|
||||||
|
viewportDragLeft: boolean;
|
||||||
wheelZoom: boolean;
|
wheelZoom: boolean;
|
||||||
selectFilter?: GraphicSelectFilter | undefined;
|
selectFilter?: GraphicSelectFilter | undefined;
|
||||||
constructor() {
|
constructor() {
|
||||||
this.boxSelect = true;
|
this.boxSelect = true;
|
||||||
this.viewportDrag = true;
|
this.viewportDrag = true;
|
||||||
this.wheelZoom = true;
|
this.wheelZoom = true;
|
||||||
|
this.viewportDragLeft = false;
|
||||||
}
|
}
|
||||||
update(options: IMouseToolOptions) {
|
update(options: IMouseToolOptions) {
|
||||||
if (options.boxSelect != undefined) {
|
if (options.boxSelect != undefined) {
|
||||||
@ -51,6 +57,9 @@ class CompleteMouseToolOptions implements IMouseToolOptions {
|
|||||||
if (options.viewportDrag != undefined) {
|
if (options.viewportDrag != undefined) {
|
||||||
this.viewportDrag = options.viewportDrag;
|
this.viewportDrag = options.viewportDrag;
|
||||||
}
|
}
|
||||||
|
if (options.viewportDragLeft != undefined) {
|
||||||
|
this.viewportDragLeft = options.viewportDragLeft;
|
||||||
|
}
|
||||||
if (options.wheelZoom != undefined) {
|
if (options.wheelZoom != undefined) {
|
||||||
this.wheelZoom = options.wheelZoom;
|
this.wheelZoom = options.wheelZoom;
|
||||||
}
|
}
|
||||||
@ -132,6 +141,14 @@ export class CommonMouseTool extends AppInteractionPlugin {
|
|||||||
this.app.on('drag_op_move', this.onDragMove, this);
|
this.app.on('drag_op_move', this.onDragMove, this);
|
||||||
this.app.on('drag_op_end', this.onDragEnd, this);
|
this.app.on('drag_op_end', this.onDragEnd, this);
|
||||||
if (this.options.viewportDrag) {
|
if (this.options.viewportDrag) {
|
||||||
|
if (this.options.viewportDragLeft) {
|
||||||
|
this.app.viewport.drag({
|
||||||
|
mouseButtons: 'left',
|
||||||
|
});
|
||||||
|
canvas.on('mousedown', this.setLeftCursor, this);
|
||||||
|
canvas.on('mouseup', this.resumeLeftCursor, this);
|
||||||
|
canvas.on('mouseupoutside', this.resumeLeftCursor, this);
|
||||||
|
} else {
|
||||||
this.app.viewport.drag({
|
this.app.viewport.drag({
|
||||||
mouseButtons: 'right',
|
mouseButtons: 'right',
|
||||||
});
|
});
|
||||||
@ -139,6 +156,7 @@ export class CommonMouseTool extends AppInteractionPlugin {
|
|||||||
canvas.on('rightup', this.resumeCursor, this);
|
canvas.on('rightup', this.resumeCursor, this);
|
||||||
canvas.on('rightupoutside', this.resumeCursor, this);
|
canvas.on('rightupoutside', this.resumeCursor, this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (this.options.wheelZoom) {
|
if (this.options.wheelZoom) {
|
||||||
this.app.viewport.wheel({
|
this.app.viewport.wheel({
|
||||||
percent: 0.01,
|
percent: 0.01,
|
||||||
@ -156,6 +174,9 @@ export class CommonMouseTool extends AppInteractionPlugin {
|
|||||||
this.app.off('drag_op_end', this.onDragEnd, this);
|
this.app.off('drag_op_end', this.onDragEnd, this);
|
||||||
|
|
||||||
this.app.viewport.plugins.remove('drag');
|
this.app.viewport.plugins.remove('drag');
|
||||||
|
canvas.off('mousedown', this.setLeftCursor, this);
|
||||||
|
canvas.off('mouseup', this.resumeLeftCursor, this);
|
||||||
|
canvas.off('mouseupoutside', this.resumeLeftCursor, this);
|
||||||
canvas.off('rightdown', this.setCursor, this);
|
canvas.off('rightdown', this.setCursor, this);
|
||||||
canvas.off('rightup', this.resumeCursor, this);
|
canvas.off('rightup', this.resumeCursor, this);
|
||||||
canvas.off('rightupoutside', this.resumeCursor, this);
|
canvas.off('rightupoutside', this.resumeCursor, this);
|
||||||
@ -199,6 +220,25 @@ export class CommonMouseTool extends AppInteractionPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setLeftCursor(e: FederatedMouseEvent) {
|
||||||
|
const target = e.target as DisplayObject;
|
||||||
|
this.leftDownTarget = target;
|
||||||
|
if (target.isCanvas() && this.app.pixi.view.style) {
|
||||||
|
this.app.pixi.view.style.cursor = 'grab';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resumeLeftCursor() {
|
||||||
|
if (
|
||||||
|
this.leftDownTarget &&
|
||||||
|
this.leftDownTarget.isCanvas() &&
|
||||||
|
this.app.pixi.view.style
|
||||||
|
) {
|
||||||
|
this.app.pixi.view.style.cursor = 'inherit';
|
||||||
|
}
|
||||||
|
this.leftDownTarget = null;
|
||||||
|
}
|
||||||
|
|
||||||
setCursor(e: FederatedMouseEvent) {
|
setCursor(e: FederatedMouseEvent) {
|
||||||
const target = e.target as DisplayObject;
|
const target = e.target as DisplayObject;
|
||||||
this.rightTarget = target;
|
this.rightTarget = target;
|
||||||
|
Loading…
Reference in New Issue
Block a user