|
14 | 14 | " |
15 | 15 | class="pa-0" |
16 | 16 | @click="get_x_y" |
17 | | - @keydown.esc="app_store.toggle_picking_mode(false)" |
| 17 | + @keydown.esc="viewer_store.toggle_picking_mode(false)" |
18 | 18 | /> |
19 | 19 | </div> |
20 | 20 | </ClientOnly> |
|
24 | 24 | import vtkRemoteView from "@kitware/vtk.js/Rendering/Misc/RemoteView" |
25 | 25 | import { useElementSize, useWindowSize } from "@vueuse/core" |
26 | 26 | import viewer_schemas from "@geode/opengeodeweb-viewer/schemas.json" |
| 27 | + import Status from "@/utils/status.js" |
27 | 28 |
|
28 | | - const viewer_store = use_viewer_store() |
29 | | - const { client, is_running, picking_mode } = storeToRefs(viewer_store) |
| 29 | + const props = defineProps({ |
| 30 | + viewId: { type: String, default: "-1" }, |
| 31 | + }) |
30 | 32 |
|
31 | | - const viewer = ref(null) |
| 33 | + const viewer_store = use_viewer_store() |
| 34 | + const viewer = useTemplateRef("viewer") |
32 | 35 | const { width, height } = useElementSize(viewer) |
33 | 36 |
|
34 | 37 | const { width: windowWidth, height: windowHeight } = useWindowSize() |
35 | 38 |
|
36 | 39 | function get_x_y(event) { |
37 | | - if (picking_mode.value === true) { |
| 40 | + if (viewer_store.picking_mode.value === true) { |
38 | 41 | const { offsetX, offsetY } = event |
39 | 42 | viewer_store.set_picked_point(offsetX, offsetY) |
40 | 43 | viewer_call({ |
|
44 | 47 | } |
45 | 48 | } |
46 | 49 |
|
47 | | - const props = defineProps({ |
48 | | - viewId: { type: String, default: "-1" }, |
49 | | - }) |
50 | | -
|
51 | | - const { viewId } = toRefs(props) |
52 | 50 | const connected = ref(false) |
53 | | -
|
54 | 51 | const view = vtkRemoteView.newInstance({ |
55 | 52 | rpcWheelEvent: "viewport.mouse.zoom.wheel", |
56 | 53 | }) |
|
70 | 67 | resize() |
71 | 68 | }) |
72 | 69 |
|
73 | | - watch(picking_mode, (value) => { |
74 | | - const cursor = value ? "crosshair" : "pointer" |
75 | | - view.getCanvasView().setCursor(cursor) |
76 | | - }) |
| 70 | + watch( |
| 71 | + () => viewer_store.picking_mode, |
| 72 | + (value) => { |
| 73 | + const cursor = value ? "crosshair" : "pointer" |
| 74 | + view.getCanvasView().setCursor(cursor) |
| 75 | + }, |
| 76 | + ) |
77 | 77 |
|
78 | 78 | watch([width, height], () => { |
79 | 79 | resize() |
80 | 80 | }) |
81 | 81 |
|
82 | | - watch(client, () => { |
83 | | - connect() |
84 | | - }) |
85 | | -
|
86 | | - watch(viewId, (id) => { |
87 | | - if (connected.value) { |
88 | | - view.setViewId(id) |
89 | | - view.render() |
90 | | - } |
91 | | - }) |
| 82 | + watch( |
| 83 | + () => viewer_store.client, |
| 84 | + () => { |
| 85 | + connect() |
| 86 | + }, |
| 87 | + ) |
| 88 | +
|
| 89 | + watch( |
| 90 | + () => props.viewId, |
| 91 | + (id) => { |
| 92 | + if (connected.value) { |
| 93 | + view.setViewId(id) |
| 94 | + view.render() |
| 95 | + } |
| 96 | + }, |
| 97 | + ) |
92 | 98 |
|
93 | 99 | function connect() { |
94 | | - if (!is_running.value) { |
| 100 | + if (viewer_store.status !== Status.CONNECTED) { |
95 | 101 | return |
96 | 102 | } |
97 | | - const session = client.value.getConnection().getSession() |
| 103 | + const session = viewer_store.client.value.getConnection().getSession() |
98 | 104 | view.setSession(session) |
99 | | - view.setViewId(viewId.value) |
| 105 | + view.setViewId(props.viewId) |
100 | 106 | connected.value = true |
101 | 107 | view.render() |
102 | 108 | } |
|
0 commit comments