Adding a KML layer
The arrival of Google Maps leads to an explosion in the world of GIS and web mapping. Google introduced not only an API but also some file formats.
The Keyhole Markup Language (KML) had become one of the most extensively used formats, and finally it became an OGC standard.
This recipe 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 available on the Packt Publishing website.
How to do it...
Create an HTML file including the OpenLayers library and insert the following code in it. First, add the
DOM
element that will hold the map:<!-- Map DOM element --> <div id="ch3_kml" style="width: 100%; height: 100%;"></div>
Next, initialize a map instance, add a base layer, add a layer switcher control, and center the view:
<!-- The magic comes here --> <script type="text/javascript"> // Create the map using the specified DOM element var map...