osrm library

This file contains the full SDK for Project-OSRM in Dart.

To use this SDK, you will need to import this file into your Dart project.

Here are the steps to use this SDK:

  1. Import this file into your Dart project:

    import 'path/to/osrm.dart';
    
  2. Create an instance of the OSRM class:

    final osrm = Osrm();
    // you can set extra options example:
    final _osrm = Osrm(
       source: OsrmSource(
         ///...
       ),
    );
    

    Replace http://localhost:5000 with the URL of your OSRM server.

  3. Use the OSRM instance to make requests to the OSRM server:

    final route = await osrm.route(
      waypoints: [
        Waypoint(location: Location(latitude: 52.5160, longitude: 13.3779)),
        Waypoint(location: Location(latitude: 52.5206, longitude: 13.3862)),
      ],
      steps: true,
      // other parameters
    );
    

    This example makes a request to the OSRM server to calculate a route between two waypoints.

    The route variable will contain a Route object that represents the calculated route.

    You can customize the request by passing additional parameters to the route method.

    For more information on the available parameters, see the documentation for the OSRM class.

This SDK follows best practices for Dart development, including the use of asynchronous methods and the dart:io library for making HTTP requests.

Classes

MapboxServerBuilder
MapboxServerBuilder class for the Mapbox server builder
NearestOptions
NearestOptions Options for the nearest service.
NearestResponse
NearestResponse class for the nearest response
OpenstreetmapServerBuilder
OpenstreetmapServerBuilder class for the openstreetmap server builder
Osrm
Osrm the main class for the SDK This class contains all methods for the OSRM requests. The class is initialized with an OsrmSource which is used to make the requests. The OsrmSource is an interface which can be implemented by any class. The SDK contains a default implementation of the OsrmSource which can be used (use your server url template builder). The SDK also contains a OsrmMockSource which can be used for testing.
OsrmAlternative
OsrmAlternative enum for the alternative parameter in reality this is a bool or num but dart does not support union types so we use an enum instead, the underscore is added because the name true and false are reserved for dart see: https://dart.dev/guides/language/language-tour#keywords in case of adding num support we can use the OsrmAlternative.number
OsrmBannerInstructions
OsrmBannerInstructions class for banner instructions
OsrmGeneralRequest
OsrmGeneralRequest General options for all OSRM requests.
OsrmGeometry
OsrmGeometry it have 3 values
OsrmIntersection
OsrmIntersection class for a intersection
OsrmLane
OsrmLane class for a lane
OsrmLaneIndication
OsrmLaneIndication class for a lane indication
OsrmLineString
OsrmLineString class for a line string read more: https://tools.ietf.org/html/rfc7946#section-3.1.4 basically it is a list of OsrmCoordinate
OsrmLocation
OsrmModel<T>
OsrmModel abstract class for all the models its insure that all the models have toMap method
OsrmParameters
OsrmParameters Parameters for all OSRM requests.
OsrmRequest
OsrmRequest abstract class for all OSRM requests
OsrmResponse
OsrmResponse class for all OSRM responses
OsrmRoute
OsrmRoute class for a route
OsrmRouteLeg
OsrmRouteLeg class for a route leg
OsrmRouteStep
OsrmRouteStep class for a route step
OsrmServerBuilder
OsrmServerBuilder This class contains some default server builders for the OSRM server. please read the policy of the project-osrm and openstreetmap before using these servers.
OsrmSource
OsrmSource interface for the source of the requests This interface can be implemented by any class.
OsrmStepManeuver
OsrmStepManeuver class for a step maneuver
OsrmVoiceInstructions
OsrmVoiceInstructions class for voice instructions
OsrmWaypoint
OsrmWaypoint class for a waypoint
ProjectOsrmServerBuilder
ProjectOsrmServerBuilder class for the project-osrm server builder
RouteRequest
RouteRequest Options for the route service.
RouteResponse
RouteResponse class for the route response
Union<A, B>
Union class for the union types Till dart supports union types we use this workaround for creating union type we extend this class and add the union value as dynamic field

Enums

MapboxOsrmAnnotation
TODO:
OsrmAnnotation
OsrmAnnotation enum for the annotation parameter the underscore is added because the name true and false are reserved for dart see: https://dart.dev/guides/language/language-tour#keywords when you get Enum.name it will return the correct name without the underscore
OsrmApproach
OsrmApproach enum for the approach to a coordinate
OsrmContinueStraight
OsrmContinueStraight enum for the continue_straight parameter the underscore is added because the name false are reserved for dart see: https://dart.dev/guides/language/language-tour#keywords params are default (default), true_ , false_
OsrmFormat
OsrmFormat enum for the format of the response
OsrmGaps
OsrmGaps enum for the gaps parameter
OsrmGeometries
OsrmGeometries enum for the geometries parameter
OsrmOverview
OsrmOverview enum for the overview parameter the underscore is added because the name false are reserved for dart see: https://dart.dev/guides/language/language-tour#keywords
OsrmRequestProfile
OsrmRequestProfile enum for the mode of transportation
OsrmResponseCode
OsrmResponseCode enum for the code of the response
OsrmService
OsrmService enum for the service to use for the request

Mixins

EnumMixinHelper
EnumMixinHelper mixin to get the name of an enum

Typedefs

OsrmCoordinate = (double, double)
LongLat
OsrmPolyline = String
OsrmPolyline is just a string
OsrmPolyline6 = String
OsrmPolyline is just a string
ServerBuildFn = Uri Function(OsrmRequest options)
OsrmCoordinate class for a location with latitude and longitude Uri build(OsrmRequest options)

Exceptions / Errors

OsrmResponseException
OsrmResponseException class for all OSRM response exceptions