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 – creating a Vector Layer


In this first example, we'll use the code similar to what we just saw above—making use of all three classes to build our vector layer, which will request data from a URL.

There are two caveats to this example. The first is that it assumes you have a file called ex5_data.json in the same directory as your map file. You can find it in this book's source code files at http://vasir.net/openlayers_book/files/.

Secondly, unless you are running this on a server, it won't work. It will need a proxy host, which we'll cover right after this example. If you do not have access to a server, you can view the example in action at the URL above.

  1. Start a new map file using the base template from Chapter 1. We'll use the Protocol, Format, and Strategy classes. So first, let's create objects for each of them. Let's start with the format object, as the protocol object will use it. We'll use the GeoJSON format.

    //Create a Format object 
    var vector_format = 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