map() html()
A map (maps plugin): html()->map($spec) is _class('maps')->render($spec); one div with the spec as JSON, drawn by the yf_maps starter.
html()->map($spec = [])Options
| Option | Meaning |
|---|---|
center, zoom | [lat, lng] (PHP order) and 0-22; default the markers, else the whole world. |
tiles | osm, mapy[:basic|outdoor|winter|aerial] (key), pmtiles[:auto|light|dark] (own archive or the bundled world basemap), custom:<name>. |
markers | List of lat, lng, title (tooltip), popup (text) or popup_html (HTML from your code only). |
cluster, fit | Cluster the markers; fit the view to them (default with several markers and no center). |
height | CSS length or pixels (default 360px). |
consent | auto (default: click to load for tiles that are not self-hosted), none, always. |
scroll_zoom, min_zoom, max_zoom, id, class, title | Wheel zoom (on), zoom limits, attributes of the div. |
Example
Code
return html()->map(['tiles' => 'pmtiles', 'center' => [48.5, 20], 'zoom' => 3, 'height' => 260, 'markers' => [
['lat' => 50.4501, 'lng' => 30.5234, 'title' => 'Kyiv', 'popup' => 'Kyiv'],
['lat' => 48.8566, 'lng' => 2.3522, 'title' => 'Paris', 'popup' => 'Paris'],
]]);Notes
- No inline script: the spec goes out as JSON with every HTML character escaped; popup text is set as text in the browser.
- Maps in content that htmx swaps in start too; maps htmx removes are destroyed.
- The example uses the bundled world basemap, served by this site: no key and no third party.
See also: html/map_view, form/map_select