You are here

LeafletDisableUserInteraction.php in Geolocation Field 8.2

File

modules/geolocation_leaflet/src/Plugin/geolocation/MapFeature/LeafletDisableUserInteraction.php
View source
<?php

namespace Drupal\geolocation_leaflet\Plugin\geolocation\MapFeature;

use Drupal\geolocation\MapFeatureBase;
use Drupal\Core\Render\BubbleableMetadata;

/**
 * Provides disabled interaction.
 *
 * @MapFeature(
 *   id = "leaflet_disable_user_interaction",
 *   name = @Translation("Disable User Interaction"),
 *   description = @Translation("Disable direct user interaction like zooming or panning"),
 *   type = "leaflet",
 * )
 */
class LeafletDisableUserInteraction extends MapFeatureBase {

  /**
   * {@inheritdoc}
   */
  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,
              ],
            ],
          ],
        ],
      ],
    ]);
    return $render_array;
  }

}

Classes

Namesort descending Description
LeafletDisableUserInteraction Provides disabled interaction.