<?php
function theme_nicemap_map($points = array(), $map, $width = 200, $height = 200, $js = true) {
drupal_add_css(drupal_get_path('module', 'nicemap') .'/nicemap.css');
if ($js) {
drupal_add_js(drupal_get_path('module', 'nicemap') .'/nicemap.js');
}
$points = $map->process($points, array('width' => $width, 'height' => $height));
$options = array(
'width' => $width,
'height' => $height,
);
return _theme_nicemap_map_full($points, $map, $options);
}
function theme_nicemap_point($point) {
$weight = $point['weight'] ? ' weight-'. $point['weight'] : '';
$title = "<span>". strip_tags($point['title']) ."</span>";
$point['attributes']['class'] = $point['attributes']['class'] ?
$point['attributes']['class'] ." geopoint $weight" :
"geopoint $weight";
$point['attributes']['style'] = 'left: '. $point['x'] .'%; top: '. $point['y'] .'%;';
$point['attributes']['id'] = "geopoint-". $point['i'];
return l($title, $point['href'], array('attributes' => $point['attributes'], 'query' => null, 'fragment' => null, 'absolute' => TRUE, 'html' => TRUE));
}
function theme_nicemap_content($point) {
$content = $point['content'];
$close = "<span class='close'>". t('Close') ."</span>";
return "<div class='geoitem' id='geoitem-". $point['i'] ."'>$close $content</div>";
}
function _theme_nicemap_map_full($points, $map, $options) {
$w = $options['width'] .'px';
$h = $options['height'] .'px';
$map_url = $map->url($options);
if ($map_url) {
$map_bg = "background-image:url('$map_url');";
}
$i = 0;
foreach ($points as $point) {
$point['i'] = $i;
$geopoints .= theme('nicemap_point', $point);
$geocontent .= theme('nicemap_content', $point);
$i++;
}
$attr = array(
"class" => "nicemap-map",
"style" => "$map_bg width:$w; height:$h;",
);
$attr = drupal_attributes($attr);
return "
<div $attr>
$geopoints
<div class='hidden'>$geocontent</div>
</div>
";
}