You are here

function geocoder_widget_resolve_deltas in Geocoder 7

Geocoder Widget - Resolve Deltas.

Given a list of geometries, and user configuration on how to handle deltas, we created a list of items to be inserted into the fields.

1 call to geocoder_widget_resolve_deltas()
geocoder_widget_get_field_value in ./geocoder.widget.inc
Get a field's value based on geocoded data.

File

./geocoder.widget.inc, line 538
geocoder.widget.inc

Code

function geocoder_widget_resolve_deltas($geometries, $delta_handling = 'default', $target_info) {
  $values = array();

  // Default delta handling: just pass one delta to the next.
  if ($delta_handling === 'default') {
    foreach ($geometries as $geometry) {
      $values[] = geocoder_widget_values_from_geometry($geometry, $target_info);
    }
  }

  // Single-to-multiple handling - if we can, explode out the component
  // geometries.
  if ($delta_handling === 's_to_m' || $delta_handling === 'c_to_m') {
    $type = $geometries[0]
      ->geometryType();
    $geometry_types = array(
      'MultiPoint',
      'MultiLineString',
      'MultiPolygon',
      'GeometryCollection',
    );
    if (in_array($type, $geometry_types, TRUE)) {
      $components = $geometries[0]
        ->getComponents();
      foreach ($components as $component) {
        $values[] = geocoder_widget_values_from_geometry($component, $target_info);
      }
    }
    else {
      $values[] = geocoder_widget_values_from_geometry($geometries[0], $target_info);
    }
  }

  // For multiple-to-single handling, run it though geometryReduce.
  if ($delta_handling === 'm_to_s' || $delta_handling === 'c_to_s') {
    $reduced_geom = geoPHP::geometryReduce($geometries);
    $values[] = geocoder_widget_values_from_geometry($reduced_geom, $target_info);
  }
  return $values;
}