Adding a GML layer
The Geography Markup Language (GML) is an XML grammar used to express geographic features. It is an OGC standard and is very well accepted by the GIS community.
In this recipe, we will show you how to create a vector layer from a GML file.
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...
Create an HTML file with the required OpenLayers dependencies and insert the following code. First add the
div
element to hold the map:<!-- Map DOM element --> <div id="ch3_gml" style="width: 100%; height: 100%;"></div>
Next, add the JavaScript code to initialize the map, add a base layer, and a layer switcher control:
<!-- The magic comes here --> <script type="text/javascript"> // Create the map using the specified DOM element var map = new OpenLayers.Map("ch3_gml"); var layer = new OpenLayers.Layer.OSM("OpenStreetMap"); map.addLayer...