Monday, December 6, 2010

Variable Styling

This page describes how to do variable styling in OpenLayers 2.x module.

Attribute Replacement

The OpenLayers library allows you to use a specific syntax, ${variable_name}, to easily style a feature based on its attributes. The most direct use of this is with the OpenLayers Views Display plugin.
  1. Setup your Views Display according to Getting Started with OpenLayers.
  2. Add fields to your view that you want to use for styling (the 'attributes'). These attributes may be used as radius or color, or even icon URL later on.
  3. The values of these attributes are included in the OpenLayers Data view based Overlay layer that you can add to any preset.
  4. You need to reference each attribute by its machine-readable ID. Lookup the ID trough the Theme:Information link in the basic settings of your view. They have names like field_myfield_value.
  5. In the style associated with your preset, you can apply your attribute as a style like this:
    • pointRadius: ${field_radius_value}
    • fillColor: ${field_color_value}
  6. Finally, create your map with your Views layer and assign it your new style; then when your map is rendered, OpenLayers will replace these values per feature.
More ways of variable styling to come.

For more information about Drupal Development, Drupal Expert, Drupal Developer and Drupal Programmer visit at


No comments:

Post a Comment