1

How I can put an image that goes from point p1 to point p2? Anyone can suggest a way to me?

Edit: I follow this example, Draw Line between two Geo Points in JMapViewer, to draw a path between two geoPoints. But when I try to delete a MapPolygon, that I created first, it's not work and I don't know why. The input is correct, trust me!

List<Coordinate> route = new ArrayList<Coordinate>(Arrays.asList(one, two, two));
        List<MapPolygon> lista=cartina.getMapPolygonList();
        MapPolygon arrow=new MapPolygonImpl(route);
        cartina.removeMapPolygon(arrow);

Edit: I do this:

private Coordinate one;
private Coordinate two;
public ExampleClass(Coordinate one, Coordinate two) {
    this.one=one;
    this.two=two;
}

public method (){ //click button
    List<Coordinate> route = new ArrayList<Coordinate>(Arrays.asList(one, two, two));
    map.addMapPolygon(new MapPolygonImpl(route));
}

public methodB(){// click anothe button
 List<Coordinate> route = new ArrayList<Coordinate>(Arrays.asList(one, two, two));
    map.removeMapPolygon()(new MapPolygonImpl(route));
}
Community
  • 1
  • 1
doflamingo
  • 77
  • 1
  • 1
  • 9
  • You can draw an arrow shaped polygon, for [example](http://stackoverflow.com/a/10747783/230513). – trashgod Oct 23 '14 at 18:55
  • @trashgod thanks for your link it works correct. But I have another question. IF I add a MapPolygon in MapPolygon list and after I would delete a MapPolygon and I use the algorithm that you linked me and I create another LinkedList etc... the JMapViewer don't delete the MapPolygon... do you know why? How i can delete a MapPolygon after that I add in MapPolygonList – doflamingo Oct 24 '14 at 16:08
  • Good question; I've elaborated [below](http://stackoverflow.com/a/26554830/230513); please update your question to reflect your addition concern. – trashgod Oct 24 '14 at 19:21

1 Answers1

2

How I can put an [arrow] that goes from point p1 to point p2?

As shown in this example, you can add an arrow shaped MapPolygon to your JMapViewer using addMapPolygon().

After I delete a MapPolygon…and I create another LinkedList…the JMapViewer doesn't delete the MapPolygon. Do you know why?

Use the complementary method removeMapPolygon() to remove a MapPolygon, but be sure that it's a reference to the same MapPolygon that you added and not a reference to a LinkedList you might have used while creating the arrow. Use removeAllMapPolygons() to completely clear() the map viewer's internal list of polygons.

Addendum: Here's a concrete example illustrating addMapPolygon() and removeMapPolygon().

List<Coordinate> route = new ArrayList<>(Arrays.asList(one, two, three));
final MapPolygonImpl mapPolygon = new MapPolygonImpl(route);
map.addMapPolygon(mapPolygon);
toolBar.add(new JButton(new AbstractAction("Remove") {

    @Override
    public void actionPerformed(ActionEvent e) {
        map.removeMapPolygon(mapPolygon);
    }
}));
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I think that it's better post the question: http://stackoverflow.com/questions/26552250/dont-delete-mappolygon-in-jmapviewer?noredirect=1#comment41731447_26552250 if you look in this link I use removeMalPolygon() but it doesn't work!! the two points that I use are the same trust me! – doflamingo Oct 24 '14 at 19:36
  • now I urdestand!! if I use this way: http://stackoverflow.com/questions/26552250/dont-delete-mappolygon-in-jmapviewer?noredirect=1#comment41731447_26552250 it's doesn't work because it's not the same reference?? – doflamingo Oct 24 '14 at 19:43
  • I'm not sure form your fragment; please edit your question to include a [complete example](http://stackoverflow.com/help/mcve). – trashgod Oct 25 '14 at 01:56