The main class responsible for all the user interaction and for the routing itself.

Hierarchy

  • MapLibreGlDirectionsEvented
    • default

Constructors

Properties

_hoverable: boolean = false
_interactive: boolean = false
_waypoints: Feature<Point, GeoJsonProperties>[] = []
abortController: undefined | AbortController

A publicly-available abort-controller that allows to manually abort an ongoing routing-request.

Only exists (!== undefined) when there's an ongoing routing-request.

Example

direсtions.abortController.abort();
allowRouteSwitch: boolean = false

Allows user to switch to alternative routes while in non-interactive mode. Only takes effect when hoverable is true.

buildPoint: ((coordinate, type, properties?) => Feature<Point>) = buildPoint

Type declaration

buildRequest: ((configuration, waypointsCoordinates, waypointsBearings?) => RequestData) = buildRequest

Type declaration

    • (configuration, waypointsCoordinates, waypointsBearings?): RequestData
    • Protected

      Builds the routing-request method, URL and payload based on the provided configuration and the waypoints' coordinates.

      Parameters

      Returns RequestData

buildRoutelines: ((requestOptions, routes, selectedRouteIndex, snappoints) => Feature<LineString>[][]) = buildRoutelines

Type declaration

    • (requestOptions, routes, selectedRouteIndex, snappoints): Feature<LineString>[][]
    • Protected

      Creates route lines from the server response.

      Each route line is an array of legs, where each leg is an array of segments. A segment is a |GeoJSON LineString Feature. Route legs are divided into segments by their congestion levels. If there's no congestions, each route leg consists of a single segment.

      Parameters

      • requestOptions: Partial<Record<string, string>>
      • routes: Route[]
      • selectedRouteIndex: number
      • snappoints: Feature<Point, GeoJsonProperties>[]

      Returns Feature<LineString>[][]

buildSnaplines: ((waypointsCoordinates, snappointsCoordinates, hoverpointCoordinates, departSnappointIndex, showHoverpointSnaplines?) => Feature<LineString>[]) = buildSnaplines

Type declaration

    • (waypointsCoordinates, snappointsCoordinates, hoverpointCoordinates, departSnappointIndex, showHoverpointSnaplines?): Feature<LineString>[]
    • Protected

      Creates a $|GeoJSON LineString Features array where each feature represents a line connecting a waypoint with its respective snappoint and the hoverpoint with its respective snappoints.

      Parameters

      • waypointsCoordinates: [number, number][]
      • snappointsCoordinates: [number, number][]
      • hoverpointCoordinates: undefined | [number, number]
      • departSnappointIndex: number
      • showHoverpointSnaplines: boolean = false

      Returns Feature<LineString>[]

currentMousePosition: {
    x: number;
    y: number;
} = ...

Type declaration

  • x: number
  • y: number
departSnappointIndex: number = -1
dragDownPosition: {
    x: number;
    y: number;
} = ...

Type declaration

  • x: number
  • y: number
highlightedSnappoints: Feature<Point, GeoJsonProperties>[] = []
highlightedWaypoints: Feature<Point, GeoJsonProperties>[] = []
hoverpoint: undefined | Feature<Point, GeoJsonProperties> = undefined
lastRequestMousePosition: {
    x: number;
    y: number;
} = ...

Type declaration

  • x: number
  • y: number
liveRefreshHandler: ((e) => void)

Type declaration

map: Map$1
noMouseMovementTimer?: number
onClickHandler: ((e) => void)

Type declaration

onDragDownHandler: ((e) => void)

Type declaration

onDragMoveHandler: ((e) => void)

Type declaration

onDragUpHandler: ((e) => void)

Type declaration

onMoveHandler: ((e) => void)

Type declaration

profiles: string[] = []
refreshOnMoveIsRefreshing: boolean = false
routelines: Feature<LineString, GeoJsonProperties>[][] = []
selectedRouteIndex: number = 0
snappoints: Feature<Point, GeoJsonProperties>[] = []
waypointBeingDragged?: Feature<Point, GeoJsonProperties>
waypointBeingDraggedInitialCoordinates?: [number, number]

Accessors

  • get hoverable(): boolean
  • Allows hover effects in non-interactive mode. Can be set to true while interactive is false for the features to be highlighted when hovered over by the user. Does nothing when interactive is true.

    Returns boolean

  • set hoverable(hoverable): void
  • Parameters

    • hoverable: boolean

    Returns void

  • get interactive(): boolean
  • The interactivity state of the instance. When true, the user is allowed to interact with the features drawn on the map and to add waypoints by clicking the map. Automatically set to false whenever there's an ongoing routing request.

    Returns boolean

  • set interactive(interactive): void
  • Parameters

    • interactive: boolean

    Returns void

  • get waypoints(): [number, number][]
  • Returns all the waypoints' coordinates in the order they appear.

    Returns [number, number][]

  • set waypoints(waypoints): void
  • Parameters

    • waypoints: [number, number][]

    Returns void

    Alias

    Synchronous analogue of setWaypoints.

  • get waypointsBearings(): (undefined | [number, number])[]
  • Returns all the waypoints' bearings values or an empty array if the bearings configuration option is not enabled.

    Returns (undefined | [number, number])[]

  • set waypointsBearings(bearings): void
  • Sets the waypoints' bearings values. Does not produce any effect in case the bearings configuration option is disabled.

    Parameters

    • bearings: (undefined | [number, number])[]

    Returns void

  • get waypointsCoordinates(): [number, number][]
  • Returns [number, number][]

    Alias

    waypoints

    Aliased for the sakes of naming-consistency.

Methods

  • Adds a waypoint at the specified coordinates to the map and re-fetches the routes.

    Parameters

    • waypoint: [number, number]

      The coordinates at which the waypoint should be added

    • Optional index: number

      The index the waypoint should be inserted at. If omitted, the waypoint is inserted at the end

    Returns Promise<void>

    Resolved after the routing request has finished

  • Clears the map from all the instance's traces: waypoints, snappoints, routes, etc.

    Returns void

  • Removes all the added MapLibreGlDirections-specific layers and sources. Must be called manually before de-initializing the instance.

    Returns void

  • Parameters

    • skipSelectedRouteRedraw: boolean = true

    Returns void

  • Registers an event listener.

    Type Parameters

    Parameters

    • type: T
    • listener: MapLibreGlDirectionsEventListener<T>

    Returns void

  • Registers an event listener to be invoked only once.

    Type Parameters

    Parameters

    • type: T
    • listener: MapLibreGlDirectionsEventListener<T>

    Returns void

  • Removes a waypoint and its related snappoint by the waypoint's index from the map and re-fetches the routes.

    Parameters

    • index: number

      The index of the waypoint to remove

    Returns Promise<void>

    Resolved after the routing request has finished

  • Replaces all the waypoints with the specified ones and re-fetches the routes.

    Parameters

    • waypoints: [number, number][]

      The coordinates at which the waypoints should be added

    • profiles: string[] = []

      Profiles for fetching directions between waypoints.

    Returns Promise<void>

    Resolved after the routing request has finished

Generated using TypeDoc