You are here

gmap_location.module in GMap Module 7

GMap Location module is a module to add some gmap funcationality based on location.modules information.

The main functions are to provide a map showing all of the nodes or users that have location information on a map.

File

gmap_location.module
View source
<?php

/**
 * @file
 * GMap Location module is a module to add some gmap funcationality based on location.modules information.
 *
 * The main functions are to provide a map showing all of the nodes or users that have location information on a map.
 */

/**
 * Implementation of hook_theme().
 */
function gmap_location_theme() {
  return array(
    'gmap_location_user_page' => array(
      'variables' => array(
        'header' => '',
        'map' => '',
        'footer' => '',
      ),
    ),
    'gmap_location_node_page' => array(
      'variables' => array(
        'count' => 0,
        'header' => '',
        'map' => '',
        'footer' => '',
      ),
    ),
    // @@@ Test this one thoroughly.
    'gmap_location_infowindow_node' => array(
      'pattern' => 'gmap_location_infowindow_node__',
      'variables' => array(
        'node' => NULL,
        'opt' => NULL,
      ),
    ),
    'gmap_location_infowindow_user' => array(
      'variables' => array(
        'account' => NULL,
      ),
    ),
  );
}

/**
 * Implementation of hook_permission().
 */
function gmap_location_permission() {
  return array(
    'view node map' => array(
      'title' => t('View node map'),
      'description' => t('See the sitewide node map.'),
    ),
    'view user map' => array(
      'title' => t('View user map'),
      'description' => t('See the sitewide user map.'),
    ),
    'view user location details' => array(
      'title' => t('View user location details'),
      'description' => t('See the users associated with markers on the sitewide user map.'),
    ),
  );
}

/**
 * Get the user map variable defaults.
 */
function _gmap_location_user_map_defaults() {
  return array(
    'macro' => '[gmap |id=usermap|center=40,0|zoom=3|width=100%|height=400px]',
    'header' => 'This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.',
    'footer' => '',
    'markermode' => 1,
  );
}

/**
 * Get the node map variable defaults.
 */
function _gmap_location_node_map_defaults() {
  return array(
    'macro' => '[gmap |id=nodemap|center=40,0|zoom=3|width=100%|height=400px]',
    'header' => 'This map illustrates the locations of the nodes on this website. Each marker indicates a node associated with a specific location.',
    'footer' => '',
    'markermode' => 1,
  );
}

/**
 * Implementation of hook_menu().
 */
function gmap_location_menu() {
  $items['map/user'] = array(
    'type' => MENU_NORMAL_ITEM,
    'title' => 'User locations',
    'access arguments' => array(
      'view user map',
    ),
    'page callback' => 'gmap_location_user_page',
  );
  $items['map/user/load'] = array(
    'type' => MENU_CALLBACK,
    'access arguments' => array(
      'view user map',
    ),
    'page callback' => 'gmap_location_user_point',
  );
  $items['map/node'] = array(
    'type' => MENU_NORMAL_ITEM,
    'title' => 'Node locations',
    'access arguments' => array(
      'view node map',
    ),
    'page callback' => 'gmap_location_node_page',
  );
  $items['map/node/load/%node/%'] = array(
    'type' => MENU_CALLBACK,
    'access arguments' => array(
      'view node map',
    ),
    'page callback' => 'gmap_location_node_point',
    'page arguments' => array(
      3,
      4,
    ),
  );
  $items['admin/config/services/gmap_location'] = array(
    'type' => MENU_NORMAL_ITEM,
    'title' => 'GMap Location',
    'access arguments' => array(
      'administer site configuration',
    ),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'gmap_location_admin_settings',
    ),
    'description' => 'Configure GMap Location settings.',
  );
  return $items;
}

/**
 * Draws a page with a google map that has all of the site users.
 */
