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

Preface

Web mapping is the process of designing, implementing, generating, and delivering maps on the World Wide Web and its products. OpenLayers is a powerful, community driven, open source, pure JavaScript web-mapping library. With it, you can easily create your own web map mashup using WMS, Google Maps, and a myriad of other map backends. Interested in knowing more about OpenLayers? This book is going to help you learn OpenLayers from scratch.

OpenLayers 2.10 Beginner's Guide will walk you through the OpenLayers library in the easiest and most efficient way possible. The core components of OpenLayers are covered in detail, with examples, structured so that you can easily refer back to them later.

The book starts off by introducing you to the OpenLayers library and ends with developing and deploying a full-fledged web map application, guiding you through every step of the way.

Throughout the book, you'll learn about each component of the OpenLayers library. You'll work with backend services like WMS, third-party APIs like Google Maps, and even create maps from static images. You'll load data from KML and GeoJSON files, create interactive vector layers, and customize the behavior and appearance of your maps.

There is a growing trend in mixing location data with web applications. OpenLayers 2.10 Beginner's Guide will show you how to create powerful web maps using the best web mapping library around.

This book will guide you to develop powerful web maps with ease using the open source JavaScript library OpenLayers.

What you need for this book

The only thing you'll need for this book is a computer and text editor. Your operating system will come with a text editor, and any will do, but if you are using Windows I recommend using Notepad++ (http://notepad-plus-plus.org/), VI if you are using Linux, and Textmate if on OSX. An Internet connection will be required to view the maps, and you'll also need a modern web browser such as Firefox, Google Chrome, Safari, or Opera. While a modern browser is required to get the most of the library, OpenLayers even provides support for non standards based browsers such as Internet Explorer (even IE6, to some extent).

No knowledge of Geographic Information Systems (GIS) is required, nor is extensive JavaScript experience. A basic understanding of JavaScript syntax and HTML / CSS will greatly aid in understanding the material, but is not required.

What this book covers

Chapter 1: Getting Started with OpenLayers. This chapter will introduce OpenLayers and some programming concepts behind it. It covers how to create a map, walking through how to set up the code and configure various settings.

Chapter 2: Squashing Bugs with Firebug. This chapter will cover setting up the Firebug plugin, which we'll use throughout the book, so that we can do simple debugging and better understand how OpenLayers works behind the scenes.

Chapter 3: The 'Layers' in OpenLayers. Here, we'll cover one of the core classes of OpenLayers—the Layer class. We'll discuss what a 'Layer' is, how to work with layers and the different layer classes.

Chapter 4: Wrapping our Heads Around Projections. This chapter will cover a few basic geography concepts and why understanding them will help us use OpenLayers. We'll also cover projections, why they are used, and how to use them.

Chapter 5: Interacting With Third Party APIs. This chapter will focus on creating an OpenLayers map using different third party APIs, such as Google Maps and OpenStreetMaps.

Chapter 6: Taking Control of Controls. We'll cover another core class of OpenLayers, the Control class. We'll cover what controls are and discuss the various types of controls, along with how to work with the events.

Chapter 7: Giving Controls Some Style. This chapter will walk through how OpenLayers uses CSS to style controls.

Chapter 8: Charting the Map Class. This chapter will discuss another core component of OpenLayers—the Map class. We'll learn about how to map functions and their properties, along with how to set up multiple maps on the same page.

Chapter 9: Using Vector Layers. Here, we'll learn what a Vector layer is and how it works. We'll also cover how to work with the data, such as KML files.

Chapter 10: Vector Layer Style Guide. In this chapter we'll cover how to style the vector layer and how to use the Rule and Filter classes.

Chapter 11: Creating Web Map Applications. This final chapter will go over how to build a web-mapping application from scratch, and how to use the OpenLayers build file.

Who this book is for

This book is for anyone who has any interest in using maps on their website, from hobbyists to professional web developers. OpenLayers provides a powerful, but easy-to-use, pure JavaScript and HTML (no third-party plug-ins involved) toolkit to quickly make cross-browser web maps. A basic understanding of JavaScript will be helpful, but there is no prior knowledge required to use this book. If you've never worked with maps before, this book will introduce you to some common mapping topics and gently guide you through the OpenLayers library. If you're an experienced application developer, this book will also serve as a reference to the core components of OpenLayers.

How to read this book

This book is primarily designed to be read from start to finish, with chapters building on each other and increasing in complexity. At the same time, however, the chapters are modular so that each can also serve as reference once you've learned the material. This book should preferably be read straight through first, of course, and then serve as a reference later.

Conventions

In this book, you will find several headings appearing frequently.

To give clear instructions of how to complete a procedure or task, we use:

Time for action – heading

  1. Action 1

  2. Action 2

  3. Action 3

Instructions often need some extra explanation so that they make sense, so they are followed with:

What just happened?

This heading explains the working of tasks or instructions that you have just completed.

You will also find some other learning aids in the book, including:

Pop quiz – heading

These are short questions intended to help you test your own understanding.

Have a go hero – heading

These set practical challenges and give you ideas for experimenting with what you have learned.

You will also find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "You can download it as either a tar.gz or .zip."

A block of code is set as follows:

Lines [21] to [23]
  if(!map.getCenter()){
    map.zoomToMaxExtent();
  }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

  var wms_layer = new OpenLayers.Layer.WMS(
    'WMS Layer Title',
    'http://vmap0.tiles.osgeo.org/wms/vmap0',
    {layers: 'basic'},
    {}
  );

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "By default, your map adds an argParser control which will try to pull information from a permalink.".

Note

Warnings or important notes appear in a box like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.