You are here

function geofield_map_googlemap_render in Geofield Map 8.2

Same name and namespace in other branches
  1. 8 geofield_map.module \geofield_map_googlemap_render()

Load all Geofield Google Map client files and return markup for a map.

Parameters

array $js_settings: The map rendering data.

Return value

array The returned render array.

2 calls to geofield_map_googlemap_render()
GeofieldGoogleMapFormatter::viewElements in src/Plugin/Field/FieldFormatter/GeofieldGoogleMapFormatter.php
Builds a renderable array for a field value.
GeofieldGoogleMapViewStyle::render in src/Plugin/views/style/GeofieldGoogleMapViewStyle.php
Renders the View.

File

./geofield_map.module, line 62
Contains the geofield_map.module.

Code

function geofield_map_googlemap_render(array $js_settings) {
  $attached_libraries = [
    'geofield_map/geojson',
    'geofield_map/geofield_google_map',
  ];

  // Add the intersection_observer library, if lazy load is enabled.
  if ($js_settings['map_settings']['map_lazy_load']) {
    $attached_libraries[] = 'geofield_map/intersection_observer';
  }

  // Add the Marker Cluster library, if asked.
  if ($js_settings['map_settings']['map_markercluster']['markercluster_control']) {
    $attached_libraries[] = 'geofield_map/marker_cluster';
  }

  // Add the OverlappingMarkerSpiderfier library, if asked.
  if (!isset($js_settings['map_settings']['map_oms']['map_oms_control']) || $js_settings['map_settings']['map_oms']['map_oms_control']) {
    $attached_libraries[] = 'geofield_map/overlappingmarkerspiderfier';
  }

  // Add the Leaflet Geocoder library and functionalities, if requested,
  // and the user has access to Geocoder Api Enpoints.
  if (\Drupal::service('module_handler')
    ->moduleExists('geocoder') && class_exists('\\Drupal\\geocoder\\Controller\\GeocoderApiEnpoints') && isset($js_settings['map_settings']['map_geocoder']) && $js_settings['map_settings']['map_geocoder']['control'] && \Drupal::service('current_user')
    ->hasPermission('access geocoder api endpoints')) {
    $attached_libraries[] = 'geofield_map/geocoder';

    /* @var \Drupal\geofield_map\Services\GeocoderService $geofield_map_geocoder_service */
    $geofield_map_geocoder_service = \Drupal::service('geofield_map.geocoder');

    // Get Filtered Js Map Geocoder Settings.
    $js_settings['map_settings']['map_geocoder']['settings'] = $geofield_map_geocoder_service
      ->getJsGeocoderSettings($js_settings['map_settings']['map_geocoder']['settings']);
  }
  $render_array = [
    '#theme' => 'geofield_google_map',
    '#mapid' => $js_settings['mapid'],
    '#height' => $js_settings['map_settings']['map_dimensions']['height'],
    '#width' => $js_settings['map_settings']['map_dimensions']['width'],
    '#attached' => [
      'library' => $attached_libraries,
      'drupalSettings' => [
        'geofield_google_map' => [
          $js_settings['mapid'] => $js_settings,
        ],
      ],
    ],
    '#cache' => [
      'contexts' => [
        'url.path',
        'url.query_args',
      ],
    ],
  ];
  return $render_array;
}