Junior — Middle+
Function for animated display of cars on the map
livecode
Task condition
void displayCars(List<Car> cars) { final existingMarkers = <CarId, MapPlacemarkId>{}; final newMarkers = <CarId, Geometry>{};
// Map existing markers for (var marker in _markers) { existingMarkers[marker.carId] = marker.placemarkId; }
// Prepare new markers and update existing ones for (var car in cars) { final geometry = _createGeometry(car); newMarkers[car.id] = geometry;
if (existingMarkers.containsKey(car.id)) {
// Animate movement from current position to new position
final placemarkId = existingMarkers[car.id]!;
// Assuming we have previous position stored, animate to new position
// For simplicity, directly update to new geometry
plugin.updatePlacemark(placemarkId, geometry);
} else {
// Add new marker
final placemarkId = plugin.addPlacemark(geometry);
// Store the marker with its carId if needed
}
}
// Remove markers that are no longer present for (var carId in existingMarkers.keys) { if (!cars.any((car) => car.id == carId)) { plugin.removePlacemark(existingMarkers[carId]!); } } }