| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Wrapper theme function allows for easy overriding of map style
|
| 6 |
*
|
| 7 |
* @param $points
|
| 8 |
* Array An array of points in the form:
|
| 9 |
* array('title' => 'Chester',
|
| 10 |
* 'content' => 'Test',
|
| 11 |
* 'lat' => 40.47,
|
| 12 |
* 'lon' => -74.41,
|
| 13 |
* 'weight' => 5,
|
| 14 |
* ),
|
| 15 |
* @param $map
|
| 16 |
* nicemap_map object
|
| 17 |
* @param $width
|
| 18 |
* int Desired width of the resulting image
|
| 19 |
* @param $height
|
| 20 |
* int Desire height of the resulting image
|
| 21 |
*
|
| 22 |
* @return
|
| 23 |
* A fully themed map
|
| 24 |
*/
|
| 25 |
function theme_nicemap_map($points = array(), $map, $width = 200, $height = 200, $js = true) {
|
| 26 |
drupal_add_css(drupal_get_path('module', 'nicemap') .'/nicemap.css');
|
| 27 |
if ($js) {
|
| 28 |
drupal_add_js(drupal_get_path('module', 'nicemap') .'/nicemap.js');
|
| 29 |
}
|
| 30 |
$points = $map->process($points, array('width' => $width, 'height' => $height));
|
| 31 |
$options = array(
|
| 32 |
'width' => $width,
|
| 33 |
'height' => $height,
|
| 34 |
);
|
| 35 |
return _theme_nicemap_map_full($points, $map, $options);
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Theme a point on a map
|
| 40 |
*
|
| 41 |
* @param $point
|
| 42 |
* an array which, by default requires the keys
|
| 43 |
* title, weight, x, y and an optional array of attributes
|
| 44 |
*
|
| 45 |
*/
|
| 46 |
function theme_nicemap_point($point) {
|
| 47 |
$weight = $point['weight'] ? ' weight-'. $point['weight'] : '';
|
| 48 |
$title = "<span>". strip_tags($point['title']) ."</span>";
|
| 49 |
$point['attributes']['class'] = $point['attributes']['class'] ?
|
| 50 |
$point['attributes']['class'] ." geopoint $weight" :
|
| 51 |
"geopoint $weight";
|
| 52 |
|
| 53 |
// sorry, we're gonna bulldoze your style attributes
|
| 54 |
$point['attributes']['style'] = 'left: '. $point['x'] .'%; top: '. $point['y'] .'%;';
|
| 55 |
// and your id attributes
|
| 56 |
$point['attributes']['id'] = "geopoint-". $point['i'];
|
| 57 |
return l($title, $point['href'], array('attributes' => $point['attributes'], 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE));
|
| 58 |
}
|
| 59 |
|
| 60 |
function theme_nicemap_content($point) {
|
| 61 |
$content = $point['content'];
|
| 62 |
$close = "<span class='close'>". t('Close') ."</span>";
|
| 63 |
return "<div class='geoitem' id='geoitem-". $point['i'] ."'>$close $content</div>";
|
| 64 |
}
|
| 65 |
|
| 66 |
function _theme_nicemap_map_full($points, $map, $options) {
|
| 67 |
$w = $options['width'] .'px';
|
| 68 |
$h = $options['height'] .'px';
|
| 69 |
$map_url = $map->url($options);
|
| 70 |
if ($map_url) {
|
| 71 |
$map_bg = "background-image:url('$map_url');";
|
| 72 |
}
|
| 73 |
|
| 74 |
// use a hardcoded index to associate point to item
|
| 75 |
$i = 0;
|
| 76 |
foreach ($points as $point) {
|
| 77 |
$point['i'] = $i;
|
| 78 |
$geopoints .= theme('nicemap_point', $point);
|
| 79 |
$geocontent .= theme('nicemap_content', $point);
|
| 80 |
$i++;
|
| 81 |
}
|
| 82 |
|
| 83 |
$attr = array(
|
| 84 |
"class" => "nicemap-map",
|
| 85 |
"style" => "$map_bg width:$w; height:$h;",
|
| 86 |
);
|
| 87 |
|
| 88 |
$attr = drupal_attributes($attr);
|
| 89 |
|
| 90 |
return "
|
| 91 |
<div $attr>
|
| 92 |
$geopoints
|
| 93 |
<div class='hidden'>$geocontent</div>
|
| 94 |
</div>
|
| 95 |
";
|
| 96 |
}
|