Estoy usando JMapViewer
, lo que quiero hacer es:
En el
JMapViewer
al hacer click sobre el mapa mundo se añada un MapMarkerDot justo donde se realizo el click.Al hacer click o pasar el puntador sobre lo
MapMarkerDot
que han sido añadidos , se logre visualizar la latitud y longitud de cada uno de ellos, la idea general es que cada MapMarkerDot sea "clickable".
No logro encontrar la forma de hacer un MapMarkerDot
"clickable".
import java.awt.EventQueue;
import java.awt.Point;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.openstreetmap.gui.jmapviewer.JMapViewer;
import org.openstreetmap.gui.jmapviewer.MapMarkerDot;
import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
public class Map {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Map window = new Map();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Map() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 547, 458);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JMapViewer theMap = new JMapViewer();
theMap.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Point point = e.getPoint();
ICoordinate coord = theMap.getPosition(point);
theMap.addMapMarker(new MapMarkerDot(coord.getLat(), coord.getLon()));
}
});
theMap.setBounds(0, 0, 487, 263);
JPanel panel = new JPanel();
panel.setBounds(21, 25, 487, 263);
frame.getContentPane().add(panel);
panel.setLayout(null);
panel.add(theMap);
JLabel numeroMarkerDot = new JLabel("Numero");
numeroMarkerDot.setBounds(21, 323, 67, 14);
frame.getContentPane().add(numeroMarkerDot);
JLabel Latitud = new JLabel("markerLatitud");
Latitud.setBounds(93, 323, 91, 14);
frame.getContentPane().add(Latitud);
JLabel Longitud = new JLabel("markerLongitud");
Longitud.setBounds(222, 323, 113, 14);
frame.getContentPane().add(Longitud);
}
}