我正在Google Map 上绘制折线 . 我正在使用:
private Map<UUID, PolylineOptions> data;
private void drawFeatures() {
for (Feature feature : features) {
feature.setUuid(UUID.fromString((String) feature.getProperties().get("id")));
PolylineOptions options = new PolylineOptions();
List<Coordinates> coordinates = ((LineString) feature.getGeometry()).getCoordinates();
for (Coordinates coordinate : coordinates) {
// can't use "addAll(...) since 'coordinates' are not instance of 'LatLng'
options.add(new LatLng(coordinate.getLatitude(), coordinate.getLongitude()));
options.color(Color.RED);
}
mMap.addPolyline(options);
data.put(feature.getUuid(), options);
}
}
然后一切都好 . 我的所有折线都使用良好的宽度和颜色正确绘制 .
然而,在那之后,我正在尝试更新宽度和颜色(不删除和重绘所有折线) . 我正在努力做到:
private void changeColor() {
for (Map.Entry<UUID, PolylineOptions> entry : data.entrySet()) {
entry.getValue().color(Color.CYAN);
}
}
但是我的 Map 上没有任何变化:/我已经阅读了Google Developers文档,但我没有找到任何相关信息 .
如何在不必删除和重新添加折线的情况下更新折线的颜色?
2 回答
PolylineOptions
只是Polylines
的构建器,它是绘制到 Map 中的对象 .因此,一旦它们在 Map 上,更改
PolylineOptions
将不会影响Polyline
.你的
private Map<UUID, PolylineOptions> data;
应该是private Map<UUID, Polyline> data;
,你需要像这样添加Map
的元素:may this help you