? 710514-activated-layers-02.patch ? 710514-activated-layers-03.patch ? 744360-openlayers_behavior_drawfeatures.js_.patch ? 744360-openlayers_behavior_drawfeatures_reroll.patch ? 744360-openlayers_behavior_drawfeatures_rerolled.patch ? 764340-zoom-to-layer-cck-13.patch ? 764340-zoom-to-layer-cck-patch-14.patch ? callback_pointRadius.patch ? cleanup_openlayers.patch ? dependency-detection-2.patch ? dependency-detection-3.patch ? dependency-detection.patch ? dependency_detection.patch ? display_projection_fix.patch ? docs_oa ? features_dependencies.patch ? fix_multiple.patch ? maptiler_layer_type.patch ? modify_feature.diff ? multilingual.diff ? openlayers-maxextent.patch ? openlayers_views_handling.patch ? overlay_baselayer_unification.patch ? rmup.sh ? stash.diff ? stash.patch.2 ? styles_all.patch ? titles_and_translation.diff ? unification_full.patch ? vector_layer_type_property.patch ? wms_and_dependencies.patch ? wms_projection.patch ? includes/.openlayers.render.inc.swp ? includes/behaviors/openlayers_behavior_cluster.inc ? includes/behaviors/js/openlayers_behavior_cluster.js ? includes/layer_types/multimap.inc ? includes/layer_types/multimap.js ? includes/layer_types/wms_client.inc ? js/openlayers ? modules/openlayers_cck/includes/behaviors/js/CustomEditingToolbar.js ? modules/openlayers_ui/includes/.openlayers_ui.styles.inc.swp 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 24 May 2010 02:55:08 -0000 @@ -55,6 +55,20 @@ function _openlayers_behaviors_render($b } /** + * Turn a basic callback into a Drupal settings-openlayers function + */ +function _openlayers_style_callback_wrap($style, $callbacks) { + // TODO: make map-specific + $functions = array(); + foreach ($callbacks as $attribute => $callback) { + if (!empty($callback['value'])) { + $functions[] = "$attribute: function(feature) { " . $callback['value'] . " }"; + } + } + return "Drupal.settings.openlayers.callbacks.$style = { " . implode(',', $functions) . "};"; +} + +/** * Process Styles * * Get full data for any styles @@ -76,6 +90,7 @@ function _openlayers_styles_process($sty $processed = array(); foreach ($styles as $k => $style) { // Check if array, if array, just pass on + // TODO: remove, unify if (is_array($style)) { $processed[$k] = $style; } @@ -85,10 +100,12 @@ function _openlayers_styles_process($sty } // Add layer styles + // TODO: kill, rewrite foreach ($layer_styles as $style) { if (!isset($processed[$style]) && !empty($styles_info[$style]) && $info = $styles_info[$style]->data) { + drupal_add_js(_openlayers_style_callback_wrap($style, $info['callback']), 'inline'); $processed[$style] = $info; } } Index: js/openlayers.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/openlayers/js/openlayers.js,v retrieving revision 1.47.2.31 diff -u -p -r1.47.2.31 openlayers.js --- js/openlayers.js 17 May 2010 12:31:20 -0000 1.47.2.31 +++ js/openlayers.js 24 May 2010 02:55:08 -0000 @@ -21,6 +21,7 @@ document.namespaces; Drupal.settings.openlayers = {}; Drupal.settings.openlayers.maps = {}; +Drupal.settings.openlayers.callbacks = {}; /** * This should move down and be a part of another object @@ -278,10 +279,15 @@ Drupal.openlayers = { // 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]); + stylesAdded['default'] = new OpenLayers.Style(map.styles[style], + { + 'context': Drupal.settings.openlayers.callbacks[style] + } + ); } return new OpenLayers.StyleMap(stylesAdded); } + // TODO: defaults are not here, they should be pulled from the map // Default styles return new OpenLayers.StyleMap({ 'default': new OpenLayers.Style({ 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.5 diff -u -p -r1.1.2.5 openlayers_ui.styles.inc --- modules/openlayers_ui/includes/openlayers_ui.styles.inc 22 Mar 2010 23:55:10 -0000 1.1.2.5 +++ modules/openlayers_ui/includes/openlayers_ui.styles.inc 24 May 2010 02:55:08 -0000 @@ -10,6 +10,30 @@ */ /** + * Shortcut for implementing a form of a callback + */ +function openlayers_ui_styles_form_callback($attribute, $style) { + return array( + '#title' => t('Callback: !s', array('!s' => $attribute)), + '#type' => 'fieldset', + '#collapsible' => TRUE, + '#collapsed' => empty($style->data['callback'][$attribute]['value']), + 'value' => array( + '#type' => 'textarea', + '#default_value' => + isset($style->data['callback'][$attribute]['value']) ? + $style->data['callback'][$attribute]['value'] : '', + '#description' => t('Enter Javascript code composing the body of a + function that returns the value of this %a and is provided with + the variable "feature"', + array('%a' => $attribute)), + ) + ); +} + + + +/** * Styles add/edit form. */ function openlayers_ui_styles_form(&$form_state, $style = NULL, $edit = FALSE) { @@ -46,6 +70,20 @@ function openlayers_ui_styles_form(&$for '#default_value' => isset($style->data['externalGraphic']) ? $style->data['externalGraphic'] : '', ); + + $form['data']['callback'] = array( + '#weight' => 10, + '#type' => 'fieldset', + '#title' => t('Style Callbacks'), + '#description' => t('Style callbacks are optional Javascript fragments that + dynamically style map features. To use a callback, enter Javascript code + for an attribute and set the attribute value in the form above to ${attributeName}, + with the name of the specific attribute.') + ); + + $form['data']['callback']['externalGraphic'] = + openlayers_ui_styles_form_callback('externalGraphic', $style); + $form['data']['pointRadius'] = array( '#title' => 'pointRadius', '#type' => 'textfield', @@ -55,12 +93,20 @@ function openlayers_ui_styles_form(&$for '#default_value' => isset($style->data['pointRadius']) ? $style->data['pointRadius'] : 5, ); + + $form['data']['callback']['pointRadius'] = + openlayers_ui_styles_form_callback('pointRadius', $style); + $form['data']['fillColor'] = array( '#title' => 'fillColor', '#type' => 'textfield', '#default_value' => isset($style->data['fillColor']) ? $style->data['fillColor'] : "#FFFFFF", ); + + $form['data']['callback']['fillColor'] = + openlayers_ui_styles_form_callback('fillColor', $style); + $form['data']['strokeColor'] = array( '#title' => 'strokeColor', '#type' => 'textfield', @@ -69,6 +115,10 @@ function openlayers_ui_styles_form(&$for '#default_value' => isset($style->data['strokeColor']) ? $style->data['strokeColor'] : "#FFFFFF", ); + + $form['data']['callback']['strokeColor'] = + openlayers_ui_styles_form_callback('strokeColor', $style); + $form['data']['strokeWidth'] = array( '#title' => 'strokeWidth', '#type' => 'textfield', @@ -77,6 +127,10 @@ function openlayers_ui_styles_form(&$for '#default_value' => isset($style->data['strokeWidth']) ? $style->data['strokeWidth'] : 5, ); + + $form['data']['callback']['strokeWidth'] = + openlayers_ui_styles_form_callback('strokeWidth', $style); + $form['data']['fillOpacity'] = array( '#title' => 'fillOpacity', '#type' => 'textfield', @@ -84,10 +138,14 @@ function openlayers_ui_styles_form(&$for $style->data['fillOpacity'] : 0.5, ); + $form['data']['callback']['fillOpacity'] = + openlayers_ui_styles_form_callback('fillOpacity', $style); + $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); + return $form; } @@ -112,64 +170,3 @@ function openlayers_ui_styles_form_submi form_set_error('openlayers', t('Error trying to save style.')); } } - -// /** -// * Import a preset from cut & paste -// */ -// function openlayers_ui_styles_import_form(&$form_state) { -// $form['name'] = array( -// '#type' => 'textfield', -// '#title' => t('Style name'), -// '#description' => t('Enter the name to use for this style if it is different from the source style. Leave blank to use the name of the style.'), -// ); -// -// $form['style'] = array( -// '#type' => 'textarea', -// '#title' => t('Paste style code here'), -// '#required' => TRUE, -// ); -// -// $form['submit'] = array( -// '#type' => 'submit', -// '#value' => t('Import'), -// '#submit' => array('openlayers_ui_style_import_submit'), -// '#validate' => array('openlayers_ui_style_import_validate'), -// ); -// return $form; -// } -// -// /** -// * Validate handler to import a preset -// */ -// function openlayers_ui_styles_import_validate($form, &$form_state) { -// $view = ''; -// ob_start(); -// eval($form_state['values']['style']); -// ob_end_clean(); -// -// if (!is_object($style)) { -// return form_error($form['style'], t('Unable to interpret preset code.')); -// } -// -// // View name must be alphanumeric or underscores, no other punctuation. -// if (!empty($form_state['values']['name']) && preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) { -// form_error($form['name'], t('Preset name must be alphanumeric or underscores only.')); -// } -// -// if ($form_state['values']['name']) { -// $preset->name = $form_state['values']['name']; -// } -// -// /* -// * TODO: replace with style code -// if ($test && $test->type != t('Default')) { -// form_set_error('', t('A preset by that name already exists; please choose a different name')); -// } -// */ -// -// // TODO: The import process should test layer existence -// $form_state['style'] = &$style; -// $a = array(); -// $form = openlayers_ui_styles_form($a); -// openlayers_ui_styles_form_submit(&$form, &$form_state); -// }