You are here

function getlocations_leaflet_library in Get Locations 7

Same name and namespace in other branches
  1. 7.2 modules/getlocations_leaflet/getlocations_leaflet.module \getlocations_leaflet_library()

Implements hook_library().

File

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

Code

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;
}