0

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);


}
}
Suleman Jamil
  • 43
  • 1
  • 7

1 Answers1

0

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.

whyn0t
  • 301
  • 2
  • 14
  • I have edit the code could you now recheck it please – Suleman Jamil Aug 08 '16 at 13:19
  • sorry Jamil but the code is incomplete try to make the checks I told you, make sure the clicked locations are all stored in the model (to check this you can analyse what is being done when you click the map what are objects that are notified) – whyn0t Aug 08 '16 at 13:58
  • I can understand but i am stuck at this point drawNew method draw the waypoints on map but i did not get the point why it is not showing previous waypoints on the map. What kind of modification i have to made in drawNew method so that it can show previous waypoints. – Suleman Jamil Aug 08 '16 at 14:15
  • either you are storing only the last location and painting it (check the variable where the locations are stored you are maybe overwriting the this variable content each time rather then keeping it) – whyn0t Aug 09 '16 at 09:56
  • when i click the first time on map it show the marker on that point but when i click the 2nd click on map it show the marker on the 2nd click point and the first waypoint marker disappear same hapen for further click only one waypoint marker is shown – Suleman Jamil Aug 09 '16 at 10:08
  • you told me that yesterday :). you have to read the code carefully and find what is happening when you click the map to see if the locations are properly stored and not overwritten – whyn0t Aug 09 '16 at 10:12