O'Reilly logo

OpenLayers 2.10 by Erik Hazzard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ), { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required