function gmap_location_node_page in GMap Module 6.2
Same name and namespace in other branches
- 5 gmap_location.module \gmap_location_node_page()
- 6 gmap_location.module \gmap_location_node_page()
- 7.2 gmap_location.module \gmap_location_node_page()
- 7 gmap_location.module \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.
Parameters
$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.
1 string reference to 'gmap_location_node_page'
- gmap_location_menu in ./
gmap_location.module - Implementation of hook_menu().
File
- ./
gmap_location.module, line 233 - GMap Location module is a module to add some gmap funcationality based on location.modules information.
Code
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();
}
$marker_sql1 = '';
$marker_sql2 = '';
if (module_exists('gmap_taxonomy')) {
$marker_sql1 = ', m.marker';
$marker_sql2 = 'LEFT JOIN {gmap_taxonomy_node} m ON n.vid = m.vid';
}
$add_sql = is_numeric($nid) && $nid > 0 ? ' AND n.nid = %d' : '';
$result = db_query(db_rewrite_sql("\n SELECT n.nid, n.type, n.title, l.latitude, l.longitude {$marker_sql1}\n FROM {node} n\n INNER JOIN {location_instance} i\n ON n.vid = i.vid\n INNER JOIN {location} l\n ON l.lid = i.lid\n {$marker_sql2}\n WHERE\n n.status = 1\n AND\n (l.latitude != 0 OR l.longitude != 0)\n " . $add_sql), $nid);
$count = 0;
while ($row = db_fetch_object($result)) {
$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 = %d\n AND\n o.is_active >= 1\n AND\n (l.latitude != 0 OR l.longitude != 0)\n GROUP BY\n o.uid", $nid, 'user');
while ($row = db_fetch_object($result)) {
$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;
}
}
}
return theme('gmap_location_node_page', $count, $nodemap['header'], theme('gmap', array(
'#settings' => $map,
)), $nodemap['footer']);
}