return function () {
$maps = _class('maps');
$cities = [
['title' => 'Kyiv', 'lat' => 50.4501, 'lng' => 30.5234],
['title' => 'Lviv', 'lat' => 49.8397, 'lng' => 24.0297],
['title' => 'Prague', 'lat' => 50.0755, 'lng' => 14.4378],
['title' => 'Vienna', 'lat' => 48.2082, 'lng' => 16.3738],
['title' => 'Warsaw', 'lat' => 52.2297, 'lng' => 21.0122],
['title' => 'Berlin', 'lat' => 52.52, 'lng' => 13.405],
['title' => 'Paris', 'lat' => 48.8566, 'lng' => 2.3522],
['title' => 'Madrid', 'lat' => 40.4168, 'lng' => -3.7038],
['title' => 'Rome', 'lat' => 41.9028, 'lng' => 12.4964],
['title' => 'London', 'lat' => 51.5074, 'lng' => -0.1278],
];
$posted = '';
if (main()->is_post() && isset($_POST['place_lat'], $_POST['place_lng'])) {
$p = $maps->point([$_POST['place_lat'], $_POST['place_lng']]);
$posted = '<p class="docs-demo-result">' . ($p ? 'Posted: <code>place_lat=' . $p[0] . '</code>, <code>place_lng=' . $p[1] . '</code>' : 'Posted values are not a point.') . '</p>';
}
$intro = '<p class="docs-demo-intro">Maps of the maps plugin: one PHP spec, printed as JSON in <code>data-yf-map</code> and drawn by the
<code>yf_maps</code> starter with Leaflet when the map scrolls into view (no inline script). The first three maps use the bundled world
basemap: a small PMTiles file of the plugin (zoom 0-6, Natural Earth data), served by this site, so they load directly and need no key.
The last map uses the OpenStreetMap tile servers, a third party: it starts as a click-to-load placeholder, as every map whose tiles are
not self-hosted. Classes: <code>yf_maps</code>, <code>yf_maps_renderer_leaflet</code>, <code>yf_maps_tiles_pmtiles</code>,
<code>yf_maps_tiles_osm</code>, <code>yf_form2_map_select</code>.</p>';
$one = '<h4>A map with markers</h4>'
. html()->map(['tiles' => 'pmtiles', 'center' => [49.5, 20], 'zoom' => 4, 'height' => 320, 'id' => 'demo_map_markers', 'markers' => array_map(fn ($c) => $c + ['popup' => $c['title']], array_slice($cities, 0, 4))]);
$two = '<h4>Rows on a map, clustered</h4>'
. html()->map_view($cities, ['tiles' => 'pmtiles:light', 'height' => 320, 'id' => 'demo_map_view']);
$form = form(['place_lat' => $_POST['place_lat'] ?? '50.4501', 'place_lng' => $_POST['place_lng'] ?? '30.5234'], ['class' => 'form-vertical'])
->map_select('place', 'Pick a point', ['map' => ['tiles' => 'pmtiles', 'zoom' => 5, 'height' => 300]])
->save('', 'Post');
$three = '<h4>Pick a point (form2 map_select)</h4><p>Click the map or drag the marker; the two fields post plain numbers.</p>' . $posted . $form;
$four = '<h4>Third-party tiles: click to load</h4>'
. html()->map(['tiles' => 'osm', 'center' => [50.4501, 30.5234], 'zoom' => 11, 'height' => 300, 'id' => 'demo_map_osm', 'markers' => [['lat' => 50.4501, 'lng' => 30.5234, 'title' => 'Kyiv']]]);
return $intro . '<div class="row"><div class="col-md-6">' . $one . '</div><div class="col-md-6">' . $two . '</div></div>'
. '<div class="row"><div class="col-md-6">' . $three . '</div><div class="col-md-6">' . $four . '</div></div>';
};