1
<html xmlns="http://www.w3.org/1999/xhtml">
3
<title>OpenLayers KML Parser Example</title>
4
<link rel="stylesheet" href="style.css" type="text/css" />
5
<script src="../lib/OpenLayers.js"></script>
6
<script type="text/javascript">
7
function parseData(req) {
8
g = new OpenLayers.Format.KML({extractStyles: true});
10
features = g.read(req.responseText);
11
for(var feat in features) {
12
html += "Feature: Geometry: "+ features[feat].geometry+",";
14
for (var j in features[feat].attributes) {
15
html += "<li>Attribute "+j+":"+features[feat].attributes[j]+"</li>";
19
for (var j in features[feat].style) {
20
html += "<li>Style "+j+":"+features[feat].style[j]+"</li>";
24
document.getElementById('output').innerHTML = html;
27
OpenLayers.loadURL("kml/lines.kml", "", null, parseData);
31
<body onload="load()">
32
<h1 id="title">KML Parser Example</h1>
37
Demonstrate the operation of the KML parser.
40
<div id="output"></div>
43
This script reads data from a KML file and parses out the coordinates, appending them to a HTML string with markup tags.
44
This markup is dumped to an element in the page.