Book Image

OpenLayers 3: Beginner's Guide

By : Thomas Gratier, Paul Spencer, Erik Hazzard
Book Image

OpenLayers 3: Beginner's Guide

By: Thomas Gratier, Paul Spencer, Erik Hazzard

Overview of this book

<p>This book is a practical, hands-on guide that provides you with all the information you need to get started with mapping using the OpenLayers 3 library.</p> <p>The book starts off by showing you how to create a simple map. Through the course of the book, we will review each component needed to make a map in OpenLayers 3, and you will end up with a full-fledged web map application. You will learn the key role of each OpenLayers 3 component in making a map, and important mapping principles such as projections and layers. You will create your own data files and connect to backend servers for mapping. A key part of this book will also be dedicated to building a mapping application for mobile devices and its specific components.</p>
Table of Contents (22 chapters)
OpenLayers 3 Beginner's Guide
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Anatomy of a web mapping application


First off, what is a web-mapping application? To put it bluntly, it's some type of Internet application that makes use of a map. This could be a site that displays the latest geo-tagged images from Flickr (we'll do this in Chapter 11, Creating Web Map Apps), a map that shows markers of locations you've traveled to, or an application that tracks invasive plant species and displays them. If it contains a map and it does something, you could argue that it is a web map application. The term can be used in a pretty broad sense.

So, where exactly does OpenLayers fit in? We know OpenLayers is a client-side mapping library, but what does that mean? Let's take a look at the following figure:

This is called the client/server model and it is, essentially, the core of how all web applications operate. In the case of a web map application, some sort of map client (for example: OpenLayers) communicates with some sort of web map server (for example: a map server using the WMS (Web Map Service) standard, an OpenStreetMap backend, or some satellite images). We've added a bit of complexity in it because the truth is that you can also rely only on client-side for web mapping applications using static content that you have pre-generated. To illustrate, you can use GeoJSON files, a JSON based format to display pins. For example, it is very useful for mobile content.

Web map client

OpenLayers lives on the client-side. One of the primary tasks the client performs is to get map images from a map server. Essentially, the client asks a map server for what you want to look at. Every time you navigate or zoom around on the map, the client has to make new requests to the server—because you're asking to look at something different.

OpenLayers handles this all for you, and it is happening via AJAX (asynchronous JavaScript + XML) calls to a map server. Refer to http://en.wikipedia.org/wiki/Ajax_(programming) for further information on AJAX. To reiterate—the basic concept is that OpenLayers sends requests to a map server for map data every time you interact with the map, then OpenLayers pieces together all the returned map data (which might be images or vector data) so it looks like one big, seamless map. In Chapter 2, Key Concepts in OpenLayers, we'll cover this concept in more depth.

Web map server

A map server (or map service) provides the map itself. There are a myriad of different map server backends. The examples include:

  • The map servers using WMS and WFS standards (such as the GeoServer, Mapserver, and so on)

  • Proprietary backends provided such as Bing Maps or Esri's ArcGIS Online, mainly based on proprietary data

  • Backends based on OpenStreetMap data such as the official OpenStreetMap, Stamen maps, or MapQuest maps

If you are unfamiliar with these terms, don't sweat it. The basic principle behind all these services is that they allow you to specify the area of the map you want to look at (by sending a request), and then the map servers send back a response containing the map image. With OpenLayers, you can choose to use as many different backends in any sort of combination as you'd like.

Note

OpenLayers is not a web map server; it only consumes data from them. So, you will need access to some type of WMS. Don't worry about it though. Fortunately, there are a myriad of free and/or open source web map servers available that are remotely hosted or easy to set up yourself, such as MapServer. We speak a lot about web map servers but you must be aware that depending on your web-mapping application, you can use geographic data files to provide the needed data consumed by OpenLayers.

Throughout this book, we'll often use a freely available web-mapping service from http://www.openstreetmap.org/, so don't worry now about having to provide your own.

With many web map servers, you do not have to do anything to use them—just supplying a URL to them in OpenLayers is enough. OSGeo, OpenStreetMap, Google, Here Maps, and Bing Maps, for instance, provide access to their map servers (although some commercial restrictions may apply with various services in some situations).