You are here

function _gmap_location_author_block_view in GMap Module 7

Same name and namespace in other branches
  1. 7.2 gmap_location.module \_gmap_location_author_block_view()
1 call to _gmap_location_author_block_view()
gmap_location_block_view in ./gmap_location.module
Implement hook_block_view().

File

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

Code

function _gmap_location_author_block_view($nid) {
  $block = array();
  $node = node_load($nid);
  if (in_array($node->type, variable_get('gmap_location_author_block_types', array()))) {
    $markername = variable_get('gmap_location_author_block_marker', 'drupal');
    $author = user_load($node->uid);
    $markers = array();
    $count = 0;
    foreach ($author->locations as $loc) {

      // @@@ Todo: Client side geocoding
      if ($loc['latitude'] || $loc['longitude']) {
        $count++;
      }
      $markertitle = $author->name;
      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_author_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('Author Location');
      $element = array(
        '#type' => 'gmap',
        '#gmap_settings' => $map,
      );
      $block['content'] = drupal_render($element);

      // @@@ Better theme
    }
  }
  return $block;
}