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

Time For Action – figuring out logical filters


In this example, we'll use a few logical filters and some random points with random population and settlement_type values.

  1. Add in a WMS and vector layer.

            vector_layer = new OpenLayers.Layer.Vector('Basic Vector Layer'); 
            map.addLayer(vector_layer);
  2. Now, we'll need to create an anonymous object containing some settlement value that we'll pick from at random:

    var settlement_values = { 
        0: 'village', 
        1: 'city', 
    }
  3. Let's create some feature. We'll create twenty features, using some random population and settle_type values in each feature's attribute property:

    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), 
          'settlement_type': settlement_values[(Math.floor...