getPersistentRoadblockPathPreview static method
- required UserRoadblockPathPreviewCoordinate from,
- required Coordinates to,
- required RouteTransportMode transportMode,
Returns a preview of a persistent roadblock path between two coordinates.
The preview is calculated for the specified transportMode and returns
the list of coordinates representing the suggested path, a preview
coordinate to indicate the next likely roadblock match, and a GemError
describing success or any failure.
The from parameter should be obtained from a previous call to this method
or created via UserRoadblockPathPreviewCoordinate.fromCoordinates for
the initial call.
At the end of the operation, the returned coordinates can be used to create a path TrafficEvent representing the roadblock via the addPersistentRoadblockByCoordinates method.
Parameters
from: The starting UserRoadblockPathPreviewCoordinate.to: The destination Coordinates for the preview.transportMode: The RouteTransportMode used for routing the preview.
Returns
- A tuple containing:
- List<Coordinates>: The path preview coordinates ordered from
fromtolast. - UserRoadblockPathPreviewCoordinate: The suggested preview coordinate.
- GemError: An error code indicating success or failure.
- List<Coordinates>: The path preview coordinates ordered from
Example
Create a new UserRoadblockPathPreviewCoordinate for the starting point:
UserRoadblockPathPreviewCoordinate preview = UserRoadblockPathPreviewCoordinate.fromCoordinates(startCoordinates);
Call the method to get the subsequent UserRoadblockPathPreviewCoordinate based on the previous one:
final (coordinates, newPreviewStart, previewError) =
TrafficService.getPersistentRoadblockPathPreview(
from: preview,
to: nextCoordinates,
transportMode: RouteTransportMode.car,
);
if (previewError == GemError.success) {
preview = newPreviewStart;
}
Also see:
- addPersistentRoadblockByCoordinates to create a persistent roadblock using the returned coordinates.
- UserRoadblockPathPreviewCoordinate.fromCoordinates to create the initial preview coordinate.
Implementation
static (List<Coordinates>, UserRoadblockPathPreviewCoordinate, GemError)
getPersistentRoadblockPathPreview({
required UserRoadblockPathPreviewCoordinate from,
required Coordinates to,
required RouteTransportMode transportMode,
}) {
final OperationResult resultString = staticMethod(
'TrafficService',
'getPersistentRoadblockPathPreview',
args: <String, dynamic>{
'from': from,
'to': to,
'transportMode': transportMode.id,
},
);
final List<Coordinates> coordinates =
(resultString['result']['coords'] as List<dynamic>)
.map((dynamic e) => Coordinates.fromJson(e))
.toList();
final UserRoadblockPathPreviewCoordinate previewCoordinate =
UserRoadblockPathPreviewCoordinate.fromJson(
resultString['result']['preview'],
);
final GemError error = GemErrorExtension.fromCode(
resultString['result']['error'],
);
return (coordinates, previewCoordinate, error);
}