|
33 | 33 | import { |
34 | 34 | CameraControls, |
35 | 35 | CameraVisualizationMode, |
| 36 | + GraphDataProvider, |
36 | 37 | OriginalPositionMode, |
37 | 38 | PointVisualizationMode, |
38 | 39 | Viewer, |
|
43 | 44 |
|
44 | 45 | let cameraControls = CameraControls.Earth; |
45 | 46 | let spatialActive = true; |
| 47 | + |
| 48 | + const dataProvider = new GraphDataProvider({ accessToken }); |
46 | 49 | const viewer = new Viewer({ |
47 | | - accessToken, |
48 | 50 | cameraControls, |
49 | 51 | component: { cover: false, spatial: spatialActive }, |
50 | 52 | container: "mly", |
| 53 | + dataProvider, |
51 | 54 | }); |
52 | 55 |
|
53 | 56 | viewer.moveTo(imageId).catch((error) => console.error(error)); |
54 | 57 |
|
55 | 58 | const spatial = viewer.getComponent("spatial"); |
| 59 | + |
56 | 60 | viewer.on("click", (event) => { |
57 | 61 | spatial |
58 | 62 | .getFrameIdAt(event.pixelPoint) |
59 | 63 | .then((id) => console.log("Clicked frame:", id)); |
60 | 64 | }); |
61 | 65 |
|
62 | | - function randomColor() { |
63 | | - return `hsl(${Math.floor(360 * Math.random())}, 100%, 75%)`; |
64 | | - } |
| 66 | + let hoveredImageId = null; |
| 67 | + let paintedClusterId = null; |
| 68 | + viewer.on("mousemove", async (event) => { |
| 69 | + function paintCluster(clusterId, color) { |
| 70 | + spatial.setPointOverrideColor(clusterId, color); |
| 71 | + spatial.setCameraOverrideColor(clusterId, color); |
| 72 | + } |
65 | 73 |
|
66 | | - const colors = new Set(); |
67 | | - viewer.on("image", (event) => { |
68 | | - const clusterId = event.image.clusterId; |
69 | | - if (colors.has(clusterId)) { |
| 74 | + const imageId = await spatial.getFrameIdAt(event.pixelPoint); |
| 75 | + if (imageId === hoveredImageId) { |
70 | 76 | return; |
71 | 77 | } |
72 | | - colors.add(clusterId); |
73 | | - spatial.configureClusterColor(clusterId, randomColor()); |
| 78 | + hoveredImageId = imageId; |
| 79 | + |
| 80 | + if (paintedClusterId != null) { |
| 81 | + paintCluster(paintedClusterId, null); |
| 82 | + paintedClusterId = null; |
| 83 | + } |
| 84 | + |
| 85 | + if (hoveredImageId == null) { |
| 86 | + return; |
| 87 | + } |
| 88 | + |
| 89 | + const images = await dataProvider.getImages([imageId]); |
| 90 | + if (images.length !== 1) { |
| 91 | + return; |
| 92 | + } |
| 93 | + const image = images[0]; |
| 94 | + if (image.node.id !== hoveredImageId) { |
| 95 | + return; |
| 96 | + } |
| 97 | + const clusterId = image.node.cluster.id; |
| 98 | + if (clusterId === paintedClusterId) { |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + paintCluster(clusterId, 0xff00ff); |
| 103 | + paintedClusterId = clusterId; |
74 | 104 | }); |
75 | 105 |
|
76 | 106 | const s = Object.assign({}, spatial.defaultConfiguration, { |
|
84 | 114 | const cluster = camMode.Cluster; |
85 | 115 | const connectedComponent = camMode.ConnectedComponent; |
86 | 116 | const sequence = camMode.Sequence; |
87 | | - const manual = camMode.Manual; |
88 | 117 | const camModeRotation = {}; |
89 | 118 | camModeRotation[hidden] = homogeneous; |
90 | 119 | camModeRotation[homogeneous] = cluster; |
91 | 120 | camModeRotation[cluster] = connectedComponent; |
92 | 121 | camModeRotation[connectedComponent] = sequence; |
93 | | - camModeRotation[sequence] = manual; |
94 | | - camModeRotation[manual] = hidden; |
| 122 | + camModeRotation[sequence] = hidden; |
95 | 123 |
|
96 | 124 | return function () { |
97 | 125 | s.cameraVisualizationMode = |
|
136 | 164 | const hidden = PointVisualizationMode.Hidden; |
137 | 165 | const original = PointVisualizationMode.Original; |
138 | 166 | const cluster = PointVisualizationMode.Cluster; |
139 | | - const manual = PointVisualizationMode.Manual; |
140 | 167 | const pvmRotation = {}; |
141 | 168 | pvmRotation[hidden] = original; |
142 | 169 | pvmRotation[original] = cluster; |
143 | | - pvmRotation[cluster] = manual; |
144 | | - pvmRotation[manual] = hidden; |
| 170 | + pvmRotation[cluster] = hidden; |
145 | 171 |
|
146 | 172 | return function () { |
147 | 173 | s.pointVisualizationMode = |
|
172 | 198 | }; |
173 | 199 | })(); |
174 | 200 |
|
175 | | - function resetManualColor() { |
176 | | - for (const clusterId of colors.keys()) { |
177 | | - spatial.configureClusterColor(clusterId, randomColor()); |
178 | | - } |
179 | | - } |
180 | | - |
181 | 201 | window.document.addEventListener("keydown", (e) => { |
182 | 202 | if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { |
183 | 203 | return; |
|
224 | 244 | case "f": |
225 | 245 | setFilter(); |
226 | 246 | break; |
227 | | - case "m": |
228 | | - resetManualColor(); |
229 | | - break; |
230 | 247 | default: |
231 | 248 | break; |
232 | 249 | } |
|
0 commit comments