如何在JMapViewer中的两点之间放置像箭头一样的图像

时间:2014-10-23 16:12:59

标签: java jmap jmapviewer

如何将图像从点p1放到点p2?任何人都可以向我推荐一种方式吗?

修改:我按照此示例Draw Line between two Geo Points in JMapViewer绘制两个geoPoints之间的路径。但是当我尝试删除我首先创建的MapPolygon时,它不起作用,我不知道为什么。输入是正确的,相信我!

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

编辑:我这样做:

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

1 个答案:

答案 0 :(得分:2)

  

如何设置从p1点到p2点的[箭头]?

如此example所示,您可以使用MapPolygonJMapViewer添加addMapPolygon()形状的箭头。

  

删除MapPolygon后,我又创建了另一个LinkedList ... JMapViewer并未删除MapPolygon。你知道为什么吗?

使用补充方法removeMapPolygon()删除MapPolygon,但请确保它是对您添加的相同 MapPolygon的引用, 对您在创建箭头时可能使用过的LinkedList的引用。使用removeAllMapPolygons()完全clear()地图查看器的内部多边形列表。

附录:这是一个说明addMapPolygon()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);
    }
}));