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 addUniqueValueRules

Now that we know about addUniqueValueRules, let's see it in action.

  1. We're going to use a basic vector layer with some randomly generated features and settlement_type properties. Add a WMS layer. Then, we need a vector layer:
    vector_layer = new OpenLayers.Layer.Vector('Settlement Vector Layer');
    map.addLayer(vector_layer);
  2. Now, let's create an anonymous object consisting of integer values as the keys and our desired settlement_type values as the values. We do this because we'll need a way to randomly pick what type of settlement a feature should be.
    var  settlement_values = { 
        0: 'hut', 
        1: 'village', 
        2: 'city', 
        3: 'metropolis', 
        4: 'facebook' 
    }
  3. Ok, let's now create 20 random points. Using code similar to the ...

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