function _addressfield_static_map_render_google_maps_image in Address Field Static Map 7
Render static Google Map image for a specific address.
Parameters
string $address: The address being displayed.
array $settings: An array of settings related to the map to be displayed.
object $entity: The entity to which the field is attached.
Return value
string Rendered Google map.
3 calls to _addressfield_static_map_render_google_maps_image()
- addressfield_staticmap_block_view in ./
addressfield_staticmap.module - Implements hook_block_view().
- addressfield_staticmap_field_formatter_view in ./
addressfield_staticmap.module - Implements hook_field_formatter_view().
- _addressfield_static_map_render_google_maps in ./
addressfield_staticmap.module - Render regular Google Map for a specific address.
File
- ./
addressfield_staticmap.module, line 212 - Main file for the addressfield static map module.
Code
function _addressfield_static_map_render_google_maps_image($address, array $settings, $entity) {
global $is_https;
$url_args = array(
'external' => TRUE,
'https' => $is_https,
'query' => array(
'center' => $address,
'zoom' => $settings['zoom'],
'size' => $settings['size'],
'scale' => $settings['scale'],
'maptype' => $settings['maptype'],
'markers' => implode('|', array(
url($settings['icon_url'], array(
'external' => TRUE,
)),
$address,
)),
),
);
if ($url_args['query']['zoom'] == 'auto') {
unset($url_args['query']['zoom']);
}
// Check for Google Maps API key vs Premium Plan via Client ID & Signature.
if (isset($settings['premier']) && $settings['premier']) {
$url_args['query']['client'] = $settings['client_id'];
}
else {
$url_args['query']['key'] = $settings['api_key'];
}
$settings['staticmap_url'] = url('//maps.googleapis.com/maps/api/staticmap', $url_args);
if (!empty($settings['additional'])) {
$settings['staticmap_url'] .= '&' . $settings['additional'];
}
if (isset($settings['premier']) && $settings['premier']) {
$data = str_replace('//maps.googleapis.com', '', $settings['staticmap_url']);
$signature = hash_hmac('sha1', $data, base64_decode(strtr($settings['crypto_key'], '-_', '+/')), true);
$signature = strtr(base64_encode($signature), '+/', '-_');
$settings['staticmap_url'] .= '&signature=' . $signature;
}
// Google Maps link.
$url = '//maps.google.com/maps';
$options = array(
'external' => TRUE,
'https' => $is_https,
);
$index = $settings['index'];
$target = variable_get('addressfield_staticmap_gmap_link_target_' . $index, '');
$rel = variable_get('addressfield_staticmap_noopener_' . $index, FALSE) ? "noopener" : "";
// Add 'Get directions' text link.
if (variable_get('addressfield_staticmap_directions_link_' . $index)) {
$link_text = variable_get('addressfield_staticmap_directions_text_' . $index, t('Get directions'));
$options['query'] = array(
'daddr' => $address,
);
$options['attributes'] = empty($target) ? array(
'title' => $link_text,
) : array(
'title' => $link_text,
'target' => $target,
'rel' => $rel,
);
$settings['directions'] = l($link_text, $url, $options);
}
// Link to actual Google map.
if (variable_get('addressfield_staticmap_gmap_link_' . $index, FALSE)) {
$attributes = array();
if (!empty($target)) {
$attributes['target'] = $target;
}
if ($target == '_blank' && !empty($rel)) {
$attributes['rel'] = $rel;
}
$settings['target'] = empty($attributes) ? '' : drupal_attributes($attributes);
$options['query'] = array(
'q' => $address,
);
$settings['link'] = url($url, $options);
}
$render = theme('addressfield_staticmap_static_map', array(
'address' => $address,
'settings' => $settings,
'entity' => $entity,
));
return $render;
}