You are here

function getdirections_setup_map in Get Directions 6.2

Same name and namespace in other branches
  1. 6 getdirections.module \getdirections_setup_map()
  2. 7.3 getdirections.module \getdirections_setup_map()
  3. 7.2 getdirections.module \getdirections_setup_map()

Function to setup the map scripts

Parameters

$defaults: Required. the current settings. Sets up the call to googlemaps, css and the relevant getdirections js in html head

3 calls to getdirections_setup_map()
getdirections_direction in ./getdirections.module
Function to setup the map and form
getdirections_locations in ./getdirections.module
Function to setup the map
getdirections_locations_via in ./getdirections.module
Function to setup the map

File

./getdirections.module, line 1181
Fetches google map directions.

Code

function getdirections_setup_map($defaults, $misc_defaults) {
  global $language;
  $getdirections_paths = getdirections_paths_get();
  if (variable_get('getdirections_use_v3', 0)) {

    // v3 googlemaps API
    $key = variable_get('getdirections_api3_key', '');
    $query = array();
    if (!empty($key)) {
      $query['key'] = $key;
    }
    $query['sensor'] = 'false';
    $query['language'] = $language->language;
    $libraries = array();
    if ($defaults['advanced_autocomplete']) {
      $libraries[] = 'places';
    }
    if ($misc_defaults['panoramio_show']) {
      $libraries[] = 'panoramio';
    }

    // more libraries here
    // load libraries if any
    if (count($libraries)) {
      $query['libraries'] = implode(',', $libraries);
    }
    $scheme = 'http';
    if ($defaults['use_https']) {
      $scheme = 'https';
    }
    $gmapdomain = "maps.google.com/maps/api/js";
    if (!empty($key)) {
      $gmapdomain = "maps.googleapis.com/maps/api/js";
    }
    $head = '<script src="' . url($scheme . '://' . $gmapdomain, array(
      'query' => $query,
    )) . '" type="text/javascript"></script>';
    if ($defaults['use_advanced']) {
      if ($defaults['advanced_alternate']) {
        $js = $getdirections_paths['getdirections_v3b_path'];
      }
      else {
        $js = $getdirections_paths['getdirections_v3a_path'];
      }
    }
    else {
      $js = $getdirections_paths['getdirections_v3_path'];
    }
  }
  else {

    // v2 googlemaps API
    if (module_exists('gmap')) {
      $query = array(
        'file' => 'api',
        'v' => $defaults['api_version'] ? $defaults['api_version'] : GMAP_API_VERSION,
        'key' => gmap_get_key(),
        'hl' => $language->language,
      );
    }
    else {
      $query = array(
        'file' => 'api',
        'v' => $defaults['api_version'] ? $defaults['api_version'] : '2',
        'key' => variable_get('getdirections_api_key', ''),
        'hl' => $language->language,
      );
    }
    $scheme = 'http://maps.google.com/maps';
    if ($defaults['use_https']) {
      $scheme = 'https://maps-api-ssl.google.com/maps';
    }
    $head = '<script src="' . url($scheme, array(
      'query' => $query,
    )) . '" type="text/javascript"></script>';
    if ($defaults['use_advanced']) {
      $js = $getdirections_paths['getdirections_v2a_path'];
    }
    else {
      $js = $getdirections_paths['getdirections_v2_path'];
    }
  }
  drupal_set_html_head($head);
  drupal_add_css(GETDIRECTIONS_PATH . '/getdirections.css');
  drupal_add_js($js);
}