2017-01-19 3 views
1

Googleマップでポリラインを描画しています。私はそれを使っています:Android Googleマップはポリラインの色を変更します

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

そしてすべてはOKです。すべてのポリラインは、適切な幅と色を使用して正しく描画されます。

しかし、その後、幅と色を(ポリラインをすべて削除して再描画せずに)更新しようとしています。 私はそれをやろうとしている:

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

しかし、私の地図には変更はありません:/私はGoogleの開発者向けドキュメントを読んでいると私はそれについて何かを見つけることができません。

ポリラインを削除したり再追加しなくても、ポリラインの色を更新するにはどうすればよいですか?

答えて

2

PolylineOptionsは、地図に描画されるオブジェクトであるPolylinesのビルダーです。

したがって、PolylineOptionsを変更しても、地図上に表示されているPolylineには影響しません。

あなたprivate Map<UUID, PolylineOptions> data;private Map<UUID, Polyline> data;である必要があり、あなたはこのようなMapに要素を追加する必要があります。

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

このヘルプあなた

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."); 

     } 
かもしれません
関連する問題