? 710908_styles_fields.patch
? js/.openlayers.js.swp
? modules/openlayers_ui/includes/.openlayers_ui.presets.inc.swp
? modules/openlayers_ui/includes/.openlayers_ui.styles.inc.swp
? tests/plugins
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	18 Jul 2010 19:31:11 -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	18 Jul 2010 19:31:11 -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	18 Jul 2010 19:31:11 -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.35
diff -u -p -r1.47.2.35 openlayers.js
--- js/openlayers.js	17 Jul 2010 16:37:58 -0000	1.47.2.35
+++ js/openlayers.js	18 Jul 2010 19:31:11 -0000
@@ -110,10 +110,6 @@ Drupal.behaviors.openlayers = function(c
  * Collection of helper methods.
  */
 Drupal.openlayers = {
-
-  /**
-   * Determine path based on format.
-   */
   'relatePath': function(path, basePath) {
     // Check for a full URL or an absolute path.
     if (path.indexOf('://') >= 0 || path.indexOf('/') == 0) {
@@ -264,9 +260,6 @@ Drupal.openlayers = {
       layer.addFeatures(newFeatures);
     }
   },
-  /**
-   * getStyleMap
-   */
   'getStyleMap': function(map, layername) {
     if (map.styles) {
       var stylesAdded = {};
@@ -274,11 +267,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
+
+        // 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 +330,4 @@ Drupal.openlayers = {
 };
 
 Drupal.openlayers.layer = {};
+Drupal.openlayers.style_plugin = {};
Index: modules/openlayers_ui/openlayers_ui.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openlayers/modules/openlayers_ui/Attic/openlayers_ui.module,v
retrieving revision 1.1.2.38
diff -u -p -r1.1.2.38 openlayers_ui.module
--- modules/openlayers_ui/openlayers_ui.module	29 Jun 2010 22:54:16 -0000	1.1.2.38
+++ modules/openlayers_ui/openlayers_ui.module	18 Jul 2010 19:31:12 -0000
@@ -24,8 +24,7 @@ function openlayers_ui_help($path, $arg)
         on overlays more often than base layers, which are not affected by vector 
         styles.', array("@ols" => 'http://trac.openlayers.org/wiki/Styles')) .'</p>';
     case 'admin/build/openlayers/styles/add':
-      return '<p>'. t('The name, title, and description you give a style is for Drupal\'s 
-        interal storage. The rest of the properties are documented on openlayers.org')
+      return '<p>'. t('Style properties are documented on openlayers.org')
         . '</p>';
     case 'admin/build/openlayers/presets':
       return '<p>'. t('Presets are combinations of the layers, styles, and behaviors 
@@ -209,6 +208,16 @@ function openlayers_ui_menu() {
     'type' => MENU_NORMAL_ITEM,
     'weight' => -10,
   );
+
+  $items['admin/build/openlayers/style_plugins/%'] = array( 	 
+    'title' => 'Style Plugin AHAH',
+    'page callback' => 'openlayers_ui_styles_plugins',
+    'page arguments' => array(4),
+    'access callback' => TRUE,
+    'file' => 'includes/openlayers_ui.styles.inc',
+    'type' => MENU_CALLBACK, 
+  );
+  
   $items['admin/build/openlayers/styles/clone/%openlayers_style'] = array( 	 
     'title' => 'Clone style', 	 
     'page callback' => 'drupal_get_form', 	 
@@ -317,6 +326,7 @@ function openlayers_ui_menu() {
     'type' => MENU_LOCAL_TASK,
     'tab_parent' => 'admin/build/openlayers/presets',
   );
+
   $items['openlayers/ahah/preset'] = array(
     'title' => 'OpenLayers AHAH',
     'page callback' => 'openlayers_ui_preset_ahah',
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.25
diff -u -p -r1.1.2.25 openlayers_ui.presets.inc
--- modules/openlayers_ui/includes/openlayers_ui.presets.inc	10 Jul 2010 16:17:31 -0000	1.1.2.25
+++ modules/openlayers_ui/includes/openlayers_ui.presets.inc	18 Jul 2010 19:31:12 -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']) ? $defaults['hide_empty_map'] : FALSE,  
+    '#default_value' => isset($defaults['hide_empty_map']),  
   );
   
   // 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	18 Jul 2010 19:31:12 -0000
@@ -13,6 +13,8 @@
  * Styles add/edit form.
  */
 function openlayers_ui_styles_form(&$form_state, $style = NULL, $edit = FALSE) {
+  ctools_include('dependent');
+
   $form = array();
   
   // Available styling properies.  Defaults and descriptions are taken
@@ -159,16 +161,15 @@ function openlayers_ui_styles_form(&$for
     ),
   );
   
-  // Pass style data along
   $form['style_data'] = array(
     '#type' => 'value',
     '#value' => $properties,
   );
-
-  // Style object basics
   $form['info'] = array(
     '#type' => 'fieldset',
     '#tree' => FALSE,
+    '#title' => t('Basic Information'),
+    '#collapsible' => TRUE,
   );
   $form['info']['name'] = array(
     '#title' => t('Name'),
@@ -189,23 +190,52 @@ 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' => FALSE,
+  );
   foreach ($properties as $key => $prop) {
     $form['data'][$key] = array(
-      '#type' => !isset($prop['options']) ? 'textfield' : 'select',
+      '#type' => 'fieldset',
       '#title' => $key,
+    );
+
+    $form['data'][$key]['value'] = array(
+      '#type' => !isset($prop['options']) ? 'textfield' : 'select',
       '#description' => $prop['desc'],
+      '#process' => array('ctools_dependent_process'),
+      '#dependency' => array($key.'-uses-plugin' => array(0)),
       '#default_value' => isset($style->data[$key]) ?
         $style->data[$key] : $prop['default'],
     );
-    
-    // Add options if needed
+ 
+    $form['data'][$key]['uses_plugin'] = array(
+      '#title' => t('Use Plugin'),
+      '#type' => 'checkbox',
+      '#id' => $key . '-uses-plugin',
+      '#ahah' => array(
+        'path' => 'admin/build/openlayers/style_plugins/' . $key,
+        'wrapper' => $key . '-style-plugins',
+        'method' => 'replace',
+        'effect' => 'fade',
+      )
+    );
+
+    $form['data'][$key]['plugin'] = array(
+      '#value' => '<div id="' . $key . '-style-plugins"></div>'
+    );
+   
     if (isset($prop['options']) && is_array($prop['options'])) {
-      $form['data'][$key]['#options'] = $prop['options'];
+      $form['data'][$key]['value']['#options'] = $prop['options'];
     }
   }
-
+  
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
@@ -213,15 +243,26 @@ function openlayers_ui_styles_form(&$for
   return $form;
 }
 
+function openlayers_ui_styles_plugins($style_property) {
+  drupal_json(
+    array(
+      'status' => TRUE, 
+      'data' => openlayers_ui_get_style_plugin_options($style_property)
+    )
+  );
+}
+
+
 /**
  * Submit handler for layers.
  */
 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 +277,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 +308,37 @@ function openlayers_ui_styles_form_submi
   }
 }
 
+/**
+ * Get style plugin options.
+ */
+function openlayers_ui_get_style_plugin_options($style_property, $defaults = array()) {
+  $form = array();
+
+  foreach (openlayers_style_plugins() as $key => $plugin) {
+    $plugin_class = ctools_plugin_get_class($plugin, 'style_plugin');
+    if (!empty($plugin_class)) {
+      $options = isset($defaults['plugins'][$key]) ?
+        $defaults['plugins'][$key] : array();
+
+      $style_plugin = new $plugin_class($options);
+      $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,
+        ),
+      );
+      $form[$key]['options'] = $style_plugin->options_form($options);
+    }
+  }
+  return drupal_render($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	18 Jul 2010 19:31:12 -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() {
