? gmap-info-files.patch
? gmap-jan2.patch
? gmap.info
? gmap2.js
? gmap2.js.save
? gmap_location.info
? info-files
? wms-gs-1_0_1.js
Index: gmap.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap.js,v
retrieving revision 1.13
diff -u -r1.13 gmap.js
--- gmap.js	19 Nov 2006 07:50:04 -0000	1.13
+++ gmap.js	3 Jan 2007 02:56:04 -0000
@@ -1,6 +1,236 @@
- 
 /* $Id: gmap.js,v 1.13 2006/11/19 07:50:04 webgeer Exp $ */
 
+Drupal.gmapAutoAttach = function() {
+
+  Drupal.gmap = {};
+  Drupal.gmap.maps = {};
+  Drupal.gmap.geocoder = null;
+
+  // Init Google map facilities
+
+  // Init map divs
+  $('div.gmap-map').each(function() {
+    var mapid = this.id;
+    // If this didn't come with a settings array, give up.
+    if (!(b = Drupal.settings.gmap[mapid])) return;
+
+    a = Drupal.gmap.maps[mapid] = {};
+    // XXX Does anything particularly require this?
+    a.div = this;
+    a.controls = {};
+    a.vars = {};
+    a.vars['latlon'] = b.latlon;
+    a.vars['height'] = b.height;
+    a.vars['width'] = b.width;
+    a.vars['points'] = b.points;
+    a.vars['pointsOverlays'] = b.pointsOverlays;
+    a.vars['controltype'] = b.controltype;
+    a.vars['maptype'] = b.maptype;
+    // This part is silly.
+    a.vars['line1'] = b.line1;
+    a.vars['line2'] = b.line2;
+    a.vars['line3'] = b.line3;
+   
+    a.map = new GMap2(this);
+    a.currentControl = null;
+
+    var map = Drupal.gmap.maps[mapid].map;
+    map.addControl(new GMapTypeControl());
+    map.setCenter(new GLatLng(37.4419, -122.1419), 13);
+    map.setMapType(G_NORMAL_MAP);
+    gmap_change_controltype(mapid,a.vars.controltype);
+
+  });
+
+  // Tie controls
+  $('.gmap-control').each(function() {
+    // Determine the specifics
+    var mapid = this.id.split('-');
+    var func = mapid.pop();
+    // Throw away the leading "gmap"
+    mapid.shift();
+    // The rest of it is our map id.
+    mapid = mapid.join('-');
+
+    // Store a reference to ourselves. GEvent shadows the 'this' var.
+    var control = Drupal.gmap.maps[mapid].controls[func] = this;
+    
+    var map = Drupal.gmap.maps[mapid].map;
+
+    switch (func) {
+    case 'maptype':
+      // Google -> Drupal
+      GEvent.addListener(map, "maptypechanged", function() {
+        control.value = gmap_type_map2form(map.getCurrentMapType());
+        gmap_macrochanged(mapid);
+      });
+
+      // Drupal -> Google
+      $(this).change(function() {
+        map.setMapType(gmap_type_form2map(this.value));
+        gmap_macrochanged(mapid);
+      });
+      break;
+    case 'zoom':
+      // Google -> Drupal
+      GEvent.addListener(map, "zoomend", function(previouszoom,newzoom) {
+        control.value = newzoom;
+        gmap_macrochanged(mapid);
+      });
+
+      // Drupal -> Google
+      $(this).change(function() {
+        map.setZoom(parseInt(this.value));
+        gmap_macrochanged(mapid);
+      });
+      break;
+    case 'controltype':
+      // Drupal -> Google
+      $(this).change(function() {
+        gmap_change_controltype(mapid,this.value);
+        gmap_macrochanged(mapid);
+      });
+      // Google -> Drupal
+      // N/A
+      break;
+    case 'width':
+    case 'height':
+      // Drupal -> Google
+      $(this).change(function() {
+        a = gmap_validate_dim(this.value);
+        if (a) {
+          map.getContainer().style[func] = a;
+          this.value = a;
+          gmap_macrochanged(mapid);
+        }
+      });
+      // Google -> Drupal
+      // N/A
+      break;
+    case 'latlong':
+      // Drupal -> Google
+      $(this).change(function() {
+        var splitstring=this.value.split(",");
+        map.panTo(new GLatLng(splitstring[0],splitstring[1]));
+        Drupal.gmap.maps[mapid].vars.latlon = this.value;
+        gmap_macrochanged(mapid);
+      });
+      // Google -> Drupal
+      GEvent.addListener(map, "moveend", function() {
+        var center = map.getCenter();
+        control.value = center.lat() + ', ' + center.lng();
+        Drupal.gmap.maps[mapid].vars.latlon = control.value;
+        gmap_macrochanged(mapid);
+      });
+      break;
+    case 'address':
+      // Drupal -> Google
+      $(this).change(function() {
+        // Bind element so we can get feedback
+        var elem = this;
+        // Lazy init geocoder
+        if (!Drupal.gmap.geocoder) {
+          Drupal.gmap.geocoder = new GClientGeocoder();
+        }
+        Drupal.gmap.geocoder.getLatLng(
+          elem.value,
+          function(point) {
+            if (point) {
+              map.panTo(point);
+              // Clear out the address.
+              $(elem).val('');
+            }
+            else {
+              // Todo: Get translated value using settings.
+              $(elem).val('Geocoder error: Address not found');
+            }
+          }
+        );
+      });
+      // Google -> Drupal
+      // N/A
+      break;
+    }
+  });
+
+  // Sync
+  $('div.gmap-map').each(function() {
+    gmap_macrochanged(this.id);
+  });
+
+}
+
+function gmap_validate_dim(dim) {
+  return dim;
+  //needs to be fixed to allow either 'px' or '%'
+  var reg = /(\d+)/;
+  var ar = reg.exec(dim);
+  try {
+    valid_dim = ar[0] + 'px';
+    return valid_dim;
+  } catch (e) {alert(e);
+    return false;
+  }
+}
+
+if (Drupal.jsEnabled) {
+  $(document).ready(Drupal.gmapAutoAttach);
+}
+
+function gmap_type_map2form(maptype) {
+  if (maptype == G_NORMAL_MAP) return "Map";
+  if (maptype == G_HYBRID_MAP) return "Hybrid";
+  if (maptype == G_SATELLITE_MAP) return "Satellite";
+}
+
+function gmap_type_form2map(val) {
+  if (val == "Map") return G_NORMAL_MAP;
+  if (val == "Hybrid") return G_HYBRID_MAP;
+  if (val == "Satellite") return G_SATELLITE_MAP;
+} 
+
+function gmap_change_controltype(mapid,control) {
+  a = Drupal.gmap.maps[mapid];
+  a.vars.controltype = control;
+  if (a.currentControl) {
+    a.map.removeControl(a.currentControl);
+  }
+  if (control == "Small") a.map.addControl(a.currentControl = new GSmallMapControl());
+  if (control == "Large") a.map.addControl(a.currentControl = new GLargeMapControl());
+}
+
+function gmap_macrochanged(mapid) {
+  map = Drupal.gmap.maps[mapid];
+  if (map.controls['macrotext']) {
+    var output = '[gmap';
+    output += ' |zoom='    + map.map.getZoom();
+    output += ' |center='  + map.vars.latlon;
+    output += ' |width='   + map.vars.width;
+    output += ' |height='  + map.vars.height;
+    output += ' |id='      + mapid;
+    output += ' |control=' + map.vars.controltype;
+    output += ' |type='    + gmap_type_map2form(map.map.getCurrentMapType());
+
+    // XXX Fix this
+    //I don't know what alignment does or how to use it. Needs updating
+    //var alignment = ' |align=' + gmapObj.alignment;
+
+    if (map.vars.points.length > 0) {
+      output += ' |markers=' + map.vars.points.join(' + ');
+    }
+
+    // Wouldn't it be simpler to have an arbitrary # of lines?
+    if (map.vars.line1.length >0) output += ' |line1=' + map.vars.line1;
+    if (map.vars.line2.length >0) output += ' |line2=' + map.vars.line2;
+    if (map.vars.line3.length >0) output += ' |line3=' + map.vars.line3;
+
+    output += ']';
+    map.controls['macrotext'].value = output;
+  }
+}
+
+//////////////////// Old functions below the line /////////////////////
+
 var baseIcon=new Array();
 var geocoder = null;
  
