Markers

Docs / Markers

Overview

The <x-map-marker> component displays interactive markers on the map. Markers support custom colors, labels, tooltips, popups, dragging, and fully custom HTML content.

Basic Marker

Labels & Tooltips

Add text labels near the marker and hover tooltips using sub-components:

Rich Label & Tooltip Content

Omit the text prop on <x-marker-label> or <x-marker-tooltip> and put any HTML in the slot instead:

Marker Popup

Add a click-to-open popup to a marker with custom HTML content. By default the popup has no fixed anchor: MapLibre places it on the side with the most room, 16px above the marker. Pass anchor (e.g. "bottom") to pin it to one side:

Custom Marker Content

Replace the default marker pin with completely custom HTML using <x-marker-content>:

Multiple Markers

Add as many markers as you need, each with their own props. Use :opacity to fade a marker (the green one below is at 0.5):

Reactive Markers

Markers inside <x-map> update reactively from Livewire state. When a property changes, markers are added, moved, updated or removed without re-creating the map, so you do not need a wire:ignore wrapper. Give each marker rendered in a loop a stable wire:key:

php
class StoreMap extends Component
{
    public array $stores = [
        ['id' => 1, 'name' => 'Soho', 'lat' => 51.513, 'lng' => -0.136],
        ['id' => 2, 'name' => 'Camden', 'lat' => 51.539, 'lng' => -0.142],
    ];

    public function addStore(float $lat, float $lng): void
    {
        $this->stores[] = ['id' => uniqid(), 'name' => 'New store', 'lat' => $lat, 'lng' => $lng];
    }
}
blade
<x-map :center="[-0.14, 51.52]" :zoom="12">
    @foreach ($stores as $store)
        <x-map-marker
            wire:key="store-{{ $store['id'] }}"
            :lat="$store['lat']"
            :lng="$store['lng']"
        >
            <x-marker-label :text="$store['name']" />
        </x-map-marker>
    @endforeach
</x-map>
Calling $this->addStore(...) (or editing $stores) adds the marker on the next render. Keys must be unique and stable, so use a database id rather than the loop index.

Props

PropTypeDefaultDescription
:latfloatrequiredLatitude
:lngfloatrequiredLongitude
id?stringnullUnique identifier for events
:draggableboolfalseEnable user to drag the marker
colorstring'#1A56DB'Color for the default marker pin
anchorstring'bottom'Options: center, top, bottom, etc.
:offsetarray[0, 0]Pixel offset [x, y]
:rotationfloat0Clockwise rotation in degrees
rotation-alignmentstring'auto''map', 'viewport', or 'auto'
pitch-alignmentstring'auto''map', 'viewport', or 'auto'
:opacity?floatnullMarker opacity from 0 to 1 (null keeps it fully opaque)
classstring''CSS class for the marker container

Sub-Components

<x-marker-content>

Renders custom HTML as the marker icon. Place any HTML in the slot.

PropDescription
classCSS class for the wrapper element

<x-marker-label>

Adds a floating label to the marker. Use text for plain text, or omit it and use the slot for rich content.

PropDescription
textPlain label text (Default: null, uses the slot)
positionOptions: top, bottom, left, right (Default: bottom)
classAdditional CSS classes

<x-marker-tooltip>

Adds a hover-triggered tooltip. Use text for plain text, or omit it and use the slot for rich content.

PropDescription
textPlain tooltip text (Default: null, uses the slot)
anchorTooltip connection point, e.g. top, bottom, left (Default: null, MapLibre picks the side with the most room)
:offsetPixel offset as a number or [x, y] (Default: null, 16px above the marker)
classCSS class for the tooltip wrapper

<x-marker-popup>

Adds a click-to-open popup containing arbitrary HTML.

PropDescription
max-widthCSS max-width (Default: '300px')
:close-buttonToggle the little 'x' (Default: true)
:close-on-click-mapClose if map is clicked (Default: true)
:close-on-moveClose if map camera moves (Default: false)
anchorPopup connection point, e.g. top, bottom, left (Default: null, auto: MapLibre picks the side with the most room)
:offsetPixel offset as a number or [x, y] (Default: null, 16px above the marker)
classCSS base class for the popup container