I am using JMapViewer
, what I want to do is:
-
In the
JMapViewer
when clicking on the world map, add a MapMarkerDot just where the click was made. -
By clicking or passing the pointer on the
MapMarkerDot
that have been added, it is possible to visualize the latitude and longitude of each of them, the general idea is that each MapMarkerDot is "clickable".
I can not find a way to make a 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);
}
}