--- \\WWW1\sites\mac\Drupal 5\gmap\gmap_location.module Tue Aug 28 22:59:22 2007 +++ \\WWW1\sites\volo\www\sites\default\modules\gmap\gmap_location.module Tue Oct 09 11:24:50 2007 @@ -24,27 +24,27 @@ function gmap_location_menu($may_cache) if ($may_cache) { $items[] = array( - 'path' => 'map/user', - 'type' => MENU_NORMAL_ITEM, - 'title' => t('User locations'), - 'access' => user_access('show user map'), - 'callback' => 'gmap_location_user_page' + 'path' => 'map/user', + 'type' => MENU_NORMAL_ITEM, + 'title' => t('User locations'), + 'access' => user_access('show user map'), + 'callback' => 'gmap_location_user_page' ); $items[] = array( - 'path' => 'map/node', - 'type' => MENU_NORMAL_ITEM, - 'title' => t('Node locations'), - 'access' => user_access('show node map'), - 'callback' => 'gmap_location_node_page' + 'path' => 'map/node', + 'type' => MENU_NORMAL_ITEM, + 'title' => t('Node locations'), + 'access' => user_access('show node map'), + 'callback' => 'gmap_location_node_page' ); $items[] = array( - 'path' => 'admin/settings/gmap_location', - 'type' => MENU_NORMAL_ITEM, - 'title' => t('GMap Location'), - 'access' => user_access('administer site configuration'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('gmap_location_admin_settings'), - 'description' => t('Configure GMap Location settings.'), + 'path' => 'admin/settings/gmap_location', + 'type' => MENU_NORMAL_ITEM, + 'title' => t('GMap Location'), + 'access' => user_access('administer site configuration'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('gmap_location_admin_settings'), + 'description' => t('Configure GMap Location settings.'), ); } return $items; @@ -72,8 +72,8 @@ function gmap_location_user_page() { } $thismap = array_merge( - gmap_defaults(), - gmap_parse_macro(variable_get('gmap_user_map', '[gmap|id=usermap|center=30,0|zoom=2|width=100%|height=400px]')) + gmap_defaults(), + gmap_parse_macro(variable_get('gmap_user_map', '[gmap|id=usermap|center=30,0|zoom=2|width=100%|height=400px]')) ); $result=db_query("SELECT * FROM {location} WHERE (longitude !=0 OR latitude !=0) AND type='user'"); @@ -130,9 +130,9 @@ function gmap_location_user_page() { } $element = array( - '#type' => 'gmap', - '#map' => $thismap['id'], - '#settings' => $thismap, + '#type' => 'gmap', + '#map' => $thismap['id'], + '#settings' => $thismap, ); $output .= theme('gmap', $element); @@ -153,7 +153,8 @@ function gmap_location_node_page($nid = if (node_access('view', $n)) { $output .='

'. t(variable_get('gmap_node_map_header', 'This map illustrates the extent of nodes of this website. ')) ."

\n"; $thismap = array_merge(gmap_defaults(), gmap_parse_macro(variable_get('gmap_node_map', '[gmap|id=nodemap|center=30,0|zoom=2|width=100%|height=400px]'))); - $thismap = gmap_location_node_map($n, $thismap, TRUE); + // $thismap = gmap_location_node_map($n, $thismap, TRUE); + $thismap = gmap_location_map_add_node($thismap, $n, $n->title); $output .= '

'. theme('gmap', array('#settings' => $thismap)); // @@@ Hey! Wait a second -- Where's the closing

? return $output; @@ -173,7 +174,8 @@ function gmap_location_node_page($nid = while ($locn=db_fetch_object($result)) { $n = node_load(array('vid' => $locn->eid)); if ($n && node_access('view', $n)) { - $thismap = gmap_location_node_map($n, $thismap, FALSE); + //$thismap = gmap_location_node_map($n, $thismap, FALSE); + $thismap = gmap_location_map_add_node($thismap, $n, $n->title); } } @@ -329,9 +331,9 @@ function gmap_location_admin_settings() // Option to use a different marker for each role $form['user']['roles'] = array( - '#type' => 'fieldset', - '#title' => t('Markers per role'), - '#description' => t('Use a different marker to denote users in the following roles.'), + '#type' => 'fieldset', + '#title' => t('Markers per role'), + '#description' => t('Use a different marker to denote users in the following roles.'), ); // Retrieve and sort list of roles, sans anonymous user @@ -341,9 +343,9 @@ function gmap_location_admin_settings() // Create a selection box per role foreach ($roles as $rid => $role) { $form['user']['roles']["gmap_role_map_marker_$rid"] = array( - '#type' => 'gmap_markerchooser', - '#title' => $role, - '#default_value' => variable_get("gmap_role_map_marker_$rid", variable_get('gmap_user_map_marker', 'drupal')), + '#type' => 'gmap_markerchooser', + '#title' => $role, + '#default_value' => variable_get("gmap_role_map_marker_$rid", variable_get('gmap_user_map_marker', 'drupal')), ); } @@ -394,12 +396,12 @@ function gmap_location_block($op = 'list $form = array(); if ($delta == 0) { $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.

Alternate base map macros can be entered for a specific node type below.'), - '#default_value' => variable_get('gmap_location_block_macro', '[gmap |id=block0 |zoom=10 |width=100% |height=200px |control=Small |type=Map] '), + '#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.

Alternate base map macros can be entered for a specific node type below.'), + '#default_value' => variable_get('gmap_location_block_macro', '[gmap |id=block0 |zoom=10 |width=100% |height=200px |control=Small |type=Map] '), ); $ntypes=node_get_types(); @@ -417,12 +419,12 @@ function gmap_location_block($op = 'list } elseif ($delta == 1) { $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 |zoom=10 |width=100% |height=200px |control=Small |type=Map] '), + '#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 |zoom=10 |width=100% |height=200px |control=Small |type=Map] '), ); $ntypes = node_get_types(); @@ -472,8 +474,18 @@ function gmap_location_block($op = 'list } } } - +// Replaced with code from http://drupal.org/node/162338 #1 function _gmap_location_getlatlon($node) { + if(isset($node->locations) && count($node->locations) > 1){ //check if we havemultiple locations + $locations =array(); + foreach($node->locations as $location){ //for each found, check if it's valid + if(isset($location['longitude'])){ + array_push($locations,$location); + } + } + return $locations; + + } else if (isset($node->location['latitude']) && isset($node->location['longitude'])) { return $node->location; } @@ -509,16 +521,16 @@ function gmap_location_author_block_view $macro = variable_get('gmap_location_block_macro', '[gmap |zoom=10 |width=100% |height=200px |control=Small |type=Map]'); } $map = array( - '#map' => 'gmap_location_authorblock', - '#settings' => gmap_parse_macro($macro), + '#map' => 'gmap_location_authorblock', + '#settings' => gmap_parse_macro($macro), ); $map['#settings']['behavior']['notype'] = TRUE; $map['#settings']['markers'] = array(); $map['#settings']['markers'][] = array( - 'latitude' => $result['latitude'], - 'longitude' => $result['longitude'], - 'markername' => variable_get('gmap_user_map_marker', 'drupal'), - 'label' => check_plain($node->name), + 'latitude' => $result['latitude'], + 'longitude' => $result['longitude'], + 'markername' => variable_get('gmap_user_map_marker', 'drupal'), + 'label' => check_plain($node->name), ); $map['#settings']['latitude'] = $result['latitude']; $map['#settings']['longitude'] = $result['longitude']; @@ -530,15 +542,55 @@ function gmap_location_author_block_view } function gmap_location_map_add_node($basemap, $node, $label='') { - $location = _gmap_location_getlatlon($node); + $locations = _gmap_location_getlatlon($node); + $mode = $basemap['markermode']; + + $markername = variable_get('gmap_node_marker_'.$node->type, ''); + $newmarkers = array(); + + if($locations && !isset($locations['longitude'])){ //multiple locations have been found, change the data structure + foreach($locations as $location){ + $newmarker['latitude'] = $location['latitude']; + $newmarker['longitude'] = $location['longitude']; + $newmarker['markername']= $markername; + $newmarker['label'] = $label; + $newmarker['opts']['title'] = $label; + if ($mode == 1) { + // Autoclick + $newmarker['autoclick'] = true; + $newmarker['text'] = theme('gmapnodelabel', $node); + } + else if ($mode == 2) { + $newmarker['link'] = url('node/'. $node->nid); + } + array_push($newmarkers,$newmarker); + } + $location = $locations[0]; //so "backwards compatibility" is preserved; + } else { + $location = $locations; //Single location, like before + $newmarker['latitude'] = $location['latitude']; + $newmarker['longitude'] = $location['longitude']; + $newmarker['markername']=variable_get('gmap_node_marker_'.$node->type, ''); + $newmarker['label']=$label; + $newmarker['opts']['title'] = $label; + if ($mode == 1) { + // Autoclick + $newmarker['autoclick'] = true; + $newmarker['text'] = theme('gmapnodelabel', $node); + } + else if ($mode == 2) { + $newmarker['link'] = url('node/'. $node->nid); + } + array_push($newmarkers,$newmarker); + + } + if (empty($basemap['markers'])) { - $thismap['markers']=array(); + $basemap['markers']=array(); } - $newmarker['latitude'] = $location['latitude']; - $newmarker['longitude'] = $location['longitude']; - $newmarker['markername'] = variable_get('gmap_node_marker_'. $node->type, ''); - $newmarker['label'] = $label; - $basemap['markers'][] = $newmarker; + + //$basemap['markers'] = $newmarkers; + $basemap['markers'] = array_merge ($basemap['markers'], $newmarkers); $basemap['latitude'] = $location['latitude']; $basemap['longitude'] = $location['longitude']; return $basemap; @@ -638,20 +690,20 @@ function gmap_location_user($op, &$edit, $form['coordinates']['gmap_node'] = array(); $form['coordinates']['gmap_location_latitude'] = array( - '#type' => 'textfield', - '#title' => t('Latitude'), - '#default_value' => $edit['gmap_location_latitude'], - '#size' => 30, - '#maxlength' => 120, + '#type' => 'textfield', + '#title' => t('Latitude'), + '#default_value' => $edit['gmap_location_latitude'], + '#size' => 30, + '#maxlength' => 120, ); $form['coordinates']['gmap_location_longitude'] = array( - '#type' => 'textfield', - '#title' => t('Longitude'), - '#default_value' => $edit['gmap_location_longitude'], - '#size' => 30, - '#maxlength' => 120, - '#description' => t('The latitude and longitude will be entered here when you click on a location in the interactive map above. You can also fill in the values manually.'), + '#type' => 'textfield', + '#title' => t('Longitude'), + '#default_value' => $edit['gmap_location_longitude'], + '#size' => 30, + '#maxlength' => 120, + '#description' => t('The latitude and longitude will be entered here when you click on a location in the interactive map above. You can also fill in the values manually.'), ); // @@@ @@ -659,15 +711,15 @@ function gmap_location_user($op, &$edit, $form['coordinates']['gmap_node']['#value'] = gmap_set_location($map_macro, $form['coordinates'], array('latitude' => 'gmap_location_latitude', 'longitude' => 'gmap_location_longitude')); -/* - if (variable_get('gmap_geocode', 1)) { - $form['coordinates']['gmap_location_address'] = array( - '#type' => 'textfield', - '#title' => t('Address'), - '#description' => t('The address to be found on the map. Enter an address and then hit "TAB" and the current location will be updated. Please note that this address is not saved for the node, it is only used for finding a location.'), - ); - } -*/ + /* + if (variable_get('gmap_geocode', 1)) { + $form['coordinates']['gmap_location_address'] = array( + '#type' => 'textfield', + '#title' => t('Address'), + '#description' => t('The address to be found on the map. Enter an address and then hit "TAB" and the current location will be updated. Please note that this address is not saved for the node, it is only used for finding a location.'), + ); + } + */ } return $form; } @@ -675,57 +727,57 @@ function gmap_location_user($op, &$edit, } /* -function gmap_location_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { - if(variable_get('gmap_node_'. $node->type, 0)) { - $object->gmap_location_latitude = $node->gmap_location_latitude; - $object->gmap_location_longitude = $node->gmap_location_longitude; - $object->eid = $node->vid; - - switch ($op) { - case 'load': - $res=db_query("SELECT * FROM {location} WHERE eid=%d AND type='node'",$node->vid); - if ($gmap_node=db_fetch_array($res)) { - if ($gmap_node['latitude'] !=0) $node->gmap_location_latitude= $gmap_node['latitude']; - if ($gmap_node['longitude']!=0) $node->gmap_location_longitude=$gmap_node['longitude']; - $node->gmap_location_set=true; - } - return; - - case 'validate': - _gmap_location_validate_form($object); - return; - - case 'insert': - _gmap_location_store_location($object, 'node', false); - return; - - case 'update': - _gmap_location_store_location($object, 'node', isset($node->gmap_location_set)); - return; - - case 'delete': - db_query ("DELETE from {location} WHERE eid=%d AND type='node'", $node->vid); - return; - - } - } -} -*/ + function gmap_location_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { + if(variable_get('gmap_node_'. $node->type, 0)) { + $object->gmap_location_latitude = $node->gmap_location_latitude; + $object->gmap_location_longitude = $node->gmap_location_longitude; + $object->eid = $node->vid; + + switch ($op) { + case 'load': + $res=db_query("SELECT * FROM {location} WHERE eid=%d AND type='node'",$node->vid); + if ($gmap_node=db_fetch_array($res)) { + if ($gmap_node['latitude'] !=0) $node->gmap_location_latitude= $gmap_node['latitude']; + if ($gmap_node['longitude']!=0) $node->gmap_location_longitude=$gmap_node['longitude']; + $node->gmap_location_set=true; + } + return; + + case 'validate': + _gmap_location_validate_form($object); + return; + + case 'insert': + _gmap_location_store_location($object, 'node', false); + return; + + case 'update': + _gmap_location_store_location($object, 'node', isset($node->gmap_location_set)); + return; + + case 'delete': + db_query ("DELETE from {location} WHERE eid=%d AND type='node'", $node->vid); + return; + + } + } + } + */ /* -function _gmap_location_validate_form(&$object) { - if (isset($object->latitude)){ - if (!is_numeric($object->latitude) || abs($object->latitude)>90) { - form_set_error('gmap_location_latitude', t('Latitude must be between -90 and 90')); - } - } - if (isset($object->longitude)){ - if (!is_numeric($object->longitude) || abs($object->longitude)>180) { - form_set_error('gmap_location_longitude', t('Longitude must be between -180 and 180')); - } - } -} -*/ + function _gmap_location_validate_form(&$object) { + if (isset($object->latitude)){ + if (!is_numeric($object->latitude) || abs($object->latitude)>90) { + form_set_error('gmap_location_latitude', t('Latitude must be between -90 and 90')); + } + } + if (isset($object->longitude)){ + if (!is_numeric($object->longitude) || abs($object->longitude)>180) { + form_set_error('gmap_location_longitude', t('Longitude must be between -180 and 180')); + } + } + } + */ function _gmap_location_store_location($object, $type, $update = false) { if (isset($object->gmap_location_latitude) && isset($object->gmap_location_longitude)) {