Skip to content

Latest commit

 

History

History
executable file
·
75 lines (52 loc) · 2.56 KB

README.md

File metadata and controls

executable file
·
75 lines (52 loc) · 2.56 KB

Kirby 2 OpenStreetMap Field

This custom field for Kirby CMS displays an OpenStreetMap inside the panel (Kirby's backend) to Locate a place and get its geocoordinates.

Based on the Kirby Map Field from August Miller.

Leftlet JavaScript library from Vladimir Agafonkin.

In times of the GPDR it may be important to replace a Google Maps Plugin with a GDPR compliant one.

Features

  • Familiar OpenStreetMaps UI
  • Discrete storage of location name, latitude and longitude
  • Geocoding of location names and addresses
  • Repositionable marker (in case search doesn't nail it)
  • Support for multiple osmap fields per form
  • Support for osmap fields within structure fields
  • Support for osmap fields in file forms
  • Customizable initial position and zoom— globally and on a per-field basis
  • Compatible with Kirby 2.3.0+

Kirby OpenStreetMap Field Screenshot

Blueprint example

fields:
  location:
    label: Location
    type: osmap
    center:
      lat: 48.3985233
      lng: 9.9925550
      zoom: 9
    help: >
    

The center key allows you to customize the initial position and zoom level of the map interface.

You can also set global defaults, in your config.php:

c::set('osmap.defaults.lat', 45.5230622);
c::set('osmap.defaults.lng', -122.6764816);
c::set('osmap.defaults.zoom', 9);

These options will be overridden by any set on individual fields. Without either configured, it will default to hard-coded values.

Template Usage

The OpenStreetMap Field stores data in YAML.

You must manually transform the field to an associative array by calling the yaml field method.

The resulting array can be used just like any other:

$page->location()->yaml()['lat'];
// Or!
$location = $page->location()->yaml();
echo $location['lng']; # => 9.9925550

Properties address, lat and lng should exist in the decoded object, but may be empty.

Kirby creator Bastian Allgeier recently created the Geo Plugin, which is a great toolkit for working with coordinates. Check it out!

Setup

git clone https://github.com/fendinger/kirby-osmap-field.git site/fields/osmap From the root of your kirby install.

Alternatively you can download the zip file, unzip it's contents into site/fields/osmap.