The package dispatches events to Livewire and listens for specific commands. This allows you to interact with the map from your PHP component seamlessly.
Listen for these events in your Livewire component:
| Event | Payload | Description |
|---|---|---|
| map:loaded | — | Map style is fully loaded |
| map:click | lat, lng, detail | User clicked on the map |
| map:zoom-changed | zoom | Zoom level changed |
| map:center-changed | lat, lng | Map center changed |
| map:marker-clicked | id, lat, lng | A marker was clicked |
| map:marker-drag-end | id, lat, lng | A draggable marker was released |
Trigger these from your Livewire component using $this->dispatch():
| Command | Description |
|---|---|
| map:fly-to | Move the map smoothly to a new location |
| map:set-zoom | Change zoom level |
| map:fit-bounds | Fit the map view to specific coordinates |
| map:resize | Force a map recalculation (useful for show/hide containers) |
Smoothly animate the map to a new location from your Livewire component:
use Livewire\Component; class FlightTracker extends Component { public function centerOnPilot() { $this->dispatch('map:fly-to', [ 'center' => [-0.09, 51.5], 'zoom' => 12, 'essential' => true, ]); } public function render() { return view('livewire.flight-tracker'); } }
<div> <button wire:click="centerOnPilot"> Center on Pilot </button> <x-map :center="[-0.09, 51.5]" :zoom="8" height="400px" > <x-map-controls /> </x-map> </div>
By default the map follows the .dark class on your <html> element when theme="auto" is set. You can also force a specific theme:
theme="light"
theme="dark"
Track and control the map viewport (center, zoom, bearing, pitch) by listening to events and using Alpine.js for real-time reactivity.
| Event | Detail | Description |
|---|---|---|
| map:move | lat, lng | Fired continuously as the map moves |
| map:center-changed | lat, lng | Fired once movement ends |
| map:zoom | zoom | Fired continuously during zoom |
| map:zoom-changed | zoom | Fired once zoom ends |
| map:bearing-changed | bearing | Fired when the map is rotated |
| map:pitch-changed | pitch | Fired when the map is tilted |
Automatically fit the map to show all your markers:
public function showAllLocations() { $this->dispatch('map:fit-bounds', [ 'bounds' => [ [-0.15, 51.49], // Southwest corner [lng, lat] [-0.01, 51.54], // Northeast corner [lng, lat] ], 'padding' => 50, ]); }
Programmatically change the zoom level:
public function zoomIn() { $this->dispatch('map:set-zoom', [ 'zoom' => 16, ]); }
Force the map to recalculate its size when the container changes (e.g. tabs, accordions, modals):
public function onTabChanged() { $this->dispatch('map:resize'); }
Always use <x-map-cluster-layer> instead of individual markers when rendering more than ~50 points.
Set :min-zoom and :max-zoom to constrain tile loading and reduce network requests.
For pages with multiple maps, consider loading maps only when they scroll into view using Livewire's lazy loading.
Set load_from_cdn to false in config to serve MapLibre assets from your own server for offline or intranet use.