map() table()

A column with the row's point (maps plugin): a pin and the coordinates; a click opens a small map of the point below.

table()->map($name, $extra = [])

Options

OptionMeaning
$nameField holding lat,lng (or [lat, lng]); rows without a valid point show nothing.
lat_key, lng_keyTwo fields of the row instead (e.g. lat, lng columns).
pointCallback fn ($row) returning the point, for anything else.
labelfalse: the pin only, no coordinates.
mapSpec keys of the small map (html()->map()): tiles, zoom (13), height (220px), consent, ...
descColumn title (default Map).

Example

Name Where
Kyiv office
50.4501, 30.5234
Lviv office
49.8397, 24.0297
Remote

Code

$rows = [
    1 => ['id' => 1, 'name' => 'Kyiv office', 'point' => '50.4501,30.5234'],
    2 => ['id' => 2, 'name' => 'Lviv office', 'point' => '49.8397,24.0297'],
    3 => ['id' => 3, 'name' => 'Remote', 'point' => ''],
];
return table($rows, ['no_pages' => 1])
    ->text('name')
    ->map('point', ['desc' => 'Where', 'map' => ['tiles' => 'pmtiles', 'zoom' => 5]]);

Notes

  • Needs the maps plugin, separately distributed since it left the framework (admin docs misc/plugins_moved#plugin-maps): without it the call keeps working and draws an empty box of the map's height (on admin pages it names the install command) with one E_USER_NOTICE per request; form fields keep their inputs and values, a table column its coordinates.
  • The map of a row is drawn only when its cell is opened (a <details> element), so a long page loads no map until asked. Tiles that are not self-hosted show their click-to-load placeholder first.
  • Each opened map is a small Leaflet map with the site's default tiles unless map names others; the example uses the bundled world basemap.

See also: table/map_view, html/map_view, form/map_select