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

Zooming to the extent of a layer


When a group of features coexist on a vector map layer, such as circles and polygons, they make up a shared extent, which is also known as a bounding box. This rectangular extent accommodates all the geometries. It can be useful to acquire the extent of such a group of features so that we can reposition the map at optimal resolution for the point of interest, which is exactly what we will do in this recipe.

We will place some features on the map at low resolution, but initially, we will configure the map resolution to start much higher. The group of features will appear small to begin with, but we'll provide a button that conveniently pans and zooms the user much closer to the group of features, based on their combined extent.

The source code can be found in ch03/ch03-zoom-to-extent/. We'll end up with something that looks like the following screenshot:

How to do it…

Discover how you can zoom to the extent of some features on a layer using the following instructions...