Laravel Mapcn
Toggle sidebar

API Reference

Docs / 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.

Components

Livewire Events

The map dispatches events to Livewire and listens for specific commands.

Events Dispatched to Livewire

EventPayloadDescription
map:loadedMap style is fully loaded
map:clicklat, lng, detailUser clicked on the map
map:zoom-changedzoomZoom level changed
map:center-changedlat, lngMap center changed
map:marker-clickedid, lat, lngA marker was clicked
map:marker-drag-endid, lat, lngA draggable marker was released

Commands from Livewire

Trigger these from your Livewire component using $this->dispatch():

CommandDescription
map:fly-toMove the map smoothly to a new location
map:set-zoomChange zoom level
map:fit-boundsFit the map view to specific coordinates
map:resizeForce a map recalculation (useful for show/hide containers)

Example: Fly To

php — Livewire Component
// In Livewire Component
public function centerOnPilot()
{
    $this->dispatch('map:fly-to', [
        'center' => [-0.09, 51.5],
        'zoom' => 12,
        'essential' => true
    ]);
}

Viewport Events

Track and control the map viewport (center, zoom, bearing, pitch) using Alpine.js events:

EventDetailDescription
map:movelat, lngFired continuously as the map moves
map:center-changedlat, lngFired once movement ends
map:zoomzoomFired continuously during zoom
map:zoom-changedzoomFired once zoom ends
map:bearing-changedbearingFired when the map is rotated
map:pitch-changedpitchFired when the map is tilted

Tile Providers

Built-in tile providers you can use with the provider prop:

ProviderDescription
carto-voyagerClean, labelled basemap (default)
carto-positronLight, minimal basemap
carto-dark-matterDark basemap for dark mode
osm-rasterOpenStreetMap raster tiles
customUse with style prop for custom MapLibre JSON