Index: gmap.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap.module,v
retrieving revision 1.51
diff -u -r1.51 gmap.module
--- gmap.module	8 Dec 2006 08:13:07 -0000	1.51
+++ gmap.module	3 Jan 2007 02:56:04 -0000
@@ -28,25 +28,12 @@
 define('GMAP_CLUSTER', variable_get('gmap_cluster',0));
 define('GMAP_WMS', variable_get('gmap_wms',0));
 
-define('GMAP_API_V', '2.55a');
-
-/**
- * Implementation of hook_help.
- *
- */
-
-function gmap_help($section) {
-  switch ($section) {
-    case 'admin/modules#description':
-      return t('Filter to allow insertion of a google map into a node');
-  }
-}
+define('GMAP_API_V', '2.66');
 
 /**
  * Implementation of hook_perm.
  *
  */
-
 function gmap_perm() {
   return array('create macro');
 }
@@ -89,6 +76,14 @@
  *
  */
 function gmap_draw_map($gmap, $javascript='') {
+
+echo "DRAW_MAP CALLED";
+
+var_dump($gmap);
+return '';
+
+
+
   global $base_url, $node;
     _gmap_doheader();
     
@@ -138,8 +133,12 @@
         $style .= ' margin-left: auto; margin-right: auto;';
     }
 
+    
+
+
 //    $outtext .= "\n<!--\n\n".print_r($gmap, 1)."\n\n -->\n";
     $outtext.='<div id="'.$gmap['id'].'" style="'.$style.'" class="gmap-map"></div>
+
               <script type="text/javascript">
               //<![CDATA[
               //initialize global gmap variables
@@ -753,22 +752,22 @@
  *
  */
 function gmap_set_location($map,&$form,$fields) {
-
+echo "FOO!";
   if (!is_array($map)){
     $map=gmap_parse_macro($map);
   }
   $zoom=$map['zoom'];
 
-  $form[$fields['latitude']]['#id']='gmap-latitude';
-  $form[$fields['latitude']]['#attributes']=array('onchange'=>'gmap_textchange('.$map['id'].');');
-  $form[$fields['longitude']]['#id']='gmap-longitude';
-  $form[$fields['longitude']]['#attributes']= array('onchange'=>'gmap_textchange('.$map['id'].');');
+  $form[$fields['latitude']]['#id']='gmap-'.$map['id'].'-latitude';
+//  $form[$fields['latitude']]['#attributes']=array('onchange'=>'gmap_textchange('.$map['id'].');');
+  $form[$fields['longitude']]['#id']='gmap-'.$map['id'].'-longitude';
+//  $form[$fields['longitude']]['#attributes']= array('onchange'=>'gmap_textchange('.$map['id'].');');
   if (isset($fields['address'])) {
-    $form[$fields['address']]['#id']='gmap-address';
-    $form[$fields['address']]['#attributes']= array('onchange'=>'gmap_geocodeaddress('.$map['id'].', this.value);');
+    $form[$fields['address']]['#id']='gmap-'.$map['id'].'-address';
+//    $form[$fields['address']]['#attributes']= array('onchange'=>'gmap_geocodeaddress('.$map['id'].', this.value);');
   }
 
-  if ($form[$fields['latitude']]['#default_value']!=0 || $form[$fields['longitude']]['#default_value']!=0) {
+/*  if ($form[$fields['latitude']]['#default_value']!=0 || $form[$fields['longitude']]['#default_value']!=0) {
     $myjava .= '{id}.panTo(new GLatLng('.$form[$fields['latitude']]['#default_value'].', '.$form[$fields['longitude']]['#default_value'].'));'."\n".
              '{id}.addOverlay(thispoint=new GMarker(new GLatLng('.$form[$fields['latitude']]['#default_value'].', '.$form[$fields['longitude']]['#default_value'].')));'."\n";
   }
@@ -796,6 +795,7 @@
                 });
                // GEvent.addListener({id}, "dragend", function() {{id}.checkResize();} )
               ';
+*/
   $out = gmap_draw_map($map,$myjava);
   
 
@@ -810,8 +810,7 @@
 
   $gmap_path = drupal_get_path('module','gmap');
 
-  theme_add_style($gmap_path. '/gmap.css');
-  drupal_add_js('misc/drupal.js');
+  drupal_add_css($gmap_path .'/gmap.css');
   drupal_add_js($gmap_path. '/gmap.js');
   $js = '<script src="http://maps.google.com/maps?file=api&amp;v='.GMAP_API_V.'&amp;key='.variable_get('googlemap_api_key', '').'" type="text/javascript"></script>';
   drupal_set_html_head($js);
@@ -940,9 +939,18 @@
       'access' => user_access('create macro')||user_access('show user map')||user_access('show node map'),
     );  */
     $items[] = array(
+      'path' => 'admin/settings/gmap',
+      'title' => t('GMap'),
+      'description' => t('Configure GMap settings'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'gmap_admin_settings',
+      'access' => user_access('administer site configuration'),
+      'type' => MENU_NORMAL_ITEM,
+    );
+    $items[] = array(
       'path' => 'map/macro',
       'type' => MENU_NORMAL_ITEM,
-      'title' => t('build a GMap macro'),
+      'title' => t('Build a GMap macro'),
       'access' => user_access('create macro'),
       'callback' => 'gmap_macro_page',
     );
@@ -955,7 +963,7 @@
   return $items;
 }
 
-function gmap_settings() {
+function gmap_admin_settings() {
   //note the same google api key variable name as in the googlemap module is used
   //note the name of the variable for center of the map is latlong although the format is actually longitude, latitude
 
@@ -1125,116 +1133,186 @@
     '#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]'),
-                                           '#size'=>50,
-    '#description'=>t('The gmap macro for the map to be used in the location.module for setting latitude and longitude.'),
+    '#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]'),
+    '#size' => 50,
+    '#description' => t('The gmap macro for the map to be used in the location.module for setting latitude and longitude.'),
   );
-  return $form;
+  return system_settings_form($form);
 }
 
 function gmap_macro_page() {
   drupal_add_js(drupal_get_path('module','gmap'). '/gmapmacro.js');
   _gmap_doheader();
-  return gmap_macro_form();
+  return drupal_get_form('gmap_macro_form');
+}
+
+/**
+ * Implementation of hook_elements().
+ */
+function gmap_elements() {
+  return array(
+    'gmap' => array(
+      '#input' => FALSE, // This isn't a *form* input!!
+      '#id' => 'map',
+      '#settings' => array(
+        'width' => GMAP_WIDTH,
+        'height' => GMAP_HEIGHT,
+        'latlon' => GMAP_LONGLAT,
+        'id' => 'map', // @@@ I hate this.
+        'points' => array(),
+        'pointsOverlays' => array(),
+        'controltype' => GMAP_CONTROL,
+        'maptype' => GMAP_TYPE,
+        'linecolors' => array(GMAP_LINECOLOR1, GMAP_LINECOLOR2, GMAP_LINECOLOR3),
+        'line1' => array('overlay' => null, 'points' => null, 'line' => ""),
+        'line2' => array('overlay' => null, 'points' => null, 'line' => ""),
+        'line3' => array('overlay' => null, 'points' => null, 'line' => ""),
+      ),
+    ),
+  );
+}
+
+function theme_gmap($element) {
+  $element['#attributes']['class'] = implode(' ',array($element['#attributes']['class'],'gmap','gmap-map'));
+  $o = '<div id="'.$element['#settings']['id'].'" style="width: '.$element['#settings']['width'].'; height: '.$element['#settings']['height'].';" class="'.$element['#attributes']['class'].'"></div>';
+  // *maybe* rethink this.
+  // Right now, it all goes to the header.
+  drupal_add_js(array('gmap' => array($element['#settings']['id'] => $element['#settings'])),'setting');
+  return $o;
 }
