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
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Adding a GML layer


The Geography Markup Language (GML) is an XML grammar that is used to express geographic features. It is an OGC standard and is very widely accepted by the GIS community.

In this recipe (the source code is in ch03/ch03-gml-layer/), we will show you how to create a vector layer from a GML file which can be seen in the following screenshot:

Note

You can find the necessary files in the GML format attached to the source code of this book on the Packt Publishing website.

How to do it…

In order to import features in GML format into the map, follow these instructions:

  1. Create an HTML file with the required OpenLayers dependencies and prepare the div element to hold the map:

    <div id="js-map"></div>
  2. Create the JavaScript file to initialize the map with a base layer, then add the vector layer pointing to the GML source, as follows:

    var map = new ol.Map({
      view: new ol.View({
        zoom: 4,
        center: [-7494000, 2240000]
      }),
      target: 'js-map',
      layers: [
        new ol.layer.Tile...