function gmap_location_user_page() {
  $markertypes = variable_get('gmap_role_markers', array(
    DRUPAL_AUTHENTICATED_RID => 'drupal',
  ));
  $usermap = variable_get('gmap_user_map', _gmap_location_user_map_defaults());
  $map = array_merge(gmap_defaults(), gmap_parse_macro($usermap['macro']));
  $mode = $usermap['markermode'];
  $map['rmtcallback'] = url('map/user/load');
  $map['markermode'] = $usermap['markermode'];

  // Find the highest rid, if available, for each user with a location.
  $result = db_query("\n    SELECT\n      u.name, MAX(r.rid) as role, i.uid, i.lid, l.latitude, l.longitude\n    FROM\n      {users} u\n    INNER JOIN\n      {location_instance} i\n      ON\n        u.uid = i.uid\n    INNER JOIN\n      {location} l\n      ON\n        i.lid = l.lid\n    LEFT JOIN\n      {users_roles} r\n      ON\n        i.uid = r.uid\n    WHERE\n      u.status = 1\n    AND\n      u.access != 0\n    AND\n      (l.latitude != 0 OR l.longitude != 0)\n    GROUP BY\n      i.uid, i.lid, u.name, l.latitude, l.longitude");

  // The u.name, l.latitude, and l.longitude in the GROUP BY are needed for
  // PostgreSQL.
  foreach ($result as $row) {

    // Determine marker type to show.
    $marker = $markertypes[DRUPAL_AUTHENTICATED_RID];
    if ($row->role && isset($markertypes[$row->role])) {
      $marker = $markertypes[$row->role];
    }

    // Users with the 'view user location details' permission are allowed to see who
    // each marker represents.
    if (user_access('view user location details')) {
      if ($mode == 1) {
        $newmarker['rmt'] = $row->uid;
      }
      elseif ($mode == 2) {
        $newmarker['link'] = url('user/' . $row->uid);
      }
      $newmarker['latitude'] = $row->latitude;
      $newmarker['longitude'] = $row->longitude;
      $newmarker['markername'] = $marker;
      $newmarker['opts']['title'] = check_plain($row->name);
    }
    else {
      $newmarker['latitude'] = $row->latitude;
      $newmarker['longitude'] = $row->longitude;
      $newmarker['markername'] = $marker;
    }
    $map['markers'][] = $newmarker;
  }

  // @@@ Move to gmap_addons.

  /*
    if (user_access('view user location details') && function_exists('buddylist_get_buddies') && count($locationbyuser)>0) {
      //create lines for buddies
      if (!isset($thismap['shapes'])) {
        $thismap['shapes']=array();
      }
      ksort($locationbyuser);
      foreach ($locationbyuser as $key => $value) {
        $buddies= buddylist_get_buddies($key);
        foreach ($buddies as $bkey => $bvalue) {
          if ($bkey > $key && isset($locationbyuser[$bkey])) {
            $thismap['shape'][] = array(
              'points' => array($locationbyuser[$key], $locationbyuser[$bkey]),
              'type' => 'line'
            );
          }
        }
      }
    }
  */
  $element = array(
    '#type' => 'gmap',
    '#gmap_settings' => $map,
  );
  return theme('gmap_location_user_page', array(
    'header' => $usermap['header'],
    'map' => drupal_render($element),
    'footer' => $usermap['footer'],
  ));
}

/**
 * AHAH callback for getting the contents of a user point popup.
 */
function gmap_location_user_point() {
  $uid = arg(3);
  if (is_numeric($uid) && ($account = user_load($uid))) {
    echo theme('gmap_location_infowindow_user', array(
      'account' => $account,
    ));
    exit;
  }
}

/**
 * Theme function for displaying the user page.
 */
function theme_gmap_location_user_page(&$vars) {
  $header = $vars['header'];
  $map = $vars['map'];
  $footer = $vars['footer'];
  global $user;
  $output = "<p>{$header}</p>\n<p>{$map}</p>\n<p>{$footer}</p>";
  if ($user->uid > 0) {
    $output .= '<p>' . t('To add/change your location to the user map, <a href="@url">edit your location</a>.', array(
      '@url' => url('user/' . $user->uid . '/edit'),
    )) . '</p>';
  }
  return $output;
}

/**
 * Draws a page with a google map with the node on it, or if no node is set all of the nodes on it.
 *
 * @param $nid
 *   The node nid to draw on the map.
 *   If this is not set, or is null then all of the nodes will be drawn.
 */
function gmap_location_node_page($nid = NULL) {
  $nodemap = variable_get('gmap_node_map', _gmap_location_node_map_defaults());
  $markertypes = variable_get('gmap_node_markers', array());
  $map = array_merge(gmap_defaults(), gmap_parse_macro($nodemap['macro']));
  $mode = $nodemap['markermode'];
  $map['rmtcallback'] = url('map/node/load');
  $map['markermode'] = $nodemap['markermode'];
  if (!isset($map['markers']) || !is_array($map['markers'])) {
    $map['markers'] = array();
  }
  $query = db_select('node', 'n');
  $query
    ->condition('n.status', 1)
    ->condition(db_or()
    ->condition('l.latitude', 0, '!=')
    ->condition('l.longitude', 0, '!='))
    ->fields('n', array(
    'nid',
    'type',
    'title',
  ))
    ->fields('l', array(
    'latitude',
    'longitude',
  ));
  $query
    ->innerjoin('location_instance', 'i', 'n.vid = i.vid');
  $query
    ->innerjoin('location', 'l', 'l.lid = i.lid');
  if (is_numeric($nid) && $nid > 0) {
    $query
      ->condition('n.nid', $nid);
  }
  if (module_exists('gmap_taxonomy')) {
    $query
      ->fields('m', array(
      'marker',
    ))
      ->leftjoin('gmap_taxonomy_node', 'm', 'n.nid = m.nid');
  }
  $query
    ->addTag('node_access');
  $result = $query
    ->execute();
  $count = 0;
  foreach ($result as $row) {
    $count++;
    $newmarker = array();
    if ($mode == 1) {

      // Popup
      $newmarker['rmt'] = $row->nid . '/0';
    }
    elseif ($mode == 2) {

      // Link
      $newmarker['link'] = url('node/' . $row->nid);
    }
    $newmarker['latitude'] = $row->latitude;
    $newmarker['longitude'] = $row->longitude;
    $newmarker['markername'] = isset($markertypes[$row->type]) ? $markertypes[$row->type] : 'drupal';
    if (isset($row->marker) && !empty($row->marker)) {
      $newmarker['markername'] = $row->marker;
    }
    $newmarker['opts']['title'] = $row->title;
    $map['markers'][] = $newmarker;
  }

  // Special stuff for single marker
  if ($count == 1) {

    // Center map on only marker.
    $map['latitude'] = $map['markers'][0]['latitude'];
    $map['longitude'] = $map['markers'][0]['longitude'];

    // Autoclick in single marker case.
    if ($mode == 1) {
      $map['markers'][0]['autoclick'] = TRUE;
    }
  }

  // Special cases for single node view.
  if (is_numeric($nid) && ($node = node_load($nid))) {

    // Organic groups. Group nodes are displayed as a map of the users who belong to the group.
    if (user_access('view user location details') && function_exists('og_is_group_type') && og_is_group_type($node->type)) {
      $rolemarkers = variable_get('gmap_role_markers', array());
      $map['markers'] = array();

      // Reset markers.
      $result = db_query("\n        SELECT\n          MAX(r.rid) as role, i.uid, l.latitude, l.longitude\n        FROM\n          {og_uid} o\n        INNER JOIN {location_instance} i\n          ON i.uid = o.uid\n        INNER JOIN {location} l\n          ON l.lid = i.lid\n        LEFT JOIN {users_roles} r\n          ON i.uid = r.uid\n        WHERE\n          o.nid = :nid\n        AND\n          o.is_active >= 1\n        AND\n          (l.latitude != 0 OR l.longitude != 0)\n        GROUP BY\n          o.uid", array(
        ':nid' => $nid,
      ));
      foreach ($result as $row) {
        $newmarker = array();
        $newmarker['rmt'] = $nid . '/' . $row->uid;

        // Determine marker type to show.
        $newmarker['markername'] = $markertypes[DRUPAL_AUTHENTICATED_RID];
        if ($row->role && isset($rolemarkers[$row->role])) {
          $newmarker['markername'] = $rolemarkers[$row->role];
        }
        $newmarker['latitude'] = $row->latitude;
        $newmarker['longitude'] = $row->longitude;
        $map['markers'][] = $newmarker;
      }
    }
  }
  $element = array(
    '#type' => 'gmap',
    '#gmap_settings' => $map,
  );
  return theme('gmap_location_node_page', array(
    'count' => $count,
    'header' => $nodemap['header'],
    'map' => drupal_render($element),
    'footer' => $nodemap['footer'],
  ));
}

/**
 * AHAH callback for getting the contents of a node point popup.
 */
function gmap_location_node_point($node, $opt) {
  $output = '';

  // @@@ Make sure $node->type is an ok thing to do here..
  echo theme(array(
    "gmap_location_infowindow_node__{$node->type}",
    'gmap_location_infowindow_node',
  ), array(
    'node' => $node,
    'opt' => $opt,
  ));

  // exit();
  return;
}

/**
 * Theme function for displaying the node page.
 */
function theme_gmap_location_node_page(&$vars) {
  $count = $vars['count'];
  $header = $vars['header'];
  $map = $vars['map'];
  $footer = $vars['footer'];
  $output = '';
  if ($header) {
    $output .= "<p>{$header}</p>";
  }
  $output .= $map;
  if ($footer) {
    $output .= "<p>{$footer}</p>";
  }
  return $output;
}

/**
 * Admin Settings Page
 *
 */
function gmap_location_admin_settings() {
  $form['user'] = array(
    '#type' => 'fieldset',
    '#title' => t('User settings'),
  );

  // gmap_user_map defaults
  $temp = variable_get('gmap_user_map', _gmap_location_user_map_defaults());
  $form['user']['gmap_user_map'] = array(
    '#type' => 'fieldset',
    '#title' => t('User Map (<em>map/user</em>)'),
    '#tree' => TRUE,
  );
  $form['user']['gmap_user_map']['macro'] = array(
    '#type' => 'textfield',
    '#title' => t('Macro'),
    '#default_value' => $temp['macro'],
    '#size' => 50,
    '#maxlength' => 500,
    '#description' => t('The gmap macro where the user information will be diplayed on.'),
  );
  $form['user']['gmap_user_map']['header'] = array(
    '#type' => 'textarea',
    '#title' => t('Page header'),
    '#description' => t('Text at the top of the user map.', array(
      '@url' => url('map/user'),
    )),
    '#default_value' => $temp['header'],
    '#cols' => 50,
    '#rows' => 6,
  );
  $form['user']['gmap_user_map']['footer'] = array(
    '#type' => 'textarea',
    '#title' => t('Page footer'),
    '#description' => t('Text at the bottom of the user map.'),
    '#default_value' => $temp['footer'],
    '#cols' => 50,
    '#rows' => 6,
  );
  $form['user']['gmap_user_map']['markermode'] = array(
    '#type' => 'radios',
    '#title' => t('Marker action'),
    '#description' => t('Perform this action when a marker is clicked.'),
    '#options' => array(
      t('Do nothing'),
      t('Open info window'),
      t('Open link'),
    ),
    '#default_value' => $temp['markermode'],
  );

  // Option to use a different marker for each role
  $form['user']['gmap_role_markers'] = array(
    '#type' => 'fieldset',
    '#title' => t('Markers per role'),
    '#description' => t('Choose a marker to represent each user role on the user map. If a user belongs to multiple roles, the marker for the highest Role ID will be used.'),
    '#tree' => TRUE,
  );

  // Retrieve and sort list of roles, sans anonymous user
  $roles = user_roles(TRUE);

  //asort($roles);
  $defaults = variable_get('gmap_role_markers', array());

  // Create a selection box per role
  foreach ($roles as $rid => $role) {
    $form['user']['gmap_role_markers'][$rid] = array(
      '#type' => 'gmap_markerchooser',
      '#title' => t('%role (Role ID: %rid)', array(
        '%role' => $role,
        '%rid' => $rid,
      )),
      '#default_value' => isset($defaults[$rid]) ? $defaults[$rid] : 'drupal',
    );
  }
  $form['node'] = array(
    '#type' => 'fieldset',
    '#title' => t('Node settings'),
  );

  // gmap_node_map defaults
  $temp = variable_get('gmap_node_map', _gmap_location_node_map_defaults());
  $form['node']['gmap_node_map'] = array(
    '#type' => 'fieldset',
    '#title' => t('Node Map (<em>map/node</em>)'),
    '#tree' => TRUE,
  );
  $form['node']['gmap_node_map']['macro'] = array(
    '#type' => 'textfield',
    '#title' => t('Macro'),
    '#default_value' => $temp['macro'],
    '#size' => 50,
    '#maxlength' => 500,
    '#description' => t('The gmap macro where the node information will be diplayed on.'),
  );
  $form['node']['gmap_node_map']['header'] = array(
    '#type' => 'textarea',
    '#title' => t('Page header'),
    '#description' => t('Text at the top of the node map.'),
    '#default_value' => $temp['header'],
    '#cols' => 50,
    '#rows' => 6,
  );
  $form['node']['gmap_node_map']['footer'] = array(
    '#type' => 'textarea',
    '#title' => t('Page footer'),
    '#description' => t('Text at the bottom of the node map.'),
    '#default_value' => $temp['footer'],
    '#cols' => 50,
    '#rows' => 6,
  );
  $form['node']['gmap_node_map']['markermode'] = array(
    '#type' => 'radios',
    '#title' => t('Marker action'),
    '#description' => t('Perform this action when a marker is clicked.'),
    '#options' => array(
      t('Do nothing'),
      t('Open info window'),
      t('Open link'),
    ),
    '#default_value' => $temp['markermode'],
  );

  // Option to use a different marker for each content type.
  $form['node']['gmap_node_markers'] = array(
    '#type' => 'fieldset',
    '#title' => t('Markers per content type'),
    '#description' => t('Choose a marker to represent each type of content on the node map.'),
    '#tree' => TRUE,
  );
  $ntypes = node_type_get_types();
  $defaults = variable_get('gmap_node_markers', array());
  foreach ($ntypes as $key => $value) {
    $form['node']['gmap_node_markers'][$key] = array(
      '#type' => 'gmap_markerchooser',
      '#title' => t('Marker for %type', array(
        '%type' => $value->name,
      )),
      '#default_value' => isset($defaults[$key]) ? $defaults[$key] : 'drupal',
    );
    $settings = variable_get("location_settings_node_{$key}", FALSE);
    if (!(isset($settings['multiple']['max']) && $settings['multiple']['max'] || variable_get("location_maxnum_{$key}", 0))) {
      $form['node']['gmap_node_markers'][$key]['#description'] = t('This content type is not currently Location enabled.');
    }
  }
  return system_settings_form($form);
}

/**
 * Implement hook_block_info().
 */
function gmap_location_block_info() {
  return array(
    0 => array(
      'info' => t('Location map'),
      'cache' => DRUPAL_NO_CACHE,
    ),
    1 => array(
      'info' => t('Author map'),
      'cache' => DRUPAL_NO_CACHE,
    ),
  );
}

/**
 * Implement hook_block_configure().
 */
function gmap_location_block_configure($delta = '') {
  if ($delta == 0) {

    // Location map
    $form['gmap_location_block_macro'] = array(
      '#type' => 'textfield',
      '#title' => t('Map Macro'),
      '#size' => 60,
      '#maxlength' => 500,
      '#description' => t('A macro to be used as a base map for the location block.  This map will be recentered on the location, so the center is not that important. <p>Alternate base map macros can be entered for a specific node type below.'),
      '#default_value' => variable_get('gmap_location_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]'),
    );
    $ntypes = node_type_get_types();
    foreach ($ntypes as $key => $value) {
      $settings = variable_get("location_settings_node_{$key}", FALSE);
      if (isset($settings['multiple']['max']) && $settings['multiple']['max'] || variable_get("location_maxnum_{$key}", 0)) {
        $form["gmap_location_block_macro_{$key}"] = array(
          '#type' => 'textfield',
          '#title' => t('Map Macro for %type', array(
            '%type' => $value->name,
          )),
          '#size' => 60,
          '#maxlength' => 500,
          '#default_value' => variable_get("gmap_location_block_macro_{$key}", ''),
        );
      }
    }
  }
  elseif ($delta == 1) {

    // Author map
    $form['gmap_location_author_block_macro'] = array(
      '#type' => 'textfield',
      '#title' => t('Map Macro'),
      '#size' => 60,
      '#maxlength' => 500,
      '#description' => t('A macro to be used as a base map for the location block author.  This map will be recentered on the location, so the center is not that important.'),
      '#default_value' => variable_get('gmap_location_author_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]'),
    );
    $form['gmap_location_author_block_types'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Enable author block for the following content types'),
      '#options' => array_map('check_plain', node_type_get_names()),
      '#default_value' => variable_get('gmap_location_author_block_types', array()),
    );
    $form['gmap_location_author_block_marker'] = array(
      '#type' => 'gmap_markerchooser',
      '#title' => t('Marker to use for author map'),
      '#default_value' => variable_get('gmap_location_author_block_marker', 'drupal'),
    );
  }
  return $form;
}

/**
 * Implement hook_block_save().
 */
function gmap_location_block_save($delta = '', $edit = array()) {
  if ($delta == 0) {

    // Save macro, if customized.
    $macro = trim($edit['gmap_location_block_macro']);
    if ($macro == '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]' || empty($macro)) {

      // If the user doesn't customize the variable, don't set it.
      // This saves a lot of headache in the future.
      variable_del('gmap_location_block_macro');
    }
    else {
      variable_set('gmap_location_block_macro', $macro);
    }

    // Save node type specific macros.
    $ntypes = node_type_get_types();
    foreach ($ntypes as $key => $value) {
      $settings = variable_get("location_settings_node_{$key}", FALSE);
      if (isset($settings['multiple']['max']) && $settings['multiple']['max'] || variable_get("location_maxnum_{$key}", 0)) {
        $val = trim($edit["gmap_location_block_macro_{$key}"]);
        if (empty($val)) {
          variable_del("gmap_location_block_macro_{$key}");
        }
        else {
          variable_set('gmap_location_block_macro_' . $key, $edit['gmap_location_block_macro_' . $key]);
        }
      }
    }
  }
  elseif ($delta == 1) {

    // Save macro, if customized.
    $macro = trim($edit['gmap_location_author_block_macro']);
    if ($macro == '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]' || empty($macro)) {

      // If the user doesn't customize the variable, don't set it.
      // This saves a lot of headache in the future.
      variable_del('gmap_location_author_block_macro');
    }
    else {
      variable_set('gmap_location_author_block_macro', $macro);
    }

    // Save "enabled on" types.
    variable_set('gmap_location_author_block_types', array_keys(array_filter($edit['gmap_location_author_block_types'])));

    // Save marker.
    variable_set('gmap_location_author_block_marker', $edit['gmap_location_author_block_marker']);
  }
}

/**
 * Implement hook_block_view().
 */
function gmap_location_block_view($delta = '') {
  switch ($delta) {
    case 0:
      if (arg(0) == 'node' && is_numeric(arg(1))) {
        return _gmap_location_block_view(arg(1));
      }
      break;
    case 1:
      if (arg(0) == 'node' && is_numeric(arg(1))) {
        return _gmap_location_author_block_view(arg(1));
      }
      break;
  }
}
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');
      $element = array(
        '#type' => 'gmap',
        '#gmap_settings' => $map,
      );
      $block['content'] = drupal_render($element);

      // @@@ Better theme
    }
  }
  return $block;
}
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;
}

/**
 * Default theme for image nodes.
 * @@@ Todo: Move to a tpl.
 */
