Maps

The maps plugin draws maps from one PHP spec. A renderer draws the map in the browser (Leaflet), a tile provider gives the map images (OpenStreetMap, Mapy.com, a tile server of your own, or a PMTiles archive of your own), and a geocoder turns place names into coordinates on the server. Your code names what it wants; the site's settings pick the defaults. The spec goes to the page as JSON in a data-yf-map attribute and the yf_maps starter script draws the map when it scrolls into view, also in content that htmx swaps in. There is no inline script per map.

Live examples without a key: demo maps/maps.

A map

echo html()->map([
    'center' => [50.087, 14.421],   // [lat, lng]
    'zoom' => 12,
    'markers' => [['lat' => 50.087, 'lng' => 14.421, 'title' => 'Old Town', 'popup' => 'Old Town Square']],
]);
// the same: _class('maps')->render([...])

Coordinates in PHP are [lat, lng] (or ['lat' => .., 'lng' => ..], or the string "lat,lng"); values outside -90..90 / -180..180 are dropped. popup and title are text: the browser shows them as text, so data from your database cannot inject HTML. popup_html takes HTML, for markup your own code builds.

Spec keys

KeyMeaning
center, zoomThe view. Without a center: the markers, else the site's default centre or the whole world.
tiles<provider>[:<style>], see below; default from the site settings.
rendererleaflet (the only one for now).
markersList of lat, lng, title, popup / popup_html. At most 5,000 by default.
clusterGroup nearby markers (Leaflet.markercluster).
fitFit the view to the markers; on by default when there are several markers and no center.
heightCSS length (360px, 50vh) or pixels.
consentauto, none or always: see consent.
scroll_zoom, min_zoom, max_zoomMouse wheel zoom (on) and zoom limits.
id, class, titleAttributes of the map element; title is its accessible name.

Unknown keys are ignored. An unknown renderer or tile provider falls back to the default with a notice in the log.

Tile providers

TilesWhatKeyLoads
osmOpenStreetMap standard tiles. Free for light use: busy sites should use their own PMTiles or another provider.noafter a click
mapy, mapy:outdoor, mapy:winter, mapy:aerialMapy.com (Seznam), strong in Central Europe; its logo is shown on the map.yesafter a click
pmtiles, pmtiles:light, pmtiles:darkA PMTiles archive of your own (one file of vector tiles on your server or bucket); without one, the bundled world basemap (zoom 0-6, Natural Earth data, about 1.6 MB). auto follows the light or dark colour mode of the page.nodirectly
custom:<name>A raster tile server the site names in its config (its own, or a commercial one).as setdirectly if it is the site's own

Each provider's attribution is shown on the map as its terms require; do not hide it with CSS. Google Maps is available through the form field google_maps().

Loading tiles from another service sends the visitor's IP address and the page address to it. So a map whose tiles are not served by the site itself starts as a placeholder: the provider's name, a Load map button and an Always load maps from ... on this site box (kept in the browser). OpenStreetMap is a third party too. Maps of your own PMTiles, of your own tile server and of the site's tile proxy load directly. consent => always asks even for your own tiles; none loads directly, when your page already asked.

A cookie banner or consent manager opens all waiting maps (or those of one provider) with an event:

document.dispatchEvent(new CustomEvent('yf:maps-consent', {detail: {provider: '*'}}));   // or 'osm', 'mapy'
// remember the choice in the browser too:
document.dispatchEvent(new CustomEvent('yf:maps-consent', {detail: {provider: 'osm', remember: true}}));

Forms: pick a point

form($row)
    ->map_select('place', 'Location')                            // posts place_lat and place_lng
    ->map_select('shop', 'Shop', ['lat_field' => 'latitude', 'lng_field' => 'longitude'])
    ->map_select('spot', 'Spot', ['single' => true])            // posts spot = "lat,lng"
    ->save();

A click on the map or a dragged marker fills the inputs, a typed value moves the marker, and "Use my location" asks the browser only after a click. The inputs post plain numbers, so the field works with any column type (for example DECIMAL(10,7)). Reference: map_select().

Rows on a map

$shops = db()->get_all('SELECT name, lat, lng FROM shops WHERE active = 1');
echo html()->map_view($shops, ['title_key' => 'name', 'height' => 400]);   // clustered, fitted

Reference: html()->map(), html()->map_view().

Place names to coordinates

$found = _class('maps')->geocode('Lviv', ['country' => 'UA', 'limit' => 5]);
// [['lat' => 49.83826, 'lng' => 24.02324, 'name' => 'Lviv', 'country' => 'UA', 'source' => 'local'], ...]

Geocoding runs on the server only. The local geocoder searches the GeoNames places of the geo plugin (imported in the admin under Tools / Geo): no third party and no key. It finds places by name prefix, biggest first.

In the browser

  • yf_maps.get(element): the Leaflet map of a map element, once drawn; the element fires yf:map-ready (detail: map, spec).
  • yf_maps.init(root): start the maps of content your own script inserted (htmx swaps are handled).
  • yf_maps.consent(provider, remember): the same as the consent event.

Your own provider

Drivers are small classes in classes/maps/ of a plugin: yf_maps_tiles_<name> (tiles), yf_maps_renderer_<name>, yf_maps_geocoder_<name>. A site adds one as site__maps_tiles_<name> extending yf_maps_tiles and lists the name in $PROJECT_CONF['maps']['PROVIDERS']:

class site__maps_tiles_topo extends yf_maps_tiles
{
    public $NAME = 'topo';
    public $TITLE = 'My topo tiles';
    public $URL = 'https://tiles.example.com/topo/{z}/{x}/{y}.png';
    public $ATTRIBUTION = '&copy; Example';
    public $MAX_ZOOM = 17;
}

Libraries: Leaflet (BSD-2-Clause), Leaflet.markercluster (MIT), protomaps-leaflet (BSD-3-Clause); vendored copies come with the framework. Design notes: docs/rnd/2026-11-22-maps.md in the repository.