You are here

function gmap_regenerate_markers in GMap Module 7.2

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 gmap.module \gmap_regenerate_markers()

Regenerate the markerdata file.

@todo move this to GmapCacheToolbox

3 calls to gmap_regenerate_markers()
gmap_flush_caches in ./gmap.module
Implements hook_flush_caches().
_gmap_pre_render_map in ./gmap.module
Pre render function to make sure all required JS is available.
_gmap_rebuild_marker_js_submit in ./gmap_settings_ui.inc
Rebuild marker js.

File

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

Code

function gmap_regenerate_markers() {
  $contents = '';
  $contents .= "// GMap marker image data.\n";
  $contents .= "Drupal.gmap = Drupal.gmap || {};\n";
  $contents .= "Drupal.gmap.icondata = " . drupal_json_encode(gmap_get_icondata(TRUE)) . ";\n";
  $dir = 'public://js/';
  $filepath = $dir . 'gmap_markers.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 ($file === FALSE) {
      drupal_set_message(t('GMap is unable to save the marker bundle. Please check gmap_markers.js permissions!'), 'error');
    }
    else {
      variable_set('gmap_marker_file', $file->fid);
    }
  }
  else {
    drupal_set_message(t('GMap is unable to save the marker bundle, so the markers will not work. Please check file system permissions of the %filepath!', array(
      '%filepath' => $filepath,
    )), 'error');
    watchdog('gmap', 'GMap write error when saving the marker bundle to %filepath.', array(
      '%filepath' => $filepath,
    ), WATCHDOG_ERROR);
  }

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