bigfork/silverstripe-mapboxfield

Mapbox CMS field for SilverStripe 5

Installs: 3 054

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 4

Forks: 11

Open Issues: 4

Language:JavaScript

Type:silverstripe-vendormodule

2.0.0 2025-03-07 12:31 UTC

README

Adds a Mapbox map to the CMS with a draggable marker to allow content authors to add a location to a DataObject or Page.

Installation

composer require bigfork/silverstripe-mapboxfield:*

Configuration

---
Name: 'app-mapbox'
After: 'silverstripe-mapboxfield'
---
Bigfork\SilverStripeMapboxField\MapboxField:
  access_token: '<your mapbox key>'
  style: 'mapbox://styles/mapbox/standard'

The style is optional, and defaults to mapbox://styles/mapbox/standard but allows you to specify a different style if you need more control.

Usage

class MyDataObject extends DataObject
{
    private static $db = [
        'Latitude' => 'Decimal(10, 8)',
        'Longitude' => 'Decimal(11, 8)'
    ];

    public function getCMSFields()
    {
        // ...

        $fields->addFieldToTab(
            'Root.Map',
            MapboxField::create('LocationMap', 'Choose a location', 'Latitude', 'Longitude')
        );

        // ...
    }
}