Index: openlayers.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openlayers/openlayers.module,v
retrieving revision 1.69.2.77
diff -u -p -r1.69.2.77 openlayers.module
--- openlayers.module	4 Jul 2010 19:23:04 -0000	1.69.2.77
+++ openlayers.module	12 Jul 2010 07:57:25 -0000
@@ -447,6 +447,21 @@ function openlayers_behaviors($reset = F
 }
 
 /**
+ * Get all style plugins.
+ *
+ * @ingroup openlayers_api
+ *
+ * @param $reset
+ *   Boolean whether to reset cache or not.
+ * @return
+ *   Array of style handler info.
+ */
+function openlayers_style_plugins($reset = FALSE) {
+  ctools_include('plugins');
+  return ctools_get_plugins('openlayers', 'style_plugin');
+}
+
+/**
  * Get all openlayers styles.
  *
  * @ingroup openlayers_api
@@ -900,6 +915,87 @@ class openlayers_layer_type {
 }
 
 /**
+ * Base class for style plugins
+ *
+ * We define base classes in the core module.
+ * All other parent classes can be autoloaded through ctools.
+ */
+class openlayers_style_plugin {
+  var $options;
+
+  /**
+   * Constructor
+   *
+   * Takes options sent in and adds them to the
+   * class.
+   *
+   * @param $options
+   *   Array of options.
+   */
+  function __construct($options = array()) {
+    $this->options = $options + $this->options_init();
+  }
+
+  /**
+   * Initial default options.
+   *
+   * @return
+   *   Array of default options.
+   */
+  function options_init() {
+    return array();
+  }
+
+  /**
+   * Options form.
+   *
+   * @param $defaults
+   *   Array of default values for the form.
+   * @return
+   *   Array of Drupal form elements.
+   */
+  function options_form($defaults = array()) {
+    return array();
+  }
+
+  /**
+   * Render the style.
+   *
+   * @param $style
+   *   The style passed in to be handled.
+   */
+  function render(&$style) {
+    // Render style.
+  }
+}
+
+/**
+ * Implementation of hook_ctools_plugin_directory
+ */
+function openlayers_ctools_plugin_directory($module, $plugin) {
+  // The format of plugin includes should be the
+  // following:
+  //   modulename_plugin_name.inc
+  //
+  // For example:
+  //  openlayers_style_plugin_name.inc
+  
+  // If this module needed to supply style plugins.
+  /*
+  if ($module == 'openlayers' && $plugin == 'style_plugin') {
+    return 'plugins/style_plugin';
+  }
+  */
+  
+  // This should change to the following when converted:
+  /*
+  if ($module == 'openlayers') {
+    return 'plugins/' . $plugin;
+  }
+  */
+}
+
+/**
  * Implementation of hook_ctools_plugin
  */
 function openlayers_ctools_plugin_behaviors() {
Index: docs/openlayers.api.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openlayers/docs/Attic/openlayers.api.php,v
retrieving revision 1.2.2.5
diff -u -p -r1.2.2.5 openlayers.api.php
--- docs/openlayers.api.php	2 Jun 2010 23:13:40 -0000	1.2.2.5
+++ docs/openlayers.api.php	12 Jul 2010 07:57:26 -0000
@@ -282,3 +282,33 @@ function hook_openlayers_presets() {
   );
   return array('default' => $default);
 }
