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 – using the Format and Strategy classes alone


Let's take a look at another example now. Here, we'll do something very similar to what we did in the first example—this time, however, we won't use the Protocol. Instead, we'll read in feature data as a JavaScript object and, using the GeoJSON Format class, read in the data. This way, this example will work without having to use a server or proxy host.

  1. Create a new page using the template in Chapter 1. We'll be doing three things here—creating some feature data in GeoJSON format, creating a vector layer, and loading the GeoJSON data into it. Let's create some basic feature data. Feel free to play around with the coordinates and amount of features here:

    var feature_data = { 
                "type": "FeatureCollection", 
                "features": [ 
                    {"type":"Feature","properties":{}, "geometry":{"type":"Point", "coordinates":[-81, 42]}}, 
                    {"type":"Feature","properties":{}, "geometry":{"type":"Point", "coordinates...