Peter Robins, his website

Using OpenLayers: Introduction

The aim of this section of my website is to describe how I use OpenLayers, hereinafter called OL. It refers to the status as last updated, which is currently version 2.11. If I have time, I'll keep it updated, but no guarantees I will have time. It's a sort of tutorial, but I make no claims for it being comprehensive - there are many functions in OL I have never used. Nor is it necessarily the only or even the best way of doing things; it's simply the way I used it to achieve what I wanted. For me one of the great advantages of Javascript is that it's very flexible, and so there are often several different ways of doing something with no real criteria for one being better than another. I refer throughout to Javascript (hereinafter JS), though this is one of computing's more misleading names as it has nothing to do with Java; I could use the term ECMAScript instead, but have found that many people don't know what that is. I assume enough knowledge of JS to find your way around the OL source code.

Although when I started using OL I used the documentation on the website, I soon found that the only way to really work out what's going on is to look at the source. The simplest way of doing this is to download your own copy from Github. Another good way to work out what's going on is to load your program in the browser, and use one of the various JS monitoring tools that are about; the Firefox extension Firebug is the most comprehensive that I've come across, but these days I mainly use the console in Google Chrome.

If you do download the OL source, the download will include all the examples that are viewable on the OL website. There are now large numbers of these, and they provide simple examples of most of the functionality of OL. You can adapt these for your own purposes, and they will probably take you a long way towards meeting your needs.

For descriptive documentation, there is also a slowly growing library at docs.openlayers.org. Beware though that this is in places not up-to-date.

I'll start off with the theory: on the way OL's code is structured, and the basic concepts of OL. I'll then move on to more concrete examples of how to use OL.

Update January 2012: updated examples to use HTML5 rather than XHTML

April 2010, updated January 2012