Index: mapstraction-map.tpl.php
===================================================================
RCS file: mapstraction-map.tpl.php
diff -N mapstraction-map.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mapstraction-map.tpl.php	11 Jun 2009 22:15:05 -0000
@@ -0,0 +1,18 @@
+<?php
+// $Id$
+/* @file
+ * mapstraction.map.tpl.php
+ *
+ * this file is all about getting theme preprocess functionality.
+ *
+ * script code
+ *   $api
+ * div attributes
+ *   $width
+ *   $height
+ *   $id
+ */
+?>
+<?php print $api; ?>
+<div id="<?php print $id; ?>" style="width: <?php print $width; ?>px; height: <?php print $height; ?>px;">
+</div>
Index: mapstraction.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mapstraction/mapstraction.module,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 mapstraction.module
--- mapstraction.module	11 Jun 2009 12:40:00 -0000	1.1.2.7
+++ mapstraction.module	11 Jun 2009 22:15:05 -0000
@@ -129,21 +129,23 @@ function mapstraction_apis($full = FALSE
 
 /**
  * Theme a map from Mapstraction view.
+ * TODO static cache the loaded APIs.
+ * TODO load the APIs using drupal_set_html_head() where possible?
  */
-function theme_mapstraction_map($view, $options, $rows) {
+function template_preprocess_mapstraction_map(&$vars) {
   drupal_add_js(drupal_get_path('module', 'mapstraction') . '/mapstraction.js');
   drupal_add_js(drupal_get_path('module', 'mapstraction') . '/mapstraction.drupal.js');
 
-  $api_name = $view->style_plugin->options['api'];
+  $api_name = $vars['view']->style_plugin->options['api'];
   $apis = mapstraction_apis(TRUE);
   $api = $apis[$api_name];
   
   // Allow the API definition to override the API name.
-  $api_settings = $options['api_settings'][$api_name];
+  $api_settings = $vars['options']['api_settings'][$api_name];
   $api_name = $api['api'] ? $api['api'] : $api_name;
   
   // Clean up controls for JS
-  foreach ($options['controls'] as $control => $value) {
+  foreach ($vars['options']['controls'] as $control => $value) {
     if ($control == 'zoom') {
       $controls[$control] = $value;
     }
@@ -153,27 +155,25 @@ function theme_mapstraction_map($view, $
   }
 
   $map = array(
-    'viewName' => $view->name,
-    'currentDisplay' => $view->current_display,
+    'viewName' => $vars['view']->name,
+    'currentDisplay' => $vars['view']->current_display,
     'apiName' => $api_name,
-    'markers' => $view->style_plugin->map_points($rows),
+    'markers' => $vars['view']->style_plugin->map_points($vars['rows']),
     'controls' => $controls,
-    'initialPoint' => $options['initial_point'],
-    'behaviours' => $options['behaviours'],
+    'initialPoint' => $vars['options']['initial_point'],
+    'rows' => $vars['rows'],
+    'behaviours' => $vars['options']['behaviours'],
   );
 
   // Add the map to Drupal.settings object in JS.
   drupal_add_js(array('mapstraction' => array($map)), 'setting');
   
   // Run API-specific rendering code
-  $id = 'mapstraction-' . $view->name . '-' . $view->current_display;
+  $vars['id'] = 'mapstraction-' . $vars['view']->name . '-' . $vars['view']->current_display;
   module_load_include('inc', 'mapstraction', 'mapstraction.apis');
   if (function_exists($api['render'])) {
-    $output = $api['render']($api_settings, $api_name, $id);
+    $vars['api'] = call_user_func_array($api['render'], array($api_settings, $api_name, $vars['id']));
   }
   
-  list($width, $height) = explode('x', $options['dimensions']);
-  $output .= '<div id="' . $id . '" style="width: ' . $width . 'px; height: ' . $height . 'px;"></div>';
-
-  return $output;
+  list($var['width'], $vars['height']) = explode('x', $vars['options']['dimensions']);
 }
\ No newline at end of file
