Ajout detection du clic gauche et calcul de la lat/lon associee
This commit is contained in:
parent
b7d843338f
commit
8ab47f3588
|
|
@ -2,6 +2,7 @@
|
|||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
|
|
@ -22,6 +23,8 @@ import org.openstreetmap.gui.jmapviewer.MapMarkerDot;
|
|||
import org.openstreetmap.gui.jmapviewer.MapMarkerImage;
|
||||
import org.openstreetmap.gui.jmapviewer.MapMarkerLabel;
|
||||
import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -34,6 +37,7 @@ public class MaJFrameDemo extends JFrame {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JMapViewer map;
|
||||
private JLabel lblNewLabel_1;
|
||||
|
||||
static {
|
||||
System.setProperty("http.agent", "Gluon Mobile/1.0.3");
|
||||
|
|
@ -43,6 +47,14 @@ public class MaJFrameDemo extends JFrame {
|
|||
super("OSM Demo");
|
||||
setSize(400, 400);
|
||||
map = new JMapViewer();
|
||||
map.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.getButton()==MouseEvent.BUTTON1){
|
||||
getPosition(e.getPoint());
|
||||
}
|
||||
}
|
||||
});
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||
|
|
@ -50,7 +62,7 @@ public class MaJFrameDemo extends JFrame {
|
|||
JPanel helpPanel = new JPanel();
|
||||
getContentPane().add(panel, BorderLayout.NORTH);
|
||||
getContentPane().add(helpPanel, BorderLayout.SOUTH);
|
||||
JLabel helpLabel = new JLabel("Utilisez le bouton droit de la souris pour vous déplacer,\n"
|
||||
JLabel helpLabel = new JLabel("Utilisez le bouton droit de la souris pour vous deplacer,\n"
|
||||
+"Double-clic gauche ou molette de la souris pour zoomer.");
|
||||
helpPanel.add(helpLabel);
|
||||
panel.setLayout(new GridLayout(0, 1, 0, 0));
|
||||
|
|
@ -129,6 +141,15 @@ public class MaJFrameDemo extends JFrame {
|
|||
}
|
||||
});
|
||||
panel_2.add(buttonCleanMarkers);
|
||||
|
||||
JPanel panel_3 = new JPanel();
|
||||
panel.add(panel_3);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Position du clic gauche : ");
|
||||
panel_3.add(lblNewLabel);
|
||||
|
||||
lblNewLabel_1 = new JLabel("Coordinate[ , ]");
|
||||
panel_3.add(lblNewLabel_1);
|
||||
getContentPane().add(map, BorderLayout.CENTER);
|
||||
|
||||
//
|
||||
|
|
@ -186,7 +207,10 @@ public class MaJFrameDemo extends JFrame {
|
|||
map.addMapMarker(new MapMarkerDot(color, 10, latitude, longitude));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void getPosition(Point clic) {
|
||||
lblNewLabel_1.setText(map.getPosition(clic)+"");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue