drawRoad method
draw road
this method show route from 2 point and pass throught interesect points in the map,
you can configure your road in runtime with roadOption, and change the road type drawn by modify
the routeType.
- to delete the road use RoadInfo.key
return RoadInfo that contain road information such as distance,duration, list of geopoints
start : started point of your Road
end : last point of your road
intersectPoint : (List of GeoPoint) middle position that you want you road to pass through it
roadOption : (RoadOption) runtime configuration of the road
Implementation
Future<RoadInfo> drawRoad(
GeoPoint start,
GeoPoint end, {
RoadType roadType = RoadType.car,
List<GeoPoint>? intersectPoint,
RoadOption? roadOption,
}) async {
final road = await osrmManager.getRoad(
waypoints: [
routing.LngLat(lng: start.longitude, lat: start.latitude),
...?intersectPoint?.map(
(e) => routing.LngLat(lng: e.longitude, lat: e.latitude),
),
routing.LngLat(lng: end.longitude, lat: end.latitude),
],
roadType: switch (roadType) {
RoadType.car => routing.RoadType.car,
RoadType.bike => routing.RoadType.bike,
RoadType.foot => routing.RoadType.foot,
},
);
final instructions = await osrmManager.buildInstructions(road);
final geoPoints = road.polyline
?.map((e) => GeoPoint(latitude: e.lat, longitude: e.lng))
.toList();
final roadInfo = RoadInfo(
instructions: instructions
.map(
(e) => Instruction(
geoPoint: GeoPoint(
latitude: e.location.lat,
longitude: e.location.lng,
),
instruction: e.instruction,
),
)
.toList(),
distance: road.distance,
duration: road.duration,
route: geoPoints ?? [],
);
unawaited(
osmBaseController.drawRoadManually(
roadInfo.key,
geoPoints ?? [],
roadOption ?? const RoadOption.empty(),
),
);
return roadInfo;
// return await osmBaseController.drawRoad(
// start,
// end,
// roadType: roadType,
// interestPoints: intersectPoint,
// roadOption: roadOption,
// );
}