You are here

function _addressfield_static_map_render_google_maps in Address Field Static Map 7

Render regular Google Map 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.

2 calls to _addressfield_static_map_render_google_maps()
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().

File

./addressfield_staticmap.module, line 315
Main file for the addressfield static map module.

Code

function _addressfield_static_map_render_google_maps($address, array $settings, $entity) {

  // 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'];
  }
  $maps_url = url('//maps.googleapis.com/maps/api/js', $url_args);
  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), '+/', '-_');
    $maps_url .= '&signature=' . $signature;
  }
  drupal_add_js($maps_url, array(
    'group' => 'JS_LIBRARY',
    'type' => 'external',
  ));
  drupal_add_css(drupal_get_path('module', 'addressfield_staticmap') . '/addressfield_staticmap.css');
  $image = _addressfield_static_map_render_google_maps_image($address, $settings, $entity);
  $kml_paths = array();

  // Additional processing to attach optional KML file(s).
  $kml_field_names = array_filter(variable_get('addressfield_staticmap_field_kml', array()));
  if (!empty($kml_field_names) && isset($entity)) {
    foreach ($kml_field_names as $kml_field) {
      $kml_field = explode('|', $kml_field);

      // Check to see if the valid field settings are for this bundle.
      if ($entity->type != $kml_field[0]) {
        continue;
      }
      $kml_files = field_get_items('entity', $entity, $kml_field[1], $entity->language);
      if (empty($kml_files)) {
        continue;
      }
      foreach ($kml_files as $kml_file) {
        $kml_paths[] = file_create_url($kml_file['uri']);
      }
    }
  }
  $render = theme('addressfield_staticmap_google_map', array(
    'address' => urldecode($address),
    'settings' => $settings,
    'image' => $image,
    'kml_paths' => $kml_paths,
    'entity' => $entity,
  ));
  return $render;
}