+  
 
 function gmap_macro_form() {
-        $form['macroform'] = array(
+  $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.';" class="gmap-map"></div>'
-  );
-  $form['macroform']['javascript'] = array(
-    '#value' => drupal_call_js('gmap_set_line_colors', $linecolors),
-  );
+    '#type' => 'gmap',
+    '#attributes' => array('id'=>'map'),
+    '#settings' => array(
+      'points' => array(),
+      'pointsOverlays' => array(),
+    ),
+  );
+
+// Todo: Change this to a setting.
+drupal_add_js('gmap_set_line_colors("'.implode('","',$linecolors).'")','inline');
+
+/*$settings = array();
+$settings['map'] = array(
+  'latlon' => GMAP_LONGLAT,
+  'height' => GMAP_HEIGHT,
+  'width' => GMAP_WIDTH,
+  'points' => array(),
+  'pointsOverlays' => array(),
+  'controltype' => GMAP_CONTROL,
+  'maptype' => GMAP_TYPE,
+  'line1' => array('overlay' => null, 'points' => null, 'line' => ""),
+  'line2' => array('overlay' => null, 'points' => null, 'line' => ""),
+  'line3' => array('overlay' => null, 'points' => null, 'line' => ""),
+
+);
+ */
+//drupal_to_js(array('gmap'=>$settings),'setting');
+
+
   $form['macroform']['mapid'] = array(
     '#type' => 'textfield',
-    '#id' => 'gmap-mapid',
+    '#id' => 'gmap-map-mapid',
     '#title' => t('Map id attribute'),
     '#default_value' => variable_get('gmap_default_mapid', 'map'),
-    '#attributes' => array('onchange' => 'set_gmap_mapid(this.value)'),
+    '#attributes' => array('class' => 'gmap-control'),
   );
   $form['macroform']['maptype'] = array(
     '#type' => 'select', 
-    '#id' => 'gmap-maptype',
+    '#id' => 'gmap-map-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);'),
+    '#attributes' => array('class' => 'gmap-control'),
   );
   $form['macroform']['controltype'] = array(
     '#type' => 'select', 
-    '#id' => 'gmap-controltype',
+    '#id' => 'gmap-map-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);')
-  );  
+    '#attributes' => array('class' => 'gmap-control'),
+//'onchange' => 'set_control_type(this.value);') // XXX
+  );
+  $form['macroform']['address'] = array(
+    '#type' => 'textfield',
+    '#id' => 'gmap-map-address',
+    '#title' => t('Address'),
+//    '#required' => FALSE,
+    '#default_value' => '',
+    '#attributes' => array('class' => 'gmap-control'),
+  );
   $form['macroform']['latlong'] = array(
     '#type' => 'textfield',
-    '#id' => 'gmap-latlong',
+    '#id' => 'gmap-map-latlong',
     '#title' => t('The Latitude and Longitude of the centre of the map'),
     '#default_value' => GMAP_LONGLAT,
     '#size' => 50,
-    '#attributes' => array('onchange' => 'set_gmap_latlong(this.value);'),
+    '#attributes' => array('class' => 'gmap-control'),
   );
   $form['macroform']['width'] = array(
     '#type' => 'textfield',
-    '#id' => 'gmap-width',
+    '#id' => 'gmap-map-width',
     '#title' => t('Map width'),
     '#default_value' => GMAP_WIDTH,
     '#size' => 25,
-    '#attributes' => array('onchange' => 'set_gmap_dimension(this, \'width\');'),
+    '#attributes' => array('class' => 'gmap-control'),
   ); 
   $form['macroform']['height'] = array(
     '#type' => 'textfield',
+    '#id' => 'gmap-map-height',
     '#title' => t('Map height'),
-    '#id' => 'gmap-height',
     '#default_value' => GMAP_HEIGHT,
     '#size' => 25,
-    '#attributes' => array('onchange' => 'set_gmap_dimension(this, \'height\');'),
+    '#attributes' => array('class' => 'gmap-control'),
   ); 
   $form['macroform']['alignment'] = array(
     '#type' => 'select', 
-    '#id' => 'gmap-alignment',
+    '#id' => 'gmap-map-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);')
+    '#attributes' => array('class' => 'gmap-control'),
   );  
   $form['macroform']['clicktype'] = array(
     '#type' => 'select', 
-    '#id' => 'gmap-clicktype',
+    '#id' => 'gmap-map-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);')
+    '#attributes' => array('class' => 'gmap-control'),
   );    
   $form['macroform']['zoom'] = array(
     '#type' => 'select', 
-    '#id' => 'gmap-zoom',
+    '#id' => 'gmap-map-zoom',
     '#title' => t('The current magnification of the map'),
     '#default_value' => GMAP_ZOOM,
     '#options' => drupal_map_assoc(range(0, 17)),
-    '#attributes' => array('onchange' => 'setgmapZoom(this.value);'),
+    '#attributes' => array('class' => 'gmap-control'),
   );
   $form['macroform']['textarea'] = array(
     '#type' => 'textarea',
-    '#id' => 'gmap-macrotext',
+    '#id' => 'gmap-map-macrotext',
     '#title' => t('Macro text'),
+    '#attributes' => array('class' => 'gmap-control'),
   );
-  return drupal_get_form('macroform', $form);
+  return $form;
 }
 
 /**
@@ -1247,7 +1325,8 @@
       'theme' => 'views_view_gmap',
       'needs_fields' => true,
       'validate' => 'views_ui_plugin_validate_list',
-  ));
+    )
+  );
 }
 
 function gmap_get_markers(){
@@ -1284,10 +1363,12 @@
       foreach ($view->field as $field) {
         $marker_label .= '<div class="'. $field['field'] .'">'. views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view) .'</div>';
       }
-      $markers[] = array('markername' => variable_get('gmap_node_marker_'.$node_data->type, ''),
-                         'label' => strtr($marker_label,"'\n\r",'" '),
-                         'latitude' => $location['lat'],
-                         'longitude' => $location['lon']);
+      $markers[] = array(
+        'markername' => variable_get('gmap_node_marker_'.$node_data->type, ''),
+        'label' => strtr($marker_label,"'\n\r",'" '),
+        'latitude' => $location['lat'],
+        'longitude' => $location['lon']
+      );
     }
   }
   $thismap = array('id' => 'view_gmap', 'markers' => $markers);
Index: gmap_location.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap_location.module,v
retrieving revision 1.26
diff -u -r1.26 gmap_location.module
--- gmap_location.module	8 Dec 2006 08:14:35 -0000	1.26
+++ gmap_location.module	3 Jan 2007 02:56:04 -0000
@@ -10,46 +10,32 @@
  */
 
 /**
- * Implementation of hook_help.
- *
+ * Implementation of hook_perm().
  */
