You are here

function search_api_location_plugin_exposed_form::pre_render in Search API Location 7

Overrides views_plugin_exposed_form::pre_render

File

includes/search_api_location_plugin_exposed_form.inc, line 156

Class

search_api_location_plugin_exposed_form
The search_api_location plugin to handle radius exposed filter forms.

Code

function pre_render($values) {
  $view = $this->view;
  if (isset($view->filter['radius'])) {
    $filter = $view->filter['radius'];
    if ($filter
      ->is_exposed()) {
      $identifier = $filter->options['expose']['identifier'];
      if (isset($view->exposed_data[$identifier])) {
        $exposed_data = $view->exposed_data[$identifier];
      }
    }
  }
  if (!isset($exposed_data['current_map'])) {
    return;
  }
  foreach ($values as $marker) {
    $marker = (array) $marker;
    if (isset($marker['location:latitude']) && isset($marker['location:longitude']) && isset($marker['title'])) {
      $exposed_data['current_map']['markers'][] = array(
        'latitude' => $marker['location:latitude'],
        'longitude' => $marker['location:longitude'],
        'text' => '<div class="gmap-popup">' . $marker['title'] . '</div>',
        'markername' => 'drupal',
        'offset' => 0,
        'opts' => array(
          'clickable' => TRUE,
        ),
      );
    }
  }
  $mapdefaults = gmap_defaults();
  $map = array_merge($mapdefaults, $exposed_data['current_map']);

  // Styles is a subarray.
  if (isset($exposed_data['current_map']['styles'])) {
    $map['styles'] = array_merge($mapdefaults['styles'], $exposed_data['current_map']['styles']);
  }
  gmap_map_cleanup($map);
  gmap_module_invoke('pre_theme_map', $map);
  unset($map["shapes"]);
  drupal_add_js(array(
    'gmap' => array(
      $exposed_data['current_map']['id'] => $map,
    ),
  ), 'setting');
}