You are here

function leaflet_widget_widget_prepare_items in Leaflet Widget for Geofield 7.2

Same name and namespace in other branches
  1. 7 leaflet_widget.module \leaflet_widget_widget_prepare_items()

Prepares the field items - return a geoJSON FeatureCollection.

Parameters

array $items: The items to prepare as provided by hook_field_widget_form().

string|NULL $geom_type: The geometry type the geometry data are given. Set to NULL to use autodetect. It's recommended to define the type to speed up processing.

Return value

array A geoJSON FeatureCollection.

1 call to leaflet_widget_widget_prepare_items()
leaflet_widget_field_widget_form in ./leaflet_widget.module
Implements hook_field_widget_form().

File

./leaflet_widget.module, line 231
Leaflet widget module for Geofield.

Code

function leaflet_widget_widget_prepare_items($items, $geom_type = 'wkt') {
  $features = array();
  foreach ($items as $item) {
    if (isset($item['geom'])) {

      // Set geom type to NULL - it can be wkt or wkb depending on the form
      // state.
      $features[] = leaflet_widget_geojson_feature($item['geom'], array(), $geom_type);
    }
  }
  return leaflet_widget_geojson_feature_collection($features);
}