You are here

public function GeolocationGpx::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_gpx/src/Plugin/geolocation/DataProvider/GeolocationGpx.php, line 208

Class

GeolocationGpx
Provides GPX.

Namespace

Drupal\geolocation_gpx\Plugin\geolocation\DataProvider

Code

public function getLocationsFromItem(FieldItemInterface $fieldItem) {
  $settings = $this
    ->getSettings();
  if (!$settings['return_waypoints']) {
    return [];
  }
  $gpxFile = $this
    ->getGpxFileFromItem($fieldItem);
  if (empty($gpxFile)) {
    \Drupal::logger('geolocation_gpx')
      ->warning('Reading file as GPX failed');
    return [];
  }
  $positions = [];
  foreach ($gpxFile->waypoints as $waypoint) {
    $positions[] = [
      '#type' => 'geolocation_map_location',
      '#title' => $waypoint->name,
      '#coordinates' => [
        'lat' => $waypoint->latitude,
        'lng' => $waypoint->longitude,
      ],
    ];
  }
  return $positions;
}