Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying OpenLayers 2.10 Beginner's Guide
  • Table Of Contents Toc
  • Feedback & Rating feedback
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)
close
close
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)

Overview of this book

Table of Contents (18 chapters)
close
close
OpenLayers 2.10
In Progress | 0 / 1 sections completed | 0%
Credits
In Progress | 0 / 1 sections completed | 0%
About the Author
In Progress | 0 / 1 sections completed | 0%
About the Reviewers
In Progress | 0 / 1 sections completed | 0%
www.PacktPub.com
In Progress | 0 / 1 sections completed | 0%
Preface
In Progress | 0 / 1 sections completed | 0%
Index
In Progress | 0 / 1 sections completed | 0%

Time for Action – using rules and filters


Let's use rules and filters to assign different styles to feature objects based on their attributes.

  1. Let's jump in to using rules and filters. Add a WMS layer to the map. We'll also need a vector layer, so add in a vector layer:

            vector_layer = new OpenLayers.Layer.Vector('Basic Vector Layer'); 
            map.addLayer(vector_layer);
  2. Next, we'll need some features. We'll generate some random feature points again, and we'll create a property for each object called population which contains a random number between 0 and 2000:

    for(var i=0; i<20; i++){
      vector_layer.addFeatures([new OpenLayers.Feature.Vector(
        new OpenLayers.Geometry.Point(
         (Math.floor(Math.random() * 360) - 180),
          (Math.floor(Math.random() * 180) - 90)
        ),
        {
          'population': Math.floor(Math.random() * 2000)
        }
      )]);
    }
  3. Now we need to create a style object—rules are applied directly to style objects, and filters are applied directly to rules. So, let's create...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY