Skip to content

Commit 83b32e3

Browse files
committed
Enable minimap zoom via scroll wheel
1 parent 316ff78 commit 83b32e3

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

app/modifiers/interaction-modifier.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function cleanup(instance: InteractionModifierModifier) {
6969
canvas.removeEventListener('pointercancel', instance.onPointerCancel);
7070
canvas.removeEventListener('pointermove', instance.onPointerMove);
7171
canvas.removeEventListener('pointerstop', instance.onPointerStop);
72+
canvas.removeEventListener('wheel', instance.onWheel);
7273
document.removeEventListener('keydown', instance.keyDown);
7374
document.removeEventListener('keyup', instance.keyUp);
7475
}
@@ -138,6 +139,7 @@ export default class InteractionModifierModifier extends Modifier<InteractionMod
138139
this.canvas.addEventListener('pointerout', this.onPointerOut);
139140
this.canvas.addEventListener('pointercancel', this.onPointerCancel);
140141
this.canvas.addEventListener('pointermove', this.onPointerMove);
142+
this.canvas.addEventListener('wheel', this.onWheel);
141143

142144
document.addEventListener('keydown', this.keyDown);
143145
document.addEventListener('keyup', this.keyUp);
@@ -243,6 +245,13 @@ export default class InteractionModifierModifier extends Modifier<InteractionMod
243245
}
244246
}
245247

248+
@action
249+
onWheel(event: WheelEvent) {
250+
if (this.minimapService.isMouseInsideMinimap(event)) {
251+
this.minimapService.addZoomDelta(-event.deltaY / 1000);
252+
}
253+
}
254+
246255
@action
247256
onPointerStop(customEvent: CustomEvent<MouseStopEvent>) {
248257
if (this.pointers.length > 0) {
@@ -309,7 +318,7 @@ export default class InteractionModifierModifier extends Modifier<InteractionMod
309318
) {
310319
// check for click on Minimap
311320
let intersectedViewObjectCopy = intersectedViewObj;
312-
const isOnMinimap = this.minimapService.isClickInsideMinimap(event);
321+
const isOnMinimap = this.minimapService.isMouseInsideMinimap(event);
313322
const rayMarkers = this.minimapService.raycastForMarkers(event);
314323
// if rayMarkers are present, it means that the click was on a marker
315324
if (rayMarkers) {
@@ -378,7 +387,7 @@ export default class InteractionModifierModifier extends Modifier<InteractionMod
378387
* @returns The object that was hit by the ray
379388
*/
380389
private handleMinimapDoubleClick(event: MouseEvent) {
381-
if (this.minimapService.isClickInsideMinimap(event)) {
390+
if (this.minimapService.isMouseInsideMinimap(event)) {
382391
return this.minimapService.raycastForObjects(
383392
event,
384393
this.localUser.minimapCamera,

app/services/minimap-service.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ export default class MinimapService extends Service {
233233
* @param event MouseEvent of the click
234234
* @returns true if the click is inside the minimap
235235
*/
236-
isClickInsideMinimap(event: MouseEvent) {
236+
isMouseInsideMinimap(event: MouseEvent) {
237+
if (!this.minimapEnabled) return false;
238+
237239
const minimap = this.minimap();
238240
const minimapHeight = minimap[0];
239241
const minimapWidth = minimap[1];
@@ -382,6 +384,18 @@ export default class MinimapService extends Service {
382384
this.localUser.minimapCamera.updateProjectionMatrix();
383385
}
384386

387+
addZoomDelta(zoomDelta: number) {
388+
const zoomSetting = this.userSettings.visualizationSettings.zoom;
389+
const newZoom = zoomSetting.value + zoomDelta;
390+
if (newZoom < zoomSetting.range.min) {
391+
this.userSettings.updateSetting('zoom', zoomSetting.range.min);
392+
} else if (newZoom > zoomSetting.range.max) {
393+
this.userSettings.updateSetting('zoom', zoomSetting.range.max);
394+
} else {
395+
this.userSettings.updateSetting('zoom', newZoom);
396+
}
397+
}
398+
385399
calculateDistanceFactor(): number {
386400
return 0.2 / this.settings.visualizationSettings.zoom.value;
387401
}

app/utils/settings/default-settings.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,9 @@ export const defaultVizSettings: VisualizationSettings = {
664664
zoom: {
665665
value: 1,
666666
range: {
667-
min: 0.5,
668-
max: 3.0,
669-
step: 0.1,
667+
min: 0.1,
668+
max: 5,
669+
step: 0.05,
670670
},
671671
group: 'Minimap',
672672
displayName: 'Zoom of Minimap',

0 commit comments

Comments
 (0)