有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

如何将图像从点p1放置到点p2?有人能给我提个建议吗

Edit:我遵循这个例子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) 个答案

  1. # 1 楼答案

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

    如图example所示,您可以使用addMapPolygon()将箭头形状的MapPolygon添加到JMapViewer

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

    使用互补方法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);
        }
    }));