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
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Using the cluster strategy


Imagine a scenario where we want to show all the gas stations in every city around the world. What will happen when the user navigates within the map and sets a zoom level to look at the whole world? We're presented with an overwhelming dominance of points, overlapping each other all at the same place, providing little visual value to the user.

A solution to this problem is to cluster the features on each zoom level. OpenLayers makes this very easy to implement.

This recipe (source code in ch03/ch03-clustering) shows how easy it is to apply clustering on a vector layer, which is responsible for grouping the features to avoid a situation similar to the one discussed earlier that can be seen in the following screenshot:

How to do it…

Utilize the great clustering capability of OpenLayers using the following instructions:

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

  2. Initialize the map, as follows:

    var map = new ol.Map({
      view: new ol...