Skip to content

Latest commit

 

History

History
81 lines (54 loc) · 2.11 KB

MapField.md

File metadata and controls

81 lines (54 loc) · 2.11 KB

Smindel\GIS\Forms\MapField

feature name

Extends FormField. Form field for editing geo types.

Configuration

private static MapField::$default_location = array

Location to center empty MapFields and GridFieldMaps to

MapField::$default_location = [
    'lon' => 174.78,
    'lat' => -41.29,
];
  • lon (float) is the default location's longitude as a float
  • lat (float) is it's latitude as a float

Methods

public function MapField::enableMulti($enable = true)

Enable multi geometries like MultiPoint or MultiPolygon

  • $enable (bool) whether to enable or disable the control in the widget

Returns the MapField instance for chaining

public function MapField::hideFormField($hide = true)

Hide form field showing the actual EWKT value that will be stored in the database.

  • $hide (bool) whether to hide or shoe the readonly field

Returns the MapField instance for chaining

public function MapField::setControl($shapeType, $enabled = true) : MapField

Hide controls for selected shape types

  • $shapeType (string) Leaflet shape type, Note: those are different from the GIS shapes
  • $enabled (bool) whether to enable or disable the control in the widget

Returns the MapField instance for chaining

Examples

Adding a MapField to an admin form

After adding a new geo type to your DataObjects db fields, the form scaffolder automatically gives you a MapField to your ModelAdmin form. If you need to add one to your admin form manually e.g. because the form doesn't use the default scaffolder like CMS you can add it to your DataObject like this:

app/src/Model/CityPage.php

<?php

use Smindel\GIS\Forms\MapField;

class CityPage extends Page
{
    private static $db = [
        'Location' => 'Geometry',
    ]

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab(
            'Root.Main',
            MapField::create('Location')
                ->setControl('polygon', false)
                ->setControl('polyline', false),
            'Content'
        );
        return $fields;
    }
}