Book Image

OpenLayers 2.10 Beginner's Guide

Book Image

OpenLayers 2.10 Beginner's Guide

Overview of this book

Table of Contents (18 chapters)
OpenLayers 2.10
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Attribute replacement


One easy, but powerful, thing we can do with feature styles is called attribute replacement. It's a way to use a feature's attributes in the layer's style definition, like a variable. When creating the symbolizer, you can set the value of any property in a format of:

${variable_name}

Where variable_name is the name of a property contained in a feature's attributes property. For example, let's say all our features have an attribute property called 'size' with random integer values. If we wanted to assign the pointRadius to each feature's size property, we would use:

{ 'pointRadius': ${size} }

What happens then is that when each feature is styled, the ${size} is replaced by the feature's attribute.size property (if one exists). The best way to further explain this is through an example. Let's take a look, then go even further in depth.