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

Reading features directly using AJAX

The goal of this recipe is to show us how we can work directly with AJAX requests and load content from different data sources on the same vector layer.

OpenLayers allows us to read data from different origins and sources. We've seen that we can connect to a variety of services (such as WMS and WFS) and/or customize the request according to our needs (such as providing a URL directly pointing to a GML file).

We've seen that providing a URL and format type to the vector source is convenient and works for many cases. OpenLayers makes the AJAX request for us and automatically formats the response. However, there are times when we need even more control over the AJAX request and response, and this is where the loader function comes into play.

We have chosen to use jQuery to perform the AJAX requests. The requests will pull in two separate geometry files of different formats and add them both to the same vector layer. The source code for this recipe can be found...