public function GeolocationGpx::getShapesFromItem in Geolocation Field 8.3
Get shapes from field item list.
Parameters
\Drupal\Core\Field\FieldItemInterface $fieldItem: Views field definition.
Return value
array Renderable shapes.
Overrides DataProviderBase::getShapesFromItem
File
- modules/
geolocation_gpx/ src/ Plugin/ geolocation/ DataProvider/ GeolocationGpx.php, line 170
Class
- GeolocationGpx
- Provides GPX.
Namespace
Drupal\geolocation_gpx\Plugin\geolocation\DataProviderCode
public function getShapesFromItem(FieldItemInterface $fieldItem) {
$settings = $this
->getSettings();
if (!$settings['return_tracks']) {
return [];
}
$gpxFile = $this
->getGpxFileFromItem($fieldItem);
if (empty($gpxFile)) {
\Drupal::logger('geolocation_gpx')
->warning('Reading file as GPX failed');
return [];
}
$positions = [];
foreach ($gpxFile->tracks as $track) {
$coordinates = '';
foreach ($track->segments as $segment) {
foreach ($segment->points as $point) {
$coordinates .= $point->latitude . ',' . $point->longitude . ' ';
}
}
$positions[] = [
'#type' => 'geolocation_map_polyline',
'#title' => $track->name,
'#coordinates' => $coordinates,
'#stroke_color' => $settings['track_stroke_color_randomize'] ? sprintf('#%06X', mt_rand(0, 0xffffff)) : $settings['track_stroke_color'],
'#stroke_width' => (int) $settings['track_stroke_width'],
'#stroke_opacity' => (double) $settings['track_stroke_opacity'],
];
}
return $positions;
}