You are here

function getlocations_setup_js in Get Locations 6

Same name and namespace in other branches
  1. 6.2 getlocations.module \getlocations_setup_js()
  2. 7.2 getlocations.module \getlocations_setup_js()
  3. 7 getlocations.module \getlocations_setup_js()

Function to setup the map scripts

Parameters

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

1 call to getlocations_setup_js()
getlocations_setup_map in ./getlocations.module
Function to setup the map scripts

File

./getlocations.module, line 578
Displays locations on a map. for Drupal 6 using version 3 googlemaps API

Code

function getlocations_setup_js($defaults) {
  global $language, $getlocations_setmap;
  $current_js = drupal_get_js();
  $current_css = drupal_get_css();

  // v3 googlemaps API
  $key = variable_get('getlocations_api3_key', '');
  $query = array();
  if (!empty($key)) {
    $query['key'] = $key;
  }
  $query['sensor'] = 'false';
  $query['language'] = $language->language;
  $libraries = array();
  if ($defaults['panoramio_use']) {
    $libraries[] = 'panoramio';
  }
  if ($defaults['places']) {
    $libraries[] = 'places';
  }
  if ($defaults['weather_use']) {
    $libraries[] = 'weather';
  }

  // more libraries here
  // load libraries if any
  if (count($libraries)) {
    $query['libraries'] = implode(',', $libraries);
  }
  $scheme = 'http';
  if ($defaults['use_https']) {
    $scheme = 'https';
  }
  if (empty($getlocations_setmap)) {
    $gmapdomain = "maps.google.com/maps/api/js";
    if (!empty($key)) {
      $gmapdomain = "maps.googleapis.com/maps/api/js";
    }
    $gmaplink = '<script src="' . url($scheme . '://' . $gmapdomain, array(
      'query' => $query,
    )) . '" type="text/javascript"></script>';
    drupal_set_html_head($gmaplink);
  }
  $getlocations_setmap = 1;
  if (!stristr($current_css, GETLOCATIONS_PATH . '/getlocations.css')) {
    drupal_add_css(GETLOCATIONS_PATH . '/getlocations.css');
  }
  if (!stristr($current_js, GETLOCATIONS_PATH . '/js/icons.js')) {
    drupal_add_js(GETLOCATIONS_PATH . '/js/icons.js');
  }
  $markerfile = getlocations_get_markerfile();
  if ($markerfile && !stristr($current_js, $markerfile)) {
    drupal_add_js($markerfile);
  }
  $getlocations_paths = getlocations_paths_get();
  if ($defaults['markermanagertype'] == 1 && !stristr($current_js, $getlocations_paths['markermanager_path'])) {
    drupal_add_js($getlocations_paths['markermanager_path']);
  }
  elseif ($defaults['markermanagertype'] == 2 && !stristr($current_js, $getlocations_paths['markerclusterer_path'])) {
    drupal_add_js($getlocations_paths['markerclusterer_path']);
  }
  if ($defaults['markeraction'] == 2 && !stristr($current_js, $getlocations_paths['infobubble_path'])) {
    drupal_add_js($getlocations_paths['infobubble_path']);
    if (file_exists($getlocations_paths['infobubble_options_path'])) {
      drupal_add_js($getlocations_paths['infobubble_options_path']);
    }
  }
  if (!stristr($current_js, GETLOCATIONS_PATH . '/js/getlocations.js')) {
    drupal_add_js(GETLOCATIONS_PATH . '/js/getlocations.js');
  }
}