You are here

function gmap_regenerate_markers in GMap Module 7

Same name and namespace in other branches
  1. 5 gmap.module \gmap_regenerate_markers()
  2. 6.2 gmap.module \gmap_regenerate_markers()
  3. 6 gmap.module \gmap_regenerate_markers()
  4. 7.2 gmap.module \gmap_regenerate_markers()

Regenerate the markerdata file.

3 calls to gmap_regenerate_markers()
gmap_flush_caches in ./gmap.module
Implementation of hook_flush_caches().
gmap_gmap in ./gmap.module
Implementation of hook_gmap().
_gmap_rebuild_marker_js_submit in ./gmap_settings_ui.inc
Rebuild marker js.

File

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

Code

function gmap_regenerate_markers() {

  // This often fails in cli mode, so bail.
  if (drupal_is_cli()) {
    return;
  }
  $contents = '';
  $contents .= "// GMap marker image data.\n";
  $contents .= "Drupal.gmap = Drupal.gmap || {};\n";
  $contents .= "Drupal.gmap.iconpath = " . drupal_json_encode(base_path() . variable_get('gmap_markerfiles', drupal_get_path('module', 'gmap') . '/markers')) . ";\n";
  $contents .= "Drupal.gmap.icondata = " . drupal_json_encode(gmap_get_icondata(TRUE)) . ";\n";
  $dir = "public://js/";

  // Make sure js/ exists in the files folder.
  if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
    $file = file_save_data($contents, 'public://js/gmap_markers.js', FILE_EXISTS_REPLACE);
    if (!empty($file)) {
      variable_set('gmap_marker_file', $file->fid);
    }
  }
  else {
    drupal_set_message(t('GMap is unable to save the marker bundle. Markers will not work!'), 'error');
  }

  // Also regenerate the cached marker titles array
  gmap_get_marker_titles(TRUE);
}