对于我大学的一个项目,我需要在地图中显示芝加哥的所有十字路口和一些车站,我已经有了带有数据的 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);
}
}
}