function addressfield_staticmap_field_formatter_view in Address Field Static Map 7
Implements hook_field_formatter_view().
File
- ./
addressfield_staticmap.module, line 624 - Main file for the addressfield static map module.
Code
function addressfield_staticmap_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
foreach ($items as $delta => $item) {
$data_cleaned = array_filter($item);
// If only the country is set, skip this (for some reason the country value
// becomes mandatory if you limit the list).
if (isset($data_cleaned['country']) && count($data_cleaned) <= 1) {
continue;
}
$address = addressfield_staticmap_clean_address($item, $field['type']);
$settings = array(
'zoom' => $display['settings']['zoom_level'],
'size' => addressfield_staticmap_get_size_args($display['settings']),
'maptype' => $display['settings']['map_style'],
'scale' => $display['settings']['scale'] ? $display['settings']['scale'] : 1,
'index' => $display['settings']['advanced_settings_index'],
'scroll_lock' => $display['settings']['scroll_lock'],
'additional' => $display['settings']['additional'],
'info_window' => $display['settings']['info_window'],
'text_address' => $display['settings']['text_address'],
);
$api = variable_get('addressfield_staticmap_api_' . $settings['index'], 'google_maps');
$settings['premier'] = variable_get('addressfield_staticmap_premier_' . $settings['index'], FALSE);
// Display the address if the checkbox is set.
if ($settings['text_address']) {
$settings['text_address'] = _addressfield_staticmap_render_address($item);
}
if ($api !== 'mapquest' && $settings['premier']) {
$settings['client_id'] = variable_get('addressfield_staticmap_premium_client_id_' . $settings['index'], '');
$settings['crypto_key'] = variable_get('addressfield_staticmap_premium_crypto_key_' . $settings['index'], '');
}
else {
$settings['api_key'] = variable_get('addressfield_staticmap_api_key_' . $settings['index'], '');
}
if ($api != 'google_maps_api') {
// Need a size specified for static map.
$settings['size'] = empty($settings['size']) ? DEFAULT_MAP_SIZE : $settings['size'];
}
// Use Google Maps.
if ($api == 'google_maps') {
$settings['icon_url'] = variable_get('addressfield_staticmap_gmap_icon_url_' . $settings['index'], '');
$settings['icon_url'] = empty($settings['icon_url']) ? 'color:green' : 'icon:' . $settings['icon_url'];
$element[$delta]['#markup'] = _addressfield_static_map_render_google_maps_image($address, $settings, $entity);
}
elseif ($api == 'google_maps_api') {
$settings['icon_url'] = variable_get('addressfield_staticmap_gmap_icon_url_' . $settings['index'], '');
$settings['icon_url'] = empty($settings['icon_url']) ? 'color:green' : 'icon:' . $settings['icon_url'];
$settings['api_key'] = variable_get('addressfield_staticmap_api_key_' . $settings['index'], '');
$entity_id_field = addressfield_entity_id_from_entity_type($entity);
$settings['id'] = $entity->{$entity_id_field};
$element[$delta]['#markup'] = _addressfield_static_map_render_google_maps($address, $settings, $entity);
}
elseif ($api == 'google_maps_embed') {
$settings['icon_url'] = variable_get('addressfield_staticmap_gmap_icon_url_' . $settings['index'], '');
$settings['icon_url'] = empty($settings['icon_url']) ? 'color:green' : 'icon:' . $settings['icon_url'];
$settings['api_key'] = variable_get('addressfield_staticmap_api_key_' . $settings['index'], '');
$settings['id'] = $entity->{$entity_id_field};
$element[$delta]['#markup'] = _addressfield_embed_map_render_google_maps($address, $settings, $entity);
}
elseif ($api == 'mapquest') {
$settings['api_key'] = variable_get('addressfield_staticmap_api_key_' . $settings['index'], '');
$element[$delta]['#markup'] = _addressfield_static_map_render_mapquest_image($address, $settings);
}
}
return $element;
}