protected function GeofieldMapFieldTrait::getGeoJsonData in Geofield Map 8
Same name and namespace in other branches
- 8.2 src/GeofieldMapFieldTrait.php \Drupal\geofield_map\GeofieldMapFieldTrait::getGeoJsonData()
Transform Geofield data into Geojson features.
Parameters
mixed $items: The Geofield Data Values.
string $description: The description value.
mixed $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 348
Class
- GeofieldMapFieldTrait
- Class GeofieldMapFieldTrait.
Namespace
Drupal\geofield_mapCode
protected function getGeoJsonData($items, $description = NULL, $additional_data = NULL) {
$data = [];
foreach ($items as $delta => $item) {
/* @var \Point $geometry */
if (is_a($item, '\\Drupal\\geofield\\Plugin\\Field\\FieldType\\GeofieldItem') && isset($item->value)) {
$geometry = $this->geoPhpWrapper
->load($item->value);
}
elseif (preg_match('/^(POINT).*\\(.*.*\\)$/', $item)) {
$geometry = $this->geoPhpWrapper
->load($item);
}
if (isset($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),
'data' => $additional_data,
];
$data[] = $datum;
}
}
return $data;
}