You are here

function _gmap_location_block_view in GMap Module 7.2

Same name and namespace in other branches
  1. 7 gmap_location.module \_gmap_location_block_view()

Location block view.

1 call to _gmap_location_block_view()
gmap_location_block_view in ./gmap_location.module
Implements hook_block_view().

File

./gmap_location.module, line 766
GMap Location module is a module to add some gmap funcationality based on location.modules information.

Code

function _gmap_location_block_view($nid) {
  $block = array();
  $node = node_load($nid);
  if (!empty($node->locations)) {
    $markertypes = variable_get('gmap_node_markers', array());
    $markers = array();
    $count = 0;
    foreach ($node->locations as $loc) {

      // @@@ Todo: Client side geocoding
      if (location_has_coordinates($loc)) {
        $count++;
        $markername = isset($markertypes[$node->type]) ? $markertypes[$node->type] : 'drupal';
        if (module_exists('gmap_taxonomy')) {
          $t = db_query('SELECT marker FROM {gmap_taxonomy_node} WHERE nid = :nid', array(
            ':nid' => $node->nid,
          ))
            ->fetchField();
          if (!empty($t)) {
            $markername = $t;
          }
        }
        $markertitle = $node->title;
        if (!empty($loc['name'])) {
          $markertitle = $loc['name'];
        }
        $markers[] = array(
          'latitude' => $loc['latitude'],
          'longitude' => $loc['longitude'],
          'markername' => $markername,
          'offset' => $count - 1,
          'opts' => array(
            'title' => $markertitle,
          ),
        );
      }
    }
    if (!empty($markers)) {
      $macro = variable_get('gmap_location_block_macro_' . $node->type, '');
      if (empty($macro)) {
        $macro = variable_get('gmap_location_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]');
      }
      $map = gmap_parse_macro($macro);
      $map['latitude'] = $markers[0]['latitude'];
      $map['longitude'] = $markers[0]['longitude'];
      $map['markers'] = $markers;
      $block['subject'] = t('Location', array(), array(
        'context' => 'geolocation',
      ));
      $element = array(
        '#type' => 'gmap',
        '#gmap_settings' => $map,
      );

      // @@@ Better theme
      $block['content'] = drupal_render($element);
    }
  }
  return $block;
}