Skip to content
Snippets Groups Projects
gmap.module 43.2 KiB
Newer Older
  $form['defaults']['gmap_default_zoom']=array(
    '#type'=>'select',
    '#title'=>t('Default zoom'),
    '#default_value'=>GMAP_ZOOM,
    '#options' => drupal_map_assoc(range(0, 17)),
    '#description'=>t('The default zoom level of a Google map.'),
  );
  $form['defaults']['gmap_default_control']=array(
    '#type'=>'select',
    '#title'=>t('Default control type'),
    '#default_value'=>GMAP_CONTROL,
    '#options'=>array('None'=>t('None'),'Small'=>t('Small'),'Large'=>t('Large')),
  );
  $form['defaults']['gmap_default_type']=array(
    '#type'=>'select',
    '#title'=>t('Default map type'),
    '#default_value'=>GMAP_TYPE,
    '#options'=>array('Map'=>t('Map'),'Satellite'=>t('Satellite'),'Hybrid'=>t('Hybrid')),
  );
  $form['defaults']['gmap_default_line1_color']=array(
    '#type'=>'textfield',
    '#title'=>t('Default Line 1 Color'),
    '#default_value'=>GMAP_LINECOLOR1,
    '#size'=>25,
    '#maxlength'=>7 ,
  );
  $form['defaults']['gmap_default_line2_color']=array(
    '#type'=>'textfield',
    '#title'=>t('Default Line 2 Color'),
    '#default_value'=>GMAP_LINECOLOR2,
    '#size'=>25,
    '#maxlength'=>7 ,
  );
  $form['defaults']['gmap_default_line3_color']=array(
    '#type'=>'textfield',
    '#title'=>t('Default Line 3 Color'),
    '#default_value'=>GMAP_LINECOLOR3,
    '#size'=>25,
    '#maxlength'=>7 ,
  );

  $form['location']=array(
    '#type' => 'fieldset',
    '#title' => t('Location settings'),
  );
  $form['location']['gmap_location_map']=array(
    '#type'=>'textfield',
                                           '#title'=>t('Default location map'),
                                           '#default_value'=>variable_get('gmap_location_map','[gmap|id=locmap|center=40,0|zoom=3|width=100%|height=400px]'),
webgeer's avatar
webgeer committed
                                           '#size'=>50,
    '#description'=>t('The gmap macro for the map to be used in the location.module for setting latitude and longitude.'),
  );
webgeer's avatar
webgeer committed
}

function gmap_macro_page() {
  drupal_add_js(drupal_get_path('module','gmap'). '/gmapmacro.js');
webgeer's avatar
webgeer committed
  _gmap_doheader();
function gmap_macro_form() {
        $form['macroform'] = array(
    '#type' => 'fieldset',
    '#title' => t('Gmap macro creation'),
    '#theme' => 'gmap_macro',
  );
  $linecolors = array(GMAP_LINECOLOR1, GMAP_LINECOLOR2, GMAP_LINECOLOR3); 
  $form['macroform']['mapdiv']=array('#type'=>'markup','#value'=>'<div id="map" style="width: '.GMAP_WIDTH.'; height: '.GMAP_HEIGHT.';"></div>');
  $form['macroform']['javascript'] = array(
    '#value' => drupal_call_js('gmap_set_line_colors', $linecolors),
  );
  $form['macroform']['mapid'] = array(
    '#type' => 'textfield',
    '#id' => 'gmap-mapid',
    '#title' => t('Map id attribute'),
    '#default_value' => variable_get('gmap_default_mapid', 'map'),
    '#attributes' => array('onchange' => 'set_gmap_mapid(this.value)'),
  );
  $form['macroform']['maptype'] = array(
    '#type' => 'select', 
    '#id' => 'gmap-maptype',
    '#title' => t('Map type'), 
    '#options' => drupal_map_assoc(array('Map', 'Satellite', 'Hybrid')), 
    '#default_value' => GMAP_TYPE,
    '#required' => FALSE,
    '#attributes' => array('onchange' => 'set_gmap_type(this.value);'),
  );
  $form['macroform']['controltype'] = array(
    '#type' => 'select', 
    '#id' => 'gmap-controltype',
    '#title' => t('Controls'), 
    '#options' => drupal_map_assoc(array('None', 'Small', 'Large')), 
    '#required' => FALSE,
    '#default_value' => GMAP_CONTROL,
    '#attributes' => array('onchange' => 'set_control_type(this.value);')
  );  
webgeer's avatar
webgeer committed
  $form['macroform']['latlong'] = array(
webgeer's avatar
webgeer committed
    '#id' => 'gmap-latlong',
    '#title' => t('The Latitude and Longitude of the centre of the map'),
    '#default_value' => GMAP_LONGLAT,
    '#size' => 50,
webgeer's avatar
webgeer committed
    '#attributes' => array('onchange' => 'set_gmap_latlong(this.value);'),
  );
  $form['macroform']['width'] = array(
    '#type' => 'textfield',
    '#id' => 'gmap-width',
    '#title' => t('Map width'),
    '#default_value' => GMAP_WIDTH,
    '#size' => 25,
    '#attributes' => array('onchange' => 'set_gmap_dimension(this, \'width\');'),
  ); 
  $form['macroform']['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Map height'),
    '#id' => 'gmap-height',
    '#default_value' => GMAP_HEIGHT,
    '#size' => 25,
    '#attributes' => array('onchange' => 'set_gmap_dimension(this, \'height\');'),
  ); 
  $form['macroform']['alignment'] = array(
    '#type' => 'select', 
    '#id' => 'gmap-alignment',
    '#title' => t('Alignment'), 
    '#options' => drupal_map_assoc(array('None', 'Right', 'Left', 'Center')), 
//    '#default_value' => GMAP_ALIGNMENT,
    '#required' => FALSE,
    '#attributes' => array('onchange' => 'set_gmap_alignment(this.value);')
  );  
  $form['macroform']['clicktype'] = array(
    '#type' => 'select', 
    '#id' => 'gmap-clicktype',
    '#title' => t('What happens when you click on the map'), 
    '#options' => drupal_map_assoc(array('Points', 'Line1', 'Line2', 'Line3')), 
    '#required' => FALSE,
    '#default_value' => 'Points',
//    '#attributes' => array('onchange' => 'docontrol(this.value);')
  );    
  $form['macroform']['zoom'] = array(
    '#type' => 'select', 
    '#id' => 'gmap-zoom',
    '#title' => t('The current magnification of the map'),
    '#default_value' => GMAP_ZOOM,
    '#options' => drupal_map_assoc(range(0, 17)),
webgeer's avatar
webgeer committed
    '#attributes' => array('onchange' => 'setgmapZoom(this.value);'),
  );
  $form['macroform']['textarea'] = array(
    '#type' => 'textarea',
    '#id' => 'gmap-macrotext',
    '#title' => t('Macro text'),
  );
  return drupal_get_form('macroform', $form);
/**
 * Implementation of hook_views_style_plugins()
 */
function gmap_views_style_plugins() {
  return array(
    'gmap' => array(
      'name' => t('Gmap View'),
      'theme' => 'views_view_gmap',
      'needs_fields' => true,
      'validate' => 'views_ui_plugin_validate_list',
function gmap_get_markers(){

  static $markers='';
  if (!is_array($markers)){
    $markers=array();
    $markerdir=variable_get('gmap_markerfiles',drupal_get_path('module', 'gmap').'/markers');
    // Retrieve and sort a list of available markers
    $marker_images = file_scan_directory($markerdir, '.*\.png$',array('shadow.png','.','..'),0,true, 'filename');
    foreach ($marker_images as $marker) {
      preg_match('/markers\/([a-z]*\/*[a-zA-Z_-]+)\d*\.png/',$marker->filename,$matches);
      if ($matches) {
        //$thisfile=substr($marker->filename,strlen($markerdir)+1,-4);
        $markers[$matches[1]] = $matches[1];
      }
    }
    asort($markers);
  }
  return $markers;
}

/**
 * Display the nodes of a view in a Google Map
 */
function theme_views_view_gmap($view, $nodes) {
  $fields = _views_get_fields();
  foreach ($nodes as $node) {
    $node_data = node_load(array("nid"=>$node->nid));
    $location = $node_data->location;
    if (strlen($location['lat'])>0 && strlen($location['lon']>0)) {
webgeer's avatar
webgeer committed
      $newmarker['label'] = '';
      foreach ($view->field as $field) {
        $newmarker['label'] .= "<p>" . views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node) . "</p>";
      }
      $newmarker['point']= $location['lat'] . ',' . $location['lon'];
      $newmarker['markername']='drupal_view';
      $thismap['markers'][]= $newmarker;
    }
  }
  $output .= gmap_draw_map($thismap);
  return $output;
}