You are here

getlocations_leaflet.module in Get Locations 7

Same filename and directory in other branches
  1. 7.2 modules/getlocations_leaflet/getlocations_leaflet.module

getlocations_leaflet.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Provides Leaflet maps integration for data from Getlocations Fields, location_cck, geofield and geolocation modules.

File

modules/getlocations_leaflet/getlocations_leaflet.module
View source
<?php

/**
 * @file
 * getlocations_leaflet.module
 * @author Bob Hutchinson http://drupal.org/user/52366
 * @copyright GNU GPL
 *
 * Provides Leaflet maps integration for data from Getlocations Fields, location_cck, geofield and geolocation modules.
 *
 *
 */
define('GETLOCATIONS_LEAFLET_PATH', drupal_get_path('module', 'getlocations_leaflet'));

/**
 * Implements hook_help().
 */
function getlocations_leaflet_help($path, $arg) {
  switch ($path) {
    case 'admin/help#getlocations':
      $output = '<p>' . t('Provides Leaflet Maps integration for Getlocations.') . '</p>';
      return $output;
  }
}

/**
 * Implements hook_menu().
 */
function getlocations_leaflet_menu() {
  $items = array();
  $items[GETLOCATIONS_ADMIN_PATH . '/leaflet'] = array(
    'title' => 'Leaflet',
    'description' => 'Configure Getlocations leaflet',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'getlocations_leaflet_settings_form',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 6,
  );

  // getlocations/[entity_type]/$nid    # show all location on one entity_type
  $items['getlocations_leaflet/%getlocations_entity_type/%getlocations_id'] = array(
    'title' => 'Get locations',
    'access callback' => 'getlocations_access_location',
    'page callback' => 'getlocations_leaflet_entity_type_map',
    'page arguments' => array(
      1,
      2,
    ),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implements hook_flush_caches().
 */
function getlocations_leaflet_flush_caches() {
  if (variable_get('getlocations_leaflet_flush', 1)) {
    getlocations_leaflet_regenerate_markers();
  }
}

/**
 * Implements hook_library().
 */
function getlocations_leaflet_library() {
  $aggr = getlocations_aggr_get() ? TRUE : FALSE;
  $libraries['leaflet'] = array(
    'title' => 'Leaflet',
    'website' => 'http://leafletjs.com',
    'version' => '0.7',
  );

  // getlocations_leaflet_cdn
  $getlocations_leaflet_cdn = variable_get('getlocations_leaflet_cdn', array(
    'enable' => 0,
    'js' => '',
    'css' => '',
  ));
  if ($getlocations_leaflet_cdn['enable']) {
    $libraries['leaflet']['js'] = array(
      $getlocations_leaflet_cdn['js'] => array(
        'type' => 'external',
      ),
    );
    $libraries['leaflet']['css'] = array(
      $getlocations_leaflet_cdn['css'] => array(
        'type' => 'external',
        'media' => 'all',
      ),
    );
  }
  else {
    $libraries['leaflet']['js'] = array(
      libraries_get_path('leaflet') . '/leaflet.js' => array(
        'type' => 'file',
        'group' => JS_LIBRARY,
        'preprocess' => $aggr,
      ),
    );
    $libraries['leaflet']['css'] = array(
      libraries_get_path('leaflet') . '/leaflet.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }
  $getlocations_leaflet_paths = getlocations_leaflet_paths_get();
  $getlocations_leaflet_plugins = getlocations_leaflet_plugins();
  $libraries['getlocations-leaflet'] = array(
    'title' => 'Getlocations Leaflet javascript',
    'website' => 'http://drupal.org/project/getlocations',
    'version' => GETLOCATIONS_VERSION,
    'dependencies' => array(
      array(
        'getlocations_leaflet',
        'leaflet',
      ),
    ),
  );

  // add plugins
  $jsarr = array();
  $cssarr = array();

  // add getlocations geo library
  $getlocations_paths = getlocations_paths_get();
  $jsarr += array(
    $getlocations_paths['getlocations_geo_path'] => array(
      'type' => 'file',
      'preprocess' => $aggr,
    ),
  );
  if ($getlocations_leaflet_plugins['fullscreen_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/fullscreen/Control.FullScreen.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/fullscreen/Control.FullScreen.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }
  if ($getlocations_leaflet_plugins['graticule_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/graticule/L.Graticule.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
      GETLOCATIONS_LEAFLET_PATH . '/plugins/graticule/Control.Graticule.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/graticule/graticule.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }
  if ($getlocations_leaflet_plugins['markercluster_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/markercluster/leaflet.markercluster.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/markercluster/MarkerCluster.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
      GETLOCATIONS_LEAFLET_PATH . '/plugins/markercluster/MarkerCluster.Default.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }
  if ($getlocations_leaflet_plugins['pancontrol_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/pancontrol/L.Control.Pan.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/pancontrol/L.Control.Pan.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
      GETLOCATIONS_LEAFLET_PATH . '/plugins/pancontrol/L.Control.Pan.ie.min.css' => array(
        'browsers' => array(
          'IE' => 'lte IE 8',
          '!IE' => FALSE,
        ),
      ),
    );
  }
  if ($getlocations_leaflet_plugins['zoomslider_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/zoomslider/L.Control.Zoomslider.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/zoomslider/L.Control.Zoomslider.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
      GETLOCATIONS_LEAFLET_PATH . '/plugins/zoomslider/L.Control.Zoomslider.ie.min.css' => array(
        'browsers' => array(
          'IE' => 'lte IE 8',
          '!IE' => FALSE,
        ),
      ),
    );
  }
  if ($getlocations_leaflet_plugins['awesome_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/awesome-markers/leaflet.awesome-markers.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/font-awesome/css/font-awesome.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
      GETLOCATIONS_LEAFLET_PATH . '/plugins/awesome-markers/leaflet.awesome-markers.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }
  if ($getlocations_leaflet_plugins['mouseposition_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/mouseposition/L.Control.MousePosition.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/mouseposition/L.Control.MousePosition.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }
  if ($getlocations_leaflet_plugins['minimap_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/minimap/L.Control.Layers.Minimap.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/minimap/control.layers.minimap.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }
  if ($getlocations_leaflet_plugins['geocoder_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/geocoder/Control.Geocoder.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/geocoder/Control.Geocoder.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }
  if ($getlocations_leaflet_plugins['usermarker_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/usermarker/leaflet.usermarker.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/usermarker/leaflet.usermarker.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }
  if ($getlocations_leaflet_plugins['bouncemarker_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/bouncemarker/bouncemarker.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
  }
  if ($getlocations_leaflet_plugins['magnifyingglass_enable']) {
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/magnifyingglass/leaflet.magnifyingglass.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
      GETLOCATIONS_LEAFLET_PATH . '/plugins/magnifyingglass/Control.MagnifyingGlass.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/magnifyingglass/leaflet.magnifyingglass.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
      GETLOCATIONS_LEAFLET_PATH . '/plugins/magnifyingglass/Control.MagnifyingGlass.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }
  if ($getlocations_leaflet_plugins['terminator_enable']) {

    // L.Terminator
    $jsarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/terminator/L.Terminator.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
      GETLOCATIONS_LEAFLET_PATH . '/plugins/terminator/Control.Terminator.min.js' => array(
        'type' => 'file',
        'preprocess' => $aggr,
      ),
    );
    $cssarr += array(
      GETLOCATIONS_LEAFLET_PATH . '/plugins/terminator/terminator.min.css' => array(
        'type' => 'file',
        'media' => 'all',
      ),
    );
  }

  // leaflet hash library
  if ($getlocations_leaflet_plugins['hash_enable']) {
    $hashfile = getlocations_leaflet_hash_library_check();
    if ($hashfile) {
      $jsarr += array(
        $hashfile => array(
          'type' => 'file',
          'preprocess' => $aggr,
        ),
      );
    }
  }

  // mapquest
  $mapquest_lic = variable_get('getlocations_mapquest_lic', array(
    'key' => '',
    'type' => 'l',
  ));
  if ($mapquest_lic['key']) {
    $defaults = getlocations_defaults();
    if (!isset($defaults['is_https']) || !$defaults['is_https']) {
      global $is_https;
    }
    else {
      $is_https = $defaults['is_https'];
    }
    $scheme = $is_https ? 'https' : 'http';
    if ($mapquest_lic['type'] == 'o') {
      $dom = 'open.mapquestapi.com/sdk/leaflet/v1.s';
    }
    else {
      $dom = 'www.mapquestapi.com/sdk/leaflet/v1.s';
    }
    $url1 = $scheme . '://' . $dom . '/' . 'mq-map.js' . '?key=' . $mapquest_lic['key'];
    $jsarr += array(
      $url1 => array(
        'type' => 'external',
        'weight' => 20,
      ),
    );
    if ($getlocations_leaflet_plugins['mapquest_traffic_enable']) {
      $url2 = $scheme . '://' . $dom . '/' . 'mq-traffic.js' . '?key=' . $mapquest_lic['key'];
      $jsarr += array(
        $url2 => array(
          'type' => 'external',
          'weight' => 21,
        ),
      );
    }
    if ($getlocations_leaflet_plugins['mapquest_routing_enable']) {
      $url2 = $scheme . '://' . $dom . '/' . 'mq-routing.js' . '?key=' . $mapquest_lic['key'];
      $jsarr += array(
        $url2 => array(
          'type' => 'external',
          'weight' => 22,
        ),
      );
    }
    if ($getlocations_leaflet_plugins['mapquest_geocoder_enable']) {
      $url2 = $scheme . '://' . $dom . '/' . 'mq-geocoding.js' . '?key=' . $mapquest_lic['key'];
      $jsarr += array(
        $url2 => array(
          'type' => 'external',
          'weight' => 23,
        ),
      );
    }
  }
  $jsarr += array(
    $getlocations_leaflet_paths['getlocations_leaflet_providers_path'] => array(
      'type' => 'file',
      'preprocess' => $aggr,
    ),
    $getlocations_leaflet_paths['getlocations_leaflet_path'] => array(
      'type' => 'file',
      'weight' => 10,
      'preprocess' => $aggr,
    ),
  );
  if (module_exists('field_group')) {
    $jsarr += array(
      $getlocations_leaflet_paths['getlocations_leaflet_field_group_path'] => array(
        'type' => 'file',
        'weight' => 10,
        'preprocess' => $aggr,
      ),
    );
  }
  $libraries['getlocations-leaflet']['js'] = $jsarr;
  if (!empty($cssarr)) {
    $libraries['getlocations-leaflet']['css'] = $cssarr;
  }
  return $libraries;
}

/**
 * Implements hook_views_api().
 */
function getlocations_leaflet_views_api() {
  return array(
    'api' => 3,
    'path' => GETLOCATIONS_LEAFLET_PATH . '/views',
  );
}

/**
 * Implements hook_field_info().
 * Define Field API field types.
 *
 * @return
 *   An array whose keys are field type names and whose values are arrays
 *   describing the field type.
 */
function getlocations_leaflet_field_info() {
  $info = array(
    'getlocations_leaflet' => array(
      'label' => t('Getlocations Leaflet Map'),
      'description' => t('Provide Getlocations Leaflet Map.'),
      'default_formatter' => 'getlocations_leaflet_map',
      'default_widget' => 'getlocations_leaflet_map',
      'settings' => array(
        'input_text' => 0,
      ),
    ),
  );
  return $info;
}

/**
 * Implements hook_field_formatter_info().
 *
 * Declare information about a formatter.
 *
 * @return
 *   An array keyed by formatter name. Each element of the array is an associative
 *   array with these keys and values:
 *   - "label": The human-readable label for the formatter.
 *   - "field types": An array of field type names that can be displayed using
 *     this formatter.
 *
 */
function getlocations_leaflet_field_formatter_info() {
  $formatters = array(
    'getlocations_leaflet_map' => array(
      'label' => t('Getlocations Leaflet Map Field'),
      'field types' => array(
        'getlocations_leaflet',
      ),
      'settings' => getlocations_leaflet_map_formatter_defaults(),
    ),
    'getlocations_leaflet_link' => array(
      'label' => t('Getlocations Leaflet Link Field'),
      'field types' => array(
        'getlocations_leaflet',
      ),
      'settings' => getlocations_leaflet_link_formatter_defaults(),
    ),
  );
  return $formatters;
}

/**
 * Implements hook_field_formatter_view().
 * Build a renderable array for a field value.
 *
 * @param $entity_type
 *   The type of $entity.
 * @param $entity
 *   The entity being displayed.
 * @param $field
 *   The field structure.
 * @param $instance
 *   The field instance.
 * @param $langcode
 *   The language associated with $items.
 * @param $items
 *   Array of values for this field.
 * @param $display
 *   The display settings to use, as found in the 'display' entry of instance definitions.
 * @return
 *   A renderable array for the $items, as an array of child elements keyed
 *   by numeric indexes starting from 0.
 *
 */
function getlocations_leaflet_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  global $language;
  $lang = $langcode ? $langcode : ($entity->language ? $entity->language : $language->language);
  $locative_field_name = isset($items[0]['locative_field_name']) ? $items[0]['locative_field_name'] : '';
  if (empty($locative_field_name) || !isset($entity->{$locative_field_name}[$lang])) {
    return;
  }
  $locative_fields = $entity->{$locative_field_name}[$lang];
  if (!(is_array($locative_fields) && count($locative_fields) > 0)) {
    return;
  }
  $settings = $display['settings'];
  $element = array();
  switch ($display['type']) {
    case 'getlocations_leaflet_map':
      if (empty($settings)) {
        $settings = getlocations_leaflet_map_formatter_defaults();
      }
      $module = getlocations_get_current_supported_module();
      $bundle = $instance['bundle'];
      $minmaxes = '';
      $default_settings = getlocations_leaflet_map_formatter_defaults();
      $default = getlocations_adjust_vars($default_settings, $settings);

      // awesome
      $marker = '';
      $vector = '';
      if ($settings['awesome'] && $settings['marker_type'] == 'fa') {
        if ($entity_type == 'node') {
          $per_field_markers = FALSE;
          $getlocations_node_marker = variable_get('getlocations_node_marker', array(
            'enable' => 0,
          ));
          if ($getlocations_node_marker['enable']) {
            if ($types = getlocations_get_types()) {
              foreach ($types as $type => $name) {
                if ($type == $bundle) {
                  $field_names = getlocations_get_fieldname2($type, 'node');
                  foreach ($field_names as $field_name) {
                    if ($field_name == $locative_field_name) {
                      $mkey = 'node_marker__' . drupal_strtolower($type) . '__' . $field_name;
                      $vicon = getlocations_leaflet_awesome_marker_get($settings, $mkey);
                      $per_field_markers = TRUE;
                    }
                  }
                }
              }
            }
          }
          if (!$per_field_markers) {
            $vicon = getlocations_leaflet_awesome_marker_get($settings, 'node');
          }

          // TODO per tid marker
        }
        elseif ($entity_type == 'taxonomy_term') {
          $vicon = getlocations_leaflet_awesome_marker_get($settings, 'vocabulary');

          // TODO ??? sort out vocab/term
        }
        elseif ($entity_type == 'user') {
          $vicon = getlocations_leaflet_awesome_marker_get($settings, 'user');
        }
        elseif ($entity_type == 'comment') {
          $vicon = getlocations_leaflet_awesome_marker_get($settings, 'comment');
        }
        else {
          $vicon = getlocations_leaflet_awesome_marker_get($settings);
        }
        $vector = $vicon;
      }
      else {

        // marker
        if ($entity_type == 'node') {
          $per_field_markers = FALSE;
          $getlocations_node_marker = variable_get('getlocations_node_marker', array(
            'enable' => 0,
          ));
          if ($getlocations_node_marker['enable']) {
            if ($types = getlocations_get_types()) {
              foreach ($types as $type => $name) {
                if ($type == $bundle) {
                  $field_names = getlocations_get_fieldname2($type, 'node');
                  foreach ($field_names as $field_name) {
                    if ($field_name == $locative_field_name) {
                      $marker = isset($getlocations_node_marker['content_type'][$type]['field_name'][$field_name]['map_marker']) ? $getlocations_node_marker['content_type'][$type]['field_name'][$field_name]['map_marker'] : '';
                      $per_field_markers = TRUE;
                    }
                  }
                }
              }
            }
          }
          if (!$per_field_markers) {
            $marker = isset($default['node_map_marker']) ? $default['node_map_marker'] : '';
          }
        }
        elseif ($entity_type == 'user') {
          $marker = isset($default['user_map_marker']) ? $default['user_map_marker'] : '';
        }
        elseif ($entity_type == 'taxonomy_term') {

          // TODO needs testing
          if (module_exists('taxonomy')) {

            // vocabulary markers
            if ($types = getlocations_get_vocabularies()) {
              $getlocations_vocabulary_marker = variable_get('getlocations_vocabulary_marker', array(
                'enable' => 0,
              ));
              if ($getlocations_vocabulary_marker['enable']) {
                foreach ($types as $type => $name) {
                  $field_name = getlocations_get_fieldname($type, 'taxonomy_term');
                  if ($field_name == $locative_field_name) {
                    $marker = isset($getlocations_vocabulary_marker['vocabulary'][$type]['map_marker']) ? $getlocations_vocabulary_marker['vocabulary'][$type]['map_marker'] : $default['vocabulary_map_marker'];
                  }
                }
              }
            }

            // term markers
            $getlocations_term_marker = variable_get('getlocations_term_marker', array(
              'enable' => 0,
              'vids' => 0,
              'max_depth' => '',
            ));
            if ($getlocations_term_marker['enable'] && $getlocations_term_marker['vids']) {
              $depth = is_numeric($getlocations_term_marker['max_depth']) && $getlocations_term_marker['max_depth'] > 0 ? $getlocations_term_marker['max_depth'] : NULL;
              $vids = $getlocations_term_marker['vids'];
              foreach ($vids as $vid) {
                $terms = taxonomy_get_tree($vid, 0, $depth);
                foreach ($terms as $term) {
                  $tid = $term->tid;
                  $marker = isset($getlocations_term_marker['vid'][$vid]['term'][$tid]['map_marker']) ? $getlocations_term_marker['vid'][$vid]['term'][$tid]['map_marker'] : $default['term_map_marker'];
                }
              }
            }
          }
        }
        elseif ($entity_type == 'comment') {
          $marker = isset($default['comment_map_marker']) ? $default['comment_map_marker'] : '';
        }
        else {
          $marker = isset($default['node_map_marker']) ? $default['node_map_marker'] : '';
        }
      }
      $mapzoom = FALSE;
      $iconlist = array();
      $minmaxes = array(
        'minlat' => 0,
        'minlon' => 0,
        'maxlat' => 0,
        'maxlon' => 0,
      );

      // fetch lats and lons
      $ct = 0;
      foreach (array_keys($locative_fields) as $delta) {
        $title = '';
        $lid = 0;
        if (isset($entity->{$locative_field_name}[$lang][$delta]) && ($location = $entity->{$locative_field_name}[$lang][$delta])) {

          // collect the lat and lon
          if ($module == 'getlocations_fields') {
            $lat = $location['latitude'];
            $lon = $location['longitude'];
            $lid = isset($location['glid']) ? $location['glid'] : 0;
          }
          elseif ($module == 'location_cck') {
            $lat = $location['latitude'];
            $lon = $location['longitude'];
            $lid = isset($location['lid']) ? $location['lid'] : 0;
          }
          elseif ($module == 'geofield') {
            $lat = $location['lat'];
            $lon = $location['lon'];
          }
          elseif ($module == 'geolocation') {
            $lat = $location['lat'];
            $lon = $location['lng'];
          }
          if (isset($lat) && !empty($lat) && isset($lon) && !empty($lon) && ($latlon = getlocations_latlon_check($lat . ',' . $lon))) {
            $ll = explode(',', $latlon);
            $location['latitude'] = $ll[0];
            $location['longitude'] = $ll[1];
            $entity_get_info = entity_get_info($entity_type);
            $entity_key = $entity_get_info['entity keys']['id'];

            // nid, cid, uid etc
            $entity_id = $entity->{$entity_key};
            if (isset($location['name']) && !empty($location['name'])) {
              $title = $location['name'];
            }
            else {
              $title = isset($entity->title) ? $entity->title : '';
            }
            $title = htmlspecialchars_decode(strip_tags($title), ENT_QUOTES);
            $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);

            // per item marker
            if (isset($location['marker']) && !empty($location['marker'])) {
              $marker = $location['marker'];
            }
            if (isset($location['mapzoom'])) {
              $mapzoom = $location['mapzoom'];
            }
            if ($lid && $default['markeraction'] == 'popup') {
              $extra = FALSE;
              if (isset($default['getdirections_link'])) {
                $extra['gdlink'] = $default['getdirections_link'];
              }
              $markeraction = array(
                'type' => 'popup',
                'data' => getlocations_getinfo($lid, $entity_key, $extra),
              );
            }
            elseif ($lid && $default['markeraction'] == 'link') {
              $markeraction = array(
                'type' => 'link',
                'data' => getlocations_getlidinfo($lid, $entity_key),
              );
            }
            else {
              $markeraction = array();
            }
            $iconlist[$marker] = getlocations_leaflet_get_marker($marker);
            $latlons[$ct] = array(
              $location['latitude'],
              $location['longitude'],
              $entity_key,
              $entity_id,
              $lid,
              $title,
              $marker,
              $vector,
              $markeraction,
              '',
            );
            $ct++;
          }

          // end lat lon check
        }
      }

      // end foreach
      if ($ct < 2) {
        unset($minmaxes);
        $minmaxes = '';
      }
      $map_settings = getlocations_leaflet_map_get_info('Getlocations OSM');
      $map_settings = getlocations_leaflet_get_map_layers($map_settings);
      if (!empty($settings['baselayers'])) {
        $map_layers = array();
        foreach ($settings['baselayers'] as $k => $v) {
          if (isset($map_settings['map_layers'][$k]) && $settings['baselayers'][$k]) {
            $map_layers[$k] = $map_settings['map_layers'][$k];
          }
        }
        if (!empty($map_layers)) {
          $map_settings['map_layers'] = $map_layers;
        }
      }
      $nodezoom = FALSE;
      if ($ct == 1 && $settings['nodezoom']) {
        $nodezoom = $settings['nodezoom'];
        $map_settings['map_opts']['center'] = array(
          $location['latitude'],
          $location['longitude'],
        );
        $map_settings['map_opts']['zoom'] = $nodezoom;
      }
      elseif ($ct < 1) {
        $ll = explode(',', $default['latlong']);
        $map_settings['map_opts']['center'] = array(
          $ll[0],
          $ll[1],
        );
        $map_settings['map_opts']['zoom'] = $default['zoom'];
      }
      $mapid = getlocations_setup_map('', FALSE, FALSE, TRUE);

      // add in some more
      $map_settings = getlocations_leaflet_map_settings_do($map_settings, $default, $latlons, $mapid);
      $map_settings['map_settings']['nodezoom'] = $nodezoom ? $nodezoom : $default['nodezoom'];
      $map_settings['map_settings']['minmaxes'] = empty($minmaxes) ? FALSE : implode(',', $minmaxes);
      $map_settings['icons'] = $iconlist;
      $map_settings['datanum'] = $ct;
      $map_settings['latlons'] = $latlons;
      $element[$delta] = array(
        '#theme' => 'getlocations_leaflet_map',
        '#width' => $default['width'],
        '#height' => $default['height'],
        '#map_settings' => $map_settings,
        '#mapid' => $mapid,
        '#links' => '',
      );
      break;
    case 'getlocations_leaflet_link':
      if (empty($settings) || !isset($settings['text'])) {
        $settings = getlocations_leaflet_link_formatter_defaults();
      }
      $bundle = $instance['bundle'];
      foreach (array_keys($locative_fields) as $delta) {
        $entity_get_info = entity_get_info($entity_type);
        $entity_key = $entity_get_info['entity keys']['id'];

        // nid, cid, uid etc
        $entity_id = $entity->{$entity_key};
        $link_text = $settings['text'];
        if ($settings['text_opt'] == 'page') {
          $entity_title = '';
          if (isset($entity_get_info['entity keys']['label'])) {
            $entity_title = $entity_get_info['entity keys']['label'];
          }
          elseif ($entity_type == 'user') {
            $entity_title = 'name';
          }
          if ($entity_title && isset($entity->{$entity_title})) {
            $link_text = $entity->{$entity_title};
          }
        }
        $element[$delta] = array(
          '#theme' => 'getlocations_leaflet_link',
          '#link_text' => $link_text,
          '#entity_type' => $entity_type,
          '#entity_id' => $entity_id,
        );
      }
      break;
  }

  // end switch
  return $element;
}

/**
 * Implements hook_field_formatter_settings_summary().
 * Returns a short summary for the current formatter settings of an instance.
 *
 *
 * If an empty result is returned, the formatter is assumed to have no
 * configurable settings, and no UI will be provided to display a settings
 * form.
 *
 *   The field structure.
 * @param $instance
 *   The instance structure.
 * @param $view_mode
 *   The view mode for which a settings summary is requested.
 *
 * @return
 *   A string containing a short summary of the formatter settings.
 */
function getlocations_leaflet_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $summary = array();
  switch ($display['type']) {
    case 'getlocations_leaflet_map':
      $summary[] = t('Getlocations Leaflet Map Field settings');
      if ($settings['zoomslider']) {
        $summary[] = t('Show zoom slider: Yes');
      }
      elseif ($settings['zoomControl']) {
        $summary[] = t('Show zoom control: Yes');
      }
      if ($settings['layerControl']) {
        $summary[] = t('Show layer control: Yes');
      }
      if ($settings['scaleControl']) {
        $summary[] = t('Show scale: Yes');
      }
      if ($settings['attributionControl']) {
        $summary[] = t('Show attribution: Yes');
      }
      if ($settings['fullscreen']) {
        $summary[] = t('Show fullscreen control: Yes');
      }
      if ($settings['geocoder']) {
        $summary[] = t('Show Geocoder control: Yes');
      }
      if ($settings['markercluster']) {
        $summary[] = t('Enable markercluster: Yes');
      }
      if ($settings['pancontrol']) {
        $summary[] = t('Show Pan control: Yes');
      }
      if ($settings['awesome']) {
        if ($settings['marker_type'] == 'gg') {
          $summary[] = t('Marker type: Getlocations');
        }
        elseif ($settings['marker_type'] == 'fa') {
          $summary[] = t('Marker type: Awesome fonts');
        }
      }
      if ($settings['graticule']) {
        $summary[] = t('Show grid: Yes');
      }
      if ($settings['polygons_enable']) {
        $summary[] = t('Enable polygons: Yes');
        if ($settings['polygons_clickable']) {
          $summary[] = t('Polygons clickable: Yes');
        }
      }
      if ($settings['rectangles_enable']) {
        $summary[] = t('Enable rectangles: Yes');
        if ($settings['rectangles_clickable']) {
          $summary[] = t('Rectangles clickable: Yes');
        }
      }
      if ($settings['circles_enable']) {
        $summary[] = t('Enable circles: Yes');
        if ($settings['circles_clickable']) {
          $summary[] = t('Circles clickable: Yes');
        }
      }
      if ($settings['polylines_enable']) {
        $summary[] = t('Enable polylines: Yes');
        if ($settings['polylines_clickable']) {
          $summary[] = t('Polylines clickable: Yes');
        }
      }
      if ($settings['usermarker']) {
        $summary[] = t('GPS button: Yes');
      }
      if ($settings['bouncemarker']) {
        $summary[] = t('Bounce markers: Yes');
      }
      if ($settings['magnifyingglass']) {
        $summary[] = t('Magnifying Glass: Yes');
      }
      if ($settings['terminator']) {
        $summary[] = t('Day/Night: Yes');
      }
      break;
    case 'getlocations_leaflet_link':
      $summary[] = t('Getlocations Leaflet Link Field settings');
      if ($settings['text_opt']) {
        $summary[] = t('Text options: @a', array(
          '@a' => $settings['text_opt'],
        ));
      }
      if ($settings['text']) {
        $summary[] = t('Text: @a', array(
          '@a' => $settings['text'],
        ));
      }
      break;
  }
  return implode('<br />', $summary);
}

/**
 * Implements hook_field_formatter_settings_form().
 * Returns form elements for a formatter's settings.
 *
 * @param $field
 *   The field structure being configured.
 * @param $instance
 *   The instance structure being configured.
 * @param $view_mode
 *   The view mode being configured.
 * @param $form
 *   The (entire) configuration form array, which will usually have no use here.
 * @param $form_state
 *   The form state of the (entire) configuration form.
 *
 * @return
 *   The form elements for the formatter settings.
 */
function getlocations_leaflet_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $getlocations_leaflet_paths = getlocations_leaflet_paths_get();
  drupal_add_js($getlocations_leaflet_paths['getlocations_leaflet_formatter_path']);
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $element = array();
  switch ($display['type']) {
    case 'getlocations_leaflet_map':
      $settings['map_resize'] = 0;
      $settings['fullscreen_disable'] = 0;
      $settings['styles'] = '';
      $labels = array(
        'width' => t('Width'),
        'height' => t('Height'),
      );
      $element += getlocations_map_display_basics_form($settings, $labels);
      unset($element['map_resize']);
      unset($element['fullscreen_disable']);
      unset($element['styles']);
      $element['width']['#element_validate'] = array(
        'getlocations_element_validate_dim',
      );
      $element['height']['#element_validate'] = array(
        'getlocations_element_validate_dim',
      );
      $element['latlong']['#element_validate'] = array(
        'getlocations_element_validate_latlon',
      );
      unset($element['zoom']['#options']['21']);
      unset($element['zoom']['#options']['20']);
      unset($element['zoom']['#options']['19']);
      unset($element['minzoom_map']['#options']['21']);
      unset($element['minzoom_map']['#options']['20']);
      unset($element['minzoom_map']['#options']['19']);
      unset($element['maxzoom_map']['#options']['21']);
      unset($element['maxzoom_map']['#options']['20']);
      unset($element['maxzoom_map']['#options']['19']);
      $element += getlocations_leaflet_display_options_form($settings, TRUE);
      unset($element['nodezoom']['#options']['21']);
      unset($element['nodezoom']['#options']['20']);
      unset($element['nodezoom']['#options']['19']);

      // awesome?
      break;
    case 'getlocations_leaflet_link':
      $element['text'] = array(
        '#type' => 'textfield',
        '#title' => t('Default text'),
        '#description' => t('The text to use if no other option is available.'),
        '#default_value' => $settings['text'],
        '#size' => 25,
      );
      $element['text_opt'] = array(
        '#type' => 'select',
        '#title' => t('Display format'),
        '#default_value' => $settings['text_opt'],
        '#options' => $settings['text_options'],
      );
      break;
  }
  return $element;
}

/**
 * Implements hook_field_widget_info().
 * Expose Field API widget types.
 *
 * @return
 *   An array describing the widget types implemented by the module.
 *
 */
function getlocations_leaflet_field_widget_info() {
  $info = array(
    'getlocations_leaflet_map' => array(
      'label' => t('Getlocations Leaflet Map Field'),
      'field types' => array(
        'getlocations_leaflet',
      ),
      'settings' => array(),
    ),
  );
  return $info;
}

/**
 * Implements hook_field_widget_form().
 * Return the form for a single field widget.
 *
 * @param $form
 *   The form structure where widgets are being attached to. This might be a
 *   full form structure, or a sub-element of a larger form.
 * @param $form_state
 *   An associative array containing the current state of the form.
 * @param $field
 *   The field structure.
 * @param $instance
 *   The field instance.
 * @param $langcode
 *   The language associated with $items.
 * @param $items
 *   Array of default values for this field.
 * @param $delta
 *   The order of this item in the array of subelements (0, 1, 2, etc).
 * @param $element
 *   A form element array containing basic properties for the widget.
 * @return
 *   The form elements for a single widget for this field.
 */
function getlocations_leaflet_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch ($instance['widget']['type']) {
    case 'getlocations_leaflet_map':

      // is this real or a demo in settings
      $active = TRUE;
      if (empty($element['#entity'])) {
        $active = FALSE;
      }
      $entity_type = $element['#entity_type'];
      $bundle = $element['#bundle'];
      $module = getlocations_get_current_supported_module();
      $fieldnames = array();
      $query = db_select('field_config', 'f');
      $query
        ->fields('i', array(
        'field_name',
        'data',
      ));
      $query
        ->join('field_config_instance', 'i', 'f.id=i.field_id');
      $query
        ->condition('i.bundle', $bundle)
        ->condition('f.module', $module)
        ->condition('i.entity_type', $entity_type)
        ->condition('f.active', 1);
      $rows = $query
        ->execute();
      foreach ($rows as $row) {
        $data = unserialize($row->data);
        $fieldnames[$row->field_name] = $data['label'];
      }
      $cardinality = $field['cardinality'];

      // Wrap in a fieldset for single fields
      if ($cardinality == 1) {
        $element['#type'] = 'fieldset';
        $element['#collapsible'] = TRUE;
        $element['#collapsed'] = FALSE;
      }
      if (!empty($fieldnames)) {
        $element['#delta'] = $delta;
        $dval = isset($items[$delta]['locative_field_name']) ? $items[$delta]['locative_field_name'] : (isset($instance['default_value'][$delta]['locative_field_name']) ? $instance['default_value'][$delta]['locative_field_name'] : '');
        if ($active && module_exists('views_bulk_operations') && isset($settings['input_text']) && $settings['input_text']) {
          $element['locative_field_name'] = array(
            '#type' => 'textfield',
            '#title' => t('Location Field'),
            '#description' => t('Field to take locative data from'),
            '#default_value' => $dval,
            '#size' => 30,
          );
        }
        else {

          // items only see which field, no choice
          if ($active && $dval) {
            $element['locative_field_name'] = array(
              '#type' => 'value',
              '#value' => $dval,
            );
            $element['locative_field_name_markup'] = array(
              '#markup' => '<p>' . t('Locative data taken from !f', array(
                '!f' => $fieldnames[$dval],
              )) . '</p>',
            );
          }
          else {
            $element['locative_field_name'] = array(
              '#type' => 'select',
              '#title' => t('Location Field'),
              '#options' => $fieldnames,
              '#description' => t('Field to take locative data from'),
              '#default_value' => $dval,
            );
          }
        }
      }
      else {
        if (!$active) {
          $element['some_info'] = array(
            '#type' => 'markup',
            '#markup' => '<p>' . t('You must attach an instance of !m', array(
              '!m' => $module,
            )),
          );
        }
      }
      break;
  }
  return $element;
}

/**
 * Implements hook_field_widget_error().
 *
 * hook_field_widget_error() lets us figure out what to do with errors
 * we might have generated in hook_field_validate(). Generally, we'll just
 * call form_error().
 *
 */
function getlocations_leaflet_field_widget_error($element, $error, $form, &$form_state) {
  switch ($error['error']) {
    case 'getlocations_leaflet_field_invalid':
      form_error($element, $error['message']);
      break;
  }
}

/**
 * Implements hook_field_is_empty().
 * Define what constitutes an empty item for a field type.
 * hook_field_is_emtpy() is where Drupal asks us if this field is empty.
 * Return TRUE if it does not contain data, FALSE if it does. This lets
 * the form API flag an error when required fields are empty.
 *
 * @param $item
 *   An item that may or may not be empty.
 * @param $field
 *   The field to which $item belongs.
 * @return
 *   TRUE if $field's type considers $item not to contain any data;
 *   FALSE otherwise.
 */
function getlocations_leaflet_field_is_empty($item, $field) {
  return FALSE;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_map_formatter_defaults() {
  return getlocations_leaflet_defaults();
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_link_formatter_defaults() {
  return array(
    'text' => t('this location'),
    'text_opt' => 'page',
    'text_options' => array(
      '' => t('None'),
      'page' => t('Page title'),
    ),
  );
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_map_settings_do($map_settings, $defaults, $latlons, $mapid) {
  $map_settings['map_opts']['dragging'] = $defaults['dragging'] ? TRUE : FALSE;
  $map_settings['map_opts']['scrollWheelZoom'] = $defaults['scrollWheelZoom'] ? TRUE : FALSE;
  $map_settings['map_opts']['doubleClickZoom'] = $defaults['doubleClickZoom'] ? TRUE : FALSE;
  $map_settings['map_opts']['touchZoom'] = $defaults['touchZoom'] ? TRUE : FALSE;
  $map_settings['map_opts']['trackResize'] = $defaults['trackResize'] ? TRUE : FALSE;
  $map_settings['map_opts']['fadeAnimation'] = $defaults['fadeAnimation'] ? TRUE : FALSE;
  $map_settings['map_opts']['zoomAnimation'] = $defaults['zoomAnimation'] ? TRUE : FALSE;
  $map_settings['map_opts']['closePopupOnClick'] = $defaults['closePopupOnClick'] ? TRUE : FALSE;
  $map_settings['map_opts']['boxZoom'] = $defaults['boxZoom'] ? TRUE : FALSE;
  $map_settings['map_opts']['tap'] = $defaults['tap'] ? TRUE : FALSE;
  $map_settings['map_opts']['tapTolerance'] = $defaults['tapTolerance'];
  $map_settings['map_opts']['bounceAtZoomLimits'] = $defaults['bounceAtZoomLimits'] ? TRUE : FALSE;
  $getlocations_leaflet_plugins = getlocations_leaflet_plugins();
  if ($getlocations_leaflet_plugins['fullscreen_enable']) {
    $map_settings['map_settings']['fullscreen'] = $defaults['fullscreen'] ? TRUE : FALSE;
  }
  else {
    $map_settings['map_settings']['fullscreen'] = FALSE;
  }
  $map_settings['map_settings']['fullscreenposition'] = $defaults['fullscreenposition'];
  if ($getlocations_leaflet_plugins['graticule_enable']) {
    $map_settings['map_settings']['graticule'] = $defaults['graticule'] ? TRUE : FALSE;
    $map_settings['map_settings']['graticule_color'] = $defaults['graticule_color'];
    $map_settings['map_settings']['graticule_opacity'] = $defaults['graticule_opacity'];
    $map_settings['map_settings']['graticule_weight'] = $defaults['graticule_weight'];
    $map_settings['map_settings']['graticule_interval'] = $defaults['graticule_interval'];
    $map_settings['map_settings']['graticule_ov_label'] = $defaults['graticule_ov_label'];
    $map_settings['map_settings']['graticule_position'] = $defaults['graticule_position'];
    $map_settings['map_settings']['graticule_show'] = $defaults['graticule_show'];
    $map_settings['map_settings']['graticule_state'] = $defaults['graticule_state'];
  }
  else {
    $map_settings['map_settings']['graticule'] = FALSE;
  }
  if ($getlocations_leaflet_plugins['mouseposition_enable']) {
    $map_settings['map_settings']['mouseposition'] = $defaults['mouseposition'] ? TRUE : FALSE;
    $map_settings['map_settings']['mouseposition_position'] = $defaults['mouseposition_position'];
    $map_settings['map_settings']['mouseposition_display_dms'] = $defaults['mouseposition_display_dms'];
  }
  else {
    $map_settings['map_settings']['mouseposition'] = FALSE;
  }
  if ($getlocations_leaflet_plugins['minimap_enable']) {
    $map_settings['map_settings']['minimap'] = $defaults['minimap'] ? TRUE : FALSE;
  }
  else {
    $map_settings['map_settings']['minimap'] = FALSE;
  }

  // mapquest
  $mapquest_lic = variable_get('getlocations_mapquest_lic', array(
    'key' => '',
    'type' => 'l',
  ));
  $map_settings['map_settings']['mapquest_key'] = $mapquest_lic['key'];
  if ($getlocations_leaflet_plugins['geocoder_enable']) {
    $map_settings['map_settings']['geocoder'] = $defaults['geocoder'] ? TRUE : FALSE;
    $map_settings['map_settings']['geocoderposition'] = $defaults['geocoderposition'];
    $map_settings['map_settings']['geocodersrc'] = $defaults['geocodersrc'];
    $map_settings['map_settings']['geocodercollapsed'] = $defaults['geocodercollapsed'];
    $map_settings['map_settings']['geocoder_bing_key'] = $defaults['geocoder_bing_key'];
    $map_settings['map_settings']['geocoder_mapquest_key'] = $defaults['geocoder_mapquest_key'];
    $map_settings['map_settings']['geocoder_mapbox_key'] = $defaults['geocoder_mapbox_key'];
    $map_settings['map_settings']['geocoder_google_key'] = $defaults['geocoder_google_key'];
    $map_settings['map_settings']['geocoder_placeholder'] = $defaults['geocoder_placeholder'];
    $map_settings['map_settings']['geocoder_errormessage'] = $defaults['geocoder_errormessage'];
  }
  else {
    $map_settings['map_settings']['geocoder'] = FALSE;
  }

  // usermarker
  if ($getlocations_leaflet_plugins['usermarker_enable']) {
    $map_settings['map_settings']['usermarker'] = $defaults['usermarker'] ? TRUE : FALSE;
    $map_settings['map_settings']['usermarker_pulsing'] = $defaults['usermarker_pulsing'] ? TRUE : FALSE;
    $map_settings['map_settings']['usermarker_smallicon'] = $defaults['usermarker_smallicon'] ? TRUE : FALSE;
    $map_settings['map_settings']['usermarker_accuracy'] = $defaults['usermarker_accuracy'] ? TRUE : FALSE;
    $map_settings['map_settings']['usermarker_circle_stroke'] = $defaults['usermarker_circle_stroke'] ? TRUE : FALSE;
    $map_settings['map_settings']['usermarker_circle_strokecolor'] = $defaults['usermarker_circle_strokecolor'];
    $map_settings['map_settings']['usermarker_circle_strokeopacity'] = $defaults['usermarker_circle_strokeopacity'];
    $map_settings['map_settings']['usermarker_circle_strokeweight'] = $defaults['usermarker_circle_strokeweight'];
    $map_settings['map_settings']['usermarker_circle_fillcolor'] = $defaults['usermarker_circle_fillcolor'];
    $map_settings['map_settings']['usermarker_circle_fillopacity'] = $defaults['usermarker_circle_fillopacity'];
    $map_settings['map_settings']['usermarker_button_label'] = $defaults['usermarker_button_label'];
  }
  else {
    $map_settings['map_settings']['usermarker'] = FALSE;
  }

  // bouncemarker
  if ($getlocations_leaflet_plugins['bouncemarker_enable']) {
    $map_settings['map_settings']['bouncemarker'] = $defaults['bouncemarker'] ? TRUE : FALSE;
    $map_settings['map_settings']['bouncemarker_duration'] = $defaults['bouncemarker_duration'];
    $map_settings['map_settings']['bouncemarker_height'] = $defaults['bouncemarker_height'];
  }
  if ($getlocations_leaflet_plugins['markercluster_enable']) {
    $map_settings['map_settings']['markercluster'] = $defaults['markercluster'] ? TRUE : FALSE;
  }
  else {
    $map_settings['map_settings']['markercluster'] = FALSE;
  }
  if ($getlocations_leaflet_plugins['magnifyingglass_enable']) {
    $map_settings['map_settings']['magnifyingglass'] = $defaults['magnifyingglass'] ? TRUE : FALSE;
    $map_settings['map_settings']['magnifyingglasscontrolposition'] = $defaults['magnifyingglasscontrolposition'];
    $map_settings['map_settings']['magnifyingglassradius'] = $defaults['magnifyingglassradius'];
    $map_settings['map_settings']['magnifyingglasszoomoffset'] = $defaults['magnifyingglasszoomoffset'];

    #$map_settings['map_settings']['magnifyingglasstitle'] = $defaults['magnifyingglasstitle'];
  }
  else {
    $map_settings['map_settings']['magnifyingglass'] = FALSE;
  }
  if ($getlocations_leaflet_plugins['terminator_enable']) {
    $map_settings['map_settings']['terminator'] = $defaults['terminator'] ? TRUE : FALSE;
    $map_settings['map_settings']['terminator_strokecolor'] = $defaults['terminator_strokecolor'];
    $map_settings['map_settings']['terminator_strokeopacity'] = $defaults['terminator_strokeopacity'];
    $map_settings['map_settings']['terminator_strokeweight'] = $defaults['terminator_strokeweight'];
    $map_settings['map_settings']['terminator_fillcolor'] = $defaults['terminator_fillcolor'];
    $map_settings['map_settings']['terminator_fillopacity'] = $defaults['terminator_fillopacity'];
    $map_settings['map_settings']['terminator_position'] = $defaults['terminator_position'];
    $map_settings['map_settings']['terminator_show'] = $defaults['terminator_show'];
    $map_settings['map_settings']['terminator_state'] = $defaults['terminator_state'];
    $map_settings['map_settings']['terminator_label'] = $defaults['terminator_label'];
  }
  else {
    $map_settings['map_settings']['terminator'] = FALSE;
  }

  // mapquest
  $map_settings['map_settings']['mapquest_traffic_enable'] = $getlocations_leaflet_plugins['mapquest_traffic_enable'] ? 1 : 0;
  $map_settings['map_settings']['mapquest_traffic_flow'] = $defaults['mapquest_traffic_flow'] ? 1 : 0;
  $map_settings['map_settings']['mapquest_traffic_flow_on'] = $defaults['mapquest_traffic_flow_on'] ? 1 : 0;
  $map_settings['map_settings']['mapquest_traffic_incident'] = $defaults['mapquest_traffic_incident'] ? 1 : 0;
  $map_settings['map_settings']['mapquest_traffic_incident_on'] = $defaults['mapquest_traffic_incident_on'] ? 1 : 0;
  $map_settings['map_settings']['mapquest_routing_enable'] = $getlocations_leaflet_plugins['mapquest_routing_enable'] ? 1 : 0;
  $map_settings['map_settings']['mapquest_geocoder_enable'] = $getlocations_leaflet_plugins['mapquest_geocoder_enable'] ? 1 : 0;
  $map_settings['map_settings']['mapquest_maps_enable'] = $getlocations_leaflet_plugins['mapquest_maps_enable'] ? 1 : 0;
  $map_settings['map_settings']['mapquest_maps_default'] = $defaults['mapquest_maps_default'];
  $map_settings['map_settings']['mapquest_maps_maplayer'] = $defaults['mapquest_maps_maplayer'];
  $map_settings['map_settings']['mapquest_maps_satellitelayer'] = $defaults['mapquest_maps_satellitelayer'];
  $map_settings['map_settings']['mapquest_maps_hybridlayer'] = $defaults['mapquest_maps_hybridlayer'];
  $map_settings['map_settings']['mapquest_maps_use'] = $defaults['mapquest_maps_use'];
  if ($getlocations_leaflet_plugins['pancontrol_enable']) {
    $map_settings['map_settings']['leaflet_pancontrol'] = $defaults['pancontrol'] ? TRUE : FALSE;
  }
  else {
    $map_settings['map_settings']['leaflet_pancontrol'] = FALSE;
  }
  $map_settings['map_settings']['pancontrolposition'] = $defaults['pancontrolposition'];
  $map_settings['map_settings']['awesome'] = $getlocations_leaflet_plugins['awesome_enable'] ? TRUE : FALSE;
  $map_settings['map_settings']['markerclusteroptions'] = '';
  if (file_exists(GETLOCATIONS_LEAFLET_PATH . '/plugins/markercluster/markerclusteroptions.inc')) {
    module_load_include('inc', 'getlocations_leaflet', 'plugins/markercluster/markerclusteroptions');
    if (function_exists('getlocations_leaflet_get_markerclusteroptions')) {
      $map_settings['map_settings']['markerclusteroptions'] = getlocations_leaflet_get_markerclusteroptions();
    }
  }

  // Zoom
  if ($defaults['zoomControl']) {
    $map_settings['map_opts']['zoomControl'] = FALSE;
    $map_settings['map_settings']['zoomControl'] = TRUE;
  }
  else {
    $map_settings['map_opts']['zoomControl'] = FALSE;
    $map_settings['map_settings']['zoomControl'] = FALSE;
  }
  $map_settings['map_settings']['zoomcontrolposition'] = $defaults['zoomcontrolposition'];

  // zoomslider
  if ($getlocations_leaflet_plugins['zoomslider_enable']) {
    $map_settings['map_settings']['leaflet_zoomslider'] = $defaults['zoomslider'] ? TRUE : FALSE;

    // kill off zoomcontrol
    if ($defaults['zoomslider']) {
      $map_settings['map_settings']['zoomControl'] = FALSE;
      $map_settings['map_opts']['zoomControl'] = FALSE;
    }
  }
  else {
    $map_settings['map_settings']['leaflet_zoomslider'] = FALSE;
  }
  $map_settings['map_settings']['zoomsliderposition'] = $defaults['zoomsliderposition'];

  // Attribution
  if ($defaults['attributionControl'] && $defaults['attributioncontrolposition']) {
    $map_settings['map_opts']['attributionControl'] = FALSE;
    $map_settings['map_settings']['attributionControl'] = TRUE;
    $map_settings['map_settings']['attributioncontrolposition'] = $defaults['attributioncontrolposition'];
  }
  else {
    $map_settings['map_opts']['attributionControl'] = $defaults['attributionControl'] ? TRUE : FALSE;
    $map_settings['map_settings']['attributionControl'] = FALSE;
    $map_settings['map_settings']['attributioncontrolposition'] = '';
  }

  // Layer
  if ($defaults['layerControl'] && $defaults['layercontrolposition']) {
    $map_settings['map_opts']['layerControl'] = FALSE;
    $map_settings['map_settings']['layerControl'] = TRUE;
    $map_settings['map_settings']['layercontrolposition'] = $defaults['layercontrolposition'];
  }
  else {
    $map_settings['map_opts']['layerControl'] = FALSE;
    $map_settings['map_settings']['layerControl'] = $defaults['layerControl'] ? TRUE : FALSE;
    $map_settings['map_settings']['layercontrolposition'] = '';
  }

  // overlays
  $map_settings['map_settings']['layercontrol_mark_ov'] = $defaults['layercontrol_mark_ov'] ? TRUE : FALSE;
  $map_settings['map_settings']['layercontrol_mark_ov_label'] = $defaults['layercontrol_mark_ov_label'];
  $map_settings['map_settings']['layercontrol_circ_ov'] = $defaults['layercontrol_circ_ov'] ? TRUE : FALSE;
  $map_settings['map_settings']['layercontrol_circ_ov_label'] = $defaults['layercontrol_circ_ov_label'];
  $map_settings['map_settings']['layercontrol_polyl_ov'] = $defaults['layercontrol_polyl_ov'] ? TRUE : FALSE;
  $map_settings['map_settings']['layercontrol_polyl_ov_label'] = $defaults['layercontrol_polyl_ov_label'];
  $map_settings['map_settings']['layercontrol_polyg_ov'] = $defaults['layercontrol_polyg_ov'] ? TRUE : FALSE;
  $map_settings['map_settings']['layercontrol_polyg_ov_label'] = $defaults['layercontrol_polyg_ov_label'];
  $map_settings['map_settings']['layercontrol_rect_ov'] = $defaults['layercontrol_rect_ov'] ? TRUE : FALSE;
  $map_settings['map_settings']['layercontrol_rect_ov_label'] = $defaults['layercontrol_rect_ov_label'];

  // default map
  $ml = getlocations_leaflet_map_get_info('Getlocations OSM');
  $map_settings['map_settings']['default_layer_name'] = $defaults['default_baselayer'];
  $map_settings['map_settings']['default_layer_label'] = $ml['map_layers'][$defaults['default_baselayer']]['label'];

  // if only one has been selected
  if (isset($map_settings['map_layers']) && count($map_settings['map_layers']) == 1) {
    $map_keys = array_keys($map_settings['map_layers']);
    if ($map_settings['map_layers'][$map_keys[0]]['type'] == 'base') {
      $map_settings['map_settings']['default_layer_name'] = $map_keys[0];
      $map_settings['map_settings']['default_layer_label'] = $map_settings['map_layers'][$map_keys[0]]['label'];
    }
  }

  // Scale
  $map_settings['map_settings']['scaleControl'] = $defaults['scaleControl'] ? TRUE : FALSE;
  $map_settings['map_settings']['scalecontrolposition'] = $defaults['scalecontrolposition'];
  $map_settings['map_settings']['scalecontrolunits'] = $defaults['scalecontrolunits'];
  if ($defaults['minzoom_map'] > -1) {
    $map_settings['map_opts']['minZoom'] = $defaults['minzoom_map'];
  }
  if ($defaults['maxzoom_map'] > -1) {
    $map_settings['map_opts']['maxZoom'] = $defaults['maxzoom_map'];
  }
  $map_settings['map_settings']['show_maplinks'] = $defaults['show_maplinks'];
  $map_settings['map_settings']['show_maplinks_viewport'] = $defaults['show_maplinks_viewport'];
  $map_settings['map_settings']['show_search_distance'] = $defaults['show_search_distance'];
  $map_settings['map_settings']['views_search_marker_enable'] = $defaults['views_search_marker_enable'];
  $map_settings['map_settings']['views_search_marker'] = $defaults['views_search_marker'];
  $map_settings['map_settings']['views_search_marker_info'] = '';
  if ($defaults['views_search_marker']) {
    $map_settings['map_settings']['views_search_marker_info'] = getlocations_leaflet_get_marker($defaults['views_search_marker']);
  }
  $map_settings['map_settings']['views_search_marker_toggle'] = $defaults['views_search_marker_toggle'];
  $map_settings['map_settings']['views_search_marker_toggle_active'] = $defaults['views_search_marker_toggle_active'];
  $map_settings['map_settings']['views_search_radshape_enable'] = $defaults['views_search_radshape_enable'];
  $map_settings['map_settings']['views_search_radshape_strokecolor'] = $defaults['views_search_radshape_strokecolor'];
  $map_settings['map_settings']['views_search_radshape_strokeopacity'] = $defaults['views_search_radshape_strokeopacity'];
  $map_settings['map_settings']['views_search_radshape_strokeweight'] = $defaults['views_search_radshape_strokeweight'];
  $map_settings['map_settings']['views_search_radshape_fillcolor'] = $defaults['views_search_radshape_fillcolor'];
  $map_settings['map_settings']['views_search_radshape_fillopacity'] = $defaults['views_search_radshape_fillopacity'];
  $map_settings['map_settings']['views_search_radshape_toggle'] = $defaults['views_search_radshape_toggle'];
  $map_settings['map_settings']['views_search_radshape_toggle_active'] = $defaults['views_search_radshape_toggle_active'];
  $map_settings['map_settings']['views_search_center'] = $defaults['views_search_center'];
  $map_settings['map_settings']['geolocation_mobile_check'] = $defaults['geolocation_mobile_check'];

  // field group support;
  $map_settings['map_settings']['field_group_enable'] = module_exists('field_group') ? 1 : 0;

  // leaflet hash
  $map_settings['map_settings']['hashurl'] = $getlocations_leaflet_plugins['hash_enable'] ? $defaults['hashurl'] : 0;
  $getlocations_leaflet_paths = getlocations_leaflet_paths_get();

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

    #$map_settings['map_settings']['what3words_key'] = $what3words_lic['key'];
    $map_settings['map_settings']['what3words_enable'] = $defaults['what3words_enable'];
    $map_settings['map_settings']['what3words_search'] = $defaults['what3words_search'];

    #$map_settings['map_settings']['what3words_map_marker']  = $defaults['what3words_map_marker'];
    $map_settings['map_settings']['what3words_map_marker'] = $icon;
    $map_settings['map_settings']['what3words_center'] = $defaults['what3words_center'];
    $map_settings['map_settings']['what3words_zoom'] = $defaults['what3words_zoom'];
    $map_settings['map_settings']['what3words_show'] = $defaults['what3words_show'];
    $map_settings['map_settings']['what3words_marker_show'] = $defaults['what3words_marker_show'];
    $map_settings['map_settings']['what3words_click'] = $defaults['what3words_click'];
    $map_settings['map_settings']['what3words_size'] = $defaults['what3words_size'];
    $map_settings['map_settings']['what3words_path'] = url($defaults['what3words_path']);
    drupal_add_js($getlocations_leaflet_paths['getlocations_leaflet_what3words_path']);
  }
  else {
    $map_settings['map_settings']['what3words_enable'] = 0;
  }

  // shapes
  // 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_leaflet_polygons' => $polygon_settings,
      ), 'setting');
      drupal_add_js($getlocations_leaflet_paths['getlocations_leaflet_polygons_path']);
    }
  }

  // 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_leaflet_rectangles' => $rectangle_settings,
      ), 'setting');
      drupal_add_js($getlocations_leaflet_paths['getlocations_leaflet_rectangles_path']);
    }
  }

  // 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_leaflet_circles' => $circle_settings,
      ), 'setting');
      drupal_add_js($getlocations_leaflet_paths['getlocations_leaflet_circles_path']);
    }
  }

  // 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_leaflet_polylines' => $polyline_settings,
      ), 'setting');
      drupal_add_js($getlocations_leaflet_paths['getlocations_leaflet_polylines_path']);
    }
  }

  // geojson
  if ($defaults['geojson_enable'] && !empty($defaults['geojson_data']) && ($geojson_path = getlocations_get_geojson_path())) {
    drupal_add_js($geojson_path);
    $geojson_settings = array(
      $mapid => array(
        'geojson_data' => $defaults['geojson_data'],
        'geojson_options' => $defaults['geojson_options'],
      ),
    );
    drupal_add_js(array(
      'getlocations_leaflet_geojson' => $geojson_settings,
    ), 'setting');
    drupal_add_js($getlocations_leaflet_paths['getlocations_leaflet_geojson_path']);
  }
  return $map_settings;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_js_settings_do($defaults, $mapid) {
  $settings = array(
    $mapid => $defaults,
  );
  drupal_add_js(array(
    'getlocations_leaflet' => $settings,
  ), 'setting');
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_get_icondata($reset = FALSE) {
  static $icons;
  if (is_array($icons) && !$reset) {
    return $icons;
  }
  $icons = cache_get('getlocations_leaflet_icondata');
  if ($icons) {
    $icons = $icons->data;
  }
  if ($reset || !$icons) {
    module_load_include('inc', 'getlocations_leaflet', 'getlocations_leaflet.markerinfo');
    $icons = _getlocations_leaflet_get_icondata();
  }
  if ($icons) {
    cache_set('getlocations_leaflet_icondata', $icons, 'cache');
  }
  return $icons;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_regenerate_markers() {
  $icons = getlocations_leaflet_get_icondata(TRUE);
  if (!$icons) {

    // no markers found
    drupal_set_message(t('No markers found, you need to install some markers, please see the project page for details.'), 'error');
    watchdog('getlocations_leaflet', 'No markers found.', array(), WATCHDOG_ERROR);
    return FALSE;
  }
  return TRUE;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_get_marker($key) {
  $icons = getlocations_leaflet_get_icondata();
  if (isset($icons[$key])) {
    return $icons[$key];
  }
  return FALSE;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_marker_list() {
  $icons = getlocations_leaflet_get_icondata();
  if (!$icons) {

    // no markers found
    drupal_set_message(t('No markers found, you need to install some markers, please see the project page for details.'), 'error');
    watchdog('getlocations_leaflet', 'No markers found.', array(), WATCHDOG_ERROR);
    return FALSE;
  }
  $data = array();
  foreach ($icons as $k => $v) {
    $data[$k] = $v['name'];
  }
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_controlpositions($dd = TRUE) {
  if ($dd) {
    $controlpositions = array(
      '' => t('Default'),
      'topleft' => t('Top Left'),
      'topright' => t('Top Right'),
      'bottomright' => t('Bottom Right'),
      'bottomleft' => t('Bottom Left'),
    );
  }
  else {
    $controlpositions = array(
      'topleft',
      'topright',
      'bottomright',
      'bottomleft',
    );
  }
  return $controlpositions;
}

/**
 * Get all available Leaflet map definitions.
 *
 * Derived from the leaflet module
 *
 * @param string $map
 */
function getlocations_leaflet_map_get_info($map = NULL) {
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['getlocations_leaflet_map_info'] =& drupal_static(__FUNCTION__);
  }
  $map_info =& $drupal_static_fast['getlocations_leaflet_map_info'];
  if (empty($map_info)) {
    if ($cache = cache_get("getlocations_leaflet_map_info")) {
      $map_info = $cache->data;
    }
    else {
      $map_info = module_invoke_all('getlocations_leaflet_map_info');

      // Let other modules alter the map info.
      drupal_alter('getlocations_leaflet_map_info', $map_info);
      cache_set("getlocations_leaflet_map_info", $map_info);
    }
  }
  if (empty($map)) {
    return $map_info;
  }
  elseif (isset($map_info[$map])) {
    return $map_info[$map];
  }
}

/**
 * Implements hook_getlocations_leaflet_map_info().
 *
 */
function getlocations_leaflet_getlocations_leaflet_map_info() {
  $map_info = array(
    'Getlocations OSM' => array(
      'label' => 'Getlocations OSM',
      'description' => t('Getlocations Leaflet maps.'),
      'map_opts' => array(
        'dragging' => TRUE,
        'touchZoom' => TRUE,
        'scrollWheelZoom' => TRUE,
        'doubleClickZoom' => TRUE,
        'boxZoom' => TRUE,
        'tap' => TRUE,
        'tapTolerance' => 15,
        'zoomControl' => TRUE,
        'attributionControl' => TRUE,
        'trackResize' => TRUE,
        'fadeAnimation' => TRUE,
        'zoomAnimation' => TRUE,
        'closePopupOnClick' => TRUE,
        'bounceAtZoomLimits' => TRUE,
        'layerControl' => TRUE,
        'minZoom' => 0,
        'maxZoom' => 18,
      ),
      'map_settings' => array(
        'zoomcontrolposition' => '',
        'attributioncontrolposition' => '',
        'layercontrolposition' => '',
        'scaleControl' => FALSE,
        'scalecontrolposition' => '',
        'scalecontrolunits' => '',
        'markeraction' => '',
      ),
      'map_layers' => array(
        'OpenStreetMap.Mapnik' => array(
          'label' => t('OpenStreetMap Default'),
          'type' => 'base',
        ),
        'OpenStreetMap.BlackAndWhite' => array(
          'label' => t('OpenStreetMap Black and White'),
          'type' => 'base',
        ),
        'OpenStreetMap.DE' => array(
          'label' => t('OpenStreetMap German Style'),
          'type' => 'base',
        ),
        'OpenStreetMap.HOT' => array(
          'label' => t('OpenStreetMap H.O.T'),
          'type' => 'base',
        ),
        'Thunderforest.OpenCycleMap' => array(
          'label' => t('Thunderforest OpenCycleMap'),
          'type' => 'base',
        ),
        'Thunderforest.Transport' => array(
          'label' => t('Thunderforest Transport'),
          'type' => 'base',
        ),
        'Thunderforest.Landscape' => array(
          'label' => t('Thunderforest Landscape'),
          'type' => 'base',
        ),
        'Thunderforest.Outdoors' => array(
          'label' => t('Thunderforest Outdoors'),
          'type' => 'base',
        ),
        'MapQuestOpen.OSM' => array(
          'label' => t('MapQuestOpen OSM'),
          'type' => 'base',
        ),
        'MapQuestOpen.Aerial' => array(
          'label' => t('MapQuestOpen Aerial'),
          'type' => 'base',
        ),
        'Stamen.Toner' => array(
          'label' => t('Stamen Toner'),
          'type' => 'base',
        ),
        'Stamen.TonerBackground' => array(
          'label' => t('Stamen Toner Background'),
          'type' => 'base',
        ),
        'Stamen.TonerHybrid' => array(
          'label' => t('Stamen Toner Hybrid'),
          'type' => 'base',
        ),
        'Stamen.TonerLines' => array(
          'label' => t('Stamen Toner Lines'),
          'type' => 'base',
        ),
        'Stamen.TonerLabels' => array(
          'label' => t('Stamen Toner Labels'),
          'type' => 'base',
        ),
        'Stamen.TonerLite' => array(
          'label' => t('Stamen Toner Lite'),
          'type' => 'base',
        ),
        'Stamen.Terrain' => array(
          'label' => t('Stamen Terrain'),
          'type' => 'base',
        ),
        'Stamen.TerrainBackground' => array(
          'label' => t('Stamen Terrain Background'),
          'type' => 'base',
        ),
        'Stamen.Watercolor' => array(
          'label' => t('Stamen Watercolor'),
          'type' => 'base',
        ),
        'Esri.WorldStreetMap' => array(
          'label' => t('Esri WorldStreetMap'),
          'type' => 'base',
        ),
        'Esri.DeLorme' => array(
          'label' => t('Esri DeLorme'),
          'type' => 'base',
        ),
        'Esri.WorldTopoMap' => array(
          'label' => t('Esri WorldTopoMap'),
          'type' => 'base',
        ),
        'Esri.WorldImagery' => array(
          'label' => t('Esri WorldImagery'),
          'type' => 'base',
        ),
        'Esri.WorldTerrain' => array(
          'label' => t('Esri WorldTerrain'),
          'type' => 'base',
        ),
        'Esri.WorldShadedRelief' => array(
          'label' => t('Esri WorldShadedRelief'),
          'type' => 'base',
        ),
        'Esri.WorldPhysical' => array(
          'label' => t('Esri WorldPhysical'),
          'type' => 'base',
        ),
        'Esri.OceanBasemap' => array(
          'label' => t('Esri OceanBasemap'),
          'type' => 'base',
        ),
        'Esri.NatGeoWorldMap' => array(
          'label' => t('Esri NatGeoWorldMap'),
          'type' => 'base',
        ),
        'Esri.WorldGrayCanvas' => array(
          'label' => t('Esri WorldGrayCanvas'),
          'type' => 'base',
        ),
        'Acetate.all' => array(
          'label' => t('Acetate all'),
          'type' => 'base',
        ),
        'Acetate.basemap' => array(
          'label' => t('Acetate basemap'),
          'type' => 'base',
        ),
        'Acetate.terrain' => array(
          'label' => t('Acetate terrain'),
          'type' => 'base',
        ),
        'Acetate.foreground' => array(
          'label' => t('Acetate foreground'),
          'type' => 'base',
        ),
        'Acetate.roads' => array(
          'label' => t('Acetate roads'),
          'type' => 'base',
        ),
        'Acetate.labels' => array(
          'label' => t('Acetate labels'),
          'type' => 'base',
        ),
        'Acetate.hillshading' => array(
          'label' => t('Acetate hillshading'),
          'type' => 'base',
        ),
        'OpenSeaMap' => array(
          'label' => t('OpenSeaMap Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.Clouds' => array(
          'label' => t('OpenWeatherMap Clouds Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.CloudsClassic' => array(
          'label' => t('OpenWeatherMap Clouds Classic Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.Precipitation' => array(
          'label' => t('OpenWeatherMap Precipitation Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.PrecipitationClassic' => array(
          'label' => t('OpenWeatherMap Precipitation Classic Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.Rain' => array(
          'label' => t('OpenWeatherMap Rain Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.RainClassic' => array(
          'label' => t('OpenWeatherMap Rain Classic Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.Pressure' => array(
          'label' => t('OpenWeatherMap Pressure Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.PressureContour' => array(
          'label' => t('OpenWeatherMap PressureContour Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.Wind' => array(
          'label' => t('OpenWeatherMap Wind Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.Temperature' => array(
          'label' => t('OpenWeatherMap Temperature Overlay'),
          'type' => 'overlay',
        ),
        'OpenWeatherMap.Snow' => array(
          'label' => t('OpenWeatherMap Snow Overlay'),
          'type' => 'overlay',
        ),
      ),
    ),
  );
  return $map_info;
}

/**
 * Implements hook_field_settings_form().
 * Add settings to a field settings form.
 *
 * Invoked from field_ui_field_settings_form() to allow the module defining the
 * field to add global settings (i.e. settings that do not depend on the bundle
 * or instance) to the field settings form. If the field already has data, only
 * include settings that are safe to change.
 *
 * @todo: Only the field type module knows which settings will affect the
 * field's schema, but only the field storage module knows what schema
 * changes are permitted once a field already has data. Probably we need an
 * easy way for a field type module to ask whether an update to a new schema
 * will be allowed without having to build up a fake $prior_field structure
 * for hook_field_update_forbid().
 *
 * @param $field
 *   The field structure being configured.
 * @param $instance
 *   The instance structure being configured.
 * @param $has_data
 *   TRUE if the field already has data, FALSE if not.
 *
 * @return
 *   The form definition for the field settings.
 */
function getlocations_leaflet_field_settings_form($field, $instance, $has_data) {
  $settings = $field['settings'];
  if (empty($settings)) {
    $settings = getlocations_leaflet_field_info();
  }
  $form = array();

  // input_text
  if (module_exists('views_bulk_operations')) {
    $form['input_text'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use a textfield'),
      '#description' => t('Select this setting if you intend to use VBO to update data.'),
      '#default_value' => isset($settings['input_text']) ? $settings['input_text'] : 0,
      '#return_value' => 1,
    );
  }
  else {
    $form['input_text'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  return $form;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_defaults() {
  $getlocations_defaults = getlocations_defaults();
  $newdefaults = array(
    'width' => $getlocations_defaults['width'],
    'height' => $getlocations_defaults['height'],
    'zoom' => $getlocations_defaults['zoom'],
    'minzoom_map' => $getlocations_defaults['minzoom_map'],
    'maxzoom_map' => $getlocations_defaults['maxzoom_map'],
    'latlong' => $getlocations_defaults['latlong'],
    'nodezoom' => $getlocations_defaults['nodezoom'],
    'polygons_enable' => $getlocations_defaults['polygons_enable'],
    'polygons_strokecolor' => $getlocations_defaults['polygons_strokecolor'],
    'polygons_strokeopacity' => $getlocations_defaults['polygons_strokeopacity'],
    'polygons_strokeweight' => $getlocations_defaults['polygons_strokeweight'],
    'polygons_fillcolor' => $getlocations_defaults['polygons_fillcolor'],
    'polygons_fillopacity' => $getlocations_defaults['polygons_fillopacity'],
    'polygons_coords' => $getlocations_defaults['polygons_coords'],
    'polygons_clickable' => $getlocations_defaults['polygons_clickable'],
    'polygons_message' => $getlocations_defaults['polygons_message'],
    'rectangles_enable' => $getlocations_defaults['rectangles_enable'],
    'rectangles_strokecolor' => $getlocations_defaults['rectangles_strokecolor'],
    'rectangles_strokeopacity' => $getlocations_defaults['rectangles_strokeopacity'],
    'rectangles_strokeweight' => $getlocations_defaults['rectangles_strokeweight'],
    'rectangles_fillcolor' => $getlocations_defaults['rectangles_fillcolor'],
    'rectangles_fillopacity' => $getlocations_defaults['rectangles_fillopacity'],
    'rectangles_coords' => $getlocations_defaults['rectangles_coords'],
    'rectangles_clickable' => $getlocations_defaults['rectangles_clickable'],
    'rectangles_message' => $getlocations_defaults['rectangles_message'],
    'rectangles_apply' => $getlocations_defaults['rectangles_apply'],
    'rectangles_dist' => $getlocations_defaults['rectangles_dist'],
    'circles_enable' => $getlocations_defaults['circles_enable'],
    'circles_strokecolor' => $getlocations_defaults['circles_strokecolor'],
    'circles_strokeopacity' => $getlocations_defaults['circles_strokeopacity'],
    'circles_strokeweight' => $getlocations_defaults['circles_strokeweight'],
    'circles_fillcolor' => $getlocations_defaults['circles_fillcolor'],
    'circles_fillopacity' => $getlocations_defaults['circles_fillopacity'],
    'circles_coords' => $getlocations_defaults['circles_coords'],
    'circles_clickable' => $getlocations_defaults['circles_clickable'],
    'circles_message' => $getlocations_defaults['circles_message'],
    'circles_radius' => $getlocations_defaults['circles_radius'],
    'circles_apply' => $getlocations_defaults['circles_apply'],
    'polylines_enable' => $getlocations_defaults['polylines_enable'],
    'polylines_strokecolor' => $getlocations_defaults['polylines_strokecolor'],
    'polylines_strokeopacity' => $getlocations_defaults['polylines_strokeopacity'],
    'polylines_strokeweight' => $getlocations_defaults['polylines_strokeweight'],
    'polylines_coords' => $getlocations_defaults['polylines_coords'],
    'polylines_clickable' => $getlocations_defaults['polylines_clickable'],
    'polylines_message' => $getlocations_defaults['polylines_message'],
    // categories
    'category_method' => $getlocations_defaults['category_method'],
    'category_term_reference_field' => $getlocations_defaults['category_term_reference_field'],
    'category_showhide_buttons' => $getlocations_defaults['category_showhide_buttons'],
    'categories' => $getlocations_defaults['categories'],
    'returnlink_page_enable' => $getlocations_defaults['returnlink_page_enable'],
    'returnlink_page_link' => $getlocations_defaults['returnlink_page_link'],
    'returnlink_user_enable' => $getlocations_defaults['returnlink_user_enable'],
    'returnlink_user_link' => $getlocations_defaults['returnlink_user_link'],
    'returnlink_term_enable' => $getlocations_defaults['returnlink_term_enable'],
    'returnlink_term_link' => $getlocations_defaults['returnlink_term_link'],
    'returnlink_comment_enable' => $getlocations_defaults['returnlink_comment_enable'],
    'returnlink_comment_link' => $getlocations_defaults['returnlink_comment_link'],
    'geojson_enable' => $getlocations_defaults['geojson_enable'],
    'geojson_data' => $getlocations_defaults['geojson_data'],
    'geojson_options' => $getlocations_defaults['geojson_options'],
    'fullscreen' => $getlocations_defaults['fullscreen'],
    'node_map_marker' => $getlocations_defaults['node_map_marker'],
    'user_map_marker' => $getlocations_defaults['user_map_marker'],
    'vocabulary_map_marker' => $getlocations_defaults['vocabulary_map_marker'],
    'term_map_marker' => $getlocations_defaults['term_map_marker'],
    'comment_map_marker' => $getlocations_defaults['comment_map_marker'],
    'dragging' => $getlocations_defaults['draggable'],
    'scrollWheelZoom' => $getlocations_defaults['scrollwheel'],
    'doubleClickZoom' => $getlocations_defaults['nodoubleclickzoom'] ? 0 : 1,
    'zoomControl' => $getlocations_defaults['controltype'] == 'none' ? 0 : 1,
    'scaleControl' => $getlocations_defaults['scale'],
    'jquery_colorpicker_enabled' => $getlocations_defaults['jquery_colorpicker_enabled'],
    'getdirections_link' => $getlocations_defaults['getdirections_link'],
    'show_maplinks' => $getlocations_defaults['show_maplinks'],
    'show_maplinks_viewport' => $getlocations_defaults['show_maplinks_viewport'],
    'show_search_distance' => $getlocations_defaults['show_search_distance'],
    'views_search_marker_enable' => $getlocations_defaults['views_search_marker_enable'],
    'views_search_marker' => $getlocations_defaults['views_search_marker'],
    'views_search_marker_toggle' => $getlocations_defaults['views_search_marker_toggle'],
    'views_search_marker_toggle_active' => $getlocations_defaults['views_search_marker_toggle_active'],
    'views_search_radshape_enable' => $getlocations_defaults['views_search_radshape_enable'],
    'views_search_radshape_strokecolor' => $getlocations_defaults['views_search_radshape_strokecolor'],
    'views_search_radshape_strokeopacity' => $getlocations_defaults['views_search_radshape_strokeopacity'],
    'views_search_radshape_strokeweight' => $getlocations_defaults['views_search_radshape_strokeweight'],
    'views_search_radshape_fillcolor' => $getlocations_defaults['views_search_radshape_fillcolor'],
    'views_search_radshape_fillopacity' => $getlocations_defaults['views_search_radshape_fillopacity'],
    'views_search_radshape_toggle' => $getlocations_defaults['views_search_radshape_toggle'],
    'views_search_radshape_toggle_active' => $getlocations_defaults['views_search_radshape_toggle_active'],
    'views_search_center' => $getlocations_defaults['views_search_center'],
    'geolocation_mobile_check' => $getlocations_defaults['geolocation_mobile_check'],
    'what3words_enable' => $getlocations_defaults['what3words_enable'],
    'what3words_search' => $getlocations_defaults['what3words_search'],
    'what3words_size' => $getlocations_defaults['what3words_size'],
    'what3words_map_marker' => $getlocations_defaults['what3words_map_marker'],
    'what3words_marker_show' => $getlocations_defaults['what3words_marker_show'],
    'what3words_center' => $getlocations_defaults['what3words_center'],
    'what3words_zoom' => $getlocations_defaults['what3words_zoom'],
    'what3words_show' => $getlocations_defaults['what3words_show'],
    'what3words_click' => $getlocations_defaults['what3words_click'],
    'what3words_path' => $getlocations_defaults['what3words_path'],
  );
  $newdefaults['touchZoom'] = 1;
  $newdefaults['boxZoom'] = 1;
  $newdefaults['tap'] = 1;
  $newdefaults['tapTolerance'] = 15;
  $newdefaults['bounceAtZoomLimits'] = 1;
  $newdefaults['attributionControl'] = 1;
  $newdefaults['trackResize'] = 1;
  $newdefaults['fadeAnimation'] = 1;
  $newdefaults['zoomAnimation'] = 1;
  $newdefaults['closePopupOnClick'] = 1;
  $newdefaults['layerControl'] = 0;
  $newdefaults['scalecontrolposition'] = '';
  $newdefaults['scalecontrolunits'] = '';
  $newdefaults['zoomcontrolposition'] = '';
  $newdefaults['attributioncontrolposition'] = '';
  $newdefaults['layercontrolposition'] = '';
  $newdefaults['layercontrol_mark_ov'] = 9;
  $newdefaults['layercontrol_mark_ov_label'] = t('Locations');
  $newdefaults['layercontrol_circ_ov'] = 9;
  $newdefaults['layercontrol_circ_ov_label'] = t('Circles');
  $newdefaults['layercontrol_polyl_ov'] = 9;
  $newdefaults['layercontrol_polyl_ov_label'] = t('Lines');
  $newdefaults['layercontrol_polyg_ov'] = 9;
  $newdefaults['layercontrol_polyg_ov_label'] = t('Polygons');
  $newdefaults['layercontrol_rect_ov'] = 9;
  $newdefaults['layercontrol_rect_ov_label'] = t('Rectangles');
  $newdefaults['fullscreenposition'] = '';
  $newdefaults['markeraction'] = '';
  $newdefaults['markercluster'] = 0;
  $newdefaults['graticule'] = 0;
  $newdefaults['graticule_color'] = '#333';
  $newdefaults['graticule_opacity'] = 1;
  $newdefaults['graticule_weight'] = 1;
  $newdefaults['graticule_interval'] = 20;
  $newdefaults['graticule_ov_label'] = t('Graticule');
  $newdefaults['graticule_show'] = 0;
  $newdefaults['graticule_position'] = '';
  $newdefaults['graticule_state'] = 1;
  $newdefaults['pancontrol'] = 0;
  $newdefaults['pancontrolposition'] = '';
  $newdefaults['zoomslider'] = 0;
  $newdefaults['zoomsliderposition'] = '';
  $newdefaults['mouseposition'] = 0;
  $newdefaults['mouseposition_position'] = '';
  $newdefaults['mouseposition_display_dms'] = 0;
  $newdefaults['minimap'] = 0;
  $newdefaults['geocoder'] = 0;
  $newdefaults['geocoderposition'] = '';
  $newdefaults['geocodersrc'] = 'n';

  // n = nominatim, b = bing, m = mapquest, x = mapbox, g = google
  $newdefaults['geocodercollapsed'] = 1;
  $newdefaults['geocoder_bing_key'] = '';

  // required for bing
  $newdefaults['geocoder_mapquest_key'] = '';

  // required for mapquest
  $newdefaults['geocoder_mapbox_key'] = '';

  // required for mapbox
  $apikey = variable_get('getlocations_api3_key', '');
  $newdefaults['geocoder_google_key'] = $apikey;

  // required for google
  $newdefaults['geocoder_errormessage'] = t("Nothing found.");
  $newdefaults['geocoder_placeholder'] = t("Search...");
  $newdefaults['awesome'] = 0;
  $newdefaults['awesome_icon'] = 'fa-home';
  $newdefaults['awesome_icon_color_selector'] = 'white';
  $newdefaults['awesome_icon_color'] = '';
  $newdefaults['awesome_icon_spin'] = '';
  $newdefaults['awesome_icon_pulse'] = '';
  $newdefaults['awesome_marker_color'] = 'blue';
  $newdefaults['awesome_icon_type'] = 'b';
  $newdefaults['awesome_icon_size'] = '';
  $newdefaults['awesome_icon_flip'] = '';
  $newdefaults['awesome_icon_html'] = '';
  $newdefaults['awesome_icon_class'] = 'getlocations-leaflet-div-icon';
  $newdefaults['node_marker_awesome_icon'] = '';
  $newdefaults['node_marker_awesome_icon_color_selector'] = '';
  $newdefaults['node_marker_awesome_icon_color'] = '';
  $newdefaults['node_marker_awesome_icon_spin'] = '';
  $newdefaults['node_marker_awesome_icon_pulse'] = '';
  $newdefaults['node_marker_awesome_marker_color'] = '';
  $newdefaults['node_marker_awesome_icon_type'] = 'b';
  $newdefaults['node_marker_awesome_icon_size'] = '';
  $newdefaults['node_marker_awesome_icon_flip'] = '';
  $newdefaults['node_marker_awesome_icon_html'] = '';
  $newdefaults['node_marker_awesome_icon_class'] = 'getlocations-leaflet-div-icon';
  $newdefaults['user_marker_awesome_icon'] = '';
  $newdefaults['user_marker_awesome_icon_color_selector'] = '';
  $newdefaults['user_marker_awesome_icon_color'] = '';
  $newdefaults['user_marker_awesome_icon_spin'] = '';
  $newdefaults['user_marker_awesome_icon_pulse'] = '';
  $newdefaults['user_marker_awesome_marker_color'] = '';
  $newdefaults['user_marker_awesome_icon_type'] = 'b';
  $newdefaults['user_marker_awesome_icon_size'] = '';
  $newdefaults['user_marker_awesome_icon_flip'] = '';
  $newdefaults['user_marker_awesome_icon_html'] = '';
  $newdefaults['user_marker_awesome_icon_class'] = 'getlocations-leaflet-div-icon';
  $newdefaults['term_marker_awesome_icon'] = '';
  $newdefaults['term_marker_awesome_icon_color_selector'] = '';
  $newdefaults['term_marker_awesome_icon_color'] = '';
  $newdefaults['term_marker_awesome_icon_spin'] = '';
  $newdefaults['term_marker_awesome_icon_pulse'] = '';
  $newdefaults['term_marker_awesome_marker_color'] = '';
  $newdefaults['term_marker_awesome_icon_type'] = 'b';
  $newdefaults['term_marker_awesome_icon_size'] = '';
  $newdefaults['term_marker_awesome_icon_flip'] = '';
  $newdefaults['term_marker_awesome_icon_html'] = '';
  $newdefaults['term_marker_awesome_icon_class'] = 'getlocations-leaflet-div-icon';
  $newdefaults['vocabulary_marker_awesome_icon'] = '';
  $newdefaults['vocabulary_marker_awesome_icon_color_selector'] = '';
  $newdefaults['vocabulary_marker_awesome_icon_color'] = '';
  $newdefaults['vocabulary_marker_awesome_icon_spin'] = '';
  $newdefaults['vocabulary_marker_awesome_icon_pulse'] = '';
  $newdefaults['vocabulary_marker_awesome_marker_color'] = '';
  $newdefaults['vocabulary_marker_awesome_icon_type'] = 'b';
  $newdefaults['vocabulary_marker_awesome_icon_size'] = '';
  $newdefaults['vocabulary_marker_awesome_icon_flip'] = '';
  $newdefaults['vocabulary_marker_awesome_icon_html'] = '';
  $newdefaults['vocabulary_marker_awesome_icon_class'] = 'getlocations-leaflet-div-icon';
  $newdefaults['comment_marker_awesome_icon'] = '';
  $newdefaults['comment_marker_awesome_icon_color_selector'] = '';
  $newdefaults['comment_marker_awesome_icon_color'] = '';
  $newdefaults['comment_marker_awesome_icon_spin'] = '';
  $newdefaults['comment_marker_awesome_icon_pulse'] = '';
  $newdefaults['comment_marker_awesome_marker_color'] = '';
  $newdefaults['comment_marker_awesome_icon_type'] = 'b';
  $newdefaults['comment_marker_awesome_icon_size'] = '';
  $newdefaults['comment_marker_awesome_icon_flip'] = '';
  $newdefaults['comment_marker_awesome_icon_html'] = '';
  $newdefaults['comment_marker_awesome_icon_class'] = 'getlocations-leaflet-div-icon';
  $newdefaults['marker_type'] = 'gg';

  // or 'fa'
  $newdefaults['default_baselayer'] = 'OpenStreetMap.Mapnik';
  $newdefaults['map_resize'] = 0;
  $newdefaults['fullscreen_disable'] = 0;
  $newdefaults['styles'] = '';

  // usermarker
  $newdefaults['usermarker'] = 0;
  $newdefaults['usermarker_pulsing'] = 0;
  $newdefaults['usermarker_smallicon'] = 0;
  $newdefaults['usermarker_accuracy'] = 0;
  $newdefaults['usermarker_circle_stroke'] = 1;
  $newdefaults['usermarker_circle_strokecolor'] = $getlocations_defaults['circles_strokecolor'];
  $newdefaults['usermarker_circle_strokeopacity'] = $getlocations_defaults['circles_strokeopacity'];
  $newdefaults['usermarker_circle_strokeweight'] = $getlocations_defaults['circles_strokeweight'];
  $newdefaults['usermarker_circle_fillcolor'] = $getlocations_defaults['circles_fillcolor'];
  $newdefaults['usermarker_circle_fillopacity'] = $getlocations_defaults['circles_fillopacity'];
  $newdefaults['usermarker_button_label'] = t('Show current position');

  // bouncemarker
  $newdefaults['bouncemarker'] = 0;
  $newdefaults['bouncemarker_duration'] = 1000;
  $newdefaults['bouncemarker_height'] = '';

  // magnifyingglass
  $newdefaults['magnifyingglass'] = 0;
  $newdefaults['magnifyingglasscontrolposition'] = '';
  $newdefaults['magnifyingglassradius'] = 100;
  $newdefaults['magnifyingglasszoomoffset'] = 3;
  $newdefaults['terminator'] = 0;
  $newdefaults['terminator_strokecolor'] = '#000000';
  $newdefaults['terminator_strokeopacity'] = '0.5';
  $newdefaults['terminator_strokeweight'] = '1';
  $newdefaults['terminator_fillcolor'] = '#000000';
  $newdefaults['terminator_fillopacity'] = '0.5';
  $newdefaults['terminator_position'] = '';
  $newdefaults['terminator_show'] = 0;
  $newdefaults['terminator_state'] = 1;
  $newdefaults['terminator_label'] = t('Day/Night');

  // custom content
  $newdefaults['custom_content_enable'] = 0;
  $newdefaults['custom_content_source'] = '';

  // mapquest
  $newdefaults['mapquest_traffic_flow'] = 1;
  $newdefaults['mapquest_traffic_flow_on'] = 0;
  $newdefaults['mapquest_traffic_incident'] = 1;
  $newdefaults['mapquest_traffic_incident_on'] = 0;
  $newdefaults['mapquest_maps_default'] = 'm';
  $newdefaults['mapquest_maps_maplayer'] = 1;
  $newdefaults['mapquest_maps_satellitelayer'] = 1;
  $newdefaults['mapquest_maps_hybridlayer'] = 1;
  $newdefaults['mapquest_maps_use'] = 1;

  // leaflet hash
  $newdefaults['hashurl'] = 0;
  $settings = variable_get('getlocations_leaflet_defaults', '');

  // mapquest
  if (isset($settings['geocoder_mapquest_key'])) {
    if (!empty($settings['geocoder_mapquest_key'])) {
      $mapquest_lic = variable_get('getlocations_mapquest_lic', array(
        'key' => '',
        'type' => 'l',
      ));
      if (empty($mapquest_lic['key'])) {
        $mapquest_lic['key'] = $settings['geocoder_mapquest_key'];
        variable_set('getlocations_mapquest_lic', $mapquest_lic);
      }
    }
    unset($settings['geocoder_mapquest_key']);
  }
  $newdefaults['baselayers'] = isset($settings['baselayers']) && !empty($settings['baselayers']) ? $settings['baselayers'] : array(
    'OpenStreetMap.Mapnik',
  );
  $settings = getlocations_adjust_vars($newdefaults, $settings);
  return $settings;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_plugins() {
  $defaults = array(
    'markercluster_enable' => 0,
    'fullscreen_enable' => 0,
    'graticule_enable' => 0,
    'pancontrol_enable' => 0,
    'zoomslider_enable' => 0,
    'awesome_enable' => 0,
    'mouseposition_enable' => 0,
    'minimap_enable' => 0,
    'geocoder_enable' => 0,
    'usermarker_enable' => 0,
    'bouncemarker_enable' => 0,
    'magnifyingglass_enable' => 0,
    'terminator_enable' => 0,
    'mapquest_traffic_enable' => 0,
    'mapquest_routing_enable' => 0,
    'mapquest_geocoder_enable' => 0,
    'mapquest_maps_enable' => 0,
    'hash_enable' => 0,
  );
  $settings = variable_get('getlocations_leaflet_plugins', $defaults);
  $return = getlocations_adjust_vars($defaults, $settings);
  return $return;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_get_map_layers($map_settings) {
  $map_layers = $map_settings['map_layers'];
  $add = array();

  // cloudmade
  if (module_exists('getlocations_cloudmade')) {
    $add += getlocations_cloudmade_get_map_layers();
  }

  // mapbox
  if (module_exists('getlocations_mapbox')) {
    $add += getlocations_mapbox_get_map_layers();
  }
  if (count($add)) {
    $map_layers += $add;
  }
  $map_settings['map_layers'] = $map_layers;
  return $map_settings;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_display_options_form($defaults, $admin = FALSE) {
  $form = array();
  $form['#theme'][] = 'getlocations_leaflet_display_options_form';
  $getlocations_leaflet_paths = getlocations_leaflet_paths_get();

  #$form['#attached']['js'] = array($getlocations_leaflet_paths['getlocations_leaflet_formatter_path'] => array('type' => 'file' ) );
  drupal_add_js($getlocations_leaflet_paths['getlocations_leaflet_formatter_path']);
  $controlpositions = getlocations_leaflet_controlpositions();
  $getlocations_leaflet_plugins = getlocations_leaflet_plugins();
  $mapquest_lic = variable_get('getlocations_mapquest_lic', array(
    'key' => '',
    'type' => 'l',
  ));
  $form['nodezoom'] = getlocations_element_map_zoom(t('Default Zoom for Single location'), $defaults['nodezoom'], t('The Default zoom level for a single marker.'));
  $form['scrollWheelZoom'] = getlocations_element_map_checkbox(t('Scrollwheel'), $defaults['scrollWheelZoom'], t('Enable scrollwheel zooming.'));
  $form['touchZoom'] = getlocations_element_map_checkbox(t('Touch Zoom'), $defaults['touchZoom'], t('Enable touch zooming. Applies to touchscreens.'));
  $form['dragging'] = getlocations_element_map_checkbox(t('Draggable'), $defaults['dragging'], t('Enable dragging the map.'));
  $form['doubleClickZoom'] = getlocations_element_map_checkbox(t('DoubleClick Zoom'), $defaults['doubleClickZoom'], t('Enable DoubleClick Zooming.'));
  $form['boxZoom'] = getlocations_element_map_checkbox(t('Box Zoom'), $defaults['boxZoom'], t('Enable Box Zooming.'));
  $form['tap'] = getlocations_element_map_checkbox(t('Tap'), $defaults['tap'], t('Enable Tap. Applies to touchscreens.'));
  $form['tapTolerance'] = getlocations_element_map_tf(t('Tap Tolerance'), $defaults['tapTolerance'], t('Set tap tolerance.'), 5);
  $form['bounceAtZoomLimits'] = getlocations_element_map_checkbox(t('bounce At Zoom Limits'), $defaults['bounceAtZoomLimits'], t('Enable bounce At Zoom Limits.'));

  // mapquest
  if ($getlocations_leaflet_plugins['mapquest_maps_enable']) {
    $form['mapquest_maps_use'] = getlocations_element_map_checkbox(t('Enable Mapquest maps'), $defaults['mapquest_maps_use']);
    $form['mapquest_maps_use']['#suffix'] = '<div id="wrap-getlocations-mapquest-maps-use">';
    $mapopts = array();
    if ($defaults['mapquest_maps_maplayer']) {
      $mapopts['m'] = t('Map layer');
    }
    if ($defaults['mapquest_maps_satellitelayer']) {
      $mapopts['s'] = t('Satellite layer');
    }
    if ($defaults['mapquest_maps_hybridlayer']) {
      $mapopts['h'] = t('Hybrid layer');
    }
    if (count($mapopts) < 1) {
      $mapopts['m'] = t('Map layer');
      $defaults['mapquest_maps_maplayer'] = 1;
    }
    $form['mapquest_maps_default'] = getlocations_element_dd(t('Default map'), $defaults['mapquest_maps_default'], $mapopts);
    $form['mapquest_maps_maplayer'] = getlocations_element_map_checkbox(t('Map layer'), $defaults['mapquest_maps_maplayer']);
    $form['mapquest_maps_satellitelayer'] = getlocations_element_map_checkbox(t('Satellite layer'), $defaults['mapquest_maps_satellitelayer']);
    $form['mapquest_maps_hybridlayer'] = getlocations_element_map_checkbox(t('Hybrid layer'), $defaults['mapquest_maps_hybridlayer']);
    $form['mapquest_maps_hybridlayer']['#suffix'] = '</div>';
  }
  else {
    $form['mapquest_maps_default'] = array(
      '#type' => 'value',
      '#value' => 'm',
    );
    $form['mapquest_maps_maplayer'] = array(
      '#type' => 'value',
      '#value' => 1,
    );
    $form['mapquest_maps_satellitelayer'] = array(
      '#type' => 'value',
      '#value' => 1,
    );
    $form['mapquest_maps_hybridlayer'] = array(
      '#type' => 'value',
      '#value' => 1,
    );
  }
  if ($getlocations_leaflet_plugins['mapquest_traffic_enable'] && $mapquest_lic['type'] == 'l') {
    $form['mapquest_traffic_flow'] = getlocations_element_map_checkbox(t('Enable traffic flow'), $defaults['mapquest_traffic_flow'], t('Enable Traffic Flow on the map. Limited Availability.'));
    $form['mapquest_traffic_flow_on'] = getlocations_element_map_checkbox(t('Show traffic flow'), $defaults['mapquest_traffic_flow_on'], t('Show Traffic Flow on the map on startup.'));
    $form['mapquest_traffic_incident'] = getlocations_element_map_checkbox(t('Enable traffic incident'), $defaults['mapquest_traffic_incident'], t('Enable Traffic Incident on the map. Limited Availability.'));
    $form['mapquest_traffic_incident_on'] = getlocations_element_map_checkbox(t('Show traffic incident'), $defaults['mapquest_traffic_incident_on'], t('Show Traffic Incident on the map on startup.'));
    $form['mapquest_traffic_incident_on']['#suffix'] = '';
  }
  else {
    $form['mapquest_traffic_flow'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
    $form['mapquest_traffic_flow_on'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
    $form['mapquest_traffic_incident'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
    $form['mapquest_traffic_incident_on'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
    $form['mapquest_traffic_incident_on']['#suffix'] = '';
  }
  $form['scaleControl'] = getlocations_element_map_checkbox(t('Scale'), $defaults['scaleControl'], t('Show scale.'));
  $form['scaleControl']['#suffix'] = '<div id="wrap-getlocations-scalecontrol">';
  $form['scalecontrolunits'] = getlocations_element_dd(t('Distance Units'), $defaults['scalecontrolunits'], array(
    '' => t('Defaults'),
    'metric' => t('Metric'),
    'imperial' => t('Imperial'),
  ));
  $form['scalecontrolposition'] = getlocations_element_dd(t('Position of Scale Control'), $defaults['scalecontrolposition'], $controlpositions);
  $form['scalecontrolposition']['#suffix'] = '</div>';
  $form['zoomControl'] = getlocations_element_map_checkbox(t('Zoom Control'), $defaults['zoomControl'], t('Enable Zoom Control on the map.'));
  $form['zoomControl']['#suffix'] = '<div id="wrap-getlocations-zoomcontrol">';
  $form['zoomcontrolposition'] = getlocations_element_dd(t('Position of Zoom Control'), $defaults['zoomcontrolposition'], $controlpositions);
  $form['zoomcontrolposition']['#suffix'] = '</div>';
  $form['attributionControl'] = getlocations_element_map_checkbox(t('Attribution Control'), $defaults['attributionControl'], t('Enable Attribution Control on the map.'));
  $form['attributionControl']['#suffix'] = '<div id="wrap-getlocations-attributioncontrol">';
  $form['attributioncontrolposition'] = getlocations_element_dd(t('Position of Attribution Control'), $defaults['attributioncontrolposition'], $controlpositions);
  $form['attributioncontrolposition']['#suffix'] = '</div>';
  if ($getlocations_leaflet_plugins['geocoder_enable']) {
    $form['geocoder'] = getlocations_element_map_checkbox(t('Geocoder Control'), $defaults['geocoder']);
    $form['geocoder']['#suffix'] = '<div id="wrap-getlocations-geocoder">';
    $form['geocoderposition'] = getlocations_element_dd(t('Position of Geocoder Control'), $defaults['geocoderposition'], $controlpositions);
    $apikey = variable_get('getlocations_api3_key', '');
    $mapquest_lic = variable_get('getlocations_mapquest_lic', array(
      'key' => '',
      'type' => 'l',
    ));
    $sources = array(
      'n' => t('Nominatim'),
      'b' => t('Bing'),
      'x' => t('Mapbox'),
    );
    if ($apikey) {
      $sources['g'] = t('Google');
    }
    if ($mapquest_lic['key']) {
      $sources['m'] = t('Mapquest');
    }
    $form['geocodersrc'] = getlocations_element_dd(t('Geocoding source'), $defaults['geocodersrc'], $sources, t('Only Nominatim is GPL'));
    $form['geocoder_bing_key'] = getlocations_element_map_tf(t('Bing Geocoder key'), $defaults['geocoder_bing_key'], t('A Geocoder key is required for Bing.'), 40);
    $form['geocoder_mapbox_key'] = getlocations_element_map_tf(t('Mapbox Geocoder key'), $defaults['geocoder_mapbox_key'], t('A Geocoder key is required for Mapbox.'), 40);
    $form['geocoder_placeholder'] = getlocations_element_map_tf(t('Placeholder'), $defaults['geocoder_placeholder'], '', 30);
    $form['geocoder_errormessage'] = getlocations_element_map_tf(t('Error Message'), $defaults['geocoder_errormessage'], '', 30);
    $form['geocodercollapsed'] = getlocations_element_map_checkbox(t('Geocoder Collapsed'), $defaults['geocodercollapsed']);
    $form['geocodercollapsed']['#suffix'] = '</div>';
  }
  else {
    $form['geocoder'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }

  // usermarker
  if ($getlocations_leaflet_plugins['usermarker_enable']) {
    $form['usermarker'] = getlocations_element_map_checkbox(t('Usermarker'), $defaults['usermarker'], t('Show user position.'));
    $form['usermarker']['#suffix'] = '<div id="wrap-getlocations-usermarker">';
    $form['usermarker_button_label'] = getlocations_element_map_tf(t('GPS button label'), $defaults['usermarker_button_label'], '', 30, 30, TRUE);
    $form['usermarker_pulsing'] = getlocations_element_map_checkbox(t('Usermarker pulsing'), $defaults['usermarker_pulsing']);
    $form['usermarker_smallicon'] = getlocations_element_map_checkbox(t('Usermarker Small Icon'), $defaults['usermarker_smallicon']);
    $form['usermarker_accuracy'] = getlocations_element_map_checkbox(t('Usermarker accuracy'), $defaults['usermarker_accuracy'], t('Show Geolocation accuracy as a circle'));
    $form['usermarker_circle_stroke'] = getlocations_element_map_checkbox(t('Accuracy circle stroke'), $defaults['usermarker_circle_stroke'], t('Show Geolocation accuracy circle with a border.'));

    // jquery_colorpicker
    if (module_exists('jquery_colorpicker') && $defaults['jquery_colorpicker_enabled']) {
      $form['usermarker_circle_strokecolor'] = array(
        '#type' => 'jquery_colorpicker',
        '#title' => t('Accuracy Circle line color'),
        '#default_value' => preg_replace("/^#/", '', $defaults['usermarker_circle_strokecolor']),
        '#description' => t('Click on the Colorpicker icon to select a color'),
      );
    }
    else {
      $form['usermarker_circle_strokecolor'] = getlocations_element_map_tf(t('Accuracy Circle line color'), $defaults['usermarker_circle_strokecolor'], t('HTML hex, eg #FF0000.'), 10, 10, TRUE);
    }
    $form['usermarker_circle_strokeopacity'] = getlocations_element_map_tf(t('Accuracy Circle line opacity'), $defaults['usermarker_circle_strokeopacity'], t('Must be between 0 and 1.'), 10, 10, TRUE);
    $form['usermarker_circle_strokeweight'] = getlocations_element_map_tf(t('Accuracy Circle line thickness'), $defaults['usermarker_circle_strokeweight'], t('Must be an integer.'), 10, 10, TRUE);

    // jquery_colorpicker
    if (module_exists('jquery_colorpicker') && $defaults['jquery_colorpicker_enabled']) {
      $form['usermarker_circle_fillcolor'] = array(
        '#type' => 'jquery_colorpicker',
        '#title' => t('Accuracy Circle fill color'),
        '#default_value' => preg_replace("/^#/", '', $defaults['usermarker_circle_fillcolor']),
        '#description' => t('Click on the Colorpicker icon to select a color'),
      );
    }
    else {
      $form['usermarker_circle_fillcolor'] = getlocations_element_map_tf(t('Accuracy Circle fill color'), $defaults['usermarker_circle_fillcolor'], t('HTML hex, eg #FF0000.'), 10, 10, TRUE);
    }
    $form['usermarker_circle_fillopacity'] = getlocations_element_map_tf(t('Accuracy Circle fill opacity'), $defaults['usermarker_circle_fillopacity'], t('Must be between 0 and 1.'), 10, 10, TRUE);
    $form['usermarker_circle_fillopacity']['#suffix'] = '</div>';
  }
  else {
    $form['usermarker'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }

  // bouncemarker
  if ($getlocations_leaflet_plugins['bouncemarker_enable']) {
    $form['bouncemarker'] = getlocations_element_map_checkbox(t('Bounce markers'), $defaults['bouncemarker'], t('Bounce markers on adding to the map.'));
    $form['bouncemarker']['#suffix'] = '<div id="wrap-getlocations-bouncemarker">';
    $form['bouncemarker_duration'] = getlocations_element_map_tf(t('Bouncemarker duration'), $defaults['bouncemarker_duration'], t('Must be a number, in milliseconds.'), 10, 10, TRUE);
    $form['bouncemarker_height'] = getlocations_element_map_tf(t('Bouncemarker height'), $defaults['bouncemarker_height'], t('A number, in pixels. If left empty will drop from the top of the map.'), 10, 10, FALSE);
    $form['bouncemarker_height']['#suffix'] = '</div>';
  }
  else {
    $form['bouncemarker'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }

  // Magnifying Glass
  if ($getlocations_leaflet_plugins['magnifyingglass_enable']) {
    $form['magnifyingglass'] = getlocations_element_map_checkbox(t('Magnifying Glass'), $defaults['magnifyingglass'], t('Magnifying Glass on the map.'));
    $form['magnifyingglass']['#suffix'] = '<div id="wrap-getlocations-magnifyingglass">';
    $form['magnifyingglasscontrolposition'] = getlocations_element_dd(t('Position of Magnifying Glass Control'), $defaults['magnifyingglasscontrolposition'], $controlpositions);
    $form['magnifyingglassradius'] = getlocations_element_map_tf(t('Magnifying Glass Radius'), $defaults['magnifyingglassradius'], '', 10, 10, TRUE);
    $form['magnifyingglasszoomoffset'] = getlocations_element_map_tf(t('Magnifying Glass Zoom Offset'), $defaults['magnifyingglasszoomoffset'], '', 10, 10, TRUE);
    $form['magnifyingglasszoomoffset']['#suffix'] = '</div>';
  }
  else {
    $form['magnifyingglass'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }

  // Terminator
  if ($getlocations_leaflet_plugins['terminator_enable']) {
    $form['terminator'] = getlocations_element_map_checkbox(t('Day/Night'), $defaults['terminator'], t('Show Day and Night on the map.'));
    $form['terminator']['#suffix'] = '<div id="wrap-getlocations-terminator">';

    // jquery_colorpicker
    if (module_exists('jquery_colorpicker') && $defaults['jquery_colorpicker_enabled']) {
      $form['terminator_strokecolor'] = array(
        '#type' => 'jquery_colorpicker',
        '#title' => t('Day/Night line color'),
        '#default_value' => preg_replace("/^#/", '', $defaults['terminator_strokecolor']),
        '#description' => t('Click on the Colorpicker icon to select a color'),
      );
    }
    else {
      $form['terminator_strokecolor'] = getlocations_element_map_tf(t('Day/Night line color'), $defaults['terminator_strokecolor'], t('HTML hex, eg #000000.'), 10, 10, TRUE);
    }
    $form['terminator_strokeopacity'] = getlocations_element_map_tf(t('Day/Night line opacity'), $defaults['terminator_strokeopacity'], t('Must be between 0 and 1.'), 10, 10, TRUE);
    $form['terminator_strokeweight'] = getlocations_element_map_tf(t('Day/Night line thickness'), $defaults['terminator_strokeweight'], t('Must be an integer.'), 10, 10, TRUE);

    // jquery_colorpicker
    if (module_exists('jquery_colorpicker') && $defaults['jquery_colorpicker_enabled']) {
      $form['terminator_fillcolor'] = array(
        '#type' => 'jquery_colorpicker',
        '#title' => t('Day/Night fill color'),
        '#default_value' => preg_replace("/^#/", '', $defaults['terminator_fillcolor']),
        '#description' => t('Click on the Colorpicker icon to select a color'),
      );
    }
    else {
      $form['terminator_fillcolor'] = getlocations_element_map_tf(t('Day/Night fill color'), $defaults['terminator_fillcolor'], t('HTML hex, eg #000000.'), 10, 10, TRUE);
    }
    $form['terminator_fillopacity'] = getlocations_element_map_tf(t('Day/Night fill opacity'), $defaults['terminator_fillopacity'], t('Must be between 0 and 1.'), 10, 10, TRUE);
    $form['terminator_show'] = getlocations_element_dd(t('Day/Night show options'), $defaults['terminator_show'], array(
      0 => t('Always show'),
      1 => t('Checkbox on Layercontrol'),
      2 => t('Button on the map'),
    ));
    $form['terminator_position'] = getlocations_element_dd(t('Position of Day/Night Control'), $defaults['terminator_position'], $controlpositions);
    $form['terminator_state'] = getlocations_element_map_checkbox(t('Day/Night Initial state'), $defaults['terminator_state'], t('Day and Night on  or off initially.'));
    $form['terminator_label'] = getlocations_element_map_tf(t('Day/Night Label'), $defaults['terminator_label'], t('The label to display on the Layer Control or Tooltip.'), 20);
    $form['terminator_label']['#suffix'] = '</div>';
  }
  else {
    $form['terminator'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  $form['layerControl'] = getlocations_element_map_checkbox(t('Layer Control'), $defaults['layerControl'], t('Enable Layer Control on the map.'));
  $form['layerControl']['#suffix'] = '<div id="wrap-getlocations-layercontrol">';
  if ($getlocations_leaflet_plugins['minimap_enable']) {
    $form['minimap'] = getlocations_element_map_checkbox(t('Minimap Enhanced Layer Control'), $defaults['minimap']);
  }
  else {
    $form['minimap'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  $form['layercontrol_mark_ov'] = getlocations_element_map_checkbox(t('Layer Control Marker Overlay'), $defaults['layercontrol_mark_ov'], t('Add a checkbox to switch Markers on and off to the Layer Control.'));
  $form['layercontrol_mark_ov_label'] = getlocations_element_map_tf(t('Layer Control Marker Overlay Label'), $defaults['layercontrol_mark_ov_label'], t('The label to display on the Layer Control.'), 20);
  $form['layercontrol_circ_ov'] = getlocations_element_map_checkbox(t('Layer Control Circles Overlay'), $defaults['layercontrol_circ_ov'], t('Add a checkbox to switch Circles on and off to the Layer Control.'));
  $form['layercontrol_circ_ov_label'] = getlocations_element_map_tf(t('Layer Control Circles Overlay Label'), $defaults['layercontrol_circ_ov_label'], t('The label to display on the Layer Control.'), 20);
  $form['layercontrol_polyl_ov'] = getlocations_element_map_checkbox(t('Layer Control Lines Overlay'), $defaults['layercontrol_polyl_ov'], t('Add a checkbox to switch Lines on and off to the Layer Control.'));
  $form['layercontrol_polyl_ov_label'] = getlocations_element_map_tf(t('Layer Control Lines Overlay Label'), $defaults['layercontrol_polyl_ov_label'], t('The label to display on the Layer Control.'), 20);
  $form['layercontrol_polyg_ov'] = getlocations_element_map_checkbox(t('Layer Control Polygons Overlay'), $defaults['layercontrol_polyg_ov'], t('Add a checkbox to switch Polygons on and off to the Layer Control.'));
  $form['layercontrol_polyg_ov_label'] = getlocations_element_map_tf(t('Layer Control Polygons Overlay Label'), $defaults['layercontrol_polyg_ov_label'], t('The label to display on the Layer Control.'), 20);
  $form['layercontrol_rect_ov'] = getlocations_element_map_checkbox(t('Layer Control Rectangles Overlay'), $defaults['layercontrol_rect_ov'], t('Add a checkbox to switch Rectangles on and off to the Layer Control.'));
  $form['layercontrol_rect_ov_label'] = getlocations_element_map_tf(t('Layer Control Rectangles Overlay Label'), $defaults['layercontrol_rect_ov_label'], t('The label to display on the Layer Control.'), 20);
  $form['layercontrolposition'] = getlocations_element_dd(t('Position of Layer Control'), $defaults['layercontrolposition'], $controlpositions);
  $form['layercontrolposition']['#suffix'] = '</div>';

  // baselayers
  $map_settings = getlocations_leaflet_map_get_info('Getlocations OSM');
  $map_settings = getlocations_leaflet_get_map_layers($map_settings);
  $map_layers = $map_settings['map_layers'];

  // reconfigure $defaults['baselayers']
  $old_baselayers = $defaults['baselayers'];
  $defaults['baselayers'] = array();
  $default_baselayer_opts = array();
  foreach ($map_layers as $k => $v) {
    if ($k == $defaults['default_baselayer']) {
      $defaults['baselayers'][$k] = isset($old_baselayers[$k]) ? $old_baselayers[$k] : 1;
    }
    else {
      $defaults['baselayers'][$k] = isset($old_baselayers[$k]) ? $old_baselayers[$k] : 0;
    }

    // make a list of enable baselayers for a dropdown
    if (isset($old_baselayers[$k]) && $old_baselayers[$k]) {
      if ($map_layers[$k]['type'] == 'base') {
        $default_baselayer_opts[$k] = $map_layers[$k]['label'];
      }
    }
  }
  if (count($default_baselayer_opts) > 1) {
    $form['default_baselayer'] = getlocations_element_dd(t('Default Map'), $defaults['default_baselayer'], $default_baselayer_opts);
  }
  else {
    $form['default_baselayer'] = array(
      '#type' => 'value',
      '#value' => $defaults['default_baselayer'],
    );
  }
  $form['baselayers'] = array(
    '#type' => 'fieldset',
    '#title' => t('Enable map types'),
    '#description' => t('Select which maps you want to be available. You must select at least one'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  foreach ($defaults['baselayers'] as $key => $value) {
    $label = isset($map_layers[$key]['label']) ? $map_layers[$key]['label'] : $key;
    $form['baselayers'][$key] = getlocations_element_map_checkbox($label, $defaults['baselayers'][$key], isset($map_layers[$key]['description']) ? $map_layers[$key]['description'] : '');
  }
  $form['trackResize'] = getlocations_element_map_checkbox(t('Automatic Resizing'), $defaults['trackResize'], t('Enable Automatic Resizing of the map.'));
  $form['fadeAnimation'] = getlocations_element_map_checkbox(t('fadeAnimation'), $defaults['fadeAnimation'], t('Enable fadeAnimation on the map.'));
  $form['zoomAnimation'] = getlocations_element_map_checkbox(t('zoomAnimation'), $defaults['zoomAnimation'], t('Enable zoomAnimation on the map.'));
  $form['closePopupOnClick'] = getlocations_element_map_checkbox(t('closePopupOnClick'), $defaults['closePopupOnClick'], t('Enable closePopupOnClick on the map.'));

  // plugins
  if ($getlocations_leaflet_plugins['markercluster_enable']) {
    $form['markercluster'] = getlocations_element_map_checkbox(t('Marker Cluster'), $defaults['markercluster'], t('Enable markercluster on the map.'));
  }
  else {
    $form['markercluster'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  if ($getlocations_leaflet_plugins['fullscreen_enable']) {

    // fullscreen
    $form['fullscreen'] = getlocations_element_map_checkbox(t('Fullscreen'), $defaults['fullscreen'], t('Enable Fullscreen button on the map.'));
    $form['fullscreen']['#suffix'] = '<div id="getlocations-fullscreen-wrap">';
    $form['fullscreenposition'] = getlocations_element_dd(t('Position of Fullscreen Control'), $defaults['fullscreenposition'], $controlpositions);
    $form['fullscreenposition']['#suffix'] = '</div>';
  }
  else {
    $form['fullscreen'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
    $form['fullscreenposition'] = array(
      '#type' => 'value',
      '#value' => $defaults['fullscreenposition'],
    );
  }
  if ($getlocations_leaflet_plugins['graticule_enable']) {
    $form['graticule'] = getlocations_element_map_checkbox(t('Graticule'), $defaults['graticule'], t('Enable a grid on the map.'));
    $form['graticule']['#suffix'] = '<div id="getlocations-graticule-wrap">';
    $form['graticule_color'] = getlocations_element_map_tf(t('Graticule line color'), $defaults['graticule_color'], '', 10);
    $form['graticule_weight'] = getlocations_element_map_tf(t('Graticule line thickness'), $defaults['graticule_weight'], '', 5);
    $form['graticule_opacity'] = getlocations_element_map_tf(t('Graticule line opacity'), $defaults['graticule_opacity'], '', 5);
    $form['graticule_interval'] = getlocations_element_map_tf(t('Graticule interval'), $defaults['graticule_interval'], '', 5);
    $form['graticule_show'] = getlocations_element_dd(t('Graticule show options'), $defaults['graticule_show'], array(
      0 => t('Always show'),
      1 => t('Checkbox on Layercontrol'),
      2 => t('Button on the map'),
    ));
    $form['graticule_position'] = getlocations_element_dd(t('Position of Graticule Control'), $defaults['graticule_position'], $controlpositions);
    $form['graticule_state'] = getlocations_element_map_checkbox(t('Graticule initial state'), $defaults['graticule_state'], t('Initial state of Graticule.'));
    $form['graticule_ov_label'] = getlocations_element_map_tf(t('Graticule Label'), $defaults['graticule_ov_label'], t('The label to display on the Layer Control or Tooltip.'), 20);
    $form['graticule_ov_label']['#suffix'] = '</div>';
  }
  else {
    $form['graticule'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  if ($getlocations_leaflet_plugins['mouseposition_enable']) {
    $form['mouseposition'] = getlocations_element_map_checkbox(t('Mouseposition'), $defaults['mouseposition'], t('Enable Mouseposition on the map.'));
    $form['mouseposition']['#suffix'] = '<div id="getlocations-mouseposition-wrap">';
    $form['mouseposition_position'] = getlocations_element_dd(t('Position of Mouse position Control'), $defaults['mouseposition_position'], $controlpositions);
    $form['mouseposition_display_dms'] = getlocations_element_map_checkbox(t('Show Latitude/Longitude in Degrees, minutes, seconds'), $defaults['mouseposition_display_dms'], '');
    $form['mouseposition_display_dms']['#suffix'] = '</div>';
  }
  else {
    $form['mouseposition'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  if ($getlocations_leaflet_plugins['pancontrol_enable']) {
    $form['pancontrol'] = getlocations_element_map_checkbox(t('Pancontrol'), $defaults['pancontrol'], t('Enable Pan control on the map.'));
    $form['pancontrol']['#suffix'] = '<div id="getlocations-pancontrol-wrap">';
    $form['pancontrolposition'] = getlocations_element_dd(t('Position of Pan Control'), $defaults['pancontrolposition'], $controlpositions);
    $form['pancontrolposition']['#suffix'] = '</div>';
  }
  else {
    $form['pancontrol'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  if ($getlocations_leaflet_plugins['zoomslider_enable']) {
    $form['zoomslider'] = getlocations_element_map_checkbox(t('Zoomslider'), $defaults['zoomslider'], t('Enable Zoom Slider on the map.'));
    $form['zoomslider']['#suffix'] = '<div id="getlocations-zoomslider-wrap">';
    $form['zoomsliderposition'] = getlocations_element_dd(t('Position of Zoomslider'), $defaults['zoomsliderposition'], $controlpositions);
    $form['zoomsliderposition']['#suffix'] = '</div>';
  }
  else {
    $form['zoomslider'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }

  // leaflet hash
  if ($getlocations_leaflet_plugins['hash_enable']) {
    $form['hashurl'] = getlocations_element_map_checkbox(t('Hash Url'), $defaults['hashurl'], t('Enable Url Hash for the map.'));
  }
  else {
    $form['hashurl'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  $form['markeraction'] = getlocations_element_dd(t('Marker action'), $defaults['markeraction'], array(
    '' => t('None'),
    'popup' => t('Popup'),
    'link' => t('Link to content'),
  ));
  $form['show_maplinks'] = getlocations_element_map_checkbox(t('Show map links'), $defaults['show_maplinks'], t('Show a list of links to show Popup or go to Link on the map.'));
  $form['show_maplinks']['#suffix'] = '<div id="wrap-getlocations-maplinks">';
  $form['show_maplinks_viewport'] = getlocations_element_map_checkbox(t('Only Show map links in Viewport'), $defaults['show_maplinks_viewport']);
  $form['show_maplinks_viewport']['#suffix'] = '</div>';
  if (module_exists('getdirections')) {
    $form['getdirections_link'] = getlocations_element_map_checkbox(t('Link to Getdirections in popup'), $defaults['getdirections_link'], t('Include a link to the Getdirections page in Popup.'));
  }

  // shapes
  $form += getlocations_shapes_form($defaults, '');

  // geojson
  $form += getlocations_geojson_form($defaults);
  $form['geojson_options']['#type'] = 'hidden';
  $form += getlocations_what3words_form($defaults);
  if ($getlocations_leaflet_plugins['awesome_enable']) {
    $form['marker_type'] = getlocations_element_dd(t('Default Marker type'), $defaults['marker_type'], array(
      'gg' => t('Getlocations markers'),
      'fa' => t('Awesome Fonts markers'),
    ), t('If you change this setting, save the page and revisit the form to get the selected markerset.'));

    #if ($admin) {

    #  $form['marker_type']['#suffix'] = '<div id="getlocations-awesome-wrap">';

    #  $form += getlocations_leaflet_awesome_markers_elements_get($defaults);

    #  $form['awesome_marker_color']['#suffix'] = '</div>';

    #}
    $form['awesome'] = array(
      '#type' => 'value',
      '#value' => 1,
    );
  }
  else {
    $form['awesome_icon'] = array(
      '#type' => 'value',
      '#value' => $defaults['awesome_icon'],
    );
    $form['awesome_icon_color_selector'] = array(
      '#type' => 'value',
      '#value' => $defaults['awesome_icon_color_selector'],
    );
    $form['awesome_icon_color'] = array(
      '#type' => 'value',
      '#value' => $defaults['awesome_icon_color'],
    );
    $form['awesome_marker_color'] = array(
      '#type' => 'value',
      '#value' => $defaults['awesome_marker_color'],
    );
    $form['awesome_icon_type'] = array(
      '#type' => 'value',
      '#value' => $defaults['awesome_icon_type'],
    );
    $form['awesome_icon_size'] = array(
      '#type' => 'value',
      '#value' => $defaults['awesome_icon_size'],
    );
    $form['awesome_icon_flip'] = array(
      '#type' => 'value',
      '#value' => $defaults['awesome_icon_flip'],
    );
    $form['awesome_icon_html'] = array(
      '#type' => 'value',
      '#value' => $defaults['awesome_icon_html'],
    );
    $form['awesome_icon_class'] = array(
      '#type' => 'value',
      '#value' => $defaults['awesome_icon_class'],
    );
    $form['awesome'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  return $form;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_paths_get($reset = FALSE, $min = FALSE) {
  $jq_upd = getlocations_check_jquery_version(TRUE);
  if ($min) {
    $defaults = array(
      'getlocations_leaflet_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet.min.js',
      'getlocations_leaflet_circles_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_circles.min.js',
      'getlocations_leaflet_formatter_path' => GETLOCATIONS_LEAFLET_PATH . ($jq_upd ? '/js/getlocations_leaflet_formatter_1.min.js' : '/js/getlocations_leaflet_formatter.min.js'),
      'getlocations_leaflet_polygons_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_polygons.min.js',
      'getlocations_leaflet_polylines_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_polylines.min.js',
      'getlocations_leaflet_rectangles_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_rectangles.min.js',
      'getlocations_leaflet_geojson_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_geojson.min.js',
      'getlocations_leaflet_providers_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_providers.min.js',
      'getlocations_leaflet_preview_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_preview.min.js',
      'getlocations_leaflet_field_group_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_field_group.min.js',
      'getlocations_leaflet_what3words_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_what3words.min.js',
    );
  }
  else {
    $defaults = array(
      'getlocations_leaflet_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet.js',
      'getlocations_leaflet_circles_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_circles.js',
      'getlocations_leaflet_formatter_path' => GETLOCATIONS_LEAFLET_PATH . ($jq_upd ? '/js/getlocations_leaflet_formatter_1.js' : '/js/getlocations_leaflet_formatter.js'),
      'getlocations_leaflet_polygons_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_polygons.js',
      'getlocations_leaflet_polylines_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_polylines.js',
      'getlocations_leaflet_rectangles_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_rectangles.js',
      'getlocations_leaflet_geojson_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_geojson.js',
      'getlocations_leaflet_providers_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_providers.js',
      'getlocations_leaflet_preview_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_preview.js',
      'getlocations_leaflet_field_group_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_field_group.js',
      'getlocations_leaflet_what3words_path' => GETLOCATIONS_LEAFLET_PATH . '/js/getlocations_leaflet_what3words.js',
    );
  }
  if ($reset || $min) {
    $getlocations_leaflet_paths = $defaults;
  }
  else {
    $settings = variable_get('getlocations_leaflet_paths', $defaults);
    $getlocations_leaflet_paths = getlocations_adjust_vars($defaults, $settings);
  }
  return $getlocations_leaflet_paths;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_settings_form() {
  $form = array();
  $pagetitle = '<div><h4>' . t('Getlocations Leaflet') . '</h4><p>' . t('The settings selected here will be used as the starting point for all other Leaflet maps.') . '</p></div>';
  $form['pagetitle'] = array(
    '#markup' => $pagetitle,
  );
  $form['rebuild'] = array(
    '#type' => 'fieldset',
    '#title' => t('Regenerate Getlocations leaflet marker cache'),
    '#description' => t('If you are having problems with markers, or have changed anything in the markers library, click on the Regenerate button.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $c = count(getlocations_get_marker_titles());
  if ($c) {
    $rebuildmsg = '<p>' . format_plural($c, 'You have 1 marker installed.', 'You have @count markers installed.') . '</p>';
  }
  else {
    $rebuildmsg = '<p class="error">' . t('WARNING! NO markers found.') . '</p>';
  }
  $form['rebuild']['msg'] = array(
    '#markup' => $rebuildmsg,
  );
  $form['rebuild']['rebuild_marker_js'] = array(
    '#type' => 'submit',
    '#value' => t('Regenerate'),
    '#submit' => array(
      '_getlocations_leaflet_rebuild_marker_js_submit',
    ),
  );
  $form['rebuild']['getlocations_leaflet_flush'] = getlocations_element_map_checkbox(t('Flush marker cache'), variable_get('getlocations_leaflet_flush', 1), t('Include the marker cache when the Drupal cache is flushed.'));

  // getlocations_leaflet_cdn
  $getlocations_leaflet_cdn = variable_get('getlocations_leaflet_cdn', array(
    'enable' => 0,
    'js' => '',
    'css' => '',
  ));
  $leaflet_libraries_installed = libraries_get_path('leaflet') ? TRUE : FALSE;
  $leaflet_version = '';
  if ($leaflet_libraries_installed) {
    $desc = t('The Leaflet Library is installed at !p.', array(
      '!p' => libraries_get_path('leaflet'),
    ));
    $leaflet_version = getlocations_leaflet_library_version();
    if ($leaflet_version) {
      $desc .= '&nbsp;' . t('Using version !v', array(
        '!v' => $leaflet_version,
      ));
    }
  }
  elseif ($getlocations_leaflet_cdn['enable']) {
    $desc = t('The Leaflet library is being hosted on CDN.');
  }
  else {
    $desc = '<span class="error">' . t('The Leaflet library is NOT installed.') . '</span>';
  }
  $desc .= '<br />' . t('For details on the Leaflet library please see !u', array(
    '!u' => l(t('leafletjs.com'), 'http://leafletjs.com/', array(
      'attributes' => array(
        'target' => '_blank',
      ),
    )),
  ));
  $desc .= '<br />' . t('Please read the README.txt included with getlocations_leaflet.');
  $form['getlocations_leaflet_cdn'] = array(
    '#type' => 'fieldset',
    '#title' => t('Leaflet Library'),
    '#description' => $desc,
    '#collapsible' => TRUE,
    '#collapsed' => $leaflet_libraries_installed || $getlocations_leaflet_cdn['enable'] && $getlocations_leaflet_cdn['js'] && $getlocations_leaflet_cdn['css'] ? TRUE : FALSE,
    // This will store all the defaults in one variable.
    '#tree' => TRUE,
  );
  $form['getlocations_leaflet_cdn']['enable'] = getlocations_element_map_checkbox(t('Enable CDN'), $getlocations_leaflet_cdn['enable'], t('Supply the URLs for CDN below.'));
  $form['getlocations_leaflet_cdn']['js'] = getlocations_element_map_tf(t('Leaflet library javascript URL'), $getlocations_leaflet_cdn['js'], t('The full URL to the Leaflet javascript library.'), 80, 128);
  $form['getlocations_leaflet_cdn']['css'] = getlocations_element_map_tf(t('Leaflet library CSS URL'), $getlocations_leaflet_cdn['css'], t('The full URL to the Leaflet css library.'), 80, 128);
  if ($leaflet_libraries_installed || $getlocations_leaflet_cdn['enable'] && $getlocations_leaflet_cdn['js'] && $getlocations_leaflet_cdn['css']) {

    // preview
    $form['getlocations_leaflet_preview'] = array(
      '#type' => 'fieldset',
      '#title' => t('Getlocations Leaflet Preview'),
      '#description' => t('A preview of the current map settings.') . '<br />' . t('You can adjust the default Map center and Zoom by changing the map.') . '<br />' . t('For all other changes use the form. Remember to Save configuration when you are done.'),
      // This will store all the defaults in one variable.
      '#tree' => FALSE,
    );
    $form['getlocations_leaflet_preview']['preview_map'] = array(
      '#markup' => '',
    );
  }

  // plugins
  $getlocations_leaflet_plugins = getlocations_leaflet_plugins();
  $form['getlocations_leaflet_plugins'] = array(
    '#type' => 'fieldset',
    '#title' => t('Leaflet plugins'),
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['getlocations_leaflet_plugins']['markercluster_enable'] = getlocations_element_map_checkbox(t('Enable Markercluster plugin'), $getlocations_leaflet_plugins['markercluster_enable']);
  $form['getlocations_leaflet_plugins']['fullscreen_enable'] = getlocations_element_map_checkbox(t('Enable Fullscreen plugin'), $getlocations_leaflet_plugins['fullscreen_enable']);
  $form['getlocations_leaflet_plugins']['graticule_enable'] = getlocations_element_map_checkbox(t('Enable Graticule plugin'), $getlocations_leaflet_plugins['graticule_enable']);
  $form['getlocations_leaflet_plugins']['pancontrol_enable'] = getlocations_element_map_checkbox(t('Enable Pancontrol plugin'), $getlocations_leaflet_plugins['pancontrol_enable']);
  $form['getlocations_leaflet_plugins']['zoomslider_enable'] = getlocations_element_map_checkbox(t('Enable Zoomslider plugin'), $getlocations_leaflet_plugins['zoomslider_enable']);
  $form['getlocations_leaflet_plugins']['awesome_enable'] = getlocations_element_map_checkbox(t('Enable Awesome markers plugin'), $getlocations_leaflet_plugins['awesome_enable']);
  $form['getlocations_leaflet_plugins']['mouseposition_enable'] = getlocations_element_map_checkbox(t('Enable Mouseposition plugin'), $getlocations_leaflet_plugins['mouseposition_enable']);
  $form['getlocations_leaflet_plugins']['minimap_enable'] = getlocations_element_map_checkbox(t('Enable Minimap plugin'), $getlocations_leaflet_plugins['minimap_enable']);
  $form['getlocations_leaflet_plugins']['geocoder_enable'] = getlocations_element_map_checkbox(t('Enable Geocoder plugin'), $getlocations_leaflet_plugins['geocoder_enable']);
  $form['getlocations_leaflet_plugins']['usermarker_enable'] = getlocations_element_map_checkbox(t('Enable Usermarker plugin'), $getlocations_leaflet_plugins['usermarker_enable']);
  $form['getlocations_leaflet_plugins']['bouncemarker_enable'] = getlocations_element_map_checkbox(t('Enable Bouncemarker plugin'), $getlocations_leaflet_plugins['bouncemarker_enable']);
  $form['getlocations_leaflet_plugins']['magnifyingglass_enable'] = getlocations_element_map_checkbox(t('Enable Magnifying Glass plugin'), $getlocations_leaflet_plugins['magnifyingglass_enable']);
  $form['getlocations_leaflet_plugins']['terminator_enable'] = getlocations_element_map_checkbox(t('Enable Day/Night plugin'), $getlocations_leaflet_plugins['terminator_enable']);

  // leaflet-hash
  $leaflet_hash_file = getlocations_leaflet_hash_library_check();
  if ($leaflet_hash_file) {
    $form['getlocations_leaflet_plugins']['hash_enable'] = getlocations_element_map_checkbox(t('Enable Leaflet hash plugin'), $getlocations_leaflet_plugins['hash_enable']);
  }
  else {
    $form['getlocations_leaflet_plugins']['hash_enable'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }

  // mapquest
  $mapquest_lic = variable_get('getlocations_mapquest_lic', array(
    'key' => '',
    'type' => 'l',
  ));
  if ($mapquest_lic['key']) {
    if ($mapquest_lic['type'] == 'l') {
      $form['getlocations_leaflet_plugins']['mapquest_traffic_enable'] = getlocations_element_map_checkbox(t('Enable Mapquest Traffic plugin'), $getlocations_leaflet_plugins['mapquest_traffic_enable']);
    }
    else {
      $form['getlocations_leaflet_plugins']['mapquest_traffic_enable'] = array(
        '#type' => 'value',
        '#value' => 0,
      );
    }

    #$form['getlocations_leaflet_plugins']['mapquest_routing_enable'] = getlocations_element_map_checkbox(

    #  t('Enable Mapquest Routing plugin'),

    #  $getlocations_leaflet_plugins['mapquest_routing_enable']

    #);
    $form['getlocations_leaflet_plugins']['mapquest_routing_enable'] = array(
      '#type' => 'value',
      '#value' => 0,
    );

    #$form['getlocations_leaflet_plugins']['mapquest_geocoder_enable'] = getlocations_element_map_checkbox(

    #  t('Enable Mapquest Geocoding plugin'),

    #  $getlocations_leaflet_plugins['mapquest_geocoder_enable']

    #);
    $form['getlocations_leaflet_plugins']['mapquest_geocoder_enable'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
    $form['getlocations_leaflet_plugins']['mapquest_maps_enable'] = getlocations_element_map_checkbox(t('Enable Mapquest Maps plugin'), $getlocations_leaflet_plugins['mapquest_maps_enable']);

    #$form['getlocations_leaflet_plugins']['mapquest_maps_enable'] = array('#type' => 'value', '#value' => 0);
  }
  else {
    $form['getlocations_leaflet_plugins']['mapquest_traffic_enable'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
    $form['getlocations_leaflet_plugins']['mapquest_routing_enable'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
    $form['getlocations_leaflet_plugins']['mapquest_geocoder_enable'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
    $form['getlocations_leaflet_plugins']['mapquest_maps_enable'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }

  // mapbox
  if (module_exists('getlocations_mapbox')) {
    $form += getlocations_mapbox_settings_form();
  }

  // cloudmade
  if (module_exists('getlocations_cloudmade')) {
    $form += getlocations_cloudmade_settings_form();
  }
  $settings = getlocations_leaflet_defaults();
  $form['getlocations_leaflet_defaults'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default Page settings'),
    // This will store all the defaults in one variable.
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $labels = array(
    'width' => t('Width'),
    'height' => t('Height'),
  );
  $form['getlocations_leaflet_defaults'] += getlocations_map_display_basics_form($settings, $labels);
  unset($form['getlocations_leaflet_defaults']['map_resize']);
  unset($form['getlocations_leaflet_defaults']['fullscreen_disable']);
  unset($form['getlocations_leaflet_defaults']['styles']);
  unset($form['getlocations_leaflet_defaults']['zoom']['#options']['21']);
  unset($form['getlocations_leaflet_defaults']['zoom']['#options']['20']);
  unset($form['getlocations_leaflet_defaults']['zoom']['#options']['19']);
  unset($form['getlocations_leaflet_defaults']['minzoom_map']['#options']['21']);
  unset($form['getlocations_leaflet_defaults']['minzoom_map']['#options']['20']);
  unset($form['getlocations_leaflet_defaults']['minzoom_map']['#options']['19']);
  unset($form['getlocations_leaflet_defaults']['maxzoom_map']['#options']['21']);
  unset($form['getlocations_leaflet_defaults']['maxzoom_map']['#options']['20']);
  unset($form['getlocations_leaflet_defaults']['maxzoom_map']['#options']['19']);
  $form['getlocations_leaflet_defaults'] += getlocations_leaflet_display_options_form($settings, TRUE);
  unset($form['getlocations_leaflet_defaults']['nodezoom']['#options']['21']);
  unset($form['getlocations_leaflet_defaults']['nodezoom']['#options']['20']);
  unset($form['getlocations_leaflet_defaults']['nodezoom']['#options']['19']);

  // awesome
  if ($settings['awesome'] && $settings['marker_type'] == 'fa') {

    // default
    $form['getlocations_leaflet_defaults'] += getlocations_leaflet_awesome_markers_elements_get($settings);

    // nodes
    $labels = array(
      'awesome_icon' => t('Node Awesome icon'),
      'awesome_icon_color' => t('Node Awesome icon color'),
      'awesome_marker_color' => t('Node Awesome marker color'),
      'awesome_title' => t('Node Awesome Fonts icon settings'),
      'awesome_icon_spin' => t('Node Awesome icon spin'),
      'awesome_icon_size' => t('Node Awesome icon size'),
      'awesome_icon_type' => t('Node Awesome icon type'),
      'awesome_icon_flip' => t('Node Awesome icon flip and rotate'),
      'awesome_icon_html' => t('Node Awesome icon HTML'),
      'awesome_icon_class' => t('Node Awesome icon class'),
    );
    $form['getlocations_leaflet_defaults'] += getlocations_leaflet_awesome_markers_elements_get($settings, $labels, "node");

    // node type markers
    if ($types = getlocations_get_types()) {
      $getlocations_node_marker = variable_get('getlocations_node_marker', array(
        'enable' => 0,
      ));
      if ($getlocations_node_marker['enable']) {
        $typect = 0;
        foreach ($types as $type => $name) {
          $field_names = getlocations_get_fieldname2($type, 'node');
          foreach ($field_names as $field_name) {
            $label = t('%name Map marker, field %field', array(
              '%name' => $name,
              '%field' => $field_name,
            ));
            $mkey = 'node_marker__' . drupal_strtolower($type) . '__' . $field_name;
            $labels = array(
              'awesome_icon' => t($label . ' Awesome icon'),
              'awesome_icon_color' => t($label . ' Awesome icon color'),
              'awesome_marker_color' => t($label . ' Awesome marker color'),
              'awesome_title' => t($label . ' Awesome Fonts icon settings'),
              'awesome_icon_spin' => t($label . ' Awesome icon spin'),
              'awesome_icon_size' => t($label . ' Awesome icon size'),
              'awesome_icon_type' => t($label . ' Awesome icon type'),
              'awesome_icon_flip' => t($label . ' Awesome icon flip and rotate'),
              'awesome_icon_html' => t($label . ' Awesome icon HTML'),
              'awesome_icon_class' => t($label . ' Awesome icon class'),
            );
            $form['getlocations_leaflet_defaults'] += getlocations_leaflet_awesome_markers_elements_get($settings, $labels, $mkey);
          }
        }
      }
    }

    // users
    if (getlocations_check_entity_type('user') || getlocations_check_entity_type('profile2')) {
      $labels = array(
        'awesome_icon' => t('User Awesome icon'),
        'awesome_icon_color' => t('User Awesome icon color'),
        'awesome_marker_color' => t('User Awesome marker color'),
        'awesome_title' => t('User Awesome Fonts icon settings'),
        'awesome_icon_spin' => t('User Awesome icon spin'),
        'awesome_icon_size' => t('User Awesome icon size'),
        'awesome_icon_type' => t('User Awesome icon type'),
        'awesome_icon_flip' => t('User Awesome icon flip and rotate'),
        'awesome_icon_html' => t('User Awesome icon HTML'),
        'awesome_icon_class' => t('User Awesome icon class'),
      );
      $form['getlocations_leaflet_defaults'] += getlocations_leaflet_awesome_markers_elements_get($settings, $labels, 'user');
    }
    if (module_exists('taxonomy')) {
      if ($types = getlocations_get_machine_vocabularies()) {

        // vocabulary
        // TODO per vocab
        $labels = array(
          'awesome_icon' => t('Vocabulary Awesome icon'),
          'awesome_icon_color' => t('Vocabulary Awesome icon color'),
          'awesome_marker_color' => t('Vocabulary Awesome marker color'),
          'awesome_title' => t('Vocabulary Awesome Fonts icon settings'),
          'awesome_icon_spin' => t('Vocabulary Awesome icon spin'),
          'awesome_icon_size' => t('Vocabulary Awesome icon size'),
          'awesome_icon_type' => t('Vocabulary Awesome icon type'),
          'awesome_icon_flip' => t('Vocabulary Awesome icon flip and rotate'),
          'awesome_icon_html' => t('Vocabulary Awesome icon HTML'),
          'awesome_icon_class' => t('Vocabulary Awesome icon class'),
        );
        $form['getlocations_leaflet_defaults'] += getlocations_leaflet_awesome_markers_elements_get($settings, $labels, 'vocabulary');
      }

      // terms
      // TODO per term
      $labels = array(
        'awesome_icon' => t('Term Awesome icon'),
        'awesome_icon_color' => t('Term Awesome icon color'),
        'awesome_marker_color' => t('Term Awesome marker color'),
        'awesome_title' => t('Term Awesome Fonts icon settings'),
        'awesome_icon_spin' => t('Term Awesome icon spin'),
        'awesome_icon_size' => t('Term Awesome icon size'),
        'awesome_icon_type' => t('Term Awesome icon type'),
        'awesome_icon_flip' => t('Term Awesome icon flip and rotate'),
        'awesome_icon_html' => t('Term Awesome icon HTML'),
        'awesome_icon_class' => t('Term Awesome icon class'),
      );
      $form['getlocations_leaflet_defaults'] += getlocations_leaflet_awesome_markers_elements_get($settings, $labels, 'term');
    }
    if (getlocations_check_entity_type('comment')) {

      // comment
      $labels = array(
        'awesome_icon' => t('Comment Awesome icon'),
        'awesome_icon_color' => t('Comment Awesome icon color'),
        'awesome_marker_color' => t('Comment Awesome marker color'),
        'awesome_title' => t('Comment Awesome Fonts icon settings'),
        'awesome_icon_spin' => t('Comment Awesome icon spin'),
        'awesome_icon_size' => t('Comment Awesome icon size'),
        'awesome_icon_type' => t('Comment Awesome icon type'),
        'awesome_icon_flip' => t('Comment Awesome icon flip and rotate'),
        'awesome_icon_html' => t('Comment Awesome icon HTML'),
        'awesome_icon_class' => t('Comment Awesome icon class'),
      );
      $form['getlocations_leaflet_defaults'] += getlocations_leaflet_awesome_markers_elements_get($settings, $labels, 'comment');
    }
  }
  $form['getlocations_leaflet_defaults']['returnlink_page_enable'] = getlocations_element_map_checkbox(t('Show link back to page'), $settings['returnlink_page_enable']);
  $form['getlocations_leaflet_defaults']['returnlink_page_link'] = getlocations_element_map_tf(t('Text of page return link'), $settings['returnlink_page_link'], t('Use %t to insert the page title'), 30, 64);
  if (module_exists('getlocations_fields')) {
    if (getlocations_check_entity_type('user') || getlocations_check_entity_type('profile2')) {
      $form['getlocations_leaflet_defaults']['returnlink_user_enable'] = getlocations_element_map_checkbox(t('Show link back to user'), $settings['returnlink_user_enable']);
      $form['getlocations_leaflet_defaults']['returnlink_user_link'] = getlocations_element_map_tf(t('Text of user return link'), $settings['returnlink_user_link'], t('Use %n to insert the user name'), 30, 64);
    }
    if (module_exists('taxonomy')) {
      if (getlocations_get_vocabularies()) {
        $form['getlocations_leaflet_defaults']['returnlink_term_enable'] = getlocations_element_map_checkbox(t('Show link back to term'), $settings['returnlink_term_enable']);
        $form['getlocations_leaflet_defaults']['returnlink_term_link'] = getlocations_element_map_tf(t('Text of term return link'), $settings['returnlink_term_link'], t('Use %n to insert the term name'), 30, 64);
      }
    }
    if (getlocations_check_entity_type('comment')) {
      $form['getlocations_leaflet_defaults']['returnlink_comment_enable'] = getlocations_element_map_checkbox(t('Show link back to comment'), $settings['returnlink_comment_enable']);
      $form['getlocations_leaflet_defaults']['returnlink_comment_link'] = getlocations_element_map_tf(t('Text of comment return link'), $settings['returnlink_comment_link'], t('Use %n to insert the comment subject'), 30, 64);
    }

    // search markers
    if (module_exists('getlocations_fields') && module_exists('views')) {
      $form['getlocations_leaflet_defaults'] += getlocations_fields_views_search_form($settings, 'leaflet');
    }
  }

  // javascript paths
  $getlocations_leaflet_paths = getlocations_leaflet_paths_get();
  $form['getlocations_leaflet_paths'] = array(
    '#type' => 'fieldset',
    '#title' => t('Javascript paths'),
    '#description' => t('For advanced users who want to supply their own javascript.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    // This will store all the defaults in one variable.
    '#tree' => TRUE,
  );
  $form['getlocations_leaflet_paths']['getlocations_leaflet_path'] = getlocations_element_path(t('Path to Getlocations leaflet javascript file'), $getlocations_leaflet_paths['getlocations_leaflet_path'], 80, 128, t('Where the Getlocations leaflet javascript file is located.'));
  $form['getlocations_leaflet_paths']['getlocations_leaflet_circles_path'] = getlocations_element_path(t('Path to Getlocations leaflet circles javascript file'), $getlocations_leaflet_paths['getlocations_leaflet_circles_path'], 80, 128, t('Where the Getlocations leaflet circles javascript file is located.'));
  $form['getlocations_leaflet_paths']['getlocations_leaflet_formatter_path'] = getlocations_element_path(t('Path to Getlocations leaflet formatter javascript file'), $getlocations_leaflet_paths['getlocations_leaflet_formatter_path'], 80, 128, t('Where the Getlocations leaflet formatter javascript file is located.'));
  $form['getlocations_leaflet_paths']['getlocations_leaflet_polygons_path'] = getlocations_element_path(t('Path to Getlocations leaflet polygons javascript file'), $getlocations_leaflet_paths['getlocations_leaflet_polygons_path'], 80, 128, t('Where the Getlocations leaflet polygons javascript file is located.'));
  $form['getlocations_leaflet_paths']['getlocations_leaflet_polylines_path'] = getlocations_element_path(t('Path to Getlocations leaflet polylines javascript file'), $getlocations_leaflet_paths['getlocations_leaflet_polylines_path'], 80, 128, t('Where the Getlocations leaflet polylines javascript file is located.'));
  $form['getlocations_leaflet_paths']['getlocations_leaflet_rectangles_path'] = getlocations_element_path(t('Path to Getlocations leaflet rectangles javascript file'), $getlocations_leaflet_paths['getlocations_leaflet_rectangles_path'], 80, 128, t('Where the Getlocations leaflet rectangles javascript file is located.'));
  $form['getlocations_leaflet_paths']['getlocations_leaflet_geojson_path'] = getlocations_element_path(t('Path to Getlocations leaflet geojson javascript file'), $getlocations_leaflet_paths['getlocations_leaflet_geojson_path'], 80, 128, t('Where the Getlocations leaflet geojson javascript file is located.'));
  $form['getlocations_leaflet_paths']['getlocations_leaflet_providers_path'] = getlocations_element_path(t('Path to Getlocations leaflet providers javascript file'), $getlocations_leaflet_paths['getlocations_leaflet_providers_path'], 80, 128, t('Where the Getlocations leaflet providers javascript file is located.'));
  $form['getlocations_leaflet_paths']['getlocations_leaflet_preview_path'] = getlocations_element_path(t('Path to Getlocations leaflet preview javascript file'), $getlocations_leaflet_paths['getlocations_leaflet_preview_path'], 80, 128, t('Where the Getlocations leaflet preview javascript file is located.'));
  $form['getlocations_leaflet_paths']['getlocations_leaflet_what3words_path'] = getlocations_element_path(t('Path to Getlocations leaflet what3words javascript file'), $getlocations_leaflet_paths['getlocations_leaflet_what3words_path'], 80, 128, t('Where the Getlocations leaflet what3words javascript file is located.'));
  $form['getlocations_leaflet_paths']['reset'] = getlocations_element_dd(t('Reset'), 0, array(
    0 => t('No'),
    1 => t('Reset'),
    2 => t('Reset to minified'),
  ), t('Reset the paths to the defaults.'));
  unset($form['#theme']);
  $form['#theme'] = 'getlocations_leaflet_settings_form';
  $form['#validate'][] = 'getlocations_leaflet_settings_validate';
  $form['#attached']['js'] = array(
    $getlocations_leaflet_paths['getlocations_leaflet_formatter_path'],
    $getlocations_leaflet_paths['getlocations_leaflet_preview_path'],
  );
  return system_settings_form($form);
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_settings_validate($form, &$form_state) {
  $reset = $form_state['values']['getlocations_leaflet_paths']['reset'];
  unset($form_state['values']['getlocations_leaflet_paths']['reset']);
  if ($reset == 1) {
    $form_state['values']['getlocations_leaflet_paths'] = getlocations_leaflet_paths_get(TRUE);
  }
  elseif ($reset == 2) {
    $form_state['values']['getlocations_leaflet_paths'] = getlocations_leaflet_paths_get(FALSE, TRUE);
  }

  // getlocations_leaflet_cdn
  if ($form_state['values']['getlocations_leaflet_cdn']['enable']) {
    if (empty($form_state['values']['getlocations_leaflet_cdn']['js']) || empty($form_state['values']['getlocations_leaflet_cdn']['css'])) {
      form_set_error('getlocations_leaflet_cdn][enable', t('You must supply a valid css and js URL.'));
    }
  }

  // cloudmade
  if (module_exists('getlocations_cloudmade')) {
    $form_state = getlocations_cloudmade_settings_validate($form_state);
  }

  // mapbox
  if (module_exists('getlocations_mapbox')) {
    $form_state = getlocations_mapbox_settings_validate($form_state);
  }

  // css check
  if (isset($form_state['values']['getlocations_leaflet_defaults']['width'])) {
    if ($check = getlocations_dim_check($form_state['values']['getlocations_leaflet_defaults']['width'])) {
      $form_state['values']['getlocations_leaflet_defaults']['width'] = $check;
    }
    else {
      form_set_error('getlocations_leaflet_defaults][width', t('Width must be valid css'));
    }
  }
  if (isset($form_state['values']['getlocations_leaflet_defaults']['height'])) {
    if ($check = getlocations_dim_check($form_state['values']['getlocations_leaflet_defaults']['height'])) {
      $form_state['values']['getlocations_leaflet_defaults']['height'] = $check;
    }
    else {
      form_set_error('getlocations_leaflet_defaults][height', t('Height must be valid css'));
    }
  }
}

/**
 * Rebuild marker js.
 */
function _getlocations_leaflet_rebuild_marker_js_submit($form, &$form_state) {
  if (getlocations_leaflet_regenerate_markers()) {
    drupal_set_message(t('Marker cache regenerated.'));
  }
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_entity_type_map($type, $entity_id) {
  global $language;
  $entity_type = getlocations_get_entity_type_from_path($type);
  $entity_get_info = entity_get_info($entity_type);

  // get key for entity_type
  $entity_key = $entity_get_info['entity keys']['id'];

  // nid, cid, uid etc
  $locations = getlocations_load_locations($entity_id, $entity_key);
  $getlocations_leaflet_defaults = getlocations_leaflet_defaults();
  $load_hook = $entity_get_info['load hook'];
  $object = $load_hook($entity_id);
  $lang = $object->language ? $object->language : $language->language;
  $locative_field_name = $object->field_leaflet_map[$lang][0]['locative_field_name'];
  $typemarkers = getlocations_get_markertypes($entity_type);
  $bundle = $object->type;
  $marker = '';
  $vector = '';

  // awesome
  if ($getlocations_leaflet_defaults['awesome'] && $getlocations_leaflet_defaults['marker_type'] == 'fa') {
    if ($entity_type == 'node') {
      $per_field_markers = FALSE;
      $getlocations_node_marker = variable_get('getlocations_node_marker', array(
        'enable' => 0,
      ));
      if ($getlocations_node_marker['enable']) {
        if ($types = getlocations_get_types()) {
          foreach ($types as $type => $name) {
            if ($type == $bundle) {
              $field_names = getlocations_get_fieldname2($type, 'node');
              foreach ($field_names as $field_name) {
                if ($field_name == $locative_field_name) {
                  $mkey = 'node_marker__' . drupal_strtolower($type) . '__' . $field_name;
                  $vicon = getlocations_leaflet_awesome_marker_get($getlocations_leaflet_defaults, $mkey);
                  $per_field_markers = TRUE;
                }
              }
            }
          }
        }
      }
      if (!$per_field_markers) {
        $vicon = getlocations_leaflet_awesome_marker_get($getlocations_leaflet_defaults, 'node');
      }
    }
    elseif ($entity_type == 'taxonomy_term') {
      $vicon = getlocations_leaflet_awesome_marker_get($getlocations_leaflet_defaults, 'vocabulary');
    }
    elseif ($entity_type == 'user') {
      $vicon = getlocations_leaflet_awesome_marker_get($getlocations_leaflet_defaults, 'user');
    }
    elseif ($entity_type == 'comment') {
      $vicon = getlocations_leaflet_awesome_marker_get($getlocations_leaflet_defaults, 'comment');
    }
    else {
      $vicon = getlocations_leaflet_awesome_marker_get($getlocations_leaflet_defaults);
    }
    $vector = $vicon;
  }
  else {

    // marker
    $marker = $getlocations_leaflet_defaults['node_map_marker'];
    if (isset($getlocations_leaflet_defaults[$entity_type . '_map_marker'])) {
      $marker = $getlocations_leaflet_defaults[$entity_type . '_map_marker'];
    }
    if (isset($typemarkers[$object->type]) && $typemarkers[$object->type]) {
      $marker = $typemarkers[$object->type];
    }
  }
  $entity_title = '';
  if (isset($object->title)) {
    $entity_title = $object->title;
  }
  elseif (isset($object->name)) {
    $entity_title = $object->name;
  }
  elseif (isset($object->subject)) {
    $entity_title = $object->subject;
  }
  $returnlink = FALSE;
  $links = array();

  // return link
  if ($entity_type == 'node' && $getlocations_leaflet_defaults['returnlink_page_enable']) {
    if (is_object($object)) {
      $linktext = $getlocations_leaflet_defaults['returnlink_page_link'];
      if (preg_match("/%t/", $linktext)) {
        $linktext = preg_replace("/%t/", $object->title, $linktext);
      }
      $returnlink = l($linktext, 'node/' . $object->nid);
    }
  }
  elseif ($entity_type == 'user' && $getlocations_leaflet_defaults['returnlink_user_enable']) {
    if (is_object($object)) {
      $linktext = $getlocations_leaflet_defaults['returnlink_user_link'];
      if (preg_match("/%n/", $linktext)) {
        $linktext = preg_replace("/%n/", $object->name, $linktext);
      }
      $returnlink = l($linktext, 'user/' . $object->uid);
    }
  }
  elseif (($entity_type == 'term' || $entity_type == 'taxonomy_term') && $getlocations_leaflet_defaults['returnlink_term_enable'] && module_exists('taxonomy')) {
    if (is_object($object)) {
      $linktext = $getlocations_leaflet_defaults['returnlink_term_link'];
      if (preg_match("/%n/", $linktext)) {
        $linktext = preg_replace("/%n/", $object->name, $linktext);
      }
      $returnlink = l($linktext, 'taxonomy/term/' . $object->tid);
    }
  }
  elseif ($entity_type == 'comment' && $getlocations_leaflet_defaults['returnlink_comment_enable'] && module_exists('comment')) {
    if (is_object($object)) {
      $linktext = $getlocations_leaflet_defaults['returnlink_comment_link'];
      if (preg_match("/%n/", $linktext)) {
        $linktext = preg_replace("/%n/", $object->subject, $linktext);
      }
      $returnlink = l($linktext, 'comment/' . $object->cid);
    }
  }
  if ($returnlink) {
    $links['returnlink'] = $returnlink;
  }
  $latlons = array();
  $minmaxes = array(
    'minlat' => 0,
    'minlon' => 0,
    'maxlat' => 0,
    'maxlon' => 0,
  );
  $ct = 0;
  if (count($locations)) {

    // we should loop over them and dump bummers with no lat/lon
    foreach ($locations as $key => $location) {
      if ($latlon = getlocations_latlon_check($location['latitude'] . ',' . $location['longitude'])) {
        $ll = explode(',', $latlon);
        $location['latitude'] = $ll[0];
        $location['longitude'] = $ll[1];
        $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);
        $lid = isset($location['glid']) ? $location['glid'] : (isset($location['lid']) ? $location['lid'] : 0);
        if (!isset($location['key'])) {
          $location['key'] = '';
        }
        else {
          $location['lid'] = $entity_id;
        }

        // node only
        if ($entity_type == 'node') {

          // term markers
          $marker = getlocations_get_term_marker($entity_id, $marker);

          // TODO awesome here too?
        }

        // per location marker
        if (isset($location['marker']) && !empty($location['marker'])) {
          $marker = $location['marker'];
        }
        if ($lid && $getlocations_leaflet_defaults['markeraction'] == 'popup') {
          $extra = FALSE;
          if (isset($getlocations_leaflet_defaults['getdirections_link'])) {
            $extra['gdlink'] = $getlocations_leaflet_defaults['getdirections_link'];
          }
          $markeraction = array(
            'type' => 'popup',
            'data' => getlocations_getinfo($lid, $entity_key, $extra),
          );
        }
        elseif ($lid && $getlocations_leaflet_defaults['markeraction'] == 'link') {
          $markeraction = array(
            'type' => 'link',
            'data' => getlocations_getlidinfo($lid, $entity_key),
          );
        }
        else {
          $markeraction = array();
        }
        $name = htmlspecialchars_decode($location['name'] ? strip_tags($location['name']) : strip_tags($entity_title), ENT_QUOTES);
        $latlons[$ct] = array(
          $location['latitude'],
          $location['longitude'],
          $entity_key,
          $entity_id,
          $lid,
          $entity_title,
          $marker,
          $vector,
          $markeraction,
          '',
        );
        $iconlist[$marker] = getlocations_leaflet_get_marker($marker);
        $ct++;
      }
    }

    // end foreach
    if ($ct < 2) {
      unset($minmaxes);
      $minmaxes = '';
    }
    $map_settings = getlocations_leaflet_map_get_info('Getlocations OSM');
    $map_settings = getlocations_leaflet_get_map_layers($map_settings);
    if (!empty($getlocations_leaflet_defaults['baselayers'])) {
      $map_layers = array();
      foreach ($getlocations_leaflet_defaults['baselayers'] as $k => $v) {
        if (isset($map_settings['map_layers'][$k]) && $getlocations_leaflet_defaults['baselayers'][$k]) {
          $map_layers[$k] = $map_settings['map_layers'][$k];
        }
      }
      if (!empty($map_layers)) {
        $map_settings['map_layers'] = $map_layers;
      }
    }
    $nodezoom = FALSE;
    if ($ct == 1 && $getlocations_leaflet_defaults['nodezoom']) {
      $nodezoom = $getlocations_leaflet_defaults['nodezoom'];
      $map_settings['map_opts']['center'] = array(
        $location['latitude'],
        $location['longitude'],
      );
      $map_settings['map_opts']['zoom'] = $nodezoom;
    }
    elseif ($ct < 1) {
      $ll = explode(',', $getlocations_leaflet_defaults['latlong']);
      $map_settings['map_opts']['center'] = array(
        $ll[0],
        $ll[1],
      );
      $map_settings['map_opts']['zoom'] = $getlocations_leaflet_defaults['zoom'];
    }
    $mapid = getlocations_setup_map('', FALSE, FALSE, TRUE);

    // add in some more
    $map_settings = getlocations_leaflet_map_settings_do($map_settings, $getlocations_leaflet_defaults, $latlons, $mapid);
    $map_settings['map_settings']['nodezoom'] = $nodezoom ? $nodezoom : $getlocations_leaflet_defaults['nodezoom'];
    $map_settings['map_settings']['minmaxes'] = empty($minmaxes) ? FALSE : implode(',', $minmaxes);
    $map_settings['icons'] = $iconlist;
    $map_settings['datanum'] = $ct;
    $map_settings['latlons'] = $latlons;
    $output = theme('getlocations_leaflet_map', array(
      'width' => $getlocations_leaflet_defaults['width'],
      'height' => $getlocations_leaflet_defaults['height'],
      'map_settings' => $map_settings,
      'mapid' => $mapid,
      'links' => $links,
    ));
    return $output;
  }
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_awesome_markers_list() {
  $list = array(
    "fa-500px" => t("500px"),
    "fa-adjust" => t("Adjust"),
    "fa-adn" => t("App.net"),
    "fa-align-center" => t("Align-center"),
    "fa-align-justify" => t("Align-justify"),
    "fa-align-left" => t("Align-left"),
    "fa-align-right" => t("Align-right"),
    "fa-amazon" => t("Amazon"),
    "fa-ambulance" => t("Ambulance"),
    "fa-anchor" => t("Anchor"),
    "fa-android" => t("Android"),
    "fa-angellist" => t("AngelList"),
    "fa-angle-double-down" => t("Angle Double Down"),
    "fa-angle-double-left" => t("Angle Double Left"),
    "fa-angle-double-right" => t("Angle Double Right"),
    "fa-angle-double-up" => t("Angle Double Up"),
    "fa-angle-down" => t("Angle-down"),
    "fa-angle-left" => t("Angle-left"),
    "fa-angle-right" => t("Angle-right"),
    "fa-angle-up" => t("Angle-up"),
    "fa-apple" => t("Apple"),
    "fa-archive" => t("Archive"),
    "fa-area-chart" => t("Area Chart"),
    "fa-arrow-circle-down" => t("Arrow Circle Down"),
    "fa-arrow-circle-left" => t("Arrow Circle Left"),
    "fa-arrow-circle-o-down" => t("Arrow Circle Outlined Down"),
    "fa-arrow-circle-o-left" => t("Arrow Circle Outlined Left"),
    "fa-arrow-circle-o-right" => t("Arrow Circle Outlined Right"),
    "fa-arrow-circle-o-up" => t("Arrow Circle Outlined Up"),
    "fa-arrow-circle-right" => t("Arrow Circle Right"),
    "fa-arrow-circle-up" => t("Arrow Circle Up"),
    "fa-arrow-down" => t("Arrow-down"),
    "fa-arrow-left" => t("Arrow-left"),
    "fa-arrow-right" => t("Arrow-right"),
    "fa-arrow-up" => t("Arrow-up"),
    "fa-arrows" => t("Arrows"),
    "fa-arrows-alt" => t("Arrows Alt"),
    "fa-arrows-h" => t("Arrows Horizontal"),
    "fa-arrows-v" => t("Arrows Vertical"),
    "fa-asterisk" => t("Asterisk"),
    "fa-at" => t("At"),
    "fa-backward" => t("Backward"),
    "fa-balance-scale" => t("Balance Scale"),
    "fa-ban" => t("Ban"),
    "fa-bar-chart" => t("Bar Chart"),
    "fa-barcode" => t("Barcode"),
    "fa-bars" => t("Bars"),
    "fa-battery-empty" => t("Battery Empty"),
    "fa-battery-full" => t("Battery Full"),
    "fa-battery-half" => t("Battery 1/2 Full"),
    "fa-battery-quarter" => t("Battery 1/4 Full"),
    "fa-battery-three-quarters" => t("Battery 3/4 Full"),
    "fa-bed" => t("Bed"),
    "fa-beer" => t("Beer"),
    "fa-behance" => t("Behance"),
    "fa-behance-square" => t("Behance Square"),
    "fa-bell" => t("Bell"),
    "fa-bell-o" => t("Bell Outlined"),
    "fa-bell-slash" => t("Bell Slash"),
    "fa-bell-slash-o" => t("Bell Slash Outlined"),
    "fa-bicycle" => t("Bicycle"),
    "fa-binoculars" => t("Binoculars"),
    "fa-birthday-cake" => t("Birthday Cake"),
    "fa-bitbucket" => t("Bitbucket"),
    "fa-bitbucket-square" => t("Bitbucket Square"),
    "fa-black-tie" => t("Font Awesome Black Tie"),
    "fa-bluetooth" => t("Bluetooth"),
    "fa-bluetooth-b" => t("Bluetooth"),
    "fa-bold" => t("Bold"),
    "fa-bolt" => t("Lightning Bolt"),
    "fa-bomb" => t("Bomb"),
    "fa-book" => t("Book"),
    "fa-bookmark" => t("Bookmark"),
    "fa-bookmark-o" => t("Bookmark Outlined"),
    "fa-briefcase" => t("Briefcase"),
    "fa-btc" => t("Bitcoin (BTC)"),
    "fa-bug" => t("Bug"),
    "fa-building" => t("Building"),
    "fa-building-o" => t("Building Outlined"),
    "fa-bullhorn" => t("Bullhorn"),
    "fa-bullseye" => t("Bullseye"),
    "fa-bus" => t("Bus"),
    "fa-buysellads" => t("BuySellAds"),
    "fa-calculator" => t("Calculator"),
    "fa-calendar" => t("Calendar"),
    "fa-calendar-check-o" => t("Calendar Check Outlined"),
    "fa-calendar-minus-o" => t("Calendar Minus Outlined"),
    "fa-calendar-o" => t("Calendar-o"),
    "fa-calendar-plus-o" => t("Calendar Plus Outlined"),
    "fa-calendar-times-o" => t("Calendar Times Outlined"),
    "fa-camera" => t("Camera"),
    "fa-camera-retro" => t("Camera-retro"),
    "fa-car" => t("Car"),
    "fa-caret-down" => t("Caret Down"),
    "fa-caret-left" => t("Caret Left"),
    "fa-caret-right" => t("Caret Right"),
    "fa-caret-square-o-down" => t("Caret Square Outlined Down"),
    "fa-caret-square-o-left" => t("Caret Square Outlined Left"),
    "fa-caret-square-o-right" => t("Caret Square Outlined Right"),
    "fa-caret-square-o-up" => t("Caret Square Outlined Up"),
    "fa-caret-up" => t("Caret Up"),
    "fa-cart-arrow-down" => t("Shopping Cart Arrow Down"),
    "fa-cart-plus" => t("Add to Shopping Cart"),
    "fa-cc" => t("Closed Captions"),
    "fa-cc-amex" => t("American Express Credit Card"),
    "fa-cc-diners-club" => t("Diner's Club Credit Card"),
    "fa-cc-discover" => t("Discover Credit Card"),
    "fa-cc-jcb" => t("JCB Credit Card"),
    "fa-cc-mastercard" => t("MasterCard Credit Card"),
    "fa-cc-paypal" => t("Paypal Credit Card"),
    "fa-cc-stripe" => t("Stripe Credit Card"),
    "fa-cc-visa" => t("Visa Credit Card"),
    "fa-certificate" => t("Certificate"),
    "fa-chain-broken" => t("Chain Broken"),
    "fa-check" => t("Check"),
    "fa-check-circle" => t("Check Circle"),
    "fa-check-circle-o" => t("Check Circle Outlined"),
    "fa-check-square" => t("Check Square"),
    "fa-check-square-o" => t("Check Square Outlined"),
    "fa-chevron-circle-down" => t("Chevron Circle Down"),
    "fa-chevron-circle-left" => t("Chevron Circle Left"),
    "fa-chevron-circle-right" => t("Chevron Circle Right"),
    "fa-chevron-circle-up" => t("Chevron Circle Up"),
    "fa-chevron-down" => t("Chevron-down"),
    "fa-chevron-left" => t("Chevron-left"),
    "fa-chevron-right" => t("Chevron-right"),
    "fa-chevron-up" => t("Chevron-up"),
    "fa-child" => t("Child"),
    "fa-chrome" => t("Chrome"),
    "fa-circle" => t("Circle"),
    "fa-circle-o" => t("Circle Outlined"),
    "fa-circle-o-notch" => t("Circle Outlined Notched"),
    "fa-circle-thin" => t("Circle Outlined Thin"),
    "fa-clipboard" => t("Clipboard"),
    "fa-clock-o" => t("Clock Outlined"),
    "fa-clone" => t("Clone"),
    "fa-cloud" => t("Cloud"),
    "fa-cloud-download" => t("Cloud Download"),
    "fa-cloud-upload" => t("Cloud Upload"),
    "fa-code" => t("Code"),
    "fa-code-fork" => t("Code-fork"),
    "fa-codepen" => t("Codepen"),
    "fa-codiepie" => t("Codie Pie"),
    "fa-coffee" => t("Coffee"),
    "fa-cog" => t("Cog"),
    "fa-cogs" => t("Cogs"),
    "fa-columns" => t("Columns"),
    "fa-comment" => t("Comment"),
    "fa-comment-o" => t("Comment-o"),
    "fa-commenting" => t("Commenting"),
    "fa-commenting-o" => t("Commenting Outlined"),
    "fa-comments" => t("Comments"),
    "fa-comments-o" => t("Comments-o"),
    "fa-compass" => t("Compass"),
    "fa-compress" => t("Compress"),
    "fa-connectdevelop" => t("Connect Develop"),
    "fa-contao" => t("Contao"),
    "fa-copyright" => t("Copyright"),
    "fa-creative-commons" => t("Creative Commons"),
    "fa-credit-card" => t("Credit-card"),
    "fa-credit-card-alt" => t("Credit Card"),
    "fa-crop" => t("Crop"),
    "fa-crosshairs" => t("Crosshairs"),
    "fa-css3" => t("CSS 3 Logo"),
    "fa-cube" => t("Cube"),
    "fa-cubes" => t("Cubes"),
    "fa-cutlery" => t("Cutlery"),
    "fa-dashcube" => t("DashCube"),
    "fa-database" => t("Database"),
    "fa-delicious" => t("Delicious Logo"),
    "fa-desktop" => t("Desktop"),
    "fa-deviantart" => t("DeviantART"),
    "fa-diamond" => t("Diamond"),
    "fa-digg" => t("Digg Logo"),
    "fa-dot-circle-o" => t("Dot Circle Outlined"),
    "fa-download" => t("Download"),
    "fa-dribbble" => t("Dribbble"),
    "fa-dropbox" => t("Dropbox"),
    "fa-drupal" => t("Drupal Logo"),
    "fa-edge" => t("Edge Browser"),
    "fa-eject" => t("Eject"),
    "fa-ellipsis-h" => t("Ellipsis Horizontal"),
    "fa-ellipsis-v" => t("Ellipsis Vertical"),
    "fa-empire" => t("Galactic Empire"),
    "fa-envelope" => t("Envelope"),
    "fa-envelope-o" => t("Envelope Outlined"),
    "fa-envelope-square" => t("Envelope Square"),
    "fa-eraser" => t("Eraser"),
    "fa-eur" => t("Euro (EUR)"),
    "fa-exchange" => t("Exchange"),
    "fa-exclamation" => t("Exclamation"),
    "fa-exclamation-circle" => t("Exclamation Circle"),
    "fa-exclamation-triangle" => t("Exclamation Triangle"),
    "fa-expand" => t("Expand"),
    "fa-expeditedssl" => t("ExpeditedSSL"),
    "fa-external-link" => t("External Link"),
    "fa-external-link-square" => t("External Link Square"),
    "fa-eye" => t("Eye"),
    "fa-eye-slash" => t("Eye Slash"),
    "fa-eyedropper" => t("Eyedropper"),
    "fa-facebook" => t("Facebook"),
    "fa-facebook-official" => t("Facebook Official"),
    "fa-facebook-square" => t("Facebook Square"),
    "fa-fast-backward" => t("Fast-backward"),
    "fa-fast-forward" => t("Fast-forward"),
    "fa-fax" => t("Fax"),
    "fa-female" => t("Female"),
    "fa-fighter-jet" => t("Fighter-jet"),
    "fa-file" => t("File"),
    "fa-file-archive-o" => t("Archive File Outlined"),
    "fa-file-audio-o" => t("Audio File Outlined"),
    "fa-file-code-o" => t("Code File Outlined"),
    "fa-file-excel-o" => t("Excel File Outlined"),
    "fa-file-image-o" => t("Image File Outlined"),
    "fa-file-o" => t("File Outlined"),
    "fa-file-pdf-o" => t("PDF File Outlined"),
    "fa-file-powerpoint-o" => t("Powerpoint File Outlined"),
    "fa-file-text" => t("File Text"),
    "fa-file-text-o" => t("File Text Outlined"),
    "fa-file-video-o" => t("Video File Outlined"),
    "fa-file-word-o" => t("Word File Outlined"),
    "fa-files-o" => t("Files Outlined"),
    "fa-film" => t("Film"),
    "fa-filter" => t("Filter"),
    "fa-fire" => t("Fire"),
    "fa-fire-extinguisher" => t("Fire-extinguisher"),
    "fa-firefox" => t("Firefox"),
    "fa-flag" => t("Flag"),
    "fa-flag-checkered" => t("Flag-checkered"),
    "fa-flag-o" => t("Flag Outlined"),
    "fa-flask" => t("Flask"),
    "fa-flickr" => t("Flickr"),
    "fa-floppy-o" => t("Floppy Outlined"),
    "fa-folder" => t("Folder"),
    "fa-folder-o" => t("Folder Outlined"),
    "fa-folder-open" => t("Folder Open"),
    "fa-folder-open-o" => t("Folder Open Outlined"),
    "fa-font" => t("Font"),
    "fa-fonticons" => t("Fonticons"),
    "fa-fort-awesome" => t("Fort Awesome"),
    "fa-forumbee" => t("Forumbee"),
    "fa-forward" => t("Forward"),
    "fa-foursquare" => t("Foursquare"),
    "fa-frown-o" => t("Frown Outlined"),
    "fa-futbol-o" => t("Futbol Outlined"),
    "fa-gamepad" => t("Gamepad"),
    "fa-gavel" => t("Gavel"),
    "fa-gbp" => t("GBP"),
    "fa-genderless" => t("Genderless"),
    "fa-get-pocket" => t("Get Pocket"),
    "fa-gg" => t("GG Currency"),
    "fa-gg-circle" => t("GG Currency Circle"),
    "fa-gift" => t("Gift"),
    "fa-git" => t("Git"),
    "fa-git-square" => t("Git Square"),
    "fa-github" => t("GitHub"),
    "fa-github-alt" => t("GitHub Alt"),
    "fa-github-square" => t("GitHub Square"),
    "fa-glass" => t("Glass"),
    "fa-globe" => t("Globe"),
    "fa-google" => t("Google Logo"),
    "fa-google-plus" => t("Google Plus"),
    "fa-google-plus-square" => t("Google Plus Square"),
    "fa-google-wallet" => t("Google Wallet"),
    "fa-graduation-cap" => t("Graduation Cap"),
    "fa-gratipay" => t("Gratipay (Gittip)"),
    "fa-h-square" => t("H Square"),
    "fa-hacker-news" => t("Hacker News"),
    "fa-hand-lizard-o" => t("Lizard (Hand)"),
    "fa-hand-o-down" => t("Hand Outlined Down"),
    "fa-hand-o-left" => t("Hand Outlined Left"),
    "fa-hand-o-right" => t("Hand Outlined Right"),
    "fa-hand-o-up" => t("Hand Outlined Up"),
    "fa-hand-paper-o" => t("Paper (Hand)"),
    "fa-hand-peace-o" => t("Hand Peace"),
    "fa-hand-pointer-o" => t("Hand Pointer"),
    "fa-hand-rock-o" => t("Rock (Hand)"),
    "fa-hand-scissors-o" => t("Scissors (Hand)"),
    "fa-hand-spock-o" => t("Spock (Hand)"),
    "fa-hashtag" => t("Hashtag"),
    "fa-hdd-o" => t("HDD"),
    "fa-header" => t("Header"),
    "fa-headphones" => t("Headphones"),
    "fa-heart" => t("Heart"),
    "fa-heart-o" => t("Heart Outlined"),
    "fa-heartbeat" => t("Heartbeat"),
    "fa-history" => t("History"),
    "fa-home" => t("Home"),
    "fa-hospital-o" => t("Hospital Outlined"),
    "fa-hourglass" => t("Hourglass"),
    "fa-hourglass-end" => t("Hourglass End"),
    "fa-hourglass-half" => t("Hourglass Half"),
    "fa-hourglass-o" => t("Hourglass Outlined"),
    "fa-hourglass-start" => t("Hourglass Start"),
    "fa-houzz" => t("Houzz"),
    "fa-html5" => t("HTML 5 Logo"),
    "fa-i-cursor" => t("I Beam Cursor"),
    "fa-ils" => t("Shekel (ILS)"),
    "fa-inbox" => t("Inbox"),
    "fa-indent" => t("Indent"),
    "fa-industry" => t("Industry"),
    "fa-info" => t("Info"),
    "fa-info-circle" => t("Info Circle"),
    "fa-inr" => t("Indian Rupee (INR)"),
    "fa-instagram" => t("Instagram"),
    "fa-internet-explorer" => t("Internet-explorer"),
    "fa-ioxhost" => t("Ioxhost"),
    "fa-italic" => t("Italic"),
    "fa-joomla" => t("Joomla Logo"),
    "fa-jpy" => t("Japanese Yen (JPY)"),
    "fa-jsfiddle" => t("JsFiddle"),
    "fa-key" => t("Key"),
    "fa-keyboard-o" => t("Keyboard Outlined"),
    "fa-krw" => t("Korean Won (KRW)"),
    "fa-language" => t("Language"),
    "fa-laptop" => t("Laptop"),
    "fa-lastfm" => t("Last.fm"),
    "fa-lastfm-square" => t("Last.fm Square"),
    "fa-leaf" => t("Leaf"),
    "fa-leanpub" => t("Leanpub"),
    "fa-lemon-o" => t("Lemon Outlined"),
    "fa-level-down" => t("Level Down"),
    "fa-level-up" => t("Level Up"),
    "fa-life-ring" => t("Life Ring"),
    "fa-lightbulb-o" => t("Lightbulb Outlined"),
    "fa-line-chart" => t("Line Chart"),
    "fa-link" => t("Link"),
    "fa-linkedin" => t("LinkedIn"),
    "fa-linkedin-square" => t("LinkedIn Square"),
    "fa-linux" => t("Linux"),
    "fa-list" => t("List"),
    "fa-list-alt" => t("List-alt"),
    "fa-list-ol" => t("List-ol"),
    "fa-list-ul" => t("List-ul"),
    "fa-location-arrow" => t("Location-arrow"),
    "fa-lock" => t("Lock"),
    "fa-long-arrow-down" => t("Long Arrow Down"),
    "fa-long-arrow-left" => t("Long Arrow Left"),
    "fa-long-arrow-right" => t("Long Arrow Right"),
    "fa-long-arrow-up" => t("Long Arrow Up"),
    "fa-magic" => t("Magic"),
    "fa-magnet" => t("Magnet"),
    "fa-male" => t("Male"),
    "fa-map" => t("Map"),
    "fa-map-marker" => t("Map-marker"),
    "fa-map-o" => t("Map Outline"),
    "fa-map-pin" => t("Map Pin"),
    "fa-map-signs" => t("Map Signs"),
    "fa-mars" => t("Mars"),
    "fa-mars-double" => t("Mars Double"),
    "fa-mars-stroke" => t("Mars Stroke"),
    "fa-mars-stroke-h" => t("Mars Stroke Horizontal"),
    "fa-mars-stroke-v" => t("Mars Stroke Vertical"),
    "fa-maxcdn" => t("MaxCDN"),
    "fa-meanpath" => t("Meanpath"),
    "fa-medium" => t("Medium"),
    "fa-medkit" => t("Medkit"),
    "fa-meh-o" => t("Meh Outlined"),
    "fa-mercury" => t("Mercury"),
    "fa-microphone" => t("Microphone"),
    "fa-microphone-slash" => t("Microphone Slash"),
    "fa-minus" => t("Minus"),
    "fa-minus-circle" => t("Minus Circle"),
    "fa-minus-square" => t("Minus Square"),
    "fa-minus-square-o" => t("Minus Square Outlined"),
    "fa-mixcloud" => t("Mixcloud"),
    "fa-mobile" => t("Mobile Phone"),
    "fa-modx" => t("MODX"),
    "fa-money" => t("Money"),
    "fa-moon-o" => t("Moon Outlined"),
    "fa-motorcycle" => t("Motorcycle"),
    "fa-mouse-pointer" => t("Mouse Pointer"),
    "fa-music" => t("Music"),
    "fa-neuter" => t("Neuter"),
    "fa-newspaper-o" => t("Newspaper Outlined"),
    "fa-object-group" => t("Object Group"),
    "fa-object-ungroup" => t("Object Ungroup"),
    "fa-odnoklassniki" => t("Odnoklassniki"),
    "fa-odnoklassniki-square" => t("Odnoklassniki Square"),
    "fa-opencart" => t("OpenCart"),
    "fa-openid" => t("OpenID"),
    "fa-opera" => t("Opera"),
    "fa-optin-monster" => t("Optin Monster"),
    "fa-outdent" => t("Outdent"),
    "fa-pagelines" => t("Pagelines"),
    "fa-paint-brush" => t("Paint Brush"),
    "fa-paper-plane" => t("Paper Plane"),
    "fa-paper-plane-o" => t("Paper Plane Outlined"),
    "fa-paperclip" => t("Paperclip"),
    "fa-paragraph" => t("Paragraph"),
    "fa-pause" => t("Pause"),
    "fa-pause-circle" => t("Pause Circle"),
    "fa-pause-circle-o" => t("Pause Circle Outlined"),
    "fa-paw" => t("Paw"),
    "fa-paypal" => t("Paypal"),
    "fa-pencil" => t("Pencil"),
    "fa-pencil-square" => t("Pencil Square"),
    "fa-pencil-square-o" => t("Pencil Square Outlined"),
    "fa-percent" => t("Percent"),
    "fa-phone" => t("Phone"),
    "fa-phone-square" => t("Phone Square"),
    "fa-picture-o" => t("Picture Outlined"),
    "fa-pie-chart" => t("Pie Chart"),
    "fa-pied-piper" => t("Pied Piper Logo"),
    "fa-pied-piper-alt" => t("Pied Piper Alternate Logo"),
    "fa-pinterest" => t("Pinterest"),
    "fa-pinterest-p" => t("Pinterest P"),
    "fa-pinterest-square" => t("Pinterest Square"),
    "fa-plane" => t("Plane"),
    "fa-play" => t("Play"),
    "fa-play-circle" => t("Play Circle"),
    "fa-play-circle-o" => t("Play Circle Outlined"),
    "fa-plug" => t("Plug"),
    "fa-plus" => t("Plus"),
    "fa-plus-circle" => t("Plus Circle"),
    "fa-plus-square" => t("Plus Square"),
    "fa-plus-square-o" => t("Plus Square Outlined"),
    "fa-power-off" => t("Power Off"),
    "fa-print" => t("Print"),
    "fa-product-hunt" => t("Product Hunt"),
    "fa-puzzle-piece" => t("Puzzle Piece"),
    "fa-qq" => t("QQ"),
    "fa-qrcode" => t("Qrcode"),
    "fa-question" => t("Question"),
    "fa-question-circle" => t("Question Circle"),
    "fa-quote-left" => t("Quote-left"),
    "fa-quote-right" => t("Quote-right"),
    "fa-random" => t("Random"),
    "fa-rebel" => t("Rebel Alliance"),
    "fa-recycle" => t("Recycle"),
    "fa-reddit" => t("Reddit Logo"),
    "fa-reddit-alien" => t("Reddit Alien"),
    "fa-reddit-square" => t("Reddit Square"),
    "fa-refresh" => t("Refresh"),
    "fa-registered" => t("Registered Trademark"),
    "fa-renren" => t("Renren"),
    "fa-repeat" => t("Repeat"),
    "fa-reply" => t("Reply"),
    "fa-reply-all" => t("Reply-all"),
    "fa-retweet" => t("Retweet"),
    "fa-road" => t("Road"),
    "fa-rocket" => t("Rocket"),
    "fa-rss" => t("Rss"),
    "fa-rss-square" => t("RSS Square"),
    "fa-rub" => t("Russian Ruble (RUB)"),
    "fa-safari" => t("Safari"),
    "fa-scissors" => t("Scissors"),
    "fa-scribd" => t("Scribd"),
    "fa-search" => t("Search"),
    "fa-search-minus" => t("Search Minus"),
    "fa-search-plus" => t("Search Plus"),
    "fa-sellsy" => t("Sellsy"),
    "fa-server" => t("Server"),
    "fa-share" => t("Share"),
    "fa-share-alt" => t("Share Alt"),
    "fa-share-alt-square" => t("Share Alt Square"),
    "fa-share-square" => t("Share Square"),
    "fa-share-square-o" => t("Share Square Outlined"),
    "fa-shield" => t("Shield"),
    "fa-ship" => t("Ship"),
    "fa-shirtsinbulk" => t("Shirts in Bulk"),
    "fa-shopping-bag" => t("Shopping Bag"),
    "fa-shopping-basket" => t("Shopping Basket"),
    "fa-shopping-cart" => t("Shopping-cart"),
    "fa-sign-in" => t("Sign In"),
    "fa-sign-out" => t("Sign Out"),
    "fa-signal" => t("Signal"),
    "fa-simplybuilt" => t("SimplyBuilt"),
    "fa-sitemap" => t("Sitemap"),
    "fa-skyatlas" => t("Skyatlas"),
    "fa-skype" => t("Skype"),
    "fa-slack" => t("Slack Logo"),
    "fa-sliders" => t("Sliders"),
    "fa-slideshare" => t("Slideshare"),
    "fa-smile-o" => t("Smile Outlined"),
    "fa-sort" => t("Sort"),
    "fa-sort-alpha-asc" => t("Sort Alpha Ascending"),
    "fa-sort-alpha-desc" => t("Sort Alpha Descending"),
    "fa-sort-amount-asc" => t("Sort Amount Ascending"),
    "fa-sort-amount-desc" => t("Sort Amount Descending"),
    "fa-sort-asc" => t("Sort Ascending"),
    "fa-sort-desc" => t("Sort Descending"),
    "fa-sort-numeric-asc" => t("Sort Numeric Ascending"),
    "fa-sort-numeric-desc" => t("Sort Numeric Descending"),
    "fa-soundcloud" => t("SoundCloud"),
    "fa-space-shuttle" => t("Space Shuttle"),
    "fa-spinner" => t("Spinner"),
    "fa-spoon" => t("Spoon"),
    "fa-spotify" => t("Spotify"),
    "fa-square" => t("Square"),
    "fa-square-o" => t("Square Outlined"),
    "fa-stack-exchange" => t("Stack Exchange"),
    "fa-stack-overflow" => t("Stack Overflow"),
    "fa-star" => t("Star"),
    "fa-star-half" => t("Star-half"),
    "fa-star-half-o" => t("Star Half Outlined"),
    "fa-star-o" => t("Star Outlined"),
    "fa-steam" => t("Steam"),
    "fa-steam-square" => t("Steam Square"),
    "fa-step-backward" => t("Step-backward"),
    "fa-step-forward" => t("Step-forward"),
    "fa-stethoscope" => t("Stethoscope"),
    "fa-sticky-note" => t("Sticky Note"),
    "fa-sticky-note-o" => t("Sticky Note Outlined"),
    "fa-stop" => t("Stop"),
    "fa-stop-circle" => t("Stop Circle"),
    "fa-stop-circle-o" => t("Stop Circle Outlined"),
    "fa-street-view" => t("Street View"),
    "fa-strikethrough" => t("Strikethrough"),
    "fa-stumbleupon" => t("StumbleUpon Logo"),
    "fa-stumbleupon-circle" => t("StumbleUpon Circle"),
    "fa-subscript" => t("Subscript"),
    "fa-subway" => t("Subway"),
    "fa-suitcase" => t("Suitcase"),
    "fa-sun-o" => t("Sun Outlined"),
    "fa-superscript" => t("Superscript"),
    "fa-table" => t("Table"),
    "fa-tablet" => t("Tablet"),
    "fa-tachometer" => t("Tachometer"),
    "fa-tag" => t("Tag"),
    "fa-tags" => t("Tags"),
    "fa-tasks" => t("Tasks"),
    "fa-taxi" => t("Taxi"),
    "fa-television" => t("Television"),
    "fa-tencent-weibo" => t("Tencent Weibo"),
    "fa-terminal" => t("Terminal"),
    "fa-text-height" => t("Text-height"),
    "fa-text-width" => t("Text-width"),
    "fa-th" => t("Th"),
    "fa-th-large" => t("Th-large"),
    "fa-th-list" => t("Th-list"),
    "fa-thumb-tack" => t("Thumb Tack"),
    "fa-thumbs-down" => t("Thumbs-down"),
    "fa-thumbs-o-down" => t("Thumbs Down Outlined"),
    "fa-thumbs-o-up" => t("Thumbs Up Outlined"),
    "fa-thumbs-up" => t("Thumbs-up"),
    "fa-ticket" => t("Ticket"),
    "fa-times" => t("Times"),
    "fa-times-circle" => t("Times Circle"),
    "fa-times-circle-o" => t("Times Circle Outlined"),
    "fa-tint" => t("Tint"),
    "fa-toggle-off" => t("Toggle Off"),
    "fa-toggle-on" => t("Toggle On"),
    "fa-trademark" => t("Trademark"),
    "fa-train" => t("Train"),
    "fa-transgender" => t("Transgender"),
    "fa-transgender-alt" => t("Transgender Alt"),
    "fa-trash" => t("Trash"),
    "fa-trash-o" => t("Trash Outlined"),
    "fa-tree" => t("Tree"),
    "fa-trello" => t("Trello"),
    "fa-tripadvisor" => t("TripAdvisor"),
    "fa-trophy" => t("Trophy"),
    "fa-truck" => t("Truck"),
    "fa-try" => t("Turkish Lira (TRY)"),
    "fa-tty" => t("TTY"),
    "fa-tumblr" => t("Tumblr"),
    "fa-tumblr-square" => t("Tumblr Square"),
    "fa-twitch" => t("Twitch"),
    "fa-twitter" => t("Twitter"),
    "fa-twitter-square" => t("Twitter Square"),
    "fa-umbrella" => t("Umbrella"),
    "fa-underline" => t("Underline"),
    "fa-undo" => t("Undo"),
    "fa-university" => t("University"),
    "fa-unlock" => t("Unlock"),
    "fa-unlock-alt" => t("Unlock Alt"),
    "fa-upload" => t("Upload"),
    "fa-usb" => t("USB"),
    "fa-usd" => t("US Dollar"),
    "fa-user" => t("User"),
    "fa-user-md" => t("User-md"),
    "fa-user-plus" => t("Add User"),
    "fa-user-secret" => t("User Secret"),
    "fa-user-times" => t("Remove User"),
    "fa-users" => t("Users"),
    "fa-venus" => t("Venus"),
    "fa-venus-double" => t("Venus Double"),
    "fa-venus-mars" => t("Venus Mars"),
    "fa-viacoin" => t("Viacoin"),
    "fa-video-camera" => t("Video Camera"),
    "fa-vimeo" => t("Vimeo"),
    "fa-vimeo-square" => t("Vimeo Square"),
    "fa-vine" => t("Vine"),
    "fa-vk" => t("VK"),
    "fa-volume-down" => t("Volume-down"),
    "fa-volume-off" => t("Volume-off"),
    "fa-volume-up" => t("Volume-up"),
    "fa-weibo" => t("Weibo"),
    "fa-weixin" => t("Weixin (WeChat)"),
    "fa-whatsapp" => t("What's App"),
    "fa-wheelchair" => t("Wheelchair"),
    "fa-wifi" => t("WiFi"),
    "fa-wikipedia-w" => t("Wikipedia W"),
    "fa-windows" => t("Windows"),
    "fa-wordpress" => t("WordPress Logo"),
    "fa-wrench" => t("Wrench"),
    "fa-xing" => t("Xing"),
    "fa-xing-square" => t("Xing Square"),
    "fa-y-combinator" => t("Y Combinator"),
    "fa-yahoo" => t("Yahoo Logo"),
    "fa-yelp" => t("Yelp"),
    "fa-youtube" => t("YouTube"),
    "fa-youtube-play" => t("YouTube Play"),
    "fa-youtube-square" => t("YouTube Square"),
  );
  return $list;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_awesome_colors_list() {
  $list = array(
    'red' => t('Red'),
    'darkred' => t('Dark red'),
    'orange' => t('Orange'),
    'green' => t('Green'),
    'darkgreen' => t('Dark green'),
    'blue' => t('Blue'),
    'purple' => t('Purple'),
    'darkpurple' => t('Dark purple'),
    'cadetblue' => t('Cadet blue'),
  );
  return $list;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_awesome_markers_elements_get($defaults, $labels = '', $prefix = '') {
  $iconlist = getlocations_leaflet_awesome_markers_list();
  $colorlist = getlocations_leaflet_awesome_colors_list();
  if (!empty($prefix)) {
    $prefix .= '_marker_';
  }
  if (empty($labels)) {
    $labels = array(
      'awesome_icon' => t('Awesome icon'),
      'awesome_icon_color' => t('Awesome icon color'),
      'awesome_marker_color' => t('Awesome marker color'),
      'awesome_title' => t('Awesome Fonts icon settings'),
      'awesome_icon_spin' => t('Awesome icon spin'),
      'awesome_icon_size' => t('Awesome icon size'),
      'awesome_icon_type' => t('Awesome icon type'),
      'awesome_icon_flip' => t('Awesome icon flip and rotate'),
      'awesome_icon_html' => t('Awesome icon HTML'),
      'awesome_icon_class' => t('Awesome icon class'),
    );
  }
  $form[$prefix . 'awesome_icon_type'] = getlocations_element_dd($labels['awesome_icon_type'], isset($defaults[$prefix . 'awesome_icon_type']) && $defaults[$prefix . 'awesome_icon_type'] ? $defaults[$prefix . 'awesome_icon_type'] : $defaults['awesome_icon_type'], array(
    'b' => t('Icon in marker'),
    'i' => t('Icon only'),
    'm' => t('Marker only'),
  ));
  $form[$prefix . 'awesome_icon_type']['#prefix'] = '<fieldset class="collapsible collapsed form-wrapper"><legend><span class="fieldset-legend">' . $labels['awesome_title'] . '</span></legend><div class="fieldset-wrapper">';
  $form[$prefix . 'awesome_icon'] = getlocations_element_dd($labels['awesome_icon'], isset($defaults[$prefix . 'awesome_icon']) && $defaults[$prefix . 'awesome_icon'] ? $defaults[$prefix . 'awesome_icon'] : $defaults['awesome_icon'], $iconlist);
  $form[$prefix . 'awesome_icon_color_selector'] = getlocations_element_dd($labels['awesome_icon_color'], isset($defaults[$prefix . 'awesome_icon_color_selector']) ? $defaults[$prefix . 'awesome_icon_color_selector'] : $defaults['awesome_icon_color_selector'], array(
    'white' => t('White'),
    'black' => t('Black'),
  ));
  $form[$prefix . 'awesome_icon_color'] = getlocations_element_map_tf($labels['awesome_icon_color'], isset($defaults[$prefix . 'awesome_icon_color']) && $defaults[$prefix . 'awesome_icon_color'] ? $defaults[$prefix . 'awesome_icon_color'] : $defaults['awesome_icon_color'], t('Entries here will be used instead of the default colors in the select list. Use hex, eg #F0F000'), 10);
  $form[$prefix . 'awesome_icon_size'] = getlocations_element_dd($labels['awesome_icon_size'], isset($defaults[$prefix . 'awesome_icon_size']) && $defaults[$prefix . 'awesome_icon_size'] ? $defaults[$prefix . 'awesome_icon_size'] : $defaults['awesome_icon_size'], array(
    '' => t('Default'),
    'fa-lg' => t('Large'),
    'fa-2x' => t('2x large'),
    'fa-3x' => t('3x large'),
    'fa-4x' => t('4x large'),
    'fa-5x' => t('5x large'),
  ), t('Icon size is only applied when "Icon only" has been selected in Awesome icon type.'));
  $form[$prefix . 'awesome_icon_html'] = getlocations_element_map_tf($labels['awesome_icon_html'], isset($defaults[$prefix . 'awesome_icon_html']) && $defaults[$prefix . 'awesome_icon_html'] ? $defaults[$prefix . 'awesome_icon_html'] : $defaults['awesome_icon_html'], t('Icon HTML will override any other icon HTML. This is only applied when "Icon only" has been selected in Awesome icon type.'), 40);
  $form[$prefix . 'awesome_icon_class'] = getlocations_element_map_tf($labels['awesome_icon_class'], isset($defaults[$prefix . 'awesome_icon_class']) && $defaults[$prefix . 'awesome_icon_class'] ? $defaults[$prefix . 'awesome_icon_class'] : $defaults['awesome_icon_class'], t('Icon Class will override any other icon class. This is only applied when "Icon only" has been selected in Awesome icon type.'), 40);
  $form[$prefix . 'awesome_icon_flip'] = getlocations_element_dd($labels['awesome_icon_flip'], isset($defaults[$prefix . 'awesome_icon_flip']) && $defaults[$prefix . 'awesome_icon_flip'] ? $defaults[$prefix . 'awesome_icon_flip'] : $defaults['awesome_icon_flip'], array(
    '' => t('Normal'),
    'fa-flip-horizontal' => t('Flip Horizontal'),
    'fa-flip-vertical' => t('Flip Vertical'),
    'fa-rotate-90' => t('Rotate 90 degrees'),
    'fa-rotate-180' => t('Rotate 180 degrees'),
    'fa-rotate-270' => t('Rotate 270 degrees'),
  ), t('These Icon modifiers are only applied when "Icon only" has been selected in Awesome icon type.'));
  $form[$prefix . 'awesome_icon_spin'] = getlocations_element_dd($labels['awesome_icon_spin'], isset($defaults[$prefix . 'awesome_icon_spin']) ? $defaults[$prefix . 'awesome_icon_spin'] : $defaults['awesome_icon_spin'], array(
    '' => t('Normal'),
    'fa-spin' => t('Spin'),
    'fa-pulse' => t('Pulse'),
  ));
  $form[$prefix . 'awesome_marker_color'] = getlocations_element_dd($labels['awesome_marker_color'], isset($defaults[$prefix . 'awesome_marker_color']) && $defaults[$prefix . 'awesome_marker_color'] ? $defaults[$prefix . 'awesome_marker_color'] : $defaults['awesome_marker_color'], $colorlist);
  $form[$prefix . 'awesome_marker_color']['#suffix'] = '</div></fieldset>';
  return $form;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function getlocations_leaflet_awesome_marker_get($defaults, $prefix = '') {
  if (!empty($prefix)) {
    $prefix .= '_marker_';
  }
  $awesome_icon_type = isset($defaults[$prefix . 'awesome_icon_type']) && $defaults[$prefix . 'awesome_icon_type'] ? $defaults[$prefix . 'awesome_icon_type'] : $defaults['awesome_icon_type'];
  if ($awesome_icon_type == 'i') {

    // icon only
    $icon = isset($defaults[$prefix . 'awesome_icon']) ? $defaults[$prefix . 'awesome_icon'] : $defaults['awesome_icon'];
    $selector = isset($defaults[$prefix . 'awesome_icon_color_selector']) ? $defaults[$prefix . 'awesome_icon_color_selector'] : $defaults['awesome_icon_color_selector'];
    $iconcolor = $defaults[$prefix . 'awesome_icon_color'] ? $defaults[$prefix . 'awesome_icon_color'] : $selector;
    $spin = isset($defaults[$prefix . 'awesome_icon_spin']) ? $defaults[$prefix . 'awesome_icon_spin'] : $defaults['awesome_icon_spin'];
    $flip = isset($defaults[$prefix . 'awesome_icon_flip']) ? $defaults[$prefix . 'awesome_icon_flip'] : $defaults['awesome_icon_flip'];
    $iconsize = isset($defaults[$prefix . 'awesome_icon_size']) ? $defaults[$prefix . 'awesome_icon_size'] : $defaults['awesome_icon_size'];
    $html = isset($defaults[$prefix . 'awesome_icon_html']) ? $defaults[$prefix . 'awesome_icon_html'] : $defaults['awesome_icon_html'];
    $classname = isset($defaults[$prefix . 'awesome_icon_class']) ? $defaults[$prefix . 'awesome_icon_class'] : $defaults['awesome_icon_class'];
    $px = 12;
    if ($iconsize == 'fa-lg') {
      $px = 16;
    }
    elseif ($iconsize == 'fa-2x') {
      $px = 24;
    }
    elseif ($iconsize == 'fa-3x') {
      $px = 36;
    }
    elseif ($iconsize == 'fa-4x') {
      $px = 48;
    }
    elseif ($iconsize == 'fa-5x') {
      $px = 60;
    }
    $style = '';
    $class = array();
    $class[] = 'fa';
    $class[] = $icon;
    if ($iconsize) {
      $class[] = $iconsize;
    }
    if ($spin) {
      $class[] = $spin;
    }
    if ($flip) {
      $class[] = $flip;
    }
    if ($iconcolor == 'black' || $iconcolor == 'white') {
      $class[] = 'fa-' . $iconcolor;
    }
    else {
      $style = 'style="color:' . $iconcolor . '"';
    }
    $classes = implode(' ', $class);
    if (empty($html)) {
      $html = '<i class="' . $classes . '" ' . $style . '></i>';
    }
    $vicon = array(
      'px' => $px,
      'html' => $html,
      'classname' => $classname,
    );
  }
  elseif ($awesome_icon_type == 'm') {

    // marker only, do it by providing a nonexistent icon
    $markercolor = isset($defaults[$prefix . 'awesome_marker_color']) ? $defaults[$prefix . 'awesome_marker_color'] : $defaults['awesome_marker_color'];
    $selector = isset($defaults[$prefix . 'awesome_icon_color_selector']) ? $defaults[$prefix . 'awesome_icon_color_selector'] : $defaults['awesome_icon_color_selector'];
    $iconcolor = $defaults[$prefix . 'awesome_icon_color'] ? $defaults[$prefix . 'awesome_icon_color'] : $selector;
    $html = isset($defaults[$prefix . 'awesome_icon_html']) ? $defaults[$prefix . 'awesome_icon_html'] : $defaults['awesome_icon_html'];
    $vicon = array(
      'icon' => 'fa-xxx',
      'markerColor' => $markercolor,
      'prefix' => 'fa',
      'spin' => FALSE,
      'html' => $html,
      'iconColor' => $iconcolor,
    );
  }
  else {

    // both
    $icon = isset($defaults[$prefix . 'awesome_icon']) ? $defaults[$prefix . 'awesome_icon'] : $defaults['awesome_icon'];
    $markercolor = isset($defaults[$prefix . 'awesome_marker_color']) ? $defaults[$prefix . 'awesome_marker_color'] : $defaults['awesome_marker_color'];
    $selector = isset($defaults[$prefix . 'awesome_icon_color_selector']) ? $defaults[$prefix . 'awesome_icon_color_selector'] : $defaults['awesome_icon_color_selector'];
    $iconcolor = isset($defaults[$prefix . 'awesome_icon_color']) && $defaults[$prefix . 'awesome_icon_color'] ? $defaults[$prefix . 'awesome_icon_color'] : $selector;
    $spin = isset($defaults[$prefix . 'awesome_icon_spin']) ? $defaults[$prefix . 'awesome_icon_spin'] : $defaults['awesome_icon_spin'];

    #$flip = (isset($defaults[$prefix . 'awesome_icon_flip']) ? $defaults[$prefix . 'awesome_icon_flip'] : $defaults['awesome_icon_flip']);
    $vicon = array(
      'icon' => $icon,
      'markerColor' => $markercolor,
      'iconColor' => $iconcolor,
      'prefix' => 'fa',
      'spin' => $spin,
    );
  }
  return array(
    'data' => $vicon,
    'type' => $awesome_icon_type,
  );
}

/**
 * Fetch leaflet version.
 *
 * @return
 *   Returns version number
 */
function getlocations_leaflet_library_version() {
  $version = '';
  $file = libraries_get_path('leaflet') . '/leaflet.js';
  if (file_exists($file)) {
    $contents = file_get_contents($file);
    $regex = '/version="([0-9.]+)"/';
    if (preg_match($regex, $contents, $m)) {
      $version = $m[1];
    }
  }
  return $version;
}

/**
 * Check that the library exists
 *
 */
function getlocations_leaflet_hash_library_check() {
  if ($path = libraries_get_path('leaflet-hash')) {
    $file = $path . '/leaflet-hash.js';
  }
  if ($path && file_exists($file)) {
    return $file;
  }
  else {
    return FALSE;
  }
}

/**
 * Implements hook_theme().
 *
 * This lets us tell Drupal about our theme functions and their arguments.
 */
function getlocations_leaflet_theme() {
  return array(
    'getlocations_leaflet_link' => array(
      'variables' => array(
        'link_text' => '',
        'entity_type' => '',
        'entity_id' => 0,
      ),
    ),
    'getlocations_leaflet_map' => array(
      'variables' => array(
        'width' => '',
        'height' => '',
        'map_settings' => '',
        'mapid' => '',
        'links' => '',
      ),
    ),
    'getlocations_leaflet_plugin_style_options_form' => array(
      'render element' => 'form',
    ),
    'getlocations_leaflet_settings_form' => array(
      'render element' => 'form',
    ),
    'getlocations_leaflet_display_options_form' => array(
      'render element' => 'form',
    ),
  );
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function theme_getlocations_leaflet_link($variables) {
  $link_text = $variables['link_text'];
  $entity_type = $variables['entity_type'];
  $entity_id = $variables['entity_id'];
  $output = '';
  $path = 'getlocations_leaflet/' . $entity_type . '/' . $entity_id;
  $link = t('!l on a map', array(
    '!l' => l($link_text, $path),
  ));
  $output .= '<div class="getlocations_link">' . $link . '</div>';
  return $output;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function theme_getlocations_leaflet_map($variables) {
  drupal_add_library('getlocations_leaflet', 'getlocations-leaflet');
  drupal_add_css(GETLOCATIONS_LEAFLET_PATH . '/getlocations_leaflet.css');
  $width = $variables['width'];
  $height = $variables['height'];
  $map_settings = $variables['map_settings'];
  $mapid = $variables['mapid'];
  $links = $variables['links'];
  $datanum = $map_settings['datanum'];
  $latlons = $map_settings['latlons'];
  $icons = $map_settings['icons'];
  $minmaxes = $map_settings['map_settings']['minmaxes'];
  $show_maplinks = $map_settings['map_settings']['show_maplinks'];
  unset($map_settings['datanum']);
  unset($map_settings['latlons']);
  unset($map_settings['icons']);
  unset($map_settings['map_settings']['minmaxes']);
  getlocations_leaflet_js_settings_do($map_settings, $mapid);
  $output = '';

  // links
  if (isset($links['returnlink'])) {
    $output .= '<div class="getlocations_returnlink">' . $links['returnlink'] . '</div>';
  }

  // wrap the map
  $output .= '<div class="getlocations_leaflet_map_wrapper_inner">';
  $output .= '<div id="getlocations_leaflet_wrapper_' . $mapid . '"  style="width: ' . $width . '; height: ' . $height . '" >';
  $output .= '<div class="getlocations_leaflet_canvas" id="getlocations_leaflet_canvas_' . $mapid . '" style="width: 100%; height: 100%" ></div>';
  $output .= '</div>';
  $output .= '</div>';

  // give each map its own data
  $localdata = json_encode(array(
    'datanum' => $datanum,
    'latlons' => $latlons,
    'icons' => $icons,
    'minmaxes' => $minmaxes,
  ));
  $output .= "\n" . '<script type="text/javascript">' . "\n" . '<!--//--><![CDATA[//><!--' . "\n";
  $output .= 'Drupal.getlocations_leaflet_data["' . $mapid . '"] = ' . $localdata . ';' . "\n";
  $output .= '//--><!]]>' . "\n" . '</script>' . "\n";

  // show_search_distance etc
  if (module_exists('getlocations_fields') && isset($map_settings['search_dist_info'])) {
    $output .= '<div id="getlocations_fields_search_views_search_wrapper_' . $mapid . '" class="js-hide">';
    $output .= '<div id="getlocations_fields_search_views_search_units_' . $mapid . '">' . $map_settings['search_dist_info']['search_units'] . '</div>';
    $output .= '<div id="getlocations_fields_search_views_search_latitude_' . $mapid . '">' . $map_settings['search_dist_info']['latitude'] . '</div>';
    $output .= '<div id="getlocations_fields_search_views_search_longitude_' . $mapid . '">' . $map_settings['search_dist_info']['longitude'] . '</div>';
    $output .= '<div id="getlocations_fields_search_views_search_distance_meters_' . $mapid . '">' . getlocations_convert_distance_to_meters($map_settings['search_dist_info']['search_distance'], $map_settings['search_dist_info']['search_units']) . '</div>';
    $output .= '</div>';
  }

  // show maplinks if enabled
  if ($show_maplinks) {
    $output .= '<div class="getlocations_leaflet_map_links" id="getlocations_leaflet_map_links_' . $mapid . '" ><ul></ul></div>';
  }

  // buttons
  $buttons = array();

  // usermarker
  $geolocation_mobile_check = $map_settings['map_settings']['geolocation_mobile_check'] ? FALSE : TRUE;
  if (getlocations_is_mobile($geolocation_mobile_check) && $map_settings['map_settings']['usermarker']) {
    $buttons[] = '<input type="button" value="' . $map_settings['map_settings']['usermarker_button_label'] . '" id="getlocations_leaflet_gps_show_' . $mapid . '" class="form-submit"  /><div class="getlocations_leaflet_gps_throbber getlocations_leaflet_gps_throbber_inactive" id="getlocations_leaflet_gps_throbber_' . $mapid . '">&nbsp;&nbsp;&nbsp;&nbsp;</div>';
  }

  // views_search_marker
  if (module_exists('getlocations_fields') && isset($map_settings['search_dist_info'])) {
    if ($map_settings['map_settings']['views_search_marker_enable'] && $map_settings['map_settings']['views_search_marker_toggle']) {
      $buttons[] = '<input type="button" value="' . t('Search marker !t', array(
        '!t' => $map_settings['map_settings']['views_search_marker_toggle_active'] ? t('Off') : t('On'),
      )) . '" id="getlocations_leaflet_toggleSearchMarker_' . $mapid . '" class="form-submit" />';
    }
    if ($map_settings['map_settings']['views_search_radshape_enable'] && $map_settings['map_settings']['views_search_radshape_toggle']) {
      $buttons[] = '<input type="button" value="' . t('Search area !t', array(
        '!t' => $map_settings['map_settings']['views_search_radshape_toggle_active'] ? t('Off') : t('On'),
      )) . '" id="getlocations_leaflet_toggleSearchArea_' . $mapid . '" class="form-submit" />';
    }
  }
  if (count($buttons)) {
    $output .= '<div class="getlocations_leaflet_map_buttons container-inline">';
    $output .= implode('&nbsp;', $buttons);
    $output .= '</div>';
  }

  // What3Words
  $what3words_lic = variable_get('getlocations_what3words_lic', array(
    'key' => '',
    'url' => 'http://api.what3words.com',
  ));
  if ($what3words_lic['key'] && $map_settings['map_settings']['what3words_enable']) {
    $output .= '<div class="getlocations_leaflet_what3words container-inline">';
    if ($map_settings['map_settings']['what3words_search']) {

      // textbox
      $output .= t('What3Words') . '&nbsp;&nbsp;<input type="text" id="edit-getlocations-leaflet-what3words-search" name="edit-getlocations-leaflet-what3words-search" value="" size="' . $map_settings['map_settings']['what3words_size'] . '" class="form-text" />';
      $output .= '&nbsp;&nbsp;<input type="button" value="' . t('Search') . '" id="edit-getlocations-leaflet-what3words-search-submit" class="form-submit" />';
      $output .= '<div class="getlocations_w3w_throbber getlocations_w3w_throbber_inactive" id="getlocations_w3w_throbber_' . $mapid . '">&nbsp;&nbsp;&nbsp;&nbsp;</div>';
      $output .= '<br />';
    }
    if ($map_settings['map_settings']['what3words_show']) {
      $output .= '<div id="edit-getlocations-leaflet-what3words-show"></div>';
    }
    $output .= '</div>';
  }
  return $output;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function theme_getlocations_leaflet_plugin_style_options_form($variables) {
  $form = $variables['form'];
  $form = getlocations_leaflet_display_options_fieldsets($form);
  $output = '';
  $output .= drupal_render_children($form);
  return $output;
}

/**
 * Function
 *
 * @param
 *
 * @return
 *   Returns
 *
 */
function theme_getlocations_leaflet_settings_form($variables) {
  $form = $variables['form'];
  $output = '';
  $form['getlocations_leaflet_defaults']['returnlink_page_link']['#prefix'] = '<div id="wrap-page-link">';
  $form['getlocations_leaflet_defaults']['returnlink_page_link']['#suffix'] = '</div>';
  if (isset($form['getlocations_leaflet_defaults']['returnlink_user_link'])) {
    $form['getlocations_leaflet_defaults']['returnlink_user_link']['#prefix'] = '<div id="wrap-user-link">';
    $form['getlocations_leaflet_defaults']['returnlink_user_link']['#suffix'] = '</div>';
  }
  if (isset($form['getlocations_leaflet_defaults']['returnlink_term_link'])) {
    $form['getlocations_leaflet_defaults']['returnlink_term_link']['#prefix'] = '<div id="wrap-term-link">';
    $form['getlocations_leaflet_defaults']['returnlink_term_link']['#suffix'] = '</div>';
  }
  if (isset($form['getlocations_leaflet_defaults']['returnlink_comment_link'])) {
    $form['getlocations_leaflet_defaults']['returnlink_comment_link']['#prefix'] = '<div id="wrap-comment-link">';
    $form['getlocations_leaflet_defaults']['returnlink_comment_link']['#suffix'] = '</div>';
  }

  // mapbox
  if (module_exists('getlocations_mapbox')) {
    $mapnum = $form['getlocations_leaflet_mapbox']['mapnum']['#value'];
    unset($form['getlocations_leaflet_mapbox']['mapnum']);
    for ($ct = 0; $ct < $mapnum; $ct++) {
      $form['getlocations_leaflet_mapbox']['mapbox_info'][$ct]['label']['#prefix'] = '<fieldset class="getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('MapBox map @n', array(
        '@n' => $ct + 1,
      )) . '</span></legend><div class="fieldset-wrapper">';
      $form['getlocations_leaflet_mapbox']['mapbox_info'][$ct]['type']['#suffix'] = '</div></fieldset>';
    }
  }

  // preview leaflet
  if (isset($form['getlocations_leaflet_preview']['preview_map']['#markup'])) {
    $links = array();
    $nodezoom = FALSE;
    $iconlist = array();
    $getlocations_leaflet_defaults = getlocations_leaflet_defaults();
    $map_settings = getlocations_leaflet_map_get_info('Getlocations OSM');
    $map_settings = getlocations_leaflet_get_map_layers($map_settings);
    if (!empty($getlocations_leaflet_defaults['baselayers'])) {
      $map_layers = array();
      foreach ($getlocations_leaflet_defaults['baselayers'] as $k => $v) {
        if (isset($map_settings['map_layers'][$k]) && $getlocations_leaflet_defaults['baselayers'][$k]) {
          $map_layers[$k] = $map_settings['map_layers'][$k];
        }
      }
      if (!empty($map_layers)) {
        $map_settings['map_layers'] = $map_layers;
      }
    }
    $ll = explode(',', $getlocations_leaflet_defaults['latlong']);
    $map_settings['map_opts']['center'] = array(
      $ll[0],
      $ll[1],
    );
    $map_settings['map_opts']['zoom'] = $getlocations_leaflet_defaults['zoom'];
    $mapid = getlocations_setup_map('', FALSE, FALSE, TRUE);
    $latlons = array();
    $minmaxes = array();
    $map_settings['map_settings']['dragging'] = TRUE;

    // add in some more
    $map_settings = getlocations_leaflet_map_settings_do($map_settings, $getlocations_leaflet_defaults, $latlons, $mapid);
    $map_settings['map_settings']['nodezoom'] = $nodezoom ? $nodezoom : $getlocations_leaflet_defaults['nodezoom'];
    $map_settings['map_settings']['minmaxes'] = empty($minmaxes) ? FALSE : implode(',', $minmaxes);
    $map_settings['icons'] = $iconlist;
    $map_settings['datanum'] = 0;
    $map_settings['latlons'] = $latlons;
    $map_settings['extcontrol'] = 'preview_map';
    $preview_map = theme('getlocations_leaflet_map', array(
      'width' => $getlocations_leaflet_defaults['width'],
      'height' => $getlocations_leaflet_defaults['height'],
      'map_settings' => $map_settings,
      'mapid' => $mapid,
      'links' => $links,
    ));
    $form['getlocations_leaflet_preview']['preview_map']['#markup'] = '<div id="getlocations_leaflet_preview_map">' . $preview_map . '</div>';
  }
  $output .= drupal_render_children($form);
  return $output;
}
function theme_getlocations_leaflet_display_options_form($variables) {
  $form = $variables['form'];
  $form = getlocations_leaflet_display_options_fieldsets($form);
  $output = '';
  $output .= drupal_render_children($form);
  return $output;
}
function getlocations_leaflet_display_options_fieldsets($form) {
  if (isset($form['zoomControl']) && $form['zoomControl']['#type'] !== 'value') {
    $form['zoomControl']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Zoom Control') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['zoomcontrolposition']['#suffix'];
    $form['zoomcontrolposition']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['scaleControl']) && $form['scaleControl']['#type'] !== 'value') {
    $form['scaleControl']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Scale Control') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['scalecontrolposition']['#suffix'];
    $form['scalecontrolposition']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['attributionControl']) && $form['attributionControl']['#type'] !== 'value') {
    $form['attributionControl']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Attribution Control') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['attributioncontrolposition']['#suffix'];
    $form['attributioncontrolposition']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['geocoder']) && $form['geocoder']['#type'] !== 'value') {
    $form['geocoder']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Geocoder') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['geocodercollapsed']['#suffix'];
    $form['geocodercollapsed']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['usermarker']) && $form['usermarker']['#type'] !== 'value') {
    $form['usermarker']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('User marker') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['usermarker_circle_fillopacity']['#suffix'];
    $form['usermarker_circle_fillopacity']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['bouncemarker']) && $form['bouncemarker']['#type'] !== 'value') {
    $form['bouncemarker']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Bounce marker') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['bouncemarker_height']['#suffix'];
    $form['bouncemarker_height']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['magnifyingglass']) && $form['magnifyingglass']['#type'] !== 'value') {
    $form['magnifyingglass']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Magnifying Glass') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['magnifyingglasszoomoffset']['#suffix'];
    $form['magnifyingglasszoomoffset']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['terminator']) && $form['terminator']['#type'] !== 'value') {
    $form['terminator']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Day/Night Layer') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['terminator_label']['#suffix'];
    $form['terminator_label']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['layerControl']) && $form['layerControl']['#type'] !== 'value') {
    $form['layerControl']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Layer Control') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['layercontrolposition']['#suffix'];
    $form['layercontrolposition']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['fullscreen']) && $form['fullscreen']['#type'] !== 'value') {
    $form['fullscreen']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Fullscreen Control') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['fullscreenposition']['#suffix'];
    $form['fullscreenposition']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['graticule']) && $form['graticule']['#type'] !== 'value') {
    $form['graticule']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Graticule Control') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['graticule_ov_label']['#suffix'];
    $form['graticule_ov_label']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['mouseposition']) && $form['mouseposition']['#type'] !== 'value') {
    $form['mouseposition']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Mouse position Control') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['mouseposition_display_dms']['#suffix'];
    $form['mouseposition_display_dms']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['pancontrol']) && $form['pancontrol']['#type'] !== 'value') {
    $form['pancontrol']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Pan Control') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['pancontrolposition']['#suffix'];
    $form['pancontrolposition']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['zoomslider']) && $form['zoomslider']['#type'] !== 'value') {
    $form['zoomslider']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Zoom Slider Control') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['zoomsliderposition']['#suffix'];
    $form['zoomsliderposition']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  if (isset($form['mapquest_maps_use']) && $form['mapquest_maps_use']['#type'] !== 'value') {
    $form['mapquest_maps_use']['#prefix'] = '<fieldset class="collapsible getlocations_fieldset form-wrapper"><legend><span class="fieldset-legend">' . t('Mapquest Maps') . '</span></legend><div class="fieldset-wrapper">';
    $tsuf = $form['mapquest_traffic_incident_on']['#suffix'];
    $form['mapquest_traffic_incident_on']['#suffix'] = $tsuf . '</div></fieldset>';
  }
  return $form;
}

Functions

Namesort descending Description
getlocations_leaflet_awesome_colors_list Function
getlocations_leaflet_awesome_markers_elements_get Function
getlocations_leaflet_awesome_markers_list Function
getlocations_leaflet_awesome_marker_get Function
getlocations_leaflet_controlpositions Function
getlocations_leaflet_defaults Function
getlocations_leaflet_display_options_fieldsets
getlocations_leaflet_display_options_form Function
getlocations_leaflet_entity_type_map Function
getlocations_leaflet_field_formatter_info Implements hook_field_formatter_info().
getlocations_leaflet_field_formatter_settings_form Implements hook_field_formatter_settings_form(). Returns form elements for a formatter's settings.
getlocations_leaflet_field_formatter_settings_summary Implements hook_field_formatter_settings_summary(). Returns a short summary for the current formatter settings of an instance.
getlocations_leaflet_field_formatter_view Implements hook_field_formatter_view(). Build a renderable array for a field value.
getlocations_leaflet_field_info Implements hook_field_info(). Define Field API field types.
getlocations_leaflet_field_is_empty Implements hook_field_is_empty(). Define what constitutes an empty item for a field type. hook_field_is_emtpy() is where Drupal asks us if this field is empty. Return TRUE if it does not contain data, FALSE if it does. This lets the form API flag an…
getlocations_leaflet_field_settings_form Implements hook_field_settings_form(). Add settings to a field settings form.
getlocations_leaflet_field_widget_error Implements hook_field_widget_error().
getlocations_leaflet_field_widget_form Implements hook_field_widget_form(). Return the form for a single field widget.
getlocations_leaflet_field_widget_info Implements hook_field_widget_info(). Expose Field API widget types.
getlocations_leaflet_flush_caches Implements hook_flush_caches().
getlocations_leaflet_getlocations_leaflet_map_info Implements hook_getlocations_leaflet_map_info().
getlocations_leaflet_get_icondata Function
getlocations_leaflet_get_map_layers Function
getlocations_leaflet_get_marker Function
getlocations_leaflet_hash_library_check Check that the library exists
getlocations_leaflet_help Implements hook_help().
getlocations_leaflet_js_settings_do Function
getlocations_leaflet_library Implements hook_library().
getlocations_leaflet_library_version Fetch leaflet version.
getlocations_leaflet_link_formatter_defaults Function
getlocations_leaflet_map_formatter_defaults Function
getlocations_leaflet_map_get_info Get all available Leaflet map definitions.
getlocations_leaflet_map_settings_do Function
getlocations_leaflet_marker_list Function
getlocations_leaflet_menu Implements hook_menu().
getlocations_leaflet_paths_get Function
getlocations_leaflet_plugins Function
getlocations_leaflet_regenerate_markers Function
getlocations_leaflet_settings_form Function
getlocations_leaflet_settings_validate Function
getlocations_leaflet_theme Implements hook_theme().
getlocations_leaflet_views_api Implements hook_views_api().
theme_getlocations_leaflet_display_options_form
theme_getlocations_leaflet_link Function
theme_getlocations_leaflet_map Function
theme_getlocations_leaflet_plugin_style_options_form Function
theme_getlocations_leaflet_settings_form Function
_getlocations_leaflet_rebuild_marker_js_submit Rebuild marker js.

Constants

Namesort descending Description
GETLOCATIONS_LEAFLET_PATH @file getlocations_leaflet.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL