public function DumperPluginManager::setAddressFieldFromGeojson in Geocoder 8.3
Same name and namespace in other branches
- 8.2 src/DumperPluginManager.php \Drupal\geocoder\DumperPluginManager::setAddressFieldFromGeojson()
Define an Address field value from a Geojson string.
Parameters
string $geojson: The GeoJson place string.
Return value
array An array of the Address field value.
File
- src/
DumperPluginManager.php, line 71
Class
- DumperPluginManager
- Provides a plugin manager for geocoder dumpers.
Namespace
Drupal\geocoderCode
public function setAddressFieldFromGeojson($geojson) : array {
$geojson_array = Json::decode($geojson);
$geojson_array['properties'] += [
'adminLevels' => '',
'streetName' => '',
'streetNumber' => '',
'postalCode' => '',
'locality' => '',
];
// Define an administrative_area line1 from adminLevels name, if existing.
$administrative_area = '';
if (!empty($geojson_array['properties']['adminLevels'])) {
$administrative_area = array_shift($geojson_array['properties']['adminLevels'])['name'];
}
// Define the address line1, adding a street number to it, if existing.
$address_line1 = $geojson_array['properties']['streetName'];
if (!empty($geojson_array['properties']['streetNumber'])) {
$address_line1 .= ' ' . $geojson_array['properties']['streetNumber'];
}
return [
'country_code' => $this
->setCountryFromGeojson($geojson),
'address_line1' => $address_line1,
'postal_code' => $geojson_array['properties']['postalCode'],
'locality' => $geojson_array['properties']['locality'],
'administrative_area' => $administrative_area,
];
}