diff --git a/src/MapboxField.php b/src/MapboxField.php index a30f15b..8bb2543 100644 --- a/src/MapboxField.php +++ b/src/MapboxField.php @@ -8,6 +8,14 @@ use SilverStripe\Forms\HiddenField; class MapboxField extends CompositeField { + private static $access_token = null; + private static $map_style = 'mapbox://styles/mapbox/basic-v9'; + private static $api_css_url = 'https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.css'; + private static $api_javascript_url = 'https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.js'; + private static $geocoder_css_url = 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.3.0/mapbox-gl-geocoder.css'; + private static $geocoder_javascript_url = 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.3.0/mapbox-gl-geocoder.min.js'; + private $curr_style; + /** * @param string $name * @param string $title @@ -16,17 +24,38 @@ class MapboxField extends CompositeField */ public function __construct($name, $title, $latitudeField, $longitudeField) { - $children = [ + $cfg = self::config(); + + $this->curr_style = $cfg->get('map_style'); + + parent::__construct([ HiddenField::create($latitudeField) ->setAttribute('data-mapbox-field', 'Latitude'), HiddenField::create($longitudeField) ->setAttribute('data-mapbox-field', 'Longitude') - ]; - - parent::__construct($children); - + ]); + $this->setName($name); $this->setTitle($title); - $this->addExtraClass('stacked'); } -} \ No newline at end of file + + public function getAttributes() + { + $attrs = parent::getAttributes(); + return array_merge($attrs, [ + 'class' => $attrs['class'].' stacked', + 'data-style' => $this->getStyle(), + ]); + } + + public function getStyle() + { + return $this->curr_style; + } + + public function setStyle($style) + { + $this->curr_style = $style; + return $this; + } +}