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"
/>

<x-map-route-group>

Render an array of routes where one can be "active" or "selected":

PropDescription
:routesArray of route objects with color, coordinates, etc.
idUnique identifier
:selected-routeIndex or ID of the initially selected route (Default: 0)
:fit-boundsAuto-fit map bounds to show all routes (Default: false)
:fetch-directionsFetch directions for all routes (Default: false)
:animateAnimate route drawing (Default: false)
classWrapper container classes

<x-map-route-list>

Overlay UI panel displaying route alternatives and details:

PropDescription
route-idID of the x-map-route to link to
map-idID of the x-map component
:show-distanceShow total distance (Default: true)
:show-durationShow travel time (Default: true)
:show-fastest-badgeHighlight fastest route (Default: true)
:show-time-diffShow time difference between alternatives (Default: true)
positionOptions: top-left, top-right, etc. (Default: 'top-left')
titlePanel header text (Default: 'Routes')
widthPanel width class (Default: 'w-60')
container-classExtra classes for the wrapper container
header-classExtra classes for the header section
item-classExtra classes for individual route items

Props

PropTypeDefaultDescription
:coordinatesarrayrequiredArray of [lng, lat] pairs
id?stringnullUnique identifier for the route
colorstring'#1A56DB'Route line color
:widthint4Pixel width
:opacityfloat1.0Line opacity (0.0-1.0)
:dash-array?arraynullDash pattern array
line-capstring'round'Line cap style
line-joinstring'round'Line join style
active-colorstring'#0F43C4'Color when active/selected
:active-widthint6Width when active/selected
hover-color?stringnullColor on hover
:clickablebooltrueEnable click interactions
:with-stopsboolfalseRender default markers at points
stop-colorstring'#1A56DB'Color for stop markers
:fetch-directionsboolfalseAuto-fetch geom from OSRM
directions-profilestring'driving'driving, walking, cycling
directions-url?stringnullCustom OSRM server URL
:animateboolfalseAnimate drawing effect
:animate-durationint2000Animation duration (ms)
:activeboolfalseSet as initially active
:alternativesboolfalse(OSRM) Fetch alternative routes
:max-alternativesint2Max alternatives to fetch
alternative-colorstring'#94A3B8'Color for alternatives
:alternative-opacityfloat0.5Opacity for alternatives
:alternative-widthint3Width for alternatives