function _geofield_openlayers_formatter in Geofield 7
Same name and namespace in other branches
- 7.2 geofield.formatters.inc \_geofield_openlayers_formatter()
1 call to _geofield_openlayers_formatter()
- geofield_field_formatter_view in ./
geofield.formatters.inc - Implements hook_field_formatter_view().
File
- ./
geofield.formatters.inc, line 327 - Drupal field formatter hooks and helper functions.
Code
function _geofield_openlayers_formatter($map_name, $items) {
$features = array();
// Create array of $features
foreach ($items as $delta) {
$features[] = array(
'wkt' => $delta['wkt'],
'projection' => 'EPSG:4326',
);
}
// Get map preset
$preset = openlayers_preset_load($map_name);
$map = openlayers_build_map($preset->data);
if (!isset($map['layers']['geofield_formatter'])) {
drupal_set_message(t('Trying to render a geofield formatter on a map without the placeholder layer'), 'error');
}
// Add the features to the placeholder layer
$map['layers']['geofield_formatter']['features'] = $features;
// Return themed map if no errors found
if (empty($map['errors'])) {
$js = array(
'openlayers' => array(
'maps' => array(
$map['id'] => $map,
),
),
);
drupal_add_js($js, 'setting');
// Push map through theme function and return
$output = theme('openlayers_map', array(
'map' => $map,
'map_name' => $map_name,
));
}
return $output;
}