You are here

protected function ip_geoloc_plugin_style_leaflet::fill_out_location_regions in IP Geolocation Views & Maps 7

1 call to ip_geoloc_plugin_style_leaflet::fill_out_location_regions()
ip_geoloc_plugin_style_leaflet::render in views/ip_geoloc_plugin_style_leaflet.inc
Transform the View result in a list of marker locations and render on map.

File

views/ip_geoloc_plugin_style_leaflet.inc, line 1698

Class

ip_geoloc_plugin_style_leaflet

Code

protected function fill_out_location_regions($locations) {

  // When an AddressField or hierarchical vocabulary is used, this normally
  // returns a single field name (as an array).
  if (empty($this->options['cluster_differentiator']['cluster_differentiator_fields'])) {
    return;
  }
  $region_fields = array();
  foreach ($this->options['cluster_differentiator']['cluster_differentiator_fields'] as $region_fieldname) {
    $region_field = field_info_field($region_fieldname);
    $region_fields[] = empty($region_field) ? $region_fieldname : $region_field;
  }
  if (empty($region_fields) || !reset($region_fields)) {
    return;
  }
  foreach ($this->view->result as $key => $row) {
    if (isset($locations[$key])) {
      $level = 1;
      foreach ($region_fields as $region_field) {
        $region_values = ip_geoloc_get_view_result($this, $region_field, $key);
        $field_type = isset($region_field['type']) ? $region_field['type'] : 'text';

        // If the region is multi-valued, use the last value. A particular
        // case is a hierarchical region taxonomy. We want the smallest of the
        // regions in the hierarchy.
        $region = $field_type == 'addressfield' ? $region_values : end($region_values);
        if (empty($region)) {

          // Make sure region is a string, not 0 or FALSE.
          $region = '';
        }
        $this
          ->_fill_out_location_region($field_type, $locations[$key], $region, $level);
      }
    }
  }
}