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

Creating a heat map

When you consider heat maps, you may literally think of an application that is used to visualize heat distribution across the planet, which is definitely an appropriate use case. You can, however, adapt the heat map effect to convey other properties, such as the relative quantity of any data type within areas. The more intense the 'heat', the more dense the information underneath.

For example, imagine a map that reflects how many users are currently online, playing your favorite game. We can specify locations with a weight attribute, which is indicative of the amount of players online for that geographic location. This is the scenario we'll go with for this recipe and can be seen in the following screenshot:

The source code can be found in ch03/ch03-heat-map.

How to do it…

Here's how to build a heat map of some fictional online users:

  1. Create an HTML file and add the OpenLayers dependencies and also a div element to hold the map.

  2. Next, initialize the map, add a raster layer...