You are here

function getdirections_setup_map in Get Directions 7.3

Same name and namespace in other branches
  1. 6.2 getdirections.module \getdirections_setup_map()
  2. 6 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

6 calls to getdirections_setup_map()
getdirections_direction in ./getdirections.module
Function to setup the map and form
getdirections_direction_other in ./getdirections.module
Function to setup the map and form
getdirections_fields_field_formatter_view in modules/getdirections_fields/getdirections_fields.module
Implements hook_field_formatter_view(). Build a renderable array for a field value.
getdirections_locations in ./getdirections.module
Function to setup the map
getdirections_locations_via in ./getdirections.module
Function to setup the map

... See full list

File

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

Code

function getdirections_setup_map($defaults, $misc_defaults) {
  global $language, $is_https;
  $getdirections_paths = getdirections_paths_get();

  // v3 googlemaps API
  $key = variable_get('getdirections_api3_key', '');
  $clientID = variable_get('getdirections_api3_clientID', '');
  $channel = variable_get('getdirections_api3_channel', '');
  $query = array();
  if (!empty($key)) {
    $query['key'] = $key;
  }
  if (!empty($clientID)) {
    $query['client'] = $clientID;
  }
  if (!empty($channel)) {
    $query['channel'] = $channel;
  }
  $query['sensor'] = 'false';
  $query['language'] = $language->language;
  if ($defaults['region_bias']) {
    $query['region'] = $defaults['region_bias'];
  }
  $libraries = array();
  if ($defaults['advanced_autocomplete']) {
    $libraries['places'] = 'places';
  }
  if ($misc_defaults['panoramio_use']) {
    $libraries['panoramio'] = 'panoramio';
  }
  if ($misc_defaults['weather_use']) {
    $libraries['weather'] = 'weather';
  }

  // more libraries here
  // compat with getlocations
  if (module_exists('getlocations')) {
    $getlocations_defaults = getlocations_defaults();
    if (function_exists('getlocations_places_check')) {
      if (getlocations_places_check()) {
        $libraries['places'] = 'places';
      }
    }
    elseif ($getlocations_defaults['places']) {
      $libraries['places'] = 'places';
    }
    if ($getlocations_defaults['panoramio_use']) {
      $libraries['panoramio'] = 'panoramio';
    }
    if ($getlocations_defaults['weather_use']) {
      $libraries['weather'] = 'weather';
    }
  }

  // load libraries if any
  if (count($libraries)) {
    $query['libraries'] = implode(',', $libraries);
  }
  $current_js = drupal_get_js();
  $scheme = $is_https ? 'https' : 'http';
  $gmapdomain = "maps.googleapis.com/maps/api/js";
  $gmaplink = url($scheme . '://' . $gmapdomain, array(
    'query' => $query,
  ));
  if (!stristr($current_js, $scheme . '://' . $gmapdomain)) {
    drupal_add_js($gmaplink, 'external');
  }
  if (isset($defaults['preview_map'])) {
    $js = $getdirections_paths['getdirections_preview_path'];
  }
  else {
    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'];
    }
  }
  drupal_add_css(GETDIRECTIONS_PATH . '/getdirections.css');
  drupal_add_js($js);
}