Mapbox CMS field, Geocoding and Frontend UI for SilverStripe 4
Go to file
dependabot[bot] 5fe11c2956
Bump decode-uri-component from 0.2.0 to 0.2.2
Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
- [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
- [Commits](https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2)

---
updated-dependencies:
- dependency-name: decode-uri-component
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-07 21:08:54 +00:00
_config Update config.yml 2022-06-16 00:38:24 +02:00
client IMPROVEMENT: Marker extension 2019-09-07 06:50:52 +07:00
docs/img Initial commit 2018-11-29 17:38:20 +00:00
src Update SiteConfigExtension.php 2022-06-16 00:37:46 +02:00
templates/A2nt/SilverStripeMapboxField IMPROVEMENT: Marker extension 2019-09-07 06:50:52 +07:00
.editorconfig Initial commit 2018-11-29 17:38:20 +00:00
.gitignore Initial commit 2018-11-29 17:38:20 +00:00
LICENSE Initial commit 2018-11-29 17:38:20 +00:00
README.md Initial updates 2019-09-07 07:57:59 +07:00
composer.json Update composer.json 2019-09-07 09:47:12 +07:00
package.json IMPROVEMENT: Marker extension 2019-09-07 06:50:52 +07:00
webpack.config.js Initial commit 2018-11-29 17:38:20 +00:00
yarn.lock Bump decode-uri-component from 0.2.0 to 0.2.2 2022-12-07 21:08:54 +00:00

README.md

SilverStripe Mapbox Field

Extends:

  • Symbiote\Addressable\Geocodable

Replaces:

  • dynamic/silverstripe-elemental-customer-service
  • bigfork/silverstripe-mapboxfield

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

Address will be geocoded automatically or manually using mapbox map.

Adds DataObject Extension to store and render GeoJSON data.

Installation

composer require a2nt/silverstripe-mapboxfield:*

Configuration


---
Name: 'app-map'
After:
  - 'silverstripe-mapboxfield'
  - 'addressable'
---
SilverStripe\Core\Injector\Injector:
  A2nt\SilverStripeMapboxField\MarkerExtension:
    properties:
      geocoder: %$Symbiote\Addressable\MapboxGeocodeService
  Symbiote\Addressable\GeocodeServiceInterface:
    class: Symbiote\Addressable\MapboxGeocodeService

Symbiote\Addressable\MapboxGeocodeService:
  mapbox_api_key: 'your mapbox access token'
A2nt\SilverStripeMapboxField\MapboxField:
  map_style: 'mapbox://styles/mapbox/light-v10'

Usage


class MyDataObjectMapPin extends DataObject
{
    private static $extensions = [
        Addressable::class,
        MarkerExtension::class,
    ];
}

Example

class MyPage extends \Page
{
    private static $db = [
        'MapZoom' => 'Int',
    ];
    
    public function MapPins()
    {
        return MyDataObjectMapPin::get();
    }

    public function getGeoJSON()
    {
        $pins = [];
        foreach ($this->MapPins() as $pin) {
            $pins[] = $pin->getGeo();
        }
        return json_encode([
            'type' => 'MarkerCollection',
            'features' => $pins
        ]);
    }
}

create MyDataObjectMapPin.ss template to render popup content

MyPage.ss

<div
	class="mapAPI-map-container"
	data-map-zoom="$MapZoom"
	data-key="<% if $MapAPIKey %>$MapAPIKey<% else %>$SiteConfig.MapAPIKey<% end_if %>"
	data-map-style="<% if $MapStyle %>$MapStyle<% else %>$SiteConfig.MapStyle<% end_if %>"
	data-geojson="$GeoJSON.XML"
>
    <div class="mapAPI-map"></div>
</div>

Process it with javascript on frontend, you can find an example at: https://github.com/a2nt/webpack-bootstrap-ui-kit/blob/master/src/js/_components/_ui.map.api.js