Measuring distances and areas
The capability to measure distances or areas is an important thing on many GIS applications.
In this recipe, we are going to see in action what the Measure control in OpenLayers offers to the developer.
The application will show a simple map with some buttons on top, as shown in the following screenshot. The Measure toggle button activates or deactivates the control, while the radio buttons bring us the possibility to select what to measure: a path or an area:
In addition, we can set two control options. The Geodesic control indicates if the distance of the area computation must be in geodesic metrics instead of planar. The Immediate option is useful to update the measure every time we move the mouse.
How to do it...
Here, we are going to write not the whole source code but only those pieces of code that are important for the recipe. So, we are avoiding putting here the HTML code required to build the measure button, checkboxes, options radio buttons, and the...