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

Rules and filters


For even more fine grained control, we can style objects by using the Rule and Filter classes. These two classes allow us to apply different styles to different features based on some arbitrary 'rules' we choose. We can use the feature's attributes property to apply certain styles if one (or more) of the properties match some value we choose.

How do we follow rules?

Rules allow us to apply symbolizers when certain conditions occur. Those conditions are handled via the Filter class. We can have multiple rules and filters, and even use logical operators (such as OR and AND) with them. Before we talk about that though, there are two ways we can use rules.

The first is by using the addUniqueValueRules method of the StyleMap class. This allows simple property matching and is fairly straightforward to use. We'll go over this method first.

The second way, using custom rule and filter objects, is a bit complicated, but allows us snowflake level control over what styles get applied...