map_view() table()

One map of the rows of the page with the table (maps plugin, html()->map_view()): each row with a point is a marker.

table()->map_view($extra = [])

Options

OptionMeaning
lat_key, lng_keyFields of the coordinates (default lat, lng).
point_keyOne field with lat,lng instead.
title_key, popup_keyTooltip and popup text (default title; the popup defaults to the title).
positiontop (default) or bottom of the table.
other keysMap spec keys: tiles, height, consent, cluster (on), fit (on), ...

Example

Title Lat Lng
Kyiv 50.4501 30.5234
Lviv 49.8397 24.0297
Odesa 46.4825 30.7233

Code

$rows = [
    1 => ['id' => 1, 'title' => 'Kyiv', 'lat' => 50.4501, 'lng' => 30.5234],
    2 => ['id' => 2, 'title' => 'Lviv', 'lat' => 49.8397, 'lng' => 24.0297],
    3 => ['id' => 3, 'title' => 'Odesa', 'lat' => 46.4825, 'lng' => 30.7233],
];
return table($rows, ['no_pages' => 1])
    ->text('title')
    ->text('lat')
    ->text('lng')
    ->map_view(['tiles' => 'pmtiles', 'height' => 240]);

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 shows the rows of the current page (the same query and paging as the table); a table without rows has no map.
  • Markers are text: titles and popups are shown with textContent, never as HTML.

See also: table/map, html/map_view