You are here

public function GeolocationGeometry::getLocationsFromItem in Geolocation Field 8.3

Get locations from field item list.

Parameters

\Drupal\Core\Field\FieldItemInterface $fieldItem: Views field definition.

Return value

array Renderable locations.

Overrides DataProviderBase::getLocationsFromItem

File

modules/geolocation_geometry/src/Plugin/geolocation/DataProvider/GeolocationGeometry.php, line 299

Class

GeolocationGeometry
Provides GPX.

Namespace

Drupal\geolocation_geometry\Plugin\geolocation\DataProvider

Code

public function getLocationsFromItem(FieldItemInterface $fieldItem) {
  $shapes = $locations = [];
  $this
    ->parseGeoJson($fieldItem
    ->get('geojson')
    ->getString(), $locations, $shapes);
  $positions = [];
  foreach ($locations as $location) {
    switch ($location->type) {
      case 'Point':
        $position = [
          '#type' => 'geolocation_map_location',
          '#coordinates' => [
            'lat' => $location->coordinates[1],
            'lng' => $location->coordinates[0],
          ],
        ];
        $positions[] = $position;
        break;
      case 'MultiPoint':
        $container = [
          '#type' => 'container',
          '#attributes' => [
            'class' => [
              'geolocation-multipoint',
            ],
          ],
        ];
        foreach ($location->coordinates as $key => $point) {
          $position = [
            '#type' => 'geolocation_map_location',
            '#coordinates' => [
              'lat' => $point->coordinates[1],
              'lng' => $point->coordinates[0],
            ],
          ];
          $container[$key] = $position;
        }
        $positions[] = $container;
        break;
    }
  }
  return $positions;
}