public function KmlNormalizer::denormalize in farmOS 2.x
File
- modules/
core/ kml/ src/ Normalizer/ KmlNormalizer.php, line 108
Class
- KmlNormalizer
- Normalizes GeometryWrapper objects into array for the Kml encoder.
Namespace
Drupal\farm_kml\NormalizerCode
public function denormalize($data, $type, $format = NULL, array $context = []) {
// Build array of geometry wrappers to return.
$geometries = [];
foreach ($data as $placemark) {
// Skip if there is no XML key.
if (empty($placemark['xml'])) {
continue;
}
// Load KML into a Geometry object.
$geometry = $this->geoPHP
->load($placemark['xml'], 'kml');
// Build properties.
$properties = [];
// Add an ID if provided.
if (isset($placemark['@attributes']['id'])) {
$properties['id'] = $placemark['@attributes']['id'];
}
// Add standard KML properties if included.
$keys = $this
->supportedProperties();
foreach ($keys as $property_name) {
if (isset($placemark[$property_name])) {
$properties[$property_name] = $placemark[$property_name];
}
}
$wrapper = new GeometryWrapper($geometry, $properties);
$geometries[] = $wrapper;
}
return $geometries;
}