-
-function gmap_location_help($section) {
-  switch ($section) {
-    case 'admin/modules#description':
-      return t('Display location.module information on Google Maps (needs gmap.module)');
-  }
-}
-
-/**
- * Implementation of hook_perm.
- *
- */
-
 function gmap_location_perm() {
   return array('set user location', 'show user map', 'user locations', 'show node map');
 }
 
 /**
- * Implementation of hook_menu.
+ * Implementation of hook_menu().
  *
  */
-
 function gmap_location_menu($may_cache) {
-  $items=array();
+  $items = array();
 
   if ($may_cache) {
     $items[] = array(
       'path' => 'map/user',
-        'type' => MENU_NORMAL_ITEM,
-      'title' => t('user locations'),
-        'access' => user_access('show user map'),
+      'type' => MENU_NORMAL_ITEM,
+      'title' => t('User locations'),
+      'access' => user_access('show user map'),
       'callback' => 'gmap_location_user_page'
     );
-      $items[] = array('path' => 'map/node',
-        'type' => MENU_NORMAL_ITEM,
-      'title' => t('node locations'),
-        'access' => user_access('show node map'),
+    $items[] = array(
+      'path' => 'map/node',
+      'type' => MENU_NORMAL_ITEM,
+      'title' => t('Node locations'),
+      'access' => user_access('show node map'),
       'callback' => 'gmap_location_node_page'
     );
   }
@@ -61,10 +47,9 @@
  * Draws a page with a google map that has all of the site users.
  *
  */
-
 function gmap_location_user_page() {
   global $user;
-  $locationbyuser=array();
+  $locationbyuser = array();
 
   $output ='<p>'.variable_get('gmap_user_map_header', t('This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.'))."</p>\n";
 
@@ -80,6 +65,8 @@
     }
   }
 
+  $thismap = array();
+
   $thismap = gmap_parse_macro(variable_get('gmap_user_map', '[gmap|id=usermap|center=30,0|zoom=2|width=100%|height=400px]'));
   if (empty($thismap['markers'])) {
     $thismap['markers']=array();
@@ -131,8 +118,15 @@
       }
     }
   }
+
+  $element = array(
+    '#type' => 'gmap',
+    '#settings' => $thismap
+  );
+
+  $output .= theme('gmap',$element);
   
-  $output .= '<p>'.gmap_draw_map($thismap);
+//  $output .= '<p>'.gmap_draw_map($thismap);
   if ($user->uid>0) {
     $output .= '<p>'.t('To add/change your location to the user map, ').l(t('edit your location'),'user/'.$user->uid.'/edit/gmap_user');
   }
@@ -145,8 +139,6 @@
  * @param $nn
  * The node number to draw on the map.  If this is not set, or is null then all of the nodes will be drawn.
  */
-
-
 function gmap_location_node_page($nid=null) {
   if ($nid && $n=node_load($nid)){
     if (node_access('view',$n)) {
@@ -196,7 +188,6 @@
  * @return
  * A gmap centred on the
  */
-
 function gmap_location_node_map($n,$thismap,$single=false){
   if ((isset($n->gmap_location_latitude) && isset($n->gmap_location_longitude)) || (isset($n->location['latitude']) && isset($n->location['longitude']))){
     $latitude = isset($n->gmap_location_latitude) ? $n->gmap_location_latitude : $n->location['latitude'];
@@ -255,11 +246,10 @@
 }
 
 /**
- * Implementation of hook_settings.
+ * Admin Settings Page
  *
  */
-
-function gmap_location_settings() {
+function gmap_location_admin_settings() {
 
   $markers=gmap_get_markers();
   
@@ -268,58 +258,57 @@
     '#title' => t('Geocode Locations'),
   );
   $form['geocoding']['gmap_geocode'] = array(
-    '#type'=>'radios',
-    '#title'=>t('Enable the Google Map API geocoding'),
-    '#default_value'=>variable_get('gmap_geocode', 1),
+    '#type' => 'radios',
+    '#title' => t('Enable the Google Map API geocoding'),
+    '#default_value' => variable_get('gmap_geocode', 1),
     '#options' => array(1=>'Enabled', 0=>'Disabled'),
   );
 
-
   $form['user'] = array(
     '#type' => 'fieldset', 
     '#title' => t('Location settings for users'),
   );
   $form['user']['gmap_user'] = array(
-    '#type'=>'checkbox',
-    '#title'=>t('Profile map'),
-    '#default_value'=>variable_get('gmap_user', true),
-    '#description'=>t('Let users set/edit their location in their profile.'),
+    '#type' => 'checkbox',
+    '#title' => t('Profile map'),
+    '#default_value' => variable_get('gmap_user', true),
+    '#description' => t('Let users set/edit their location in their profile.'),
   );
   $form['user']['gmap_user_profile_category'] = array(
-    '#type'=>'textfield',
-    '#title'=>t('Profile category title'),
-    '#default_value'=>variable_get('gmap_user_profile_category', "Location map"),
-    '#size'=>50,
-    '#maxlength'=>50,
-    '#description'=>t('Let users set/edit their location in their profile.'),
+    '#type' => 'textfield',
+    '#title' => t('Profile category title'),
+    '#default_value' => variable_get('gmap_user_profile_category', "Location map"),
+    '#size' => 50,
+    '#maxlength' => 50,
+    '#description' => t('Let users set/edit their location in their profile.'),
   );
   $form['user']['gmap_user_map'] = array(
-    '#type'=>'textfield',
-                                       '#title'=>t('Default user map'),
-                                       '#default_value'=>variable_get('gmap_user_map', '[gmap |id=usermap|center=40,0|zoom=3|width=100%|height=400px]'),
-                                       '#size'=>50,
-                                       '#maxlength'=>500,
-    '#description'=>t('The gmap macro where the user information will be diplayed on.'),
+    '#type' => 'textfield',
+    '#title' => t('Default user map'),
+    '#default_value' => variable_get('gmap_user_map', '[gmap |id=usermap|center=40,0|zoom=3|width=100%|height=400px]'),
+    '#size' => 50,
+    '#maxlength' => 500,
+    '#description' => t('The gmap macro where the user information will be diplayed on.'),
   );
   $form['user']['gmap_user_map_header'] = array(
-    '#type'=>'textarea',
-                                              '#title'=>t('Text at the top of the map/users page'),
-                                              '#default_value'=>variable_get('gmap_user_map_header', t('This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.')),
-                                              '#cols'=>50,
-    '#rows'=>6 ,
+    '#type' => 'textarea',
+    '#title' => t('Text at the top of the map/users page'),
+    '#default_value' => variable_get('gmap_user_map_header', t('This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.')),
+    '#cols' => 50,
+    '#rows' => 6,
   );
   $form['user']['gmap_user_map_marker'] = array(
-    '#type'=>'select',
-                                              '#title'=>t('Marker for users'),
-                                              '#default_value'=>variable_get('gmap_user_map_marker', 'drupal'),
-    '#options'=>$markers,
+    '#type' => 'select',
+    '#title' => t('Marker for users'),
+    '#default_value' => variable_get('gmap_user_map_marker', 'drupal'),
+    '#options' => $markers,
   );
 
   // Option to use a different marker for each role
   $form['user']['roles'] = array(
-    '#type'=>'fieldset',
-                               '#title'=>t('Markers per role'),
-    '#description'=>t('Use a different marker to denote users in the following roles.'),
+    '#type' => 'fieldset',
+    '#title' => t('Markers per role'),
+    '#description' => t('Use a different marker to denote users in the following roles.'),
   );
 
   // Retrieve and sort list of roles, sans anonymous user
@@ -329,10 +318,10 @@
   // Create a selection box per role
   foreach ($roles as $rid => $role) {
     $form['user']['roles']["gmap_role_map_marker_$rid"] = array(
-      '#type'=>'select',
-                                                              '#title'=>$role,
-                                                              '#default_value'=>variable_get("gmap_role_map_marker_$rid", variable_get('gmap_user_map_marker', 'drupal')),
-      '#options'=>$markers,
+      '#type' => 'select',
+      '#title' => $role,
+      '#default_value' => variable_get("gmap_role_map_marker_$rid", variable_get('gmap_user_map_marker', 'drupal')),
+      '#options' => $markers,
     );
   }
 
@@ -342,38 +331,38 @@
     '#title' => t('Location settings for nodes'),
   );
   $form['node']['gmap_node_map'] = array(
-    '#type'=>'textfield',
-                                       '#title'=>t('Default node map'),
-    '#default_value'=>variable_get('gmap_node_map', '[gmap |id=nodemap|center=40,0|zoom=3|width=100%|height=400px]'),
-                                       '#size'=>50,
-                                       '#maxlength'=>500,
-    '#description'=>t('The gmap macro where the user information will be diplayed on.'),
+    '#type' => 'textfield',
+    '#title' => t('Default node map'),
+    '#default_value' => variable_get('gmap_node_map', '[gmap |id=nodemap|center=40,0|zoom=3|width=100%|height=400px]'),
+    '#size' => 50,
+    '#maxlength' => 500,
+    '#description' => t('The gmap macro where the user information will be diplayed on.'),
   );
   $form['node']['gmap_node_map_header'] = array(
-    '#type'=>'textarea',
-                                              '#title'=>t('Text at the top of the map/nodes page'),
-                                              '#default_value'=>variable_get('gmap_node_map_header', t('This map illustrates the locations of the nodes on this website. Each marker indicates a node associated with a specific location.')),
-                                              '#cols'=>50,
-    '#rows'=>6 
+    '#type' => 'textarea',
+    '#title' => t('Text at the top of the map/nodes page'),
+    '#default_value' => variable_get('gmap_node_map_header', t('This map illustrates the locations of the nodes on this website. Each marker indicates a node associated with a specific location.')),
+    '#cols' => 50,
+    '#rows' => 6,
   );
 
   $ntypes=node_get_types();
   foreach ($ntypes as $key => $value) {
     if (variable_get('location_'. $key, 0)) {
       $form['node']['gmap_node_marker_'.$key]=array(
-        '#type'=>'select',
-                                                        '#title'=>t('Marker for '.$value),
-        '#default_value'=>variable_get('gmap_node_marker_'.$key, ''),
-        '#options'=>$markers,
+        '#type' => 'select',
+        '#title' => t('Marker for '.$value),
+        '#default_value' => variable_get('gmap_node_marker_'.$key, ''),
+        '#options' => $markers,
       );
     }
   }
   return $form;
 }
 
-/*
- * draw block of location for current node.
-*/
+/**
+ * Draw block of location for current node.
+ */
 function gmap_location_block($op = 'list', $delta = 0, $edit = array()) {
 
   // The $op parameter determines what piece of information is being requested.
@@ -578,7 +567,7 @@
 }
 
 function gmap_location_user($op, &$edit, &$user, $category = NULL) {
-  if (module_exist('gmap') && variable_get('gmap_user', 0) && user_access('set user location')) {
+  if (module_exists('gmap') && variable_get('gmap_user', 0) && user_access('set user location')) {
     $object->gmap_location_latitude = $edit['gmap_location_latitude'];
     $object->gmap_location_longitude = $edit['gmap_location_longitude'];
     $object->eid = $user->uid;
@@ -620,47 +609,46 @@
 
 function gmap_location_form_alter($form_id, &$form) {
 
-  if (module_exist('location')) {
+  if (module_exists('location')) {
     return;
   }
 
-  if(isset($form['type'])) {
-    $type = $form['type']['#value'];
-    switch ($form_id) {
-      case $type .'_node_settings':
-        $form['gmap'] = array(
-          '#type' => 'fieldset',
-          '#title' => t('Google Maps'),
-          '#weight' => 0,  //0 puts at the top, 1 puts it at the bottom below the submit??
-        );
-        $form['gmap']['gmap_node_'. $type] = array(
-          '#type' => 'checkbox',
-          '#title' => t('Allow users to add Google Maps info to this node type'),
-          '#default_value' => variable_get('gmap_node_'. $type, 0),
-          '#description' => t('The location information will be available to the google maps module, and can be shown in a block.'),
-          '#required' => FALSE,
-        );
-        $form['gmap']['gmap_node_marker_'.$type] = array(
-          '#type' => 'select',
-          '#title' => t('Marker for this nodetype'),
-          '#default_value' => variable_get('gmap_node_marker_'.$type, variable_get('gmap_user_map_marker', 'drupal')),
-          '#options' => gmap_get_markers(),
-        );
-        break;
-      case $type .'_node_form':
-        if(variable_get('gmap_node_'. $type, 0)) {
-          $edit = array();
-          _gmap_location_map_form($form, $edit, 'node');
-        }
-        break;
+  if ($form_id == 'node_type_form') {
+    $type = $form['old_type']['#value'];
+    
+    $form['gmap'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Google Maps'),
+      '#weight' => 0,  //0 puts at the top, 1 puts it at the bottom below the submit??
+    );
+    $form['gmap']['gmap_node'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Allow users to add Google Maps info to this node type'),
+      '#default_value' => variable_get('gmap_node_'. $type, 0),
+      '#description' => t('The location information will be available to the google maps module, and can be shown in a block.'),
+      '#required' => FALSE,
+    );
+    $form['gmap']['gmap_node_marker'] = array(
+      '#type' => 'select',
+      '#title' => t('Marker for this nodetype'),
+      '#default_value' => variable_get('gmap_node_marker_'.$type, variable_get('gmap_user_map_marker', 'drupal')),
+      '#options' => gmap_get_markers(),
+    );
+  }
+  else {
+    if (isset($form['type']) && $form_id == $form['type'].'_node_form') {
+      echo "Flush!";
+      if(variable_get('gmap_node_'. $type, 0)) {
+        $edit = array();
+        _gmap_location_map_form($form, $edit, 'node');
+      }
     }
   }
 }
 
 /**
- *  implementation of hook_form()
+ * Implementation of hook_form()
  */
-
 function gmap_location_form(&$node, &$param) {
 
 }
@@ -702,6 +690,7 @@
 }
 
 function _gmap_location_map_form(&$form, &$edit, $type) {
+echo "BOO!";
   if($type=="user") {
     $latitude = $edit['gmap_location_latitude'];
     $longitude = $edit['gmap_location_longitude'];
@@ -719,8 +708,8 @@
     '#collapsed' => false,
   );
   $form['coordinates']['gmap_node']=array(
-    '#type'=>'markup',
-    '#value'=>'');
+    '#type'  => 'gmap',
+  );
   $form['coordinates']['gmap_location_latitude']=array(
     '#type'=>'textfield',
     '#id'=>'gmap-latitude',
Index: gmapmacro.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmapmacro.js,v
retrieving revision 1.4
diff -u -r1.4 gmapmacro.js
--- gmapmacro.js	16 Apr 2006 07:39:48 -0000	1.4
+++ gmapmacro.js	3 Jan 2007 02:56:04 -0000
@@ -4,18 +4,26 @@
 var mapdiv;
 var colors;
 
-if (isJsEnabled()) {
-  addLoadEvent(gmap_init);
+if (Drupal.jsEnabled) {
+//  $(document).ready(gmap_init).unload(gmap_uninit);
 }
 
 function gmap_args(args) {
   gmap_args = args;
 }
 
+function gmap_uninit() {
+  // uninit.
+  alert("Test");
+  GUnload();
+}
+
 function gmap_init() {
   if (!GBrowserIsCompatible()) { return; }
-  
-  mapdiv = $('map');
+
+  $('div#map').each(function() {
+     mapdiv = this;
+  });
   map = new GMap2(mapdiv);
   
   keyboardhandler=new GKeyboardHandler(map);
@@ -28,9 +36,9 @@
 
    // extend the map object
   map.drupal = new Object();
-  map.drupal.mapid=$('gmap-mapid').value
-  map.drupal.latLongStr = $('gmap-latlong').value;
-  map.drupal.currentControlType = 'Large';
+  map.drupal.mapid = $('#gmap-mapid').val();
+  map.drupal.latLongStr = $('#gmap-latlong').val();
+  map.drupal.currentControlType = 'Large'; // $('#gmap-maptype').val();
   map.drupal.currentControl = mycontrol;
   map.drupal.linecolors = colors;
   map.drupal.points = new Array();
@@ -38,29 +46,29 @@
   map.drupal.line1overlay=null;  map.drupal.line1points=new Array(); map.drupal.line1string=new String(); map.drupal.gmapline1=new String();
   map.drupal.line2overlay=null;  map.drupal.line2points=new Array(); map.drupal.line2string=new String(); map.drupal.gmapline2=new String();
   map.drupal.line3overlay=null;  map.drupal.line3points=new Array(); map.drupal.line3string=new String(); map.drupal.gmapline3=new String();
-  $('gmap-macrotext').value = map_to_macro(map);
+  $('#gmap-macrotext').val(map_to_macro(map));
   
   // Event listeners
   GEvent.addListener(map, "moveend", function() {
     var center = map.getCenter();
     map.drupal.latLongStr = center.lat() + ', ' + center.lng() ;
 
-    $('gmap-latlong').value = map.drupal.latLongStr;
-    $('gmap-macrotext').value = map_to_macro(map);
+    $('#gmap-latlong').val(map.drupal.latLongStr);
+    $('#gmap-macrotext').val(map_to_macro(map));
   });
   
   GEvent.addListener(map, "zoomend", function(previouszoom,newzoom) {
-    $('gmap-zoom').value = newzoom;
-    $('gmap-macrotext').value = map_to_macro(map);
+    $('#gmap-zoom').val(newzoom);
+    $('#gmap-macrotext').val(map_to_macro(map));
 
   });
   
   GEvent.addListener(map, "maptypechanged", function() {
     var maptype = map.getCurrentMapType();
-    if (maptype == G_NORMAL_MAP) $('gmap-maptype').value = "Map";
-    if (maptype == G_HYBRID_MAP) $('gmap-maptype').value = "Hybrid";
-    if (maptype == G_SATELLITE_MAP) $('gmap-maptype').value = "Satellite";
-    $('gmap-macrotext').value = map_to_macro(map);
+    if (maptype == G_NORMAL_MAP) $('#gmap-maptype').val("Map");
+    if (maptype == G_HYBRID_MAP) $('#gmap-maptype').val("Hybrid");
+    if (maptype == G_SATELLITE_MAP) $('#gmap-maptype').val("Satellite");
+    $('#gmap-macrotext').val(map_to_macro(map));
   });
 
   GEvent.addListener(map, 'click', function(overlay, point) {
@@ -82,7 +90,7 @@
       map.removeOverlay(overlay);
     }
     else if (point) {
-      var selected = $('gmap-clicktype').value;
+      var selected = $('#gmap-clicktype').val();
       switch (selected) {
         // I've got the feeling that some of the following logic could be trimmed
         case 'Points':
@@ -122,15 +130,15 @@
           break;
       }      
     }
-    $('gmap-macrotext').value = map_to_macro(map);
+    $('#gmap-macrotext').val(map_to_macro(map));
   });
   //initialize default values
-  set_gmap_latlong($('gmap-latlong').value);
-  map.setZoom(parseInt($('gmap-zoom').value));
-  set_gmap_type($('gmap-maptype').value);
-  set_control_type($('gmap-controltype').value);
-  set_gmap_dimension($('gmap-height'), 'height');
-  set_gmap_dimension($('gmap-width'), 'width');
+  set_gmap_latlong($('#gmap-latlong').val());
+  map.setZoom(parseInt($('#gmap-zoom').val()));
+  set_gmap_type($('#gmap-maptype').val());
+  set_control_type($('#gmap-controltype').val());
+  set_gmap_dimension($('#gmap-height').val(), 'height');
+  set_gmap_dimension($('#gmap-width').val(), 'width');
 }
 
 function gmap_set_line_colors(args) {
@@ -143,8 +151,8 @@
 function map_to_macro(gmap) {
   var zooml = ' |zoom=' + gmap.getZoom();
   var centerStr = ' |center=' + gmap.drupal.latLongStr;
-  var width = ' |width=' + $('gmap-width').value;
-  var height = ' |height=' + $('gmap-height').value;
+  var width = ' |width=' + $('#gmap-width').val();
+  var height = ' |height=' + $('#gmap-height').val();
   var id = ' |id=' + gmap.drupal.mapid;
   var control = ' |control=' + gmap.drupal.currentControlType;
   var type = ' |type=' + gmap.drupal.currentMapType;
@@ -169,7 +177,7 @@
 
 function set_gmap_mapid(instring) {
    map.drupal.mapid=instring;
-   $('gmap-macrotext').value=map_to_macro(map);
+   $('#gmap-macrotext').val(map_to_macro(map));
 }
 
 function set_gmap_latlong(instring) {
@@ -184,7 +192,7 @@
   }
   if (incontrol == "Small") map.addControl(map.drupal.currentControl = new GSmallMapControl());
   if (incontrol == "Large") map.addControl(map.drupal.currentControl = new GLargeMapControl());
-  $('gmap-macrotext').value = map_to_macro(map);
+  $('#gmap-macrotext').val(map_to_macro(map));
 }
 
 function set_gmap_type(intype) {
@@ -192,12 +200,12 @@
   if (intype == "Map") map.setMapType(G_NORMAL_MAP);
   if (intype == "Hybrid") map.setMapType(G_HYBRID_MAP);
   if (intype == "Satellite") map.setMapType(G_SATELLITE_MAP);
-  $('gmap-macrotext').value = map_to_macro(map);
+  $('#gmap-macrotext').val(map_to_macro(map));
 }
 
 function setgmapZoom(invalue) {
   map.setZoom(parseInt(invalue));
-  $('gmap-macrotext').value = map_to_macro(map);
+  $('#gmap-macrotext').val(map_to_macro(map));
 }
 
 function set_gmap_dimension(elem, dimension) {
@@ -214,8 +222,8 @@
     }
  //   gmap_init(map);
     map.checkResize();
-    $('gmap-macrotext').value = map_to_macro(map);
-    set_gmap_latlong($('gmap-latlong').value);
+    $('#gmap-macrotext').val(map_to_macro(map));
+    set_gmap_latlong($('#gmap-latlong').val());
   }
 }
 
@@ -234,7 +242,7 @@
 }
 
 function newid() {
-  var newvalue = $('gmap-id').value;
+  var newvalue = $('#gmap-mapid').val();
   newvalue=newvalue.match(/^[0-9A-Za-z_-]+/);
   if (newvalue.length==0) {
     newvalue='map';
