readItinerary function
Lịch trình đang hiện trên bản đồ, hoặc null nếu chưa có điểm dừng nào
(hoặc engine chưa đăng ký ComponentEngine).
Implementation
Itinerary? readItinerary(ShareMapEngine engine) {
final c = engine.componentHandler;
if (c is! ComponentEngine) return null;
for (final origin in const ['ai', 'app']) {
final plan = _readPlan(c, origin);
if (plan != null && plan.stops.isNotEmpty) return plan;
}
Itinerary? best;
var bestIsAi = false;
for (final route in c.list(const ComponentQuery(type: 'route'))) {
final it = _readRoute(c, route);
if (it.stops.isEmpty) continue;
final isAi = route.origin == 'ai';
final better =
best == null ||
it.stops.length > best.stops.length ||
(it.stops.length == best.stops.length && isAi && !bestIsAi);
if (better) {
best = it;
bestIsAi = isAi;
}
}
return best;
}