In four easy steps, you will install OpenLayers and start creating your amazing web maps.
OpenLayers is a JavaScript library designed to build web maps, so you must be familiar with the most popular technologies used to create web applications. Basic knowledge of JavaScript and HTML is a prerequisite, while an understanding of CSS is not necessary but convenient.
You can write the recipe's code in a simple text editor, but as an alternative, you may consider an IDE (Integrated Development Environment) that provides you with a complete development framework. In this category, we would recommend Aptana Studio 3, an open source, cross-platform IDE with the support for JavaScript, HTML, and CSS. It offers code assist, integrated debugger, and much more. Aptana Studio 3 is available at http://www.aptana.com/products/studio3.
For Windows users, Notepad++ is a very good choice. It is not an IDE, but it is more than a simple text editor and offers syntax highlighting and plugins that are easy to use. It is an open source project, freely available at http://notepad-plus-plus.org.
The authors of this book have adopted the very popular GNU/Linux distribution called Ubuntu as their principal operating system. You may work smoothly even in a Windows or Mac OS X environment, but it would be more comfortable for you to use an Ubuntu system to follow the entire installation process step by step.
Note
If you are unfamiliar with JavaScript, HTML, and CSS, the resources on the Mozilla Developer Network at https://developer.mozilla.org/en/docs/ may be helpful.
You can download Ubuntu at www.ubuntu.com and install it natively on your hard drive as the native operating system, or use a virtual machine such as VirtualBox, available at http://www.virtualbox.org.
The latest stable build of OpenLayers is available as a .tar.gz
or .zip
archive from the homepage of the project at http://www.openlayers.org/. Choose one format and download the latest stable release of the library (2.12 at the time of writing this book).
After downloading the archive, you need to unpack it to be left with a directory called OpenLayers-2.12
, containing a number of files and folders. Now, you just need to create an empty folder in your /home
, name it openlayers_starter
, and copy the library into it.
This will be your workspace for all of the recipes and in the next (and last) step we will see where to put it to start having fun with OpenLayers.
OpenLayers is a pure client-side JavaScript library, but in a production environment, JavaScript web applications are distributed through web servers, so it is a good idea to start becoming familiar with this concept. Moreover, in some recipes, we will need to pass a proxy script to retrieve remote data and this requires a web server to be run. So, as final step, you will install and configure a minimal publishing environment on your machine with Apache 2, a very popular open source web server. Its installation in Ubuntu is easy as a pie!
Launch a terminal and type the following into it:
~: sudo apt-get install apache2
Then, in the same terminal, after the first command finishes, type the following:
~: sudo chown -R ${USER} /var/www; ln -s /var/www /home/${USER}/www
Let's explain. The first line performs the actual installation. The second line changes the owner of the web server's root directory to your user, and then creates a soft-link to it.
Go to http://localhost
with your browser. If the installation succeeds, the Apache 2 web server welcome page opens and displays the message "It works!".
Now, as very last thing, move the openlayers_starter
folder into www
.
Note
Windows users can download Apache 2 at http://httpd.apache.org/ and install it in few steps or choose between a number of ready-to-run environments for web development such as BitNami (http://bitnami.org/).