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:
- Create an HTML file with the required OpenLayers dependencies and prepare the
div
element to hold the map:<div id="js-map"></div>
- 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...