function theme_gmap_location_infowindow_node__image(&$vars) {
  $node = $vars['node'];
  $out = '<a href="' . url('node/' . $node->nid) . '">' . check_plain($node->title) . '</a> <br>';
  $out .= image_display($node, 'thumbnail');
  return $out;
}

// @@@ This is not thoroughly tested for 5.x yet!
// @@@ Or 6.x for that matter!
// @@@ 7.x is right out!

/**
 * Theme an Organic Groups node info window.
 */
function theme_gmap_location_infowindow_node__og(&$vars) {
  $node = $vars['node'];
  $opt = $vars['opt'];
  if (is_numeric($opt) && ($account = user_load($opt))) {
    $output = theme('user_picture', array(
      'account' => $account,
    ));
    $output .= theme('username', array(
      'account' => $account,
    ));
    echo $output;
    exit;
  }
}

// @@@ This is completely wrong.

/**
 * Theme a node info window.
 * @ingroup themable
 */
function theme_gmap_location_infowindow_node(&$vars) {
  $node = $vars['node'];

  // Allow a module (where the module name matches the node type name)
  // to define a custom display for the google map label.
  // For this to work with flexinode defined data types,
  // a module called 'flexinode_#.module' in your site's module
  // directory and add theme_hook_gmapnodelabel($node, $location) to it.
  // Be sure to enable your 'flexinode_#.module'.
  return '<div class="gmapnodelabel gmapnodelabel-' . drupal_clean_css_identifier($node->type) . '">' . strtr(drupal_render(node_view($node, 'teaser')), "'\n\r", '"  ') . '</div>';

  // make sure it all goes on one line.
}

/**
 * Default theme for user infowindows.
 */
function theme_gmap_location_infowindow_user(&$vars) {
  $account = $vars['account'];
  $returntxt = theme('user_picture', array(
    'account' => $account,
  ));
  $returntxt .= theme('username', array(
    'account' => $account,
  ));
  return $returntxt;
}

/**
 * Implementation of hook_node_type().
 */
function gmap_location_node_type($op, $info) {
  $temp = variable_get('gmap_node_markers', array());
  switch ($op) {
    case 'delete':
      unset($temp[$info->type]);
      break;
    case 'insert':
      $temp[$info->type] = 'drupal';
      break;
    case 'update':
      if (!empty($info->old_type) && $info->old_type != $info->type) {
        $temp[$info->type] = $temp[$info->old_type];
        unset($temp[$info->old_type]);
      }
      break;
  }
  variable_set('gmap_node_markers', $temp);
}

Functions

Namesort descending Description
gmap_location_admin_settings Admin Settings Page
gmap_location_block_configure Implement hook_block_configure().
gmap_location_block_info Implement hook_block_info().
gmap_location_block_save Implement hook_block_save().
gmap_location_block_view Implement hook_block_view().
gmap_location_menu Implementation of hook_menu().
gmap_location_node_page Draws a page with a google map with the node on it, or if no node is set all of the nodes on it.
gmap_location_node_point AHAH callback for getting the contents of a node point popup.
gmap_location_node_type Implementation of hook_node_type().
gmap_location_permission Implementation of hook_permission().
gmap_location_theme Implementation of hook_theme().
gmap_location_user_page Draws a page with a google map that has all of the site users.
gmap_location_user_point AHAH callback for getting the contents of a user point popup.
theme_gmap_location_infowindow_node Theme a node info window.
theme_gmap_location_infowindow_node__image Default theme for image nodes. @@@ Todo: Move to a tpl.
theme_gmap_location_infowindow_node__og Theme an Organic Groups node info window.
theme_gmap_location_infowindow_user Default theme for user infowindows.
theme_gmap_location_node_page Theme function for displaying the node page.
theme_gmap_location_user_page Theme function for displaying the user page.
_gmap_location_author_block_view
_gmap_location_block_view
_gmap_location_node_map_defaults Get the node map variable defaults.
_gmap_location_user_map_defaults Get the user map variable defaults.