Controls

Docs / Controls

Overview

The <x-map-controls> component adds standard interactive controls to the map such as zoom buttons, compass, geolocation, fullscreen toggle, a scale bar and a 3D view toggle. For your own buttons and panels, use <x-map-control>. Nest both inside <x-map>.

Basic Usage

With Scale Bar

Enable the scale bar to show distance measurement on the map:

Positioning

Controls can be placed in any of the four map corners using the position prop:

top-left

top-right

(default)

bottom-left

bottom-right

3D View

Add :three-d="true" to get a 3D toggle button. It eases the camera to a pitch of 60° and a bearing of -20° and back to flat (tune with :three-d-pitch, :three-d-bearing and :three-d-duration), and dispatches map:3d-toggled with { enabled }. Pair it with the openfreemap-liberty provider, which has 3D building extrusions:

With theme="auto", dark mode switches to the configured dark_provider (Carto Dark Matter by default), which has no 3D buildings. This example forces theme="light"; you could instead set dark-style. The compass also tilts with the pitch (:visualize-pitch, on by default).

Custom Controls

<x-map-control> pins any Blade or Alpine markup to the map, styled as a control group (buttons are stacked with dividers and pick up the map's light/dark theme). Inside it, the $map Alpine magic returns the MapLibre instance, so buttons can call any Map method directly:

position accepts top-left (default), top-right, bottom-left, bottom-right, top and bottom (centered). Set :group="false" to drop the control-group styling and render your own panel, legend or search box. Buttons can also use wire:click to call your Livewire component.

PropTypeDefaultDescription
positionstring'top-left'top-left, top-right, bottom-left, bottom-right, top, bottom
:groupbooltrueStyle the content as a control group
classstring''Additional CSS classes

Props

PropTypeDefaultDescription
:zoombooltrueShow zoom in/out buttons
:compassbooltrueShow compass / bearing reset
:locatebooltrueShow geolocation button
:fullscreenboolfalseShow fullscreen toggle (overlays such as route lists and custom controls stay visible)
:scaleboolfalseShow map scale bar
scale-unitstring'metric'metric, imperial or nautical
:three-dboolfalseShow a 3D view toggle button
:three-d-pitchint|float60Pitch used by the 3D toggle
:three-d-bearingint|float-20Bearing used by the 3D toggle
:three-d-durationint10003D toggle animation duration (ms)
:visualize-pitchbooltrueTilt the compass to show the current pitch
:track-userbooltrueKeep following the user's location after locating
positionstring'top-right'Position: top-right, top-left, bottom-right, bottom-left
classstring''Additional CSS classes