颤振绘制多种折线颜色

时间:2020-05-16 12:05:51

标签: google-maps flutter polyline

我有多次旅行,每次旅行都有一个位置列表。 我需要为每个行程分配一种颜色,但是发生的是,随着线条的绘制,而不是为每次行程更改新的颜色,它会更改所有已绘制的折线。 每次旅行我该怎么做?

getTrips() async {
await Future.forEach(trips, (element) async {

    List positions = element['positions'] as List;
    await Future.forEach(positions, (element) async {

        latitude = element['coordinates'][0];
        longitude = element['coordinates'][1];
        direction = element['direction'] ?? 0;

        //Current position
        position = LatLng(latitude ?? 0, longitude ?? 0);
        positionList.add(position);

        addMarker();

    });

});}

addMarker() async {

var m = markers.firstWhere((p) => p.markerId == MarkerId(equipmentId), orElse: () => null);
if (markers.isNotEmpty) {
  markers.remove(m);
}

selectedMarker = MarkerId(equipmentId);
markers
  ..add(Marker(
    visible: true,
    markerId: selectedMarker,
    position: position,
    icon: customIcon,
    anchor: Offset(0.5, 0.5),
    rotation: direction,
  ));

_polyline.add(Polyline(
  polylineId: PolylineId(_polylineIdCounter.toString()),
  visible: true,
  width: 6,
  points: positionList,
  color: tripColors[++colorIndex % tripColors.length],
));
_polylineIdCounter++;

cPosition = CameraPosition(
  zoom: cameraZoom,
  target: LatLng(position.latitude, position.longitude),
);

if (mounted) setState(() {});
_animateCamera(cPosition);
}

0 个答案:

没有答案