You are here

function _gmap_pre_render_map in GMap Module 7.2

Same name and namespace in other branches
  1. 7 gmap.module \_gmap_pre_render_map()

Pre render function to make sure all required JS is available.

Depending on the display's behavior. @todo move this to GmapElement class

1 string reference to '_gmap_pre_render_map'
gmap_element_info in ./gmap.module
Implements hook_element_info().

File

./gmap.module, line 651
GMap -- Routines to use the Google Maps API in Drupal.

Code

function _gmap_pre_render_map($element) {
  $path = drupal_get_path('module', 'gmap');
  if (!isset($element['#gmap_settings'])) {
    $element['#gmap_settings'] = $element['#settings'];
  }
  $map = $element['#gmap_settings'];
  if (isset($map['behavior']['locpick']) && $map['behavior']['locpick']) {
    $element['#attached']['js']["{$path}/js/locpick.js"] = array(
      'weight' => 2,
    );
  }
  if (!empty($map['markers']) || !empty($map['lines'])) {
    $element['#attached']['js']["{$path}/js/markerloader_static.js"] = array(
      'weight' => 5,
    );
  }
  if (!empty($map['shapes'])) {
    $element['#attached']['js']["{$path}/js/shapeloader_static.js"] = array(
      'weight' => 5,
    );
    $element['#attached']['js']["{$path}/js/gmap_shapes.js"] = array(
      'weight' => 5,
    );
  }
  if (isset($map['feed']) && is_array($map['feed'])) {
    $element['#attached']['js']["{$path}/js/markerloader_georss.js"] = array(
      'weight' => 5,
    );
  }

  // Add the markermanager.
  if (isset($map['behavior']['dynmarkers']) && $map['behavior']['dynmarkers'] || !empty($map['markers'])) {
    static $header_set = FALSE;
    if (!$header_set) {
      $header_set = TRUE;
      if (!variable_get('gmap_marker_file', FALSE)) {
        gmap_regenerate_markers();
      }
    }
  }
  $mm = variable_get('gmap_mm_type', 'gmap');
  $mms = variable_get('gmap_markermanager', array());

  // If you really really want to override the marker manager, implement
  // this, take $mm by ref, and have fun. --Bdragon
  if (function_exists('_gmap_markermanager_override')) {
    _gmap_markermanager_override($mm);
  }
  if (isset($mms[$mm]['filename'])) {
    $element['#attached']['js'][$path . '/thirdparty/' . $mms[$mm]['filename']] = array(
      'weight' => 5,
    );
    $element['#attached']['js'][] = array(
      'data' => array(
        'gmap_markermanager' => $mms[$mm],
      ),
      'type' => 'setting',
    );
  }
  $element['#attached']['js'][$path . '/js/' . $mm . '_marker.js'] = array(
    'weight' => 5,
  );
  return $element;
}