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

Getting feature information from a data source

When a vector layer is populated with features, it can be very useful to query the data source in order to retrieve feature information. OpenLayers provides some methods from the vector source class (ol.source.Vector) that enable us to perform queries, such as finding out what features are within a custom extent (getFeaturesInExtent), or returning any features at a particular coordinate (getFeaturesAtCoordinate), as well as other useful types of queries.

We are going to create a map with a tile raster layer and a vector layer with features from a custom GeoJSON file. The polygon features will represent campsites within a region, each with some properties that can be extracted for display. We will call the getFeaturesAtCoordinate source query method when the map is clicked on and display the applicable feature information within overlay if a feature exists at this coordinate.

The source code can be found in ch05/ch05-feature-info-from-source, and...