openlayers/modules/openlayers_cck/openlayers_cck.module, line 389
- Versions
- 6
theme_openlayers_cck_formatter_openlayersmapformatter_single($element)
Theme a fields using a map. Each field is given a map.
Code
<?php
function theme_openlayers_cck_formatter_openlayersmapformatter_single($element) {
// @@TODO: Put in a map form somewhere to configure the rest of the map properties.
// @@BUG: When in a view, infinite recursion if more than one value exists per field per node and "each value in it's own row" is set to false in view field settings.
// @@BUG: When in a view, and the multivalue option is set to "each value in it's own row" then the element is formed as a single, and SRID (projection) is nowhere to be found in $element. This is most likely a bug in geo - but i'm not sure.
// Define some common variables
$node = $element['#node'];
$geofield_key = $element['#field_name'];
$srid_key = $geofield_key."_srid";
$mapid = "openlayers-cck-field-". $node->nid ."-single-". $geofield_key;
// Name our features. If we are in a view, name the feature by the node name.
// If we are in a page, name the feature by the field name. This is necessary
// because the tricky $element changes it's form depending on context.
if ($element['#title']){
$feature_name = $element['#title'];
}
elseif ($node->content[$geofield_key]['field']['#title']){
$feature_name = $node->content[$geofield_key]['field']['#title'];
}
else {
$feature_name = $node->node_title;
}
// Prepare our layers array.
$layers = array();
// Add basic information to the layer in the map array
$layers[$geofield_key] = array(
'id' => $geofield_key,
'type' => 'Vector',
'name' => $feature_name,
);
$layers[$geofield_key]['features'] = array();
// Add features to the map definition
foreach ($element as $key => $feature) {
if (is_numeric($key)){
$layers[$geofield_key]['features'][] = array(
'wkt' => $feature['#item']['wkt'],
'projection' => $feature['#item'][$srid_key] ? $feature['#item'][$srid_key] : '4326',
'attributes' => array(
'name' => $feature_name,
'nid' => $node->nid,
),
);
}
}
// If there are any features to display, then display the map
if (count($layers[$geofield_key]['features'])) {
// Build our map array
$map_def = array(
'id' => $mapid,
'layers' => $layers,
'behaviors' => array(
'openlayers_cck_zoom_to_layer' => array(
'id' => 'openlayers_cck_zoom_to_layer',
'type' => 'openlayers_behaviors_zoom_to_layer',
'layer' => $geofield_key,
),
'openlayers_cck_tooltip' => array(
'id' => 'openlayers_cck_tooltip',
'type' => 'openlayers_behaviors_tooltip',
'layer' => $geofield_key,
'attribute' => 'name',
),
)
);
$map = openlayers_render_map($map_def);
return $map['themed'];
}
}
?> 