You are here

public function OpenlayersService::openlayersRenderMap in Openlayers 8.4

Load all Leaflet required client files and return markup for a map.

Parameters

array $map: The map settings array.

array $features: The features array.

string $height: The height value string.

Return value

array The leaflet_map render array.

File

src/OpenlayersService.php, line 84

Class

OpenlayersService
Provides an OpenlayersService class.

Namespace

Drupal\openlayers

Code

public function openlayersRenderMap(array $settings, $height = '300px', $cache_tags = NULL) {
  $map = $settings['map'];
  $map_id = isset($map['id']) ? $map['id'] : Html::getUniqueId('openlayers_map');
  $attached_libraries = [
    'openlayers/openlayers-drupal',
  ];
  $js_settings[$map_id] = [
    'mapid' => $map_id,
    'map' => $map,
    'features' => array_values($settings['features']),
    'zoom' => isset($settings['settings']['zoom']) ? $settings['settings']['zoom'] : 10,
    'widget' => isset($settings['widget']) ? $settings['widget'] : [],
  ];
  return [
    '#theme' => 'openlayers_map',
    '#map_id' => $map_id,
    '#height' => $height,
    '#map' => $map,
    '#attached' => [
      'library' => $attached_libraries,
      'drupalSettings' => [
        'openlayers' => $js_settings,
      ],
    ],
    '#cache' => [
      'tags' => $cache_tags,
    ],
  ];
}