protected function GeofieldMapFieldTrait::getGeoJsonData in Geofield Map 8.2
Same name and namespace in other branches
- 8 src/GeofieldMapFieldTrait.php \Drupal\geofield_map\GeofieldMapFieldTrait::getGeoJsonData()
Transform Geofield data into Geojson features.
Parameters
mixed $items: The Geofield Data Values.
int $entity_id: The Entity Id.
string $description: The description value.
string $tooltip: The tooltip value.
array $additional_data: Additional data to be added to the feature properties, i.e. GeofieldGoogleMapViewStyle will add row fields (already rendered).
Return value
array The data array for the current feature, including Geojson and additional data.
2 calls to GeofieldMapFieldTrait::getGeoJsonData()
- 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
- src/
GeofieldMapFieldTrait.php, line 336
Class
- GeofieldMapFieldTrait
- Class GeofieldMapFieldTrait.
Namespace
Drupal\geofield_mapCode
protected function getGeoJsonData($items, $entity_id, $description = NULL, $tooltip = NULL, array $additional_data = NULL) {
$data = [];
foreach ($items as $delta => $item) {
$value = $item instanceof GeofieldItem ? $item->value : $item;
try {
$geometry = $this->geoPhpWrapper
->load($value);
} catch (\Exception $exception) {
$geometry = FALSE;
}
if ($geometry instanceof \Geometry) {
$datum = [
"type" => "Feature",
"geometry" => json_decode($geometry
->out('json')),
];
$datum['properties'] = [
// If a multivalue field value with the same index exist, use this,
// else use the first item as fallback.
'description' => isset($description[$delta]) ? $description[$delta] : (isset($description[0]) ? $description[0] : NULL),
'tooltip' => $tooltip,
'data' => $additional_data,
'entity_id' => $entity_id,
];
$data[] = $datum;
}
}
return $data;
}