Book Image

OpenLayers 3.x Cookbook - Second Edition

By : J. Langley, Antonio Santiago
Book Image

OpenLayers 3.x Cookbook - Second Edition

By: J. Langley, Antonio Santiago

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 (9 chapters)
8
Index

Drawing features across multiple vector layers


We've seen various ways to add vector features to a map, such as in the recipes, Adding a GML layer from this chapter, and Creating features programmatically in Chapter 3, Working with Vector Layers. Sometimes, however, we may want to provide the user with drawing capabilities so that they can manually draw almost any shape they like on the map.

For example, you may want the user to mark out a point of interest at a location by drawing a polygon over an area for building planning purposes.

OpenLayers has an abundance of controls (more accurately, interactions) that we can add to the map for exactly this type of purpose.

In this recipe, we will allow the user to draw from a selection of different geometry types (Point, LineString, Polygon, and Circle) and add them to a vector layer of their choice. The source code can be found in ch05/ch05-drawing-features, and this will look like the following:

How to do it…

Find out how to draw different vector...