2017-01-19 2 views
1

Ich zeichne Polylinien auf meiner Google Map. Ich mache es mit:Android Google Map ändern Polylinie Farben

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

Und dann ist alles in Ordnung. Alle meine Polylinien sind korrekt gezeichnet mit der guten Breite und Farbe.

Aber danach versuche ich, die Breite und die Farbe zu aktualisieren (ohne alle Polylinien zu entfernen und neu zu zeichnen). Ich versuche, es zu tun mit:

private void changeColor() { 
     for (Map.Entry<UUID, PolylineOptions> entry : data.entrySet()) { 
      entry.getValue().color(Color.CYAN); 
     } 
    } 

Aber es gibt keine Änderungen auf meiner Karte:/Ich habe die Google Developers-Dokumentation zu lesen und ich etwas über das nicht finden.

Wie kann ich die Farbe einer Polylinie aktualisieren, ohne sie entfernen und neu hinzufügen zu müssen?

Antwort

2

PolylineOptions ist nur ein Builder für Polylines welche die Objekte sind, die in die Karte gezeichnet werden.

Die Änderung der PolylineOptions hat keinen Einfluss auf die Polyline s, sobald sie auf der Karte sind.

Ihre private Map<UUID, PolylineOptions> data; sollte private Map<UUID, Polyline> data; sein und Sie müssen Elemente der Map wie folgt hinzuzufügen:

data.put(feature.getUuid(), mMap.addPolyline(options)); 
0

kann diese Hilfe Sie

MarkerOptions markerOptions = new MarkerOptions(); 
     if (!status.equals("ZERO_RESULTS")) { 
      for (int i = 0; i < result.size(); i++) { 
       points = new ArrayList<LatLng>(); 
       points.add(driverLatLng); 
       lineOptions = new PolylineOptions(); 
       List<HashMap<String, String>> path = result.get(i); 
       for (int j = 0; j < path.size(); j++) { 
        HashMap<String, String> point = path.get(j); 

        double lat = Double.parseDouble(point.get("lat")); 
        double lng = Double.parseDouble(point.get("lng")); 
        LatLng position = new LatLng(lat, lng); 
        points.add(position); 
       } 
       points.add(storeLatLng); 
       if (points.contains(storeLongitude)) { 
        int index = points.indexOf(storeLongitude); 
        AppLog.Log(TAG, "Index Value in " + index); 
        int length = points.size(); 
        points.subList(index, length - 1); 
        AppLog.Log(TAG, "Arraylist Size after SubList Array" + points.size()); 
       } 
       lineOptions.addAll(points); 
       lineOptions.width(13); 
       lineOptions.color(getResources().getColor(R.color.title_background)); 
       lineOptions.geodesic(true); 
       lineOptions.zIndex(100); 
       AppLog.Log(TAG, "lineOptions is" + lineOptions.getPoints()); 
      } 
      mMap.addPolyline(lineOptions); 
      //DrawArrowHead(mMap, driverLatLng, storeLatLng); 
     } else { 

      GlobalMethod.snackBar(true,activity_driver,appContext,"no root found."); 

     } 
Verwandte Themen