Index: gmap.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap.module,v
retrieving revision 1.101
diff -u -p -r1.101 gmap.module
--- gmap.module	17 Apr 2009 18:31:59 -0000	1.101
+++ gmap.module	7 Jul 2009 11:04:51 -0000
@@ -912,7 +912,49 @@ function theme_gmap($element) {
   // Some markup parsers (IE) don't handle empty inners well. Use the space to let users know javascript is required.
   // @@@ Bevan sez: Google static maps could be useful here.
   // @@@ Bdragon sez: Yeah, would be nice, but hard to guarantee functionality. Not everyone uses the static markerloader.
-  $o = '<div style="'. implode('; ', $style) .';" id="'. $element['#id'] .'"'. drupal_attributes($element['#attributes']) .'>'. t('Javascript is required to view this map.') .'</div>';
+
+  // Static map size must be specified in pixels
+  $static_size = _gmap_process_size_static($map['width'], $map['height']);
+
+  if (!$static_size) {
+    // If size in pixels cannot be calculated just print the 'Javascript required' message
+    $o = '<div style="'. implode('; ', $style) .';" id="'. $element['#id'] .'"'. drupal_attributes($element['#attributes']) .'>'. t('Javascript is required to view this map.') .'</div>';
+  }
+  else {
+    // Show static map
+    $src_query = array();
+
+    if (!empty($element['#settings']['markers'])) {
+      // If not empty center automatic for google to show all markers.
+      $src_query['center'] = '';
+    }
+    else {
+      $src_query['zoom'] = $map['zoom'];
+      $src_query['center'] = $map['latitude'] .",".  $map['longitude'];
+    }
+
+    $src_query['size'] = $static_size['width'] ."x". $static_size['height'];
+    $src_query['maptype'] = $map['maptype'];
+
+    if (is_array($element['#settings']['markers'])) {
+      $aux = array();
+
+      //Add markers to the map
+      foreach ($element['#settings']['markers'] as $key => $value) {
+        $markertype = _gmap_get_markertype($value['markername']);
+        $aux[] = $value['latitude'] .",". $value['longitude'] .",". $markertype;
+      }
+      $src_query['markers'] = implode('|', $aux);
+    }
+
+    $src_query['key'] = gmap_get_key();
+    $src_query['sensor'] = 'false';
+
+    $src = url('http://maps.google.com/staticmap', array('query' => $src_query, 'external' => TRUE));
+    $static = theme('image', $src, t('Gmap'), t('Gmap'), NULL, FALSE);
+
+    $o = '<div style="'. implode('; ', $style) .';" id="'. $element['#id'] .'"'. drupal_attributes($element['#attributes']) .'>'. $static .'</div>';
+  }
 
   // $map can be manipulated by reference.
   foreach (module_implements('gmap') as $module) {
@@ -937,6 +979,44 @@ function theme_gmap($element) {
 }
 
 /**
+ * Convert gmap marker strings to google api marker types
+ *
+ * @param mixed $type name of type marker
+ * @access protected
+ * @return output name marker for static googlemaps
+ */
+function _gmap_get_markertype($type) {
+  $type = strtolower($type);
+  $type = str_replace(' ', '', $type);
+  $type = str_replace('big', 'mid', $type);
+
+  return $type;
+}
+
+/**
+ * Detect if the map size is configured in pixels and return the values
+ *
+ * @param mixed $width
+ *   The css string for the width configured in the block
+ * @param mixed $height
+ *   The css string for the height configured in the block
+ * @return void
+ *   Array with width and height in pixels or FALSE if any input is not in 'px' format
+ */
+function _gmap_process_size_static($width, $height) {
+  $matches_width = $matches_height = array();
+  $pattern = '/^([0-9]+)(px|%)$/';
+  preg_match($pattern, $width, $matches_width);
+  preg_match($pattern, $height, $matches_height);
+
+  if ($matches_width[2] == 'px' && $matches_height[2] == 'px') {
+    return array('width' => $matches_width[1], 'height' => $matches_height[1]);
+  }
+
+  return FALSE;
+}
+
+/**
  * Set up widget.
  * This function will change a form element's ID so it is found
  * by the GMap handlers system.
