View source
<?php
namespace Drupal\geolocation_leaflet\Plugin\geolocation\MapFeature;
use Drupal\geolocation\MapFeatureBase;
use Drupal\Core\Render\BubbleableMetadata;
class LeafletMaxBounds extends MapFeatureBase {
public static function getDefaultSettings() {
return [
'north' => '',
'south' => '',
'east' => '',
'west' => '',
];
}
public function getSettingsForm(array $settings, array $parents) {
$form['north'] = [
'#type' => 'textfield',
'#title' => $this
->t('North'),
'#size' => 15,
'#default_value' => $settings['north'],
];
$form['south'] = [
'#type' => 'textfield',
'#title' => $this
->t('South'),
'#size' => 15,
'#default_value' => $settings['south'],
];
$form['east'] = [
'#type' => 'textfield',
'#title' => $this
->t('East'),
'#size' => 15,
'#default_value' => $settings['east'],
];
$form['west'] = [
'#type' => 'textfield',
'#title' => $this
->t('West'),
'#size' => 15,
'#default_value' => $settings['west'],
];
return $form;
}
public function alterMap(array $render_array, array $feature_settings, array $context = []) {
$render_array = parent::alterMap($render_array, $feature_settings, $context);
$render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
'library' => [
'geolocation_leaflet/mapfeature.' . $this
->getPluginId(),
],
'drupalSettings' => [
'geolocation' => [
'maps' => [
$render_array['#id'] => [
$this
->getPluginId() => [
'enable' => TRUE,
'north' => $feature_settings['north'],
'south' => $feature_settings['south'],
'east' => $feature_settings['east'],
'west' => $feature_settings['west'],
],
],
],
],
],
]);
return $render_array;
}
}