I want to add waypoint on map whenever user click on map. I got the waypoint on map whenever user click but problem is the previous waypoint disappear and not shown on map only the wapoint drawn due to current click is shown. Following is th code for the waypoint.
public class MapPanel {
public static void acc(GeoPosition loc){
MapPanel.drawNew(loc);
}
public static void drawNew(GeoPosition location ){
GeoPosition fp = new GeoPosition(location.getLatitude(),location.getLongitude());
List<GeoPosition> track = Arrays.asList(fp);
// Create waypoints from the geo-positions
Set<Waypoint> waypoints = new HashSet<Waypoint>(Arrays.asList(
new DefaultWaypoint(fp)));
// Create a waypoint painter that takes all the waypoints
waypointPainter.setWaypoints(waypoints);
// Create a compound painter that uses both the route-painter and the waypoint-painter
List<org.jxmapviewer.painter.Painter<org.jxmapviewer.JXMapViewer>> painters = new ArrayList<org.jxmapviewer.painter.Painter<org.jxmapviewer.JXMapViewer>>();
painters.add(waypointPainter);
CompoundPainter<org.jxmapviewer.JXMapViewer> painter = new CompoundPainter<org.jxmapviewer.JXMapViewer>(painters);
frameWork.mapViewer.setOverlayPainter(painter);
}
public static void main (String args) {
frame.setContentPane(frameWork.mainPanel);
// Create a TileFactoryInfo for OpenStreetMap
TileFactoryInfo info = new OSMTileFactoryInfo();
DefaultTileFactory tileFactory = new DefaultTileFactory(info);
frameWork.mapViewer.setTileFactory(tileFactory);
// Set the Default Location
GeoPosition chemnitz = new GeoPosition(50.833333, 12.916667);
//Set the focus
frameWork.mapViewer.setZoom(1);
frameWork.mapViewer.setAddressLocation(chemnitz);
// Add interactions
MouseInputListener mia = new PanMouseInputListener(frameWork.mapViewer);
frameWork.mapViewer.addMouseListener(mia);
frameWork.mapViewer.addMouseMotionListener(mia);
frameWork.mapViewer.addMouseListener(new CenterMapListener(frameWork.mapViewer));
frameWork.mapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCenter(frameWork.mapViewer));
frameWork.mapViewer.addKeyListener(new PanKeyListener(frameWork.mapViewer));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.pack();
frame.setSize(900, 600);
frame.setVisible(true);
}
}
without full source code i can only suppose that the problem could be either in 1- the model you are using to store the WayPoints: make sure the new clicked points are added to the model not overwritten by the last one (check the size of the selected WayPoints) or 2- the view you are using is fully repainted for each add event; causing the loss of all before last painted elements.