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 and creating features from a WKT

As we're already discovering, OpenLayers comes with a great set of format helpers, which are used to read/write from/to different file data formats. GeoJSON, GML, and KML are some of the many available formats that we already explored.

If you read the Adding a GML layer recipe in this chapter, you will know that a vector layer can read the features stored in a file, specify the format of the data source, and place the contained features in the map.

For this recipe, we will programmatically create a polygon in the WKT format and then export the feature as WKT from the vector layer. You can read more about the WKT GIS format on Wikipedia ( The source code can be found in ch03/ch03-wkt-format/. Here's what we'll end up with:

How to do it…

  1. Create a new HTML file with OpenLayers dependencies. In particular, add the HTML to create the map and side panel, as follows:

    <div id="js-map"></div>