You are here

function getlocations_js_settings_do in Get Locations 7

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

Function sets up javascript settings

Parameters

array $defaults:

array $latlons:

array $minmaxes:

string $mapid:

bool $inputmap:

string $extcontrol:

7 calls to getlocations_js_settings_do()
getlocations_fields_getmap in modules/getlocations_fields/getlocations_fields.module
input map
getlocations_fields_getmap_show in modules/getlocations_fields/getlocations_fields.module
Used by theme for display output.
getlocations_map_field_formatter_view in modules/getlocations_map/getlocations_map.module
Implements hook_field_formatter_view(). Build a renderable array for a field value.
getlocations_search_getmap in modules/getlocations_search/getlocations_search.module
Set up the map and use getlocations to spit it out
getlocations_setlocations in ./getlocations.module
Set up javascript settings and map

... See full list

File

./getlocations.module, line 2761
getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_js_settings_do($defaults, $latlons, $minmaxes, $mapid, $inputmap = FALSE, $extcontrol = '') {
  global $language;
  $lla = explode(',', $defaults['latlong']);
  $lat = $lla[0];
  $lng = $lla[1];
  $settings = array(
    $mapid => array(
      'lat' => trim($lat),
      'lng' => trim($lng),
      'locale_prefix' => $language->prefix,
      'zoom' => $defaults['zoom'],
      'minzoom_map' => $defaults['minzoom_map'],
      'maxzoom_map' => $defaults['maxzoom_map'],
      'maptype' => $defaults['maptype'],
      'controltype' => $defaults['controltype'],
      'mtc' => $defaults['mtc'],
      'baselayers' => $defaults['baselayers'],
      'scale' => $defaults['scale'],
      'overview' => $defaults['overview'],
      'overview_opened' => $defaults['overview_opened'],
      'scrollwheel' => $defaults['scrollwheel'],
      'trafficinfo' => $defaults['trafficinfo'],
      'trafficinfo_state' => $defaults['trafficinfo_state'],
      'bicycleinfo' => $defaults['bicycleinfo'],
      'bicycleinfo_state' => $defaults['bicycleinfo_state'],
      'transitinfo' => $defaults['transitinfo'],
      'transitinfo_state' => $defaults['transitinfo_state'],
      'sv_show' => $defaults['sv_show'],
      'sv_showfirst' => $defaults['sv_showfirst'],
      'sv_heading' => $defaults['sv_heading'],
      'sv_zoom' => $defaults['sv_zoom'],
      'sv_pitch' => $defaults['sv_pitch'],
      'pancontrol' => $defaults['pancontrol'],
      'poi_show' => $defaults['poi_show'],
      'transit_show' => $defaults['transit_show'],
      'map_marker' => $defaults['node_map_marker'],
      'markeraction' => $defaults['markeraction'],
      'markeractiontype' => $defaults['markeractiontype'],
      'markeraction_click_zoom' => $defaults['markeraction_click_zoom'],
      'markeraction_click_center' => $defaults['markeraction_click_center'],
      'minzoom' => $defaults['minzoom'],
      'maxzoom' => $defaults['maxzoom'],
      'nodezoom' => $defaults['nodezoom'],
      'markermanagertype' => $defaults['markermanagertype'],
      'usemarkermanager' => $defaults['usemarkermanager'],
      'useclustermanager' => $defaults['useclustermanager'],
      'markerclusterer_style' => $defaults['markerclusterer_style'],
      'markerclusterer_zoom' => $defaults['markerclusterer_zoom'],
      'markerclusterer_size' => $defaults['markerclusterer_size'],
      'markerclusterer_minsize' => $defaults['markerclusterer_minsize'],
      'markerclusterer_title' => $defaults['markerclusterer_title'],
      'markerclusterer_imgpath' => $defaults['markerclusterer_imgpath'],
      'pansetting' => $defaults['pansetting'],
      'draggable' => $defaults['draggable'],
      'styles' => $defaults['styles'],
      'inputmap' => $inputmap ? 1 : 0,
      'extcontrol' => $extcontrol,
      'custom_content_enable' => $defaults['custom_content_enable'],
      'preload_data' => $defaults['preload_data'],
      'is_mobile' => getlocations_is_mobile() ? 1 : 0,
      'map_backgroundcolor' => $defaults['map_backgroundcolor'],
      'show_maplinks' => $defaults['show_maplinks'],
      'show_maplinks_viewport' => $defaults['show_maplinks_viewport'],
      'js_path' => base_path() . GETLOCATIONS_PATH . '/js/',
      'images_path' => base_path() . GETLOCATIONS_PATH . '/images/',
      'info_path' => url("getlocations_cb/info"),
      'lidinfo_path' => url("getlocations_cb/lidinfo"),
      'fullscreen' => $defaults['fullscreen'],
      'show_bubble_on_one_marker' => $defaults['show_bubble_on_one_marker'],
      'kml_url' => $defaults['kml_group']['kml_url'],
      'fullscreen_disable' => $defaults['fullscreen_disable'],
      'fullscreen_controlposition' => $defaults['fullscreen_controlposition'],
      'places' => $defaults['places'],
      'search_places' => $defaults['search_places'],
      'getdirections_enabled' => $defaults['getdirections_enabled'],
      'is_https' => $defaults['is_https'],
      'geojson_enable' => $defaults['geojson_enable'],
      'nokeyboard' => $defaults['nokeyboard'],
      'nodoubleclickzoom' => $defaults['nodoubleclickzoom'],
      'zoomcontrolposition' => $defaults['zoomcontrolposition'],
      'mapcontrolposition' => $defaults['mapcontrolposition'],
      'pancontrolposition' => $defaults['pancontrolposition'],
      'scalecontrolposition' => $defaults['scalecontrolposition'],
      'svcontrolposition' => $defaults['svcontrolposition'],
      'sv_addresscontrol' => $defaults['sv_addresscontrol'],
      // sv overlay controls
      'sv_addresscontrolposition' => $defaults['sv_addresscontrolposition'],
      'sv_pancontrol' => $defaults['sv_pancontrol'],
      'sv_pancontrolposition' => $defaults['sv_pancontrolposition'],
      'sv_zoomcontrol' => $defaults['sv_zoomcontrol'],
      'sv_zoomcontrolposition' => $defaults['sv_zoomcontrolposition'],
      'sv_linkscontrol' => $defaults['sv_linkscontrol'],
      'sv_imagedatecontrol' => $defaults['sv_imagedatecontrol'],
      'sv_scrollwheel' => $defaults['sv_scrollwheel'],
      'sv_clicktogo' => $defaults['sv_clicktogo'],
      'input_map_show' => $defaults['input_map_show'],
    ),
  );

  // only set these if wanted
  if ($defaults['kml_group']['kml_url']) {
    $settings[$mapid]['kml_url_click'] = $defaults['kml_group']['kml_url_click'];
    $settings[$mapid]['kml_url_infowindow'] = $defaults['kml_group']['kml_url_infowindow'];
    $settings[$mapid]['kml_url_viewport'] = $defaults['kml_group']['kml_url_viewport'];
    $settings[$mapid]['kml_url_button'] = $defaults['kml_group']['kml_url_button'];
    $settings[$mapid]['kml_url_button_label'] = $defaults['kml_group']['kml_url_button_label'];
    $settings[$mapid]['kml_url_button_state'] = $defaults['kml_group']['kml_url_button_state'];
  }
  if ($defaults['search_places']) {
    $settings[$mapid]['search_places_size'] = $defaults['search_places_size'];
    $settings[$mapid]['search_places_position'] = $defaults['search_places_position'];
    $settings[$mapid]['search_places_label'] = $defaults['search_places_label'];
    $settings[$mapid]['search_places_placeholder'] = $defaults['search_places_placeholder'];
    $settings[$mapid]['search_places_dd'] = $defaults['search_places_dd'];
    $settings[$mapid]['search_places_list'] = $defaults['search_places_list'];
  }
  if ($defaults['geojson_enable']) {
    $settings[$mapid]['geojson_data'] = $defaults['geojson_data'];
    $settings[$mapid]['geojson_options'] = $defaults['geojson_options'];
  }

  // categories
  if (isset($defaults['categories'])) {
    $settings[$mapid]['categories'] = $defaults['categories'];
  }
  else {
    $settings[$mapid]['categories'] = array();
  }

  // highlighting
  $settings[$mapid]['highlight_enable'] = $defaults['highlight_enable'];
  if ($defaults['highlight_enable']) {
    if (!preg_match("/^#/", $defaults['highlight_strokecolor'])) {
      $defaults['highlight_strokecolor'] = '#' . $defaults['highlight_strokecolor'];
    }
    if (!preg_match("/^#/", $defaults['highlight_fillcolor'])) {
      $defaults['highlight_fillcolor'] = '#' . $defaults['highlight_fillcolor'];
    }
    $settings[$mapid]['highlight_strokecolor'] = $defaults['highlight_strokecolor'];
    $settings[$mapid]['highlight_strokeopacity'] = $defaults['highlight_strokeopacity'];
    $settings[$mapid]['highlight_strokeweight'] = $defaults['highlight_strokeweight'];
    $settings[$mapid]['highlight_fillcolor'] = $defaults['highlight_fillcolor'];
    $settings[$mapid]['highlight_fillopacity'] = $defaults['highlight_fillopacity'];
    $settings[$mapid]['highlight_radius'] = $defaults['highlight_radius'];
  }
  $settings[$mapid]['getdirections_link'] = $defaults['getdirections_link'];
  $settings[$mapid]['show_search_distance'] = $defaults['show_search_distance'];
  $settings[$mapid]['views_search_marker_enable'] = $defaults['views_search_marker_enable'];
  $settings[$mapid]['views_search_radshape_enable'] = $defaults['views_search_radshape_enable'];
  $settings[$mapid]['views_search_center'] = $defaults['views_search_center'];
  if ($defaults['views_search_marker_enable'] || $defaults['views_search_radshape_enable']) {
    $settings[$mapid]['views_search_marker'] = $defaults['views_search_marker'];
    $settings[$mapid]['views_search_marker_toggle'] = $defaults['views_search_marker_toggle'];
    $settings[$mapid]['views_search_marker_toggle_active'] = $defaults['views_search_marker_toggle_active'];
    $settings[$mapid]['views_search_radshape_strokecolor'] = $defaults['views_search_radshape_strokecolor'];
    $settings[$mapid]['views_search_radshape_strokeopacity'] = $defaults['views_search_radshape_strokeopacity'];
    $settings[$mapid]['views_search_radshape_strokeweight'] = $defaults['views_search_radshape_strokeweight'];
    $settings[$mapid]['views_search_radshape_fillcolor'] = $defaults['views_search_radshape_fillcolor'];
    $settings[$mapid]['views_search_radshape_fillopacity'] = $defaults['views_search_radshape_fillopacity'];
    $settings[$mapid]['views_search_radshape_toggle'] = $defaults['views_search_radshape_toggle'];
    $settings[$mapid]['views_search_radshape_toggle_active'] = $defaults['views_search_radshape_toggle_active'];
  }

  // geocoder-js
  $settings[$mapid]['geocoder_enable'] = $defaults['geocoder_enable'];

  // What3Words
  $what3words_lic = variable_get('getlocations_what3words_lic', array(
    'key' => '',
    'url' => 'http://api.what3words.com',
  ));
  if ($what3words_lic['key'] && $defaults['what3words_enable']) {

    #$settings[$mapid]['what3words_key'] = $what3words_lic['key'];
    $settings[$mapid]['what3words_enable'] = $defaults['what3words_enable'];
    $settings[$mapid]['what3words_search'] = $defaults['what3words_search'];
    $settings[$mapid]['what3words_map_marker'] = $defaults['what3words_map_marker'];
    $settings[$mapid]['what3words_center'] = $defaults['what3words_center'];
    $settings[$mapid]['what3words_zoom'] = $defaults['what3words_zoom'];
    $settings[$mapid]['what3words_show'] = $defaults['what3words_show'];
    $settings[$mapid]['what3words_marker_show'] = $defaults['what3words_marker_show'];
    $settings[$mapid]['what3words_click'] = $defaults['what3words_click'];
    $settings[$mapid]['what3words_path'] = url($defaults['what3words_path']);
  }

  // baselayer settings
  $providers = getlocations_get_map_providers();
  $baselayers = $defaults['baselayers'];
  foreach ($providers as $k => $v) {
    if (isset($baselayers[$k]) && $baselayers[$k]) {
      $settings[$mapid]['baselayer_settings'][$k] = $v;
    }
  }

  // field group support;
  $settings[$mapid]['field_group_enable'] = module_exists('field_group') ? 1 : 0;
  drupal_add_js(array(
    'getlocations' => $settings,
  ), 'setting');
  if ($defaults['preload_data']) {
    $info = array();
    if (count($latlons)) {
      $ct = 0;
      foreach ($latlons as $latlon) {
        $info[$ct]['lid'] = 0;
        $info[$ct]['lidkey'] = '';
        $info[$ct]['content'] = '';
        if (isset($latlon[2]) && isset($latlon[5])) {
          $info[$ct]['lid'] = $latlon[2];
          $info[$ct]['lidkey'] = $latlon[5];
          $info[$ct]['content'] = '';
          if ($defaults['markeraction'] == 1 || $defaults['markeraction'] == 2) {
            $extra = FALSE;
            if (isset($defaults['getdirections_link'])) {
              $extra['gdlink'] = $defaults['getdirections_link'];
            }
            $info[$ct]['content'] = getlocations_getinfo($latlon[2], $latlon[5], $extra);
          }
          elseif ($defaults['markeraction'] == 3) {
            $info[$ct]['content'] = getlocations_getlidinfo($latlon[2], $latlon[5]);
          }
        }
        $ct++;
      }
    }
    $info_settings = array(
      $mapid => $info,
    );
    drupal_add_js(array(
      'getlocations_info' => $info_settings,
    ), 'setting');
  }

  // polygons
  if ($defaults['polygons_enable'] && !empty($defaults['polygons_coords'])) {
    $polygons = getlocations_get_polygon_settings($defaults);
    if ($polygons) {
      $polygon_settings = array(
        $mapid => $polygons,
      );
      drupal_add_js(array(
        'getlocations_polygons' => $polygon_settings,
      ), 'setting');
    }
  }

  // rectangles
  if ($defaults['rectangles_enable'] && (!empty($defaults['rectangles_coords']) || $defaults['rectangles_apply'] && $defaults['rectangles_dist'])) {
    if ($defaults['rectangles_apply'] && $defaults['rectangles_dist']) {

      // get latlons and set coords
      $tmp = '';
      foreach ($latlons as $ll) {
        $lats = getlocations_earth_latitude_range($ll[0], $ll[1], $defaults['rectangles_dist']);
        $lngs = getlocations_earth_longitude_range($ll[0], $ll[1], $defaults['rectangles_dist']);
        $tmp .= $lats[0] . ',' . $lngs[0] . '|' . $lats[1] . ',' . $lngs[1] . "\n";
      }
      if ($tmp) {
        $defaults['rectangles_coords'] = $tmp;
      }
    }
    $rectangles = getlocations_get_rectangle_settings($defaults);
    if ($rectangles) {
      $rectangle_settings = array(
        $mapid => $rectangles,
      );
      drupal_add_js(array(
        'getlocations_rectangles' => $rectangle_settings,
      ), 'setting');
    }
  }

  // circles
  if ($defaults['circles_enable'] && $defaults['circles_radius'] > 0 && (!empty($defaults['circles_coords']) || $defaults['circles_apply'])) {
    if ($defaults['circles_apply'] && count($latlons)) {

      // get latlons and set coords
      $tmp = '';
      foreach ($latlons as $ll) {
        $tmp .= $ll[0] . ',' . $ll[1] . "\n";
      }
      if ($tmp) {
        $defaults['circles_coords'] = $tmp;
      }
    }
    $circles = getlocations_get_circle_settings($defaults);
    if ($circles) {
      $circle_settings = array(
        $mapid => $circles,
      );
      drupal_add_js(array(
        'getlocations_circles' => $circle_settings,
      ), 'setting');
    }
  }

  // polylines
  if ($defaults['polylines_enable'] && !empty($defaults['polylines_coords'])) {
    $polylines = getlocations_get_polyline_settings($defaults);
    if ($polylines) {
      $polyline_settings = array(
        $mapid => $polylines,
      );
      drupal_add_js(array(
        'getlocations_polylines' => $polyline_settings,
      ), 'setting');
    }
  }

  // getlocations_gps
  if (module_exists('getlocations_gps') && isset($defaults['gps_button']) && $defaults['gps_button']) {
    $getlocations_gps_defaults = getlocations_gps_defaults($defaults);
    getlocations_gps_js_settings_do($getlocations_gps_defaults, $mapid);
  }

  // getlocations_smartip
  if (module_exists('getlocations_smartip') && isset($defaults['smartip_button']) && $defaults['smartip_button']) {
    $getlocations_smartip_defaults = getlocations_smartip_defaults($defaults);
    getlocations_smartip_js_settings_do($getlocations_smartip_defaults, $mapid);
  }
}