You are here

public function LeafletService::leafletProcessGeofield in Leaflet 8

Same name and namespace in other branches
  1. 2.1.x src/LeafletService.php \Drupal\leaflet\LeafletService::leafletProcessGeofield()
  2. 2.0.x src/LeafletService.php \Drupal\leaflet\LeafletService::leafletProcessGeofield()

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/LeafletService.php, line 183

Class

LeafletService
Provides a LeafletService class.

Namespace

Drupal\leaflet

Code

public function leafletProcessGeofield($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[] = $this
      ->leafletProcessGeometry($geom);
  }
  return $data;
}