| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Render a google map based on locations defined in page by geo microformats.
|
| 6 |
*
|
| 7 |
* GEOMAP creates a simple google map block that will display a map using geo microformat information
|
| 8 |
* embedded in the current page. If no geo information exists, no map will be displayed.
|
| 9 |
*
|
| 10 |
* This module has been designed to work with the Geonames_cck module, which renders locations in GEO microformat.
|
| 11 |
*
|
| 12 |
* More information on GEO Microformats: http://microformats.org/wiki/geo
|
| 13 |
*
|
| 14 |
* Our implementation of the geo microformat may need a little tweaking. The Operator module in Firefox
|
| 15 |
* complains about our default geo tags because we dont actually display the lat and long. Since this
|
| 16 |
* module was developed, the geo microformat has evolved a bit, and there are now more human friendly vesions
|
| 17 |
* of the format.
|
| 18 |
*
|
| 19 |
* TODO: Update geo microformat rendering
|
| 20 |
*
|
| 21 |
*
|
| 22 |
*/
|
| 23 |
/**
|
| 24 |
* implementation of hook_menu()
|
| 25 |
*
|
| 26 |
*/
|
| 27 |
function geomap_menu($may_cache) {
|
| 28 |
if ($may_cache) {
|
| 29 |
$items[] = array(
|
| 30 |
'path' => 'admin/settings/geomap',
|
| 31 |
'title' => t('Geomap settings'),
|
| 32 |
'callback' => 'drupal_get_form',
|
| 33 |
'callback arguments' => 'geomap_admin_form',
|
| 34 |
'access' => user_access('administer site configuration'),
|
| 35 |
'type' => MENU_NORMAL_ITEM, // optional
|
| 36 |
);
|
| 37 |
}
|
| 38 |
return $items;
|
| 39 |
}
|
| 40 |
|
| 41 |
/**
|
| 42 |
* implementaion of hook_block()
|
| 43 |
*
|
| 44 |
*/
|
| 45 |
function geomap_block($op = 'list', $delta = 0, $edit = array()) {
|
| 46 |
switch ($op) {
|
| 47 |
case "list":
|
| 48 |
$blocks['map'] = array('info' => t('Geo Microformat Googlemap'));
|
| 49 |
return $blocks;
|
| 50 |
case "configure":
|
| 51 |
break;
|
| 52 |
case "save":
|
| 53 |
break;
|
| 54 |
case "view":
|
| 55 |
$block = array('subject' => t('geo map'), 'content' => theme('geomap', $delta));
|
| 56 |
return $block;
|
| 57 |
}
|
| 58 |
}
|
| 59 |
|
| 60 |
/**
|
| 61 |
* Create a map div.
|
| 62 |
*
|
| 63 |
* The Javascript will use this div to render tha map.
|
| 64 |
* This will be empty if no geo microformats exist on the current page.
|
| 65 |
*
|
| 66 |
* @param $delta If more than one map needs to be displayed add an identifier
|
| 67 |
* @ingroup themeable
|
| 68 |
* @return Map div
|
| 69 |
*/
|
| 70 |
function theme_geomap($delta='') {
|
| 71 |
if ($google_key = variable_get('googlemaps_key', '')) {
|
| 72 |
drupal_set_html_head('<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key='. $google_key .'" ></script>');
|
| 73 |
drupal_add_js(drupal_get_path('module', 'geomap') .'/jquery.googlemaps.js', 'module');
|
| 74 |
drupal_add_js(drupal_get_path('module', 'geomap') .'/Clusterer2.js', 'module');
|
| 75 |
drupal_add_css(drupal_get_path('module', 'geomap') .'/geomap.css', 'module');
|
| 76 |
//TODO: Allow a different ID one day (use delta)
|
| 77 |
$mapid = 'map';
|
| 78 |
$output .= '<div id="'. $mapid .'" class="googlemap googlemap-'. $delta .'"></div>';
|
| 79 |
$GLOBALS['geomap'] = true;
|
| 80 |
}
|
| 81 |
else {
|
| 82 |
if (user_access('administer site configuration')) {
|
| 83 |
$output = l(t('No geomap googleapi key'), 'admin/settings/geomap');
|
| 84 |
}
|
| 85 |
}
|
| 86 |
return $output;
|
| 87 |
}
|
| 88 |
|
| 89 |
/**
|
| 90 |
* Determine whether or not the geomap has been rendered on this page.
|
| 91 |
*
|
| 92 |
* @return boolean True if map has been rendered.
|
| 93 |
*/
|
| 94 |
function geomap_rendered(){
|
| 95 |
return $GLOBALS['geomap'];
|
| 96 |
}
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
/**
|
| 101 |
* Admin form
|
| 102 |
*
|
| 103 |
* @ingroup forms
|
| 104 |
*/
|
| 105 |
function geomap_admin_form() {
|
| 106 |
$form['googlemaps_key'] = array(
|
| 107 |
'#type' => 'textfield',
|
| 108 |
'#default_value' => variable_get('googlemaps_key', ''),
|
| 109 |
'#title' => t('Google key'),
|
| 110 |
);
|
| 111 |
return system_settings_form($form);
|
| 112 |
}
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
// Thats it!. The rest of the magic is in the Javascript
|