Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • OpenLayers 2.10 Beginner's Guide
  • Toc
  • feedback
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)
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
OpenLayers 2.10
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 previous example, we'll create twenty random points and assign a random settlement type to each feature using the settlement_values object we just created.

    for(var i=0; i<20; i++){ 
        vector_layer.addFeatures([new OpenLayers...

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
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