Bonsoir,
Je cherche depuis quelques temps a pouvoir zoomer (avec la molette) et à centrer la vue sur la fleche de la souris pour une carte. Un peu comme sur Google maps
Pour se faire, j'utilise un JscrollPan. J'arrive uniquement a centrer la map avec ce cope :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 @Override public void mouseWheelMoved(MouseWheelEvent e) { if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { int i = e.getWheelRotation(); if( i > 0 ){ this.viewWeak.get().imageMap.setZoom(1.01); Rectangle bounds = this.viewWeak.get().scrollPane.getViewport().getViewRect(); Dimension size = this.viewWeak.get().scrollPane.getViewport().getViewSize(); int x = (size.width - bounds.width) / 2; int y = (size.height - bounds.height) / 2; this.viewWeak.get().scrollPane.getViewport().setViewPosition(new Point(x, y)); } else if(i < 0){ this.viewWeak.get().imageMap.setZoom(0.99); Rectangle bounds = this.viewWeak.get().scrollPane.getViewport().getViewRect(); Dimension size = this.viewWeak.get().scrollPane.getViewport().getViewSize(); int x = (size.width - bounds.width) / 2; int y = (size.height - bounds.height) / 2; this.viewWeak.get().scrollPane.getViewport().setViewPosition(new Point(x, y)); } } }
setZoom me permet de repeindre en plus gros ou plus petit.
Ici je cherche donc à définir x, y pour bouger la vue de façon progressive en fonction de la souris.
Je peux récupérer les coordonnées de la souris au moment du scroll avec e.getX() et e.getY().
Est ce que quelqu'un aurait une idée s'il vous plait ?
Blackbull
Partager