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: