Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenLayers 2.10 Beginner's Guide

You're reading from   OpenLayers 2.10 Beginner's Guide Create, optimize, and deploy stunning cross-browser web maps with the OpenLayers JavaScript web mapping library

Arrow left icon
Product type Paperback
Published in Mar 2011
Publisher
ISBN-13 9781849514125
Length 372 pages
Edition Edition
Languages
Arrow right icon
Toc

Table of Contents (18) Chapters Close

OpenLayers 2.10
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with OpenLayers FREE CHAPTER 2. Squashing Bugs With Firebug 3. The 'Layers' in OpenLayers 4. Wrapping Our Heads Around Projections 5. Interacting with Third Party APIs 6. Taking Control of Controls 7. Styling Controls 8. Charting the Map Class 9. Using Vector Layers 10. Vector Layer Style Guide 11. Making Web Map Apps Index

Time for action – downloading OpenLayers


Let's download the OpenLayers library. After you're done, you should have the OpenLayers library files set up on your computer.

  1. Go to the OpenLayers website (http://openlayers.org) and download the .zip version (or if you prefer the .tar.gz version).

  2. Extract the file you just downloaded. When you extract it, you'll end up with a folder called OpenLayers-2.10 (or whatever your version is).

  3. Open up the OpenLayers folder. Once inside, you'll see a lot of folders and files, but the ones we are concerned with right now is a file called OpenLayers.js and two folders, /img and /theme. We'll be copying these to a new folder.

  4. Create a new folder outside the OpenLayers directory; we'll use ~/code/ (if you are on Windows, then c:/code). You can name the folder whatever you like, but we'll refer to it as the code folder. Inside the code folder, copy over the OpenLayers.js and two folders (/img and /theme) from the previous step. Your new folder structure should look similar to this:

What just happened?

We just 'installed' OpenLayers by copying over a pre-built, compressed JavaScript file containing the entire OpenLayers library code and two directories containing assets (images and stylesheets). To use OpenLayers, you'll need at a minimum the OpenLayers.js file and the img and theme folders.

If you open the OpenLayers.js file, you'll notice it is nearly unreadable. This is because this is a minified version, which basically means extra white space and unnecessary characters have been stripped out to cut down on the file size. While it is no longer readable, it is a bit smaller and thus requires less time to download. If you want to look at the uncompressed source code, you can view it by looking in the OpenLayers source code folder you extracted.

You can, as we'll see in the last chapter of this book, build your own custom configurations of the library, including only the things you need. But for now, we'll just use the entire library. Now that we have our OpenLayers library files ready to use, let's make use of them!

Making our first map

The process for creating a map with OpenLayers requires, at a minimum, the following things:

  • Including the OpenLayers library files

  • Creating an HTML element that the map will appear in

  • Creating a map object from the Map class

  • Creating a layer object from a Layer class

  • Adding the layer to the map

  • Defining the map's extent (setting the area the map will initially be displaying)

Now we're finally ready to create our first map!

You have been reading a chapter from
OpenLayers 2.10 Beginner's Guide
Published in: Mar 2011
Publisher:
ISBN-13: 9781849514125
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime