Laravel Mapcn
Toggle sidebar

Routes

Docs / Routes

Overview

The <x-map-route> component draws polylines on the map. It can also fetch real driving, walking, or cycling directions from an OSRM routing service, and optionally animate the route drawing.

Basic Polyline

Draw a simple line connecting a series of coordinates:

Route with Stops

Show markers at each coordinate along the route using the :with-stops prop:

OSRM Directions

Fetch real road geometry from an OSRM server for driving, walking, or cycling directions:

The directions-profile accepts driving, walking, or cycling. The OSRM server URL can be configured in config/livewire-mapcn.php.

Animated Route

Animate the route as it draws on the map:

blade
<x-map-route
    :coordinates="$coords"
    :fetch-directions="true"
    directions-profile="driving"
    :animate="true"
    color="#06B6D4"
/>

Props

PropTypeDefaultDescription
:coordinatesarrayrequiredArray of [lng, lat] pairs
colorstring'#1A56DB'Line color
:widthint4Line width in pixels
:fetch-directionsboolfalseFetch road geometry from OSRM
directions-profilestring'driving'driving, walking, cycling
:animateboolfalseAnimate drawn route
:with-stopsboolfalseShow markers at each coordinate