KML (Keyhole Markup Language) is a popular format for vector GIS features due to its association with Google Earth and Google Maps. KML is just XML formatted according to an open specification, previously maintained by Google but now enshrined in an OGC standard. Although KML can define the placement of raster layers, we will focus on vector KML in this lesson. The key XML tag behind KML is the placemark. This defines a geographic feature, a symbol, and extra information that can appear in a popup. You can see some placemarks if you save the example KML file http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/kml/sundials.kml (link is external) and open it in a text editor. This isn’t the cleanest file, but it will do for the purposes of seeing a placemark: This particular placemark has a single coordinate, contained in the Point tag. For polylines and polygons, the LineString and Polygon tags are used, respectively, although these do not appear in the above example. The full KML file is much longer, and luckily you do not have to parse it. The OpenLayers.Layer.Vector class allows you to just supply the path of the KML, and OpenLayers will do the rest of the work of displaying the contents. Take a look at the KML Layer Example (link is external), and view the page source code. Then find and scrutinize the following code block to understand how the KML was added into the map: Notice how the strategy is defined as Fixed. This means that all the features in the KML file will be loaded into the browser at the time the map is loaded. The KML is invoked using the OpenLayers.Protocol.HTTP (link is external) object (as opposed to the OpenLayers.Protocol.SQL object which connects to databases). You have to specify the path to the file (which can be a full URL or a relative path like the one above) and then specify that the format is OpenLayers.Format.KML (link is external). If you look at all the OpenLayers.Format (link is external) classes in the API reference table of contents (see sidebar on the left, click on ‘Format’ to unfold the list), you will see many types of data you can add to your map as vectors. Again, don’t worry about memorizing all the syntax. In most scenarios, you should just be able to tweak the above example to connect to your own KML. The API reference and other online samples can help you further with understanding all the available properties. This courseware module is part of Penn State’s College of Earth and Mineral Sciences’ OER Initiative (link is external). Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License (link is external). The College of Earth and Mineral Sciences is committed to making its websites accessible to all users, and welcomes comments or suggestions on access improvements. Please send comments or suggestions on accessibility to the site editor (link sends e-mail). The site editor may also be contacted with questions or comments about this Open Educational Resource. The John A. Dutton e-Education Institute is the learning design unit of the College of Earth and Mineral Sciences (link is external) at The Pennsylvania State University (link is external). 2217 Earth and Engineering Sciences Building, University Park, Pennsylvania 16802 (link is external) 877-778-4471 | Contact Us Privacy & Legal Statements (link is external) | Copyright Information (link is external) The Pennsylvania State University © 2014 Source.