map_select() form()
Pick one point on a map (maps plugin): latitude and longitude inputs filled by a click or a dragged marker; they post plain numbers.
form()->map_select($name = '', $desc = '', $extra = [], $replace = [])Options
| Option | Meaning |
|---|---|
$name | Default point; the inputs are <name>_lat and <name>_lng. |
lat_field, lng_field | Other input names, e.g. the columns of your table. |
single | One input <name> holding lat,lng instead of two. |
map | Map spec keys (_class('maps')->render()): tiles, zoom, center, height, consent, ... |
locate | "Use my location" button (default on); the browser asks only after a click. |
disable_edit_mode, readonly | Show the point only. |
Example
Code
return form(['spot_lat' => '50.4501', 'spot_lng' => '30.5234'])->map_select('spot', 'Meeting point', ['map' => ['tiles' => 'pmtiles', 'zoom' => 5, 'height' => 260]]);Notes
- A typed value moves the marker; without JavaScript the inputs still work. Validate the posted numbers as any input (e.g.
numeric, a range). - With tiles that are not self-hosted (OpenStreetMap, Mapy.com) the map starts as a click-to-load placeholder; the inputs are usable before.
- The example uses the bundled world basemap (
tiles=>pmtiles), which is served by this site.
See also: html/map, form/google_maps