-1

对于我大学的一个项目,我需要在地图中显示芝加哥的所有十字路口和一些车站,我已经有了带有数据的 LinkedLists,我需要用十字路口的位置绘制圆圈,用车站的位置绘制矩形. 我正在使用 jxMaps 库,并且基于示例,我能够根据开发人员提供的示例绘制一个圆形和一个矩形来测试方法,但是如果我在打开地图时尝试使用循环绘制多个,它保持灰色。这是我的代码:

public class Draw extends MapView
{

    private static final long serialVersionUID = 1L;

    Map map;

    IList <Integer, Intersetion> intersections;

    IList <Integer, Station> stations;

    public Draw(MapViewOptions options, IList <Integer, Intersection> inter, IList <Integer, Station> est)
    {
        super(options);
        // Setting of a ready handler to MapView object. onMapReady will be called when map initialization is done and
        // the map object is ready to use. Current implementation of onMapReady customizes the map object.
        setOnMapReadyHandler(new MapReadyHandler()
        {
            @Override
            public void onMapReady(MapStatus status)
            {
                // Check if the map is loaded correctly
                if (status == MapStatus.MAP_STATUS_OK)
                {
                    map = getMap();
                    intersections = inter; // I Load the list with the intersections data
                    stations = est; // I load the list with the stations data
                    rectangle();
                    circle();
                    // Creating a map options object
                    MapOptions mapOptions = new MapOptions();
                    // Creating a map type control options object
                    MapTypeControlOptions controlOptions = new MapTypeControlOptions();
                    // Changing position of the map type control
                    controlOptions.setPosition(ControlPosition.TOP_RIGHT);
                    // Setting map type control options
                    mapOptions.setMapTypeControlOptions(controlOptions);
                    // Setting map options
                    map.setOptions(mapOptions);
                    // Setting the map center
                    map.setCenter(new LatLng(41.875486, -87.626570));
                    // Setting initial zoom value
                    map.setZoom(9.0);
                }
            }
        });
    }

    public void circle ()
    {
        CircleOptions options = new CircleOptions();
        options.setFillOpacity(0);
        options.setStrokeColor("#CB4335");
        options.setStrokeWeight(5.0);

        for (Intersetion inter: intersections)
        {
            Circle circle = new Circle(map);
            circle.setCenter(new LatLng(inter.darLatitude(), inter.darLongitude()));
            circle.setRadius(50);
            circle.setOptions(options);
        }
    }
    public void rectangle()
    {
        RectangleOptions options = new RectangleOptions();
        options.setFillOpacity(0);
        options.setStrokeColor("#2E86C1");
        int i = 0;
        for (Station rect: stations)
        {
            Rectangle rectangulo = new Rectangle (map);
            LatLngBounds bounds = new LatLngBounds (new LatLng (rect.darLatitude() - 0.0004, rect.darLongitude() - 0.0006), new LatLng (rect.darLatitude() + 0.0004, rect.darLongitude() + 0.0006));
            rectangle.setBounds(bounds);
            rectangle.setOptions(optionts);
        }
    }
}
4

2 回答 2

2

我已经分析了提供的源代码,它看起来不错,除了您设置笔触颜色的地方。您必须使用 HTML 格式的颜色,因此您必须更改:

options.setStrokeColor(Color.RED.toString()); to options.setStrokeColor("#FF0000");

但是,它不能成为灰屏的原因。设置地图属性 ( ) 时出现问题通常会出现灰屏inside onMapReady() handler

所以你必须检查是否发生了任何异常,如果是,则修复它的根本原因。

此外,您可以启用日志记录并检查它是否有任何错误。您可以通过将-Djxmaps.logging.level=ALL参数添加到应用程序的 VM 选项来实现。

编辑________________________________________________________________________

这是一个允许创建多个圆圈的代码示例:

map.addEventListener("click", new MapMouseEvent() {
                        @Override
                        public void onEvent(MouseEvent mouseEvent) {
                            final Circle circle = new Circle(map);
                            circle.setRadius(2000);
                            circle.setCenter(mouseEvent.latLng());
                        }
                    });
于 2018-11-12T13:21:28.447 回答
1

实际上,由于某种原因,如果我在设置地图的选项后在最后调用方法 circle 和 rectangle ,它会起作用,考虑到当我按出现的顺序创建一个圆形或一个矩形时它工作正常,这有点奇怪在问题帖子中。

于 2018-12-05T03:24:37.777 回答