-
Notifications
You must be signed in to change notification settings - Fork 0
/
KMLParserDemo.php
85 lines (56 loc) · 2.38 KB
/
KMLParserDemo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>simpleGeo KML Parser Example</title>
<style type="text/css">
body{font-family: sans serif;}
h3{margin: 0 0 0 10px;}
ul{margin: 15px 0 15px 20px;}
</style>
</head>
<body>
<h1 id="title">KML Parser Example</h1>
<div id="tags"></div>
<p id="shortdesc">
Demonstrate the operation of the KML parser with this KML file :
<a href="http://code.google.com/apis/kml/documentation/KML_Samples.kml">code.google.com/apis/kml/documentation/KML_Samples.kml</a>
</p>
<div id="output">
<?php $url = '<script type="text/javascript">document.write(document.getElementById(\'file_url\'))</script>'; ?>
<?php
require_once('lib/Format/KML.class.php');
$options = array("extractStyles"=>true);
$test = new KML($options);
/** read **/
$features = $test->read("http://code.google.com/apis/kml/documentation/KML_Samples.kml");
$html = "";
foreach($features as $feature):
$html .= "<h2>Geometry : <b>" . get_class($feature->geometry) ."</b></h2>";
if(count($feature->attributes) > 0):
$html .= "<h3>attributes : </h3>";
$html .= "<ul>";
foreach($feature->attributes as $key => $value)
{
$html .= "<li>" . $key. " : " . $value . "</li>";
}
$html .= "</ul>";
endif;
if(count($feature->style) > 0):
$html .= "<h3>style : </h3>";
foreach($feature->style as $style)
{
$html .= "<ul>";
foreach($style as $key => $value)
{
$html .= "<li>" . $key. " : " . $value . "</li>";
}
$html .= "</ul>";
}
endif;
endforeach;
echo $html;
?>
</div>
<h2>PHP object structure :</h2>
<?php var_dump($features); ?>
</body>
</html>