private function GeofieldWidget::initialDataToGeomFeatures in Openlayers 7.3
Convert an array of WKT into a Geometry and features.
Return value
array An array containing the Geometry and the features.
Throws
\exception
2 calls to GeofieldWidget::initialDataToGeomFeatures()
- GeofieldWidget::postBuild in modules/
openlayers_geofield/ src/ Plugin/ Component/ GeofieldWidget/ GeofieldWidget.php - Invoked after an objects render array is built.
- GeofieldWidget::preBuild in modules/
openlayers_geofield/ src/ Plugin/ Component/ GeofieldWidget/ GeofieldWidget.php - Invoked before an objects render array is built.
File
- modules/
openlayers_geofield/ src/ Plugin/ Component/ GeofieldWidget/ GeofieldWidget.php, line 131 - Component: GeofieldWidget.
Class
- GeofieldWidget
- Class GeofieldWidget.
Namespace
Drupal\openlayers_geofield\Plugin\Component\GeofieldWidgetCode
private function initialDataToGeomFeatures() {
geophp_load();
$initial_data = $this
->getOption('initialData', '');
$geom = new \GeometryCollection(array());
$features = array();
// Process initial data. Ensure it's WKT.
if (isset($initial_data)) {
$geoms = array();
// Process strings and arrays likewise.
if (!is_array($initial_data)) {
$initial_data = array(
$initial_data,
);
}
foreach ($initial_data as $delta => $item) {
if (is_array($item) && array_key_exists('geom', $item)) {
$geoms[] = geoPHP::load($item['geom']);
}
}
$geom = geoPHP::geometryReduce($geoms);
// If we could parse the geom process further.
if ($geom && !$geom
->isEmpty()) {
if (in_array($geom
->getGeomType(), array(
'MultiPoint',
'MultiLineString',
'MultiPolygon',
'GeometryCollection',
))) {
foreach ($geom
->getComponents() as $component) {
$features[] = array(
'wkt' => $component
->out('wkt'),
'projection' => 'EPSG:4326',
);
}
}
else {
$features[] = array(
'wkt' => $geom
->out('wkt'),
'projection' => 'EPSG:4326',
);
}
}
}
return array(
'geom' => $geom,
'features' => $features,
);
}