Book Image

OpenLayers 3.x Cookbook - Second Edition

By : Peter J. Langley, Antonio Santiago Perez
Book Image

OpenLayers 3.x Cookbook - Second Edition

By: Peter J. Langley, Antonio Santiago Perez

Overview of this book

OpenLayers 3 is one of the most important and complete open source JavaScript mapping libraries today. Throughout this book, you will go through recipes that expose various features of OpenLayers 3, allowing you to gain an insight into building complex GIS web applications. You will get to grips with the basics of creating a map with common functionality and quickly advance to more complicated solutions that address modern challenges. You will explore into maps, raster and vector layers, and styling in depth. This book also includes problem solving and how-to recipes for the most common and important tasks.
Table of Contents (14 chapters)
OpenLayers 3.x Cookbook Second Edition
About the Authors
About the Reviewer


This chapter is focused on events, which is an important concept in any JavaScript application. Although this chapter is brief, the concepts explained here are very important to understand when working with OpenLayers and mapping applications in general.

Events are fundamental in JavaScript. They are the impulses that allow us to produce a reaction. As programmers of a mapping application, we are interested in reacting when the map zoom changes, when a layer is loaded, or when a feature is added to a layer. Every class, which is susceptible to emit events, is responsible for managing its listeners (those interested in being notified when an event is fired) and also to emit events under certain circumstances.

For example, we can register a function handler that listens for the change:resolution event on the OpenLayers map view instance. Every time the view instance changes its zoom level, it has the responsibility to trigger the change:resolution event, so all its listeners will...