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
About the Authors
About the Reviewer

Measuring distances and areas

The ability to measure distances or areas is an important feature for many GIS applications. For example, a user may wish to draw out a path along some roads to figure out the distance of a journey. Or you may want to draw a polygon around your neighbor's back garden to see how many acres they have!

OpenLayers 2 conveniently came with a measuring control straight out of the box. However, at the time of writing this book, OpenLayers 3 doesn't offer this convenience. However, you'll be pleased to know that this can be cobbled together with the methods that are available to us without much fuss.

The application will contain a sidebar with radio inputs in order to select a measurement type, either area or distance. The user will be able to draw anywhere on the map and see a live update of the measurement in the sidebar as they go. For mobile, the updates will be seen after every new point has been placed on the map.

The source code can be found in ch05/ch05-measuring...