gmap_geo/gmap_geo.module, line 163
- Versions
- 6
theme_gmap_geo_formatter($element)
Themes a geo field as a gmap.
This uses gmap_picker widget settings from the cck field settings, if they exist, and otherwise uses GMap's default map settings. Bdragon and I (Bec) have talked briefly about a "gmap profile" setup, in which case we could provide a field formatter for each gmap profile ("GMap: profile_name"). This would be ideal.
- Autozoom doesn't yet zoom for polygons and lines; this field formatter
- Linestrings and polygons are rendered as "encoded polylines" in Google Maps,
Code
<?php
function theme_gmap_geo_formatter($element) {
module_load_include('inc', 'geo', 'includes/geo.wkb');
module_load_include('inc', 'gmap', 'gmap_polyutil');
foreach (element_children($element) as $i) {
$item = $element[$i]['#item'];
// get the geographic feature's points as an array
$wkb = (isset($item['wkb']) ? $item['wkb'] : $item[$element['#field_name'] . '_wkb']);
$feature = geo_wkb_get_data($wkb, 'array');
switch ($feature['type']) {
case 'point':
$map['markers'][] = array('latitude' => $item['lat'], 'longitude' => $item['lon']);
break;
case 'linestring':
$polyline = gmap_polyutil_polyline($feature['value']);
$polyline['type'] = 'encoded_line';
$map['shapes'][] = $polyline;
break;
case 'polygon':
$polyline = gmap_polyutil_polyline($feature['value']);
$map['shapes'][] = array(
'type' => 'encoded_polygon',
'polylines' => array($polyline),
);
break;
}
}
if ($map) {
// Load field instance info. If the field uses the gmap_picker widget, use
// the widget's gmap macro to build the map array.
$field = content_fields($element['#field_name'], $element['#type_name']);
if (isset($field['widget']['gmap_geo_picker_macro'])) {
$field_map = gmap_parse_macro($field['widget']['gmap_geo_picker_macro']);
$map = array_merge($field_map, $map);
}
$map['behavior'] = array('autozoom' => TRUE);
if (isset($field_map['zoom'])) {
$map['maxzoom'] = $field_map['zoom'];
}
return theme('gmap', $map);
}
}
?> 