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

Selecting features by dragging out a selection area


One common action when working with features within a vector layer is its selection, and, of course, OpenLayers has some feature selection controls that are available to us. We've already seen this demonstrated in earlier recipes, such as the Removing or cloning features using overlays recipe in Chapter 3, Working with Vector Layers. This recipe showed us how to select one feature at a time with a click or tap gesture.

This recipe will show you how to select multiple features at once using a combination of interactions. The ol.interaction.Select class is for the render intent and grouping of selected features, and the other is ol.interaction.DragBox, which is used to enable the user to drag out a rectangle over the map. The joint effort of these two controls will produce a multiselect capability.

Once these features have been selected, we'll display the selected count and enable the user to delete the selected features from the sidebar.

The...