API Reference
Overview
The livewire-mapcn package provides a collection of Blade components for building interactive maps. All components must be nested inside the root <x-map> component. Everything inside the map is reactive: when your Livewire component re-renders, children update in place (use wire:key in loops and never wrap the map in wire:ignore).
Props are listed in kebab-case as you write them in Blade. Prefix a prop with : to pass a PHP expression (arrays, booleans, numbers), e.g. :zoom="12". Coordinates are always [lng, lat] arrays, except the lat/lng props of markers and popups.
Components
<x-map>
The base component for any map. Supports providers, themes, and viewport control.
<x-map-controls>
Zoom, compass, geolocation, fullscreen, scale and 3D controls.
<x-map-control>
A custom control container for your own buttons and markup.
<x-map-marker>
Interactive markers with labels, tooltips, popups, and custom content.
<x-map-popup>
Standalone popups anchored to specific coordinates on the map.
<x-map-route>
Draw polylines or fetch real directions, with progress overlays.
<x-map-route-marker>
A marker pinned to the start, end or progress point of a route.
<x-map-route-group>
Render multiple selectable routes on the same map.
<x-map-route-list>
Overlay UI panel for displaying route alternatives.
<x-map-cluster-layer>
Efficiently handle thousands of markers with clustering.
<x-map-arc>
Curved connections between points: flight paths, trade flows.
<x-map-geojson>
Render polygons, lines and points from any GeoJSON.
<x-map>
The root component. Give it a stable id attribute (used as mapId and for Livewire morphing). Other HTML attributes are rendered on the map element. See the Map page.
| Prop | Type | Default | Description |
|---|---|---|---|
| center | array|null | config default_center ([0, 0]) | Initial center [lng, lat] |
| zoom | int|float|null | config default_zoom (7) | Initial zoom level |
| min-zoom | int|float | 0 | Minimum zoom |
| max-zoom | int|float | 22 | Maximum zoom |
| provider | string|null | config default_provider ('carto-positron') | Tile provider (see Tile Providers) |
| style | array|string|null | null | Custom MapLibre style URL or JSON, used for both themes unless dark-style is set |
| light-style | array|string|null | null | Style used in light mode |
| dark-style | array|string|null | null | Style used in dark mode (defaults to config dark_provider) |
| theme | string | 'auto' | light, dark or auto (follows the page) |
| height | int|string|null | config default_height ('full') | full (100%), an integer (px) or any CSS length |
| width | int|string | '100%' | An integer (px) or any CSS length |
| bearing | int|float | 0 | Initial rotation in degrees |
| pitch | int|float | 0 | Initial tilt in degrees |
| max-pitch | int|float|null | null | Maximum tilt (MapLibre default when null) |
| interactive | bool | true | Enable all user interaction |
| scroll-zoom | bool | true | Zoom with the scroll wheel |
| double-click-zoom | bool | true | Zoom on double-click |
| drag-pan | bool | true | Pan by dragging |
| drag-rotate | bool | true | Rotate with right-click/ctrl + drag |
| touch-zoom-rotate | bool | true | Pinch to zoom and rotate on touch devices |
| pitch-with-rotate | bool | true | Allow tilting while rotating |
| cooperative-gestures | bool | false | Require ctrl/⌘ + scroll and two-finger pan (for maps embedded in scrolling pages) |
| render-world-copies | bool | true | Repeat the world horizontally when zoomed out |
| projection | string|null | null | Map projection, e.g. globe or mercator |
| blank | bool | false | Use an empty style with no basemap (for data-only maps) |
| max-bounds | array|null | null | Restrict panning to [[west, south], [east, north]] |
| bounds | array|null | null | Initial bounds to fit, overrides center/zoom |
| bounds-padding | int | 40 | Padding in px used with bounds |
| attribution | bool | true | Show the attribution control |
| attribution-compact | bool | true | Use the collapsible compact attribution |
| loader | bool | true | Show a loading indicator until the style has loaded |
| events | array | [] | Extra MapLibre events to forward as map:{event} (merged with config custom_events) |
| options | array | [] | Extra options merged into the MapLibre Map constructor |
| class | string | '' | Extra CSS classes for the map element |
<x-map-controls>
Built-in navigation controls. See the Controls page.
| Prop | Type | Default | Description |
|---|---|---|---|
| zoom | bool | true | Zoom in/out buttons |
| compass | bool | true | Compass / reset-north button |
| visualize-pitch | bool | true | Tilt the compass icon with the map pitch |
| locate | bool | true | Geolocation button |
| track-user | bool | true | Keep following the user's location after locating |
| fullscreen | bool | false | Fullscreen button |
| scale | bool | false | Scale bar |
| scale-unit | string | 'metric' | metric, imperial or nautical |
| three-d | bool | false | 3D toggle button (fires map:3d-toggled) |
| three-d-pitch | int|float | 60 | Pitch applied when 3D is enabled |
| three-d-bearing | int|float | -20 | Bearing applied when 3D is enabled |
| three-d-duration | int | 1000 | Transition duration in ms |
| position | string | 'top-right' | top-left, top-right, bottom-left or bottom-right |
| class | string | '' | Extra CSS classes |
<x-map-control>
Places any markup over the map, styled as a control group. Inside it, the Alpine magic $map gives you the MapLibre instance.
| Prop | Type | Default | Description |
|---|---|---|---|
| position | string | 'top-left' | top-left, top-right, bottom-left, bottom-right, top or bottom |
| group | bool | true | Wrap the content in the bordered control-group style; set :group="false" for free-form panels |
| class | string | '' | Extra CSS classes |
<x-map-control position="top-left"> <button x-on:click="$map.easeTo({ pitch: 60, bearing: -20, duration: 1000 })">3D view</button> </x-map-control>
<x-map-marker>
Accepts <x-marker-content>, <x-marker-tooltip>, <x-marker-popup> and <x-marker-label> as children. See the Markers page.
| Prop | Type | Default | Description |
|---|---|---|---|
| lat | float | required | Latitude |
| lng | float | required | Longitude |
| id | string|null | auto (UUID) | Identifier sent with marker events |
| draggable | bool | false | Allow dragging (fires drag events) |
| color | string | '#1A56DB' | Color of the default dot |
| anchor | string | 'bottom' | Which part of the marker sits on the coordinate (center, top, bottom-left, …) |
| offset | array | [0, 0] | Pixel offset [x, y] |
| rotation | float | 0 | Rotation in degrees |
| rotation-alignment | string | 'auto' | map, viewport or auto |
| pitch-alignment | string | 'auto' | map, viewport or auto |
| opacity | float|null | null | Marker opacity (0–1) |
| class | string | '' | Extra CSS classes |
<x-marker-content>
Replaces the default dot with your own markup (the slot).
| Prop | Type | Default | Description |
|---|---|---|---|
| class | string | '' | Extra CSS classes for the wrapper |
<x-marker-popup>
Popup opened when the marker is clicked; the slot is the content.
| Prop | Type | Default | Description |
|---|---|---|---|
| max-width | string | '300px' | Maximum popup width |
| close-button | bool | true | Show a close button |
| close-on-click-map | bool | true | Close when the map is clicked |
| close-on-move | bool | false | Close when the map moves |
| anchor | string|null | null (auto) | Popup position relative to the marker; automatic when null |
| offset | int|array|null | null (16px) | Distance from the marker in px, or [x, y] |
| class | string | '' | Extra CSS classes |
<x-marker-tooltip>
Shown on hover.
| Prop | Type | Default | Description |
|---|---|---|---|
| text | string|null | null | Tooltip text; the slot content is used when omitted |
| anchor | string|null | null (auto) | Tooltip position relative to the marker |
| offset | int|array|null | null (16px) | Distance from the marker in px, or [x, y] |
| class | string | '' | Extra CSS classes |
<x-marker-label>
A permanent text label next to the marker.
| Prop | Type | Default | Description |
|---|---|---|---|
| text | string|null | null | Label text; the slot content is used when omitted |
| position | string | 'bottom' | top, bottom, left or right |
| class | string | '' | Extra CSS classes |
<x-map-popup>
A standalone popup at a coordinate; the slot is the content. See the Popups page.
| Prop | Type | Default | Description |
|---|---|---|---|
| lat | float | required | Latitude |
| lng | float | required | Longitude |
| id | string|null | auto (UUID) | Identifier sent with popup events |
| open | bool | true | Whether the popup is shown |
| max-width | string | '300px' | Maximum popup width |
| close-button | bool | false | Show a close button |
| close-on-click-map | bool | true | Close when the map is clicked |
| close-on-move | bool | false | Close when the map moves |
| anchor | string|null | null (auto) | Popup position relative to the coordinate |
| offset | int|array|null | [0, 0] | Offset in px, or [x, y] |
| class | string | '' | Extra CSS classes |
<x-map-route>
A polyline, optionally snapped to real roads. See the Routes page.
| Prop | Type | Default | Description |
|---|---|---|---|
| coordinates | array | required | Waypoints as [[lng, lat], …] |
| id | string|null | auto (UUID) | Identifier for events and map:*-{id} commands |
| color | string | '#1A56DB' | Line color |
| width | int|float | 4 | Line width in px |
| opacity | float | 1.0 | Line opacity |
| dash-array | array|null | null | Dash pattern, e.g. [2, 2] |
| line-cap | string | 'round' | butt, round or square |
| line-join | string | 'round' | bevel, round or miter |
| active | bool | false | Render with the active style |
| active-color | string | '#0F43C4' | Color when active |
| active-width | int|float | 6 | Width when active |
| active-opacity | float|null | null | Opacity when active (falls back to opacity) |
| active-dash-array | array|null | null | Dash pattern when active |
| hover-color | string|null | null | Color on hover |
| clickable | bool | true | Enable click/hover events and the pointer cursor |
| with-stops | bool | false | Draw a dot at every waypoint |
| stop-color | string | '#1A56DB' | Color of the stop dots |
| fetch-directions | bool | false | Snap to roads using OSRM |
| directions-profile | string | 'driving' | driving, walking or cycling |
| directions-url | string|null | config osrm_url | OSRM server base URL |
| alternatives | bool | false | Fetch and draw alternative routes |
| max-alternatives | int | 2 | Maximum number of alternatives |
| alternative-color | string | '#94A3B8' | Color of alternatives |
| alternative-opacity | float | 0.5 | Opacity of alternatives |
| alternative-width | int|float | 3 | Width of alternatives |
| animate | bool | false | Animate the line drawing in |
| animate-duration | int | 2000 | Draw animation duration in ms |
| progress | float|null | null | Fraction (0–1) of the route drawn as the progress overlay; null hides it |
| progress-color | string|null | null | Color of the progress overlay |
| progress-width | int|float|null | null | Width of the progress overlay |
| progress-opacity | float|null | null | Opacity of the progress overlay |
| progress-dash-array | array|null | null | Dash pattern of the progress overlay |
| progress-duration | int | 0 | Animate progress changes over this many ms |
| before-id | string|null | null | Insert the line below this style layer |
| fit-bounds | bool | false | Fit the map to the route once it's ready |
<x-map-route-marker>
A marker pinned to a point on its parent <x-map-route>. It follows the route as its coordinates or progress change. It accepts <x-marker-content>, <x-marker-tooltip>, <x-marker-popup> and <x-marker-label>.
| Prop | Type | Default | Description |
|---|---|---|---|
| at | string|float | 'progress' | start, end, progress (follows the route's progress) or a 0–1 fraction |
| route-id | string|null | null (parent route) | Attach to a route by id instead of the parent |
| id | string|null | auto (UUID) | Identifier sent with marker events |
| align-to-route | bool | false | Rotate the marker to the route's direction |
| color | string | '#1A56DB' | Color of the default dot |
| anchor | string | 'center' | Which part of the marker sits on the point |
| offset | array | [0, 0] | Pixel offset [x, y] |
| rotation | float | 0 | Rotation in degrees (added to the route bearing when aligned) |
| rotation-alignment | string | 'auto' | map, viewport or auto |
| pitch-alignment | string | 'auto' | map, viewport or auto |
| class | string | '' | Extra CSS classes |
<x-map-route id="delivery" :coordinates="$path" :progress="$progress" :progress-duration="800"> <x-map-route-marker at="start" color="#16a34a" /> <x-map-route-marker at="progress" :align-to-route="true"> <x-marker-tooltip text="Courier" /> </x-map-route-marker> <x-map-route-marker at="end" color="#dc2626" /> </x-map-route>
<x-map-route-group>
Several selectable routes; each item of routes has coordinates and optional id and style keys. See the Routes page.
| Prop | Type | Default | Description |
|---|---|---|---|
| routes | array | required | The routes to render |
| id | string|null | auto (UUID) | Identifier for events and map:update-route-group-{id} |
| selected-route | int|string | 0 | Index of the selected route (re-rendering with a new index selects it) |
| fit-bounds | bool | false | Fit the map to all routes once ready |
| alternative-color | string | '#94A3B8' | Color of unselected routes |
| alternative-opacity | float | 0.5 | Opacity of unselected routes |
| alternative-width | int|float | 3 | Width of unselected routes |
| line-cap | string | 'round' | Line cap |
| line-join | string | 'round' | Line join |
| clickable | bool | true | Select a route by clicking it |
| fetch-directions | bool | false | Snap every route to roads using OSRM |
| directions-profile | string | 'driving' | driving, walking or cycling |
| directions-url | string|null | config osrm_url | OSRM server base URL |
| animate | bool | false | Animate the selected route drawing in |
| animate-duration | int | 2000 | Draw animation duration in ms |
| with-stops | bool | false | Draw a dot at every waypoint |
| stop-color | string | '#1A56DB' | Color of the stop dots |
| active-color | string | '#0F43C4' | Color of the selected route |
| active-width | int|float | 6 | Width of the selected route |
| hover-color | string|null | null | Color on hover |
| active | bool | false | Render the selected route with the active style |
| dash-array | array|null | null | Dash pattern |
<x-map-route-list>
A panel listing a route's alternatives (with distance and duration) so the user can pick one. See the Routes page.
| Prop | Type | Default | Description |
|---|---|---|---|
| route-id | string | '' | Id of the <x-map-route> to list |
| map-id | string | '' | Deprecated. The list now finds its route by id anywhere on the page |
| show-distance | bool | true | Show each route's distance |
| show-duration | bool | true | Show each route's duration |
| show-fastest-badge | bool | true | Mark the fastest route |
| show-time-diff | bool | true | Show the time difference to the fastest route |
| position | string | 'top-left' | top-left, top-right, bottom-left or bottom-right |
| title | string | 'Routes' | Panel heading |
| width | string | '' | Panel width (CSS length) |
| container-class | string | '' | Extra classes for the panel |
| header-class | string | '' | Extra classes for the header |
| item-class | string | '' | Extra classes for each item |
<x-map-cluster-layer>
Clusters large point datasets. See the Clusters page.
| Prop | Type | Default | Description |
|---|---|---|---|
| data | array | [] | Items with lat/lng keys, or GeoJSON Features |
| url | string|null | null | Load GeoJSON from a URL instead of data |
| id | string|null | auto (UUID) | Identifier for map:update-cluster-data-{id} |
| cluster-max-zoom | int | 14 | Stop clustering above this zoom |
| cluster-radius | int | 50 | Cluster radius in px |
| cluster-min-points | int | 2 | Minimum points to form a cluster |
| cluster-color | string | '#1A56DB' | Cluster bubble color |
| cluster-colors | array|null | null | Colors stepped by cluster-thresholds, e.g. ['#3b82f6', '#1d4ed8', '#1e3a8a'] |
| cluster-thresholds | array|null | null | Point counts where the next color starts, e.g. [100, 750] |
| cluster-text-color | string | '#FFFFFF' | Count label color |
| cluster-size-stops | array | [[0, 18], [100, 26], [1000, 34]] | [count, radius] pairs for bubble size |
| point-color | string | '#1A56DB' | Unclustered point color |
| point-stroke-color | string | '#FFFFFF' | Unclustered point outline color |
| point-radius | int | 6 | Unclustered point radius |
| show-count | bool | true | Show the count inside clusters |
| text-font | array|null | null | Font stack for the count label |
| popup-property | string|null | null | Property shown in the point popup |
| popup-template | string|null | config cluster_popup_view | HTML with {property} placeholders for the point popup |
| disable-popup | bool | false | Don't open a popup on point click |
| click-zoom | bool | true | Zoom in when a cluster is clicked |
| buffer | int | 256 | Tile buffer size |
| tolerance | float | 0.5 | Geometry simplification tolerance |
| max-features-to-inline | int | 2000 | Deprecated. Data is always embedded as a JSON script block |
| class | string | '' | Extra CSS classes |
<x-map-arc>
Curved lines between pairs of points. Each datum is ['id' => …, 'from' => [lng, lat], 'to' => [lng, lat], …]. Extra keys become feature properties you can use in paint expressions and in the tooltip/popup slots. See the Arcs page.
| Prop | Type | Default | Description |
|---|---|---|---|
| data | array | [] | The arcs to draw |
| id | string|null | auto (UUID) | Identifier for events and map:update-arc-data-{id} |
| curvature | float | 0.2 | How strongly arcs bend (0 = straight) |
| samples | int | 64 | Points per arc (smoothness) |
| paint | array | [] | MapLibre line paint, merged over the defaults |
| layout | array | [] | MapLibre line layout |
| hover-paint | array|null | null | Paint applied to the hovered arc |
| interactive | bool | true | Enable hover/click events, tooltips and popups |
| before-id | string|null | null | Insert the layer below this style layer |
| fit-bounds | bool | false | Fit the map to all arcs |
<x-map-geojson>
Renders any GeoJSON as fill, outline and circle layers. Pass false to a paint prop to drop that layer. Supports tooltip/popup slots. See the GeoJSON page.
| Prop | Type | Default | Description |
|---|---|---|---|
| data | array|string | [] | FeatureCollection, Feature, Geometry, or a URL |
| id | string|null | auto (UUID) | Identifier for events and map:update-geojson-{id} |
| promote-id | string|null | null | Feature property to use as the feature id |
| fill-paint | array|false|null | null (default style) | Paint for polygon fills, or false to drop the layer |
| line-paint | array|false|null | null (default style) | Paint for lines and polygon outlines, or false |
| circle-paint | array|false|null | null (default style) | Paint for points, or false |
| fill-hover-paint | array|null | null | Fill paint for the hovered feature |
| line-hover-paint | array|null | null | Line paint for the hovered feature |
| circle-hover-paint | array|null | null | Circle paint for the hovered feature |
| interactive | bool | false | Enable hover/click events, tooltips and popups |
| before-id | string|null | null | Insert the layers below this style layer |
| fit-bounds | bool | false | Fit the map to the data |
| fit-bounds-padding | int | 40 | Padding in px used with fit-bounds |
Events
Events are dispatched once as bubbling DOM events that Livewire also receives. Listen with Alpine (@map:click) or Livewire (#[On('map:click')]). Every payload also includes mapId, except map:route-list-selected.
Map events
| Event | Payload | Description |
|---|---|---|
| map:loaded | center, zoom | The map is created and its first style has loaded |
| map:style-loaded | style, dark | A style finished loading (also after theme switches) |
| map:style-reloaded | — | The style was replaced via map:set-style |
| map:theme-changed | dark | The resolved light/dark theme changed (theme="auto") |
| map:click | lat, lng, lngLat, point | User clicked on the map |
| map:double-click | lat, lng | User double-clicked on the map |
| map:right-click | lat, lng | User right-clicked (context menu) on the map |
| map:move | lat, lng | Fired continuously while the map moves (throttled) |
| map:center-changed | lat, lng | Fired once movement ends |
| map:bounds-changed | north, south, east, west | Visible bounds after movement ends |
| map:viewport-changed | center, zoom, bearing, pitch | Full camera state after movement ends; center is [lng, lat] |
| map:zoom | zoom | Fired continuously while zooming (throttled) |
| map:zoom-changed | zoom | Fired once zooming ends |
| map:drag-end | lat, lng, zoom | User finished dragging the map |
| map:bearing-changed | bearing | The map was rotated (throttled) |
| map:pitch-changed | pitch | The map was tilted (throttled) |
| map:3d-toggled | enabled | The 3D button of <x-map-controls :three-d="true"> was toggled |
| map:locate-success | lat, lng, accuracy | The locate control found the user |
| map:locate-error | code, message | Geolocation failed or was denied |
| map:{event} | MapLibre event data | Extra MapLibre events forwarded via custom_events / :events |
Marker & popup events
| Event | Payload | Description |
|---|---|---|
| map:marker-clicked | id, lat, lng | A marker was clicked |
| map:marker-mouseenter | id, lat, lng | Pointer entered a marker |
| map:marker-mouseleave | id | Pointer left a marker |
| map:marker-drag-start | id, lat, lng | Dragging a draggable marker started |
| map:marker-drag | id, lat, lng | Fired while a marker is dragged (throttled) |
| map:marker-drag-end | id, lat, lng | A draggable marker was released |
| map:marker-popup-open | id | A marker popup opened |
| map:marker-popup-close | id | A marker popup closed |
| map:popup-open | id | A standalone <x-map-popup> opened |
| map:popup-close | id | A standalone popup closed |
Route events
| Event | Payload | Description |
|---|---|---|
| map:route-clicked | id, lat, lng, coordinates, point | A route line was clicked |
| map:route-mouseenter | id | Pointer entered a route |
| map:route-mouseleave | id | Pointer left a route |
| map:route-directions-ready | id, geometry, distance, duration, alternatives | Directions were fetched from OSRM |
| map:route-directions-error | id, message | Fetching directions failed (falls back to straight lines) |
| map:route-alternative-selected | id, alternativeIndex, previousIndex, geometry, distance, duration | An alternative route became the primary route |
| map:route-updated | id | A map:update-route-data-{id} command was applied |
| map:route-group-selection-changed | groupId, selectedRouteId, selectedIndex, previousRouteId, previousIndex, distance, duration | The selected route of a route group changed |
| map:route-group-directions-ready | groupId, routes | All routes of a group were resolved |
| map:route-list-selected | routeId, selectedIndex, previousIndex, distance, duration | A route was picked in <x-map-route-list> (no mapId) |
Arc, GeoJSON & cluster events
| Event | Payload | Description |
|---|---|---|
| map:arc-clicked | id, arc, lat, lng | An arc was clicked; arc is the original datum |
| map:arc-hovered | id, arc, lat, lng | Pointer moved onto an arc; on leave arc is null |
| map:geojson-clicked | id, feature, lat, lng | A feature was clicked; feature is {id, properties, geometry} |
| map:geojson-hovered | id, feature, lat, lng | Pointer moved onto a feature; on leave feature is null |
| map:cluster-clicked | cluster_id, lat, lng, count | A cluster bubble was clicked |
| map:cluster-expanded | cluster_id, zoom | The map zoomed in to expand a cluster |
| map:cluster-point-clicked | feature_id, lat, lng, properties | An unclustered point was clicked |
Commands
Dispatch these from Livewire with $this->dispatch(), using named arguments or a single array. See Targeting a Map.
Map commands
Each accepts an optional mapId. Without it the command applies to every map on the page.
| Command | Payload | Description |
|---|---|---|
| map:fly-to | center, zoom, bearing, pitch, … | Animate the camera along a flight path (MapLibre flyTo options) |
| map:ease-to | center, zoom, bearing, pitch, … | Animate the camera smoothly (MapLibre easeTo options) |
| map:jump-to | center, zoom, bearing, pitch, … | Move the camera instantly (MapLibre jumpTo options) |
| map:fit-bounds | bounds, padding, … | Fit [[west, south], [east, north]] in view; padding defaults to 40 |
| map:set-zoom | zoom | Set the zoom level |
| map:set-center | center | Set the center ([lng, lat]) |
| map:set-bearing | bearing | Set the rotation in degrees |
| map:set-pitch | pitch | Set the tilt in degrees |
| map:set-style | style | Replace the style (URL or style JSON); fires map:style-reloaded |
| map:set-theme | theme | Switch to light, dark or auto |
| map:resize | — | Recalculate the map size (after showing a hidden container) |
| map:call | method, args | Call any public MapLibre Map method, e.g. method: 'setMaxZoom', args: [12] |
Component commands
These target a component by the id you gave it, so give dynamic routes, arcs, GeoJSON and cluster layers an explicit id.
| Command | Payload | Description |
|---|---|---|
| map:update-route-data-{id} | coordinates, color, width, progress, progressDuration, … | Update a route's coordinates and/or style |
| map:route-progress-{id} | progress, duration | Animate the progress overlay to progress (0–1) over duration ms |
| map:select-route-{id} | index | Make an alternative route the primary one |
| map:force-animate | id?, duration? | Replay the draw animation of one route/group, or of all animated ones |
| map:update-route-group-{id} | selectedRoute, routes | Change the selected route or patch route styles in a group |
| map:update-arc-data-{id} | data (or a plain array) | Replace the arcs of an <x-map-arc> |
| map:update-geojson-{id} | data (or a GeoJSON object) | Replace the data of an <x-map-geojson> |
| map:update-cluster-data-{id} | data (or a FeatureCollection) | Replace the points of a cluster layer (send GeoJSON, e.g. GeoJSON::fromArray($points)) |
Example: Fly To
// In Livewire Component public function centerOnPilot() { $this->dispatch('map:fly-to', mapId: 'main-map', // optional center: [-0.09, 51.5], zoom: 12, essential: true, ); }
JavaScript API
| API | Returns | Description |
|---|---|---|
| $map (Alpine magic) | Map | null | MapLibre instance of the nearest enclosing map |
| x-map-resize (Alpine directive) | — | Resize the enclosing map when the expression becomes truthy |
| LivewireMap.getMap(id) | Map | null | MapLibre instance of a map by id |
| LivewireMap.getRoute(id) | controller | null | Route controller: setProgress(value, durationMs), selectRoute(index), animate(duration?), pointAt(at), fitBounds() |
| LivewireMap.waitForMap(id, callback) | — | Run callback(map) once the map exists and its style has loaded. Works across wire:navigate; id may be null for the first map |
| LivewireMap.maps | object | Registry of all maps by id |
| LivewireMap.version | string | Package JavaScript version |
More examples on the Advanced page.
Tile Providers
Built-in tile providers you can use with the provider prop:
| Provider | Description |
|---|---|
| carto-positron | Light, minimal basemap (default) |
| carto-voyager | Clean, labelled basemap |
| carto-dark-matter | Dark basemap (default for dark mode) |
| openfreemap-liberty | OpenFreeMap style with 3D building extrusions |
| openfreemap-bright | Colorful OpenFreeMap style |
| openfreemap-positron | Light OpenFreeMap style |
| osm-raster | OpenStreetMap raster tiles |
| blank | Empty style with no basemap |
| custom | Use with style prop for custom MapLibre JSON |
Configuration
Keys in config/livewire-mapcn.php:
| Key | Default | Description |
|---|---|---|
| default_provider | 'carto-positron' | Provider used when provider is not set |
| dark_provider | 'carto-dark-matter' | Provider used in dark mode |
| default_height | 'full' | Map height when height is not set |
| default_zoom | 7 | Initial zoom |
| default_center | [0, 0] | Initial center [lng, lat] |
| follow_system_theme | false | With theme="auto", also follow the OS color scheme when the page sets no theme |
| osrm_url | 'https://router.project-osrm.org' | OSRM server for directions |
| cluster_popup_view | null | Default Blade view for cluster point popups |
| custom_events | [] | Extra MapLibre events forwarded as map:{event} on all maps |
| maplibre_version | '6.14.0' | MapLibre GL JS version loaded from the CDN |
| load_from_cdn | true | Set to false if you bundle MapLibre yourself (as window.maplibregl) |
| cdn_url / cdn_css_url | null | Pin exact MapLibre JS/CSS URLs |
| inject_assets | 'route' | route (served by the package) or published (from public/vendor) |