@maplibre/maplibre-gl-directions - v0.10.1
    Preparing search index...

    Class default

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

    Hierarchy

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

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

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

    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: [number, number],
        type: string,
        properties?: Record<string, unknown>,
    ) => Feature<Point> = buildPoint

    Type Declaration

      • (
            coordinate: [number, number],
            type: string,
            properties?: Record<string, unknown>,
        ): Feature<Point>
      • Protected

        Creates a |GeoJSON Point Feature of one of the $known types with a given coordinate.

        Parameters

        • coordinate: [number, number]
        • type: string
        • Optionalproperties: Record<string, unknown>

        Returns Feature<Point>

    buildRequest: (
        configuration: MapLibreGlDirectionsConfiguration,
        waypointsCoordinates: [number, number][],
        waypointsBearings?: ([number, number] | undefined)[],
    ) => RequestData = buildRequest

    Type Declaration

    buildRoutelines: (
        requestOptions: Partial<Record<string, string>>,
        routes: Route[],
        selectedRouteIndex: number,
        snappoints: Feature<Point, GeoJsonProperties>[],
    ) => Feature<LineString, GeoJsonProperties>[][] = buildRoutelines

    Type Declaration

      • (
            requestOptions: Partial<Record<string, string>>,
            routes: Route[],
            selectedRouteIndex: number,
            snappoints: Feature<Point, GeoJsonProperties>[],
        ): Feature<LineString, GeoJsonProperties>[][]
      • 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, GeoJsonProperties>[][]

    buildSnaplines: (
        waypointsCoordinates: [number, number][],
        snappointsCoordinates: [number, number][],
        hoverpointCoordinates: [number, number] | undefined,
        departSnappointIndex: number,
        showHoverpointSnaplines?: boolean,
    ) => Feature<LineString, GeoJsonProperties>[] = buildSnaplines

    Type Declaration

      • (
            waypointsCoordinates: [number, number][],
            snappointsCoordinates: [number, number][],
            hoverpointCoordinates: [number, number] | undefined,
            departSnappointIndex: number,
            showHoverpointSnaplines?: boolean,
        ): Feature<LineString, GeoJsonProperties>[]
      • 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: [number, number] | undefined
        • departSnappointIndex: number
        • showHoverpointSnaplines: boolean = false

        Returns Feature<LineString, GeoJsonProperties>[]

    currentMousePosition: { x: number; y: number } = ...
    departSnappointIndex: number = -1
    dragDownPosition: { x: number; y: number } = ...
    highlightedSnappoints: Feature<Point, GeoJsonProperties>[] = []
    highlightedWaypoints: Feature<Point, GeoJsonProperties>[] = []
    hoverpoint: Feature<Point, GeoJsonProperties> | undefined = undefined
    lastRequestMousePosition: { x: number; y: number } = ...
    liveRefreshHandler: (e: MapMouseEvent | MapTouchEvent) => void
    map: Map$1
    noMouseMovementTimer?: number
    onClickHandler: (e: MapMouseEvent | MapTouchEvent) => void
    onDragDownHandler: (e: MapMouseEvent | MapTouchEvent) => void
    onDragMoveHandler: (e: MapMouseEvent | MapTouchEvent) => void
    onDragUpHandler: (e: MapMouseEvent | MapTouchEvent) => void
    onMoveHandler: (e: MapMouseEvent | MapTouchEvent) => void
    profiles: string[] = []
    refreshOnMoveIsRefreshing: boolean = false
    routelines: Feature<LineString, GeoJsonProperties>[][] = []
    selectedRouteIndex: number = 0
    snappoints: Feature<Point, GeoJsonProperties>[] = []
    waypointBeingDragged?: Feature<Point, GeoJsonProperties>
    waypointBeingDraggedInitialCoordinates?: [number, number]
    • 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: boolean): 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: boolean): 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: [number, number][]): void

      Parameters

      • waypoints: [number, number][]

      Returns void

      Synchronous analogue of setWaypoints.

    • get waypointsBearings(): ([number, number] | undefined)[]

      Returns all the waypoints' bearings values or an empty array if the bearings configuration option is not enabled.

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

    • set waypointsBearings(bearings: ([number, number] | undefined)[]): void

      Sets the waypoints' bearings values. Does not produce any effect in case the bearings configuration option is disabled.

      Parameters

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

      Returns void

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

      Returns [number, number][]

      waypoints

      Aliased for the sakes of naming-consistency.

    • 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

      • Optionalindex: 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

    • 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