mirror of
https://github.com/a2nt/silverstripe-mapboxfield.git
synced 2024-10-22 12:05:53 +00:00
Mapbox styles support
This commit is contained in:
parent
41ff0e18ae
commit
7d37cd678d
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user