You are here

function openlayers_include in Openlayers 6.2

Same name and namespace in other branches
  1. 7.2 openlayers.module \openlayers_include()

Include necessary CSS and JS for rendering maps

3 calls to openlayers_include()
openlayers_build_map in ./openlayers.module
Prepare a map for rendering.
openlayers_ui_presets_form in modules/openlayers_ui/includes/openlayers_ui.presets.inc
Menu Callback for Add Preset
openlayers_ui_presets_form_validate in modules/openlayers_ui/includes/openlayers_ui.presets.inc
OpenLayers Preset Form Validate

File

./openlayers.module, line 57
Main OpenLayers API File

Code

function openlayers_include() {

  // Use a static variable to prevent running URL check code repeatedly.
  static $once;
  if (!isset($once)) {
    $once = TRUE;
    $path = check_plain(variable_get('openlayers_source', 'http://openlayers.org/api/2.9/OpenLayers.js'));

    // Correctly handle URLs beginning with a double backslash, see RFC 1808 Section 4
    if (substr($path, 0, 2) == '//') {
      $http_protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
      $path = $http_protocol . ':' . $path;
    }

    // Check for full URL and include it manually if external.
    if (valid_url($path, TRUE)) {
      drupal_set_html_head('<script src="' . check_url($path) . '" type="text/javascript"></script>');
    }
    else {
      drupal_add_js($path);
    }
    drupal_add_css(drupal_get_path('module', 'openlayers') . '/openlayers.css', 'module');
    drupal_add_js(drupal_get_path('module', 'openlayers') . '/js/openlayers.js', 'module');
  }
}