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

Adding a KML layer

The arrival of Google Maps led to an explosion in the world of GIS and web mapping. Google introduced not only an API but also certain file formats.

The Keyhole Markup Language (KML) has become one of the most extensively-used formats, and it has become an OGC standard. For some more details on the KML standard, refer to The following screenshot shows how to create vector layers from a KML file:

This recipe (found in ch03/ch03-kml-layer/) will show you how easy it is to add features from a KML file. You can find the necessary files in the KML format attached to the source code of this book and available on the Packt Publishing website.

How to do it…

In order to import features from KML format into the map, follow these instructions:

  1. Create an HTML file that includes the OpenLayers dependencies and insert a div to contain the map:

    <div id="js-map"></div> 
  2. Create the JavaScript file and initialize the map with a...