+
+/**
+ * CTools Registration Hook (Style Plugins)
+ *
+ * IMPORTANT:
+ *
+ * In order to support style plugins, the first step is to
+ * tell CTools where to find the plugin.
+ *
+ * This function is just an example implementation of 
+ * hook_ctools_plugin_directory() and should be alter according to
+ * your module's name.
+ *
+ * For an example, please see the openlayers_test.module
+ *
+ * @param $module
+ *   Name of a module that supports CTools exportables.
+ * @param $plugin
+ *   Name of the kind of plugin supported.
+ * @return
+ *  If $module is 'openlayers', and $api is a type of exportable that
+ *  your module provides, and you are using Openlayers 2.x, then
+ *  return the directory relative to a module to look for this
+ *  particular plugin.
+ */
+function openlayers_ctools_plugin_directory($module, $plugin) {
+  if ($module == 'openlayers' && $plugin == 'style_plugin') {
+    return 'plugins/style_plugin';
+  }
+}
\ No newline at end of file
Index: includes/openlayers.render.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openlayers/includes/openlayers.render.inc,v
retrieving revision 1.3.2.16
diff -u -p -r1.3.2.16 openlayers.render.inc
--- includes/openlayers.render.inc	27 Apr 2010 15:50:15 -0000	1.3.2.16
+++ includes/openlayers.render.inc	12 Jul 2010 07:57:26 -0000
@@ -68,9 +68,31 @@ function _openlayers_behaviors_render($b
  */
 function _openlayers_styles_process($styles = array(), 
   $layer_styles = array(), &$map = array()) {
+  ctools_include('plugins');
 
   // Get styles info array
   $styles_info = openlayers_styles();
+  
+  // Process with handler if available.
+  $style_plugins = openlayers_style_plugins();
+  foreach ($styles_info as $i => $style) {
+    // Check for plugins.
+    if (isset($style->data['plugins']) && 
+      is_array($style->data['plugins'])) {
+      foreach ($style->data['plugins'] as $p => $options) {
+        // Ensure that the plugin exists
+        if (($style_plugins[$p])) {
+          $plugin_class = ctools_plugin_get_class($style_plugins[$p], 
+            'style_plugin');
+          if (isset($plugin_class)) {
+            $plugin = new $plugin_class;
+            // Render the plugin with the style.
+            $plugin->render($styles_info[$i]);
+          }
+        }
+      }
+    }
+  }
 
   // Go through styles
   $processed = array();
Index: js/openlayers.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openlayers/js/openlayers.js,v
retrieving revision 1.47.2.34
diff -u -p -r1.47.2.34 openlayers.js
--- js/openlayers.js	27 Jun 2010 14:32:09 -0000	1.47.2.34
+++ js/openlayers.js	12 Jul 2010 07:57:26 -0000
@@ -274,11 +274,39 @@ Drupal.openlayers = {
       for (var style in map.styles) {
         stylesAdded[style] = new OpenLayers.Style(map.styles[style]);
       }
+
       // Implement layer-specific styles.
       if (map.layer_styles !== undefined && map.layer_styles[layername]) {
-        var style = map.layer_styles[layername];
-        stylesAdded['default'] = new OpenLayers.Style(map.styles[style]);
+
+        var style_name = map.layer_styles[layername]; 
+        var style = map.styles[style_name]; // TODO: skip if undefined
+        
+        // Build context object
+
+        var newContext = {}
+
+        // Define parameters from plugin, if available
+        var plugins = map.styles[style_name].plugins;
+        for (var plugin_name in style.plugins)
+        {
+              var plugin_options = style.plugins[plugin_name];
+              var plugin_context = new Drupal.openlayers.style_plugin[plugin_name](plugin_options);
+
+              // Add plugin context functions to global context
+              for (var key in plugin_context) {
+                  var newkey = plugin_name + '_' + key;
+                  var val = plugin_context[key];
+                  if ( typeof val === 'function' ) {
+                      newContext[newkey] = OpenLayers.Function.bind(val, plugin_context); // plugin_method_scope);
+                  }
+              }
+        }
+      
+        // Put together style_name
+        stylesAdded['default'] = new OpenLayers.Style(style, 
+            { context: newContext } );
       }
+      
       return new OpenLayers.StyleMap(stylesAdded);
     }
     // Default styles
@@ -309,3 +337,4 @@ Drupal.openlayers = {
 };
 
 Drupal.openlayers.layer = {};
+Drupal.openlayers.style_plugin = {};
Index: modules/openlayers_ui/includes/openlayers_ui.presets.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openlayers/modules/openlayers_ui/includes/Attic/openlayers_ui.presets.inc,v
retrieving revision 1.1.2.24
diff -u -p -r1.1.2.24 openlayers_ui.presets.inc
--- modules/openlayers_ui/includes/openlayers_ui.presets.inc	2 Jul 2010 14:52:02 -0000	1.1.2.24
+++ modules/openlayers_ui/includes/openlayers_ui.presets.inc	12 Jul 2010 07:57:26 -0000
@@ -136,7 +136,7 @@ function openlayers_ui_presets_form(&$fo
     '#title' => t('Hide empty map'),
     '#description' => t("Show views empty text or hide the map if there are 
     no map overlays with features. Otherwise an empty map is displayed."),
-    '#default_value' => isset($defaults['hide_empty_map']),  
+    '#default_value' => isset($defaults['hide_empty_map']) ? $defaults['hide_empty_map'] : FALSE,  
   );
   
   // Center
Index: modules/openlayers_ui/includes/openlayers_ui.styles.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openlayers/modules/openlayers_ui/includes/Attic/openlayers_ui.styles.inc,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 openlayers_ui.styles.inc
--- modules/openlayers_ui/includes/openlayers_ui.styles.inc	29 Jun 2010 18:55:34 -0000	1.1.2.8
+++ modules/openlayers_ui/includes/openlayers_ui.styles.inc	12 Jul 2010 07:57:26 -0000
@@ -169,6 +169,9 @@ function openlayers_ui_styles_form(&$for
   $form['info'] = array(
     '#type' => 'fieldset',
     '#tree' => FALSE,
+    '#title' => t('Basic Information'),
+    '#description' => t('The basic information for the style, used to refer to and describe the style.'),
+    '#collapsible' => TRUE,
   );
   $form['info']['name'] = array(
     '#title' => t('Name'),
@@ -189,8 +192,16 @@ function openlayers_ui_styles_form(&$for
   );
 
   // OpenLayers style properties
-  $form['data'] = array('#type' => 'fieldset', '#tree' => TRUE);
-
+  $form['data'] = array(
+    '#type' => 'fieldset', 
+    '#tree' => TRUE,
+    '#title' => t('Style Properties and Plugins'),
+    '#description' => t('Style properties are properties as 
+      defined by the OpenLayers library.  Plugins are dynamically
+      process the layer at render time; plugins may override the
+      values that you have set for style properies.'),
+    '#collapsible' => TRUE,
+  );
   foreach ($properties as $key => $prop) {
     $form['data'][$key] = array(
       '#type' => !isset($prop['options']) ? 'textfield' : 'select',
@@ -205,6 +216,10 @@ function openlayers_ui_styles_form(&$for
       $form['data'][$key]['#options'] = $prop['options'];
     }
   }
+  
+  // Add style plugins
+  $form['data']['plugins'] = openlayers_ui_get_style_plugin_options(
+    isset($style->data) ? $style->data : array());
 
   $form['submit'] = array(
     '#type' => 'submit',
@@ -218,10 +233,11 @@ function openlayers_ui_styles_form(&$for
  */
 function openlayers_ui_styles_form_submit(&$form, &$form_state) {
   $style_data = $form_state['values']['style_data'];
-  
+  $data = $form_state['values']['data'];
+
   // Cast and unset values so JS can handle them better
-  foreach ($form_state['values']['data'] as $key => $value) {
-    if ($form_state['values']['data'][$key] === '') {
+  foreach ($data as $key => $value) {
+    if ($data[$key] === '') {
       unset($form_state['values']['data'][$key]);
     }
     elseif (isset($style_data[$key]['type'])) {
@@ -236,6 +252,18 @@ function openlayers_ui_styles_form_submi
     }
   }
   
+  // Process style plugins.  This allows us to have simpler
+  // arrays for plugins.  
+  foreach ($data['plugins'] as $plugin => $settings) {
+    if ($settings['enabled']) {
+      $form_state['values']['data']['plugins'][$plugin] = 
+        isset($settings['options']) ? $settings['options'] : array();
+    }
+    else {
+      unset($form_state['values']['data']['plugins'][$plugin]);
+    }
+  }
+  
   $style = new stdClass();
   $style->name = $form_state['values']['name'];
   $style->title = $form_state['values']['title'];
@@ -255,6 +283,45 @@ function openlayers_ui_styles_form_submi
   }
 }
 
+/**
+ * Get style plugin options.
+ */
+function openlayers_ui_get_style_plugin_options($defaults) {
+  $form = array();
+
+  // Get all available style plugins.
+  foreach (openlayers_style_plugins() as $key => $plugin) {
+    $plugin_class = ctools_plugin_get_class($plugin, 'style_plugin');
+    if (!empty($plugin_class)) {
+      // Create options for oprion form.
+      $options = isset($defaults['plugins'][$key]) ?
+        $defaults['plugins'][$key] : array();
+
+      // Create object
+      $style_plugin = new $plugin_class($options);
+      // Put together fieldset of options.  This should
+      // be improved so that it looks better.
+      $form[$key] = array(
+        '#tree' => TRUE,
+        '#type' => 'fieldset',
+        '#title' => $plugin['title'],
+        '#description' => $plugin['description'],
+        'enabled' => array(
+          '#type' => 'checkbox',
+          '#title' => t('Enabled'),
+          '#default_value' => isset($defaults['plugins'][$key])
+            ? $defaults['plugins'][$key] : FALSE,
+        ),
+      );
+
+      // Add extra options form.
+      $form[$key]['options'] = $style_plugin->options_form($options);
+    }
+  }
+
+  return $form;
+}
+
 // /**
 //  * Import a preset from cut & paste
 //  */
Index: tests/openlayers_test.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openlayers/tests/Attic/openlayers_test.module,v
retrieving revision 1.2.2.15
diff -u -p -r1.2.2.15 openlayers_test.module
--- tests/openlayers_test.module	27 Jun 2010 15:57:01 -0000	1.2.2.15
+++ tests/openlayers_test.module	12 Jul 2010 07:57:26 -0000
@@ -30,6 +30,16 @@ function openlayers_test_menu() {
 }
 
 /**
+ * Implementation of hook_ctools_plugin_directory
+ */
+function openlayers_test_ctools_plugin_directory($module, $plugin) {
+  if ($module == 'openlayers' && $plugin == 'style_plugin') {
+    return 'plugins/style_plugin';
+  }
+}
+  
+
+/**
  * Implementation of hook_ctools_plugin_api().
  */
 function openlayers_test_ctools_plugin_api($module, $api) {
@@ -38,6 +48,9 @@ function openlayers_test_ctools_plugin_a
     switch ($api) {
       case 'openlayers_presets':
         return array('version' => 1);
+        
+      case 'openlayers_styles':
+        return array('version' => 1);
 
     }
   }
@@ -53,6 +66,32 @@ function openlayers_test_views_api() {
 }
 
 /**
+ * Implementation of hook_openlayers_styles()
+ */
+function openlayers_test_openlayers_styles() {
+  $styles = array();
+
+  $style = new stdClass();
+  $style->api_version = 1;
+  $style->name = 'test_context';
+  $style->title = t('Test: Context style');
+  $style->description = t('A style to test context styling.');
+  $style->data = array(
+    'pointRadius' => '6',
+    'fillColor' => '#77777',
+    'strokeColor' => '#222222',
+    'strokeWidth' => '2',
+    'strokeOpacity' => '0.8',
+    'plugins' => array(
+      'openlayers_test_test_plugin' => array(),
+    ),
+  );
+  $styles[$style->name] = $style;
+
+  return $styles;
+}
+
+/**
  * Implementation of hook_openlayers_presets().
  */
 function openlayers_test_openlayers_presets() {
