public function OpenlayersService::openlayersProcessGeofield in Openlayers 8.4
Convert a geofield into an array of map points.
The map points can then be fed into $this->leafletRenderMap().
Parameters
mixed $items: A single value or array of geo values, each as a string in any of the supported formats or as an array of $item elements, each with a $item['wkt'] field.
Return value
array The return array.
File
- src/
OpenlayersService.php, line 169
Class
- OpenlayersService
- Provides an OpenlayersService class.
Namespace
Drupal\openlayersCode
public function openlayersProcessGeofield($items = []) {
if (!is_array($items)) {
$items = [
$items,
];
}
$data = [];
foreach ($items as $item) {
// Auto-detect and parse the format (e.g. WKT, JSON etc).
/* @var \GeometryCollection $geom */
if (!($geom = $this->geoPhpWrapper
->load(isset($item['wkt']) ? $item['wkt'] : $item))) {
continue;
}
$data[] = $geom;
}
return $data;
}