Skip to content

Commit 56f19aa

Browse files
committed
Merge pull request #1 from yariksheptykin/master
Enabling XMLBuilder to handle creation of time primitives and documents inside folders
2 parents 07b4fc1 + 958c058 commit 56f19aa

5 files changed

Lines changed: 141 additions & 5 deletions

File tree

libKML/KMLBuilder.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function processContainer(&$container, $containerXMLObject) {
6464
$containerContent = $containerXMLObject->children();
6565

6666
$object_properties = array('NetworkLink', 'Placemark', 'PhotoOverlay', 'ScreenOverlay', 'GroundOverlay',
67-
'Folder');
67+
'Folder', 'Document');
6868

6969
foreach($containerContent as $key => $value) {
7070
if (in_array($key, $object_properties)) {
@@ -644,6 +644,16 @@ function buildKML($kmlXMLObject) {
644644
return $kml;
645645
}
646646

647+
function buildTimeStamp($kmlXMLObject) {
648+
$kml = new TimeStamp();
649+
$kml->setWhen($kmlXMLObject->when);
650+
return $kml;
651+
}
647652

648-
649-
?>
653+
function buildTimeSpan($kmlXMLObject) {
654+
$kml = new TimeSpan();
655+
$kml->setBegin($kmlXMLObject->begin);
656+
$kml->setEnd($kmlXMLObject->end);
657+
return $kml;
658+
}
659+
?>

libKML/time/TimePrimitive.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
* TimePrimitive abstract class
66
*/
77

8-
abstract class TimePrimitive extends KMLObject {}
9-
?>
8+
abstract class TimePrimitive extends KMLObject {
9+
public function __toString() {
10+
return "";
11+
}
12+
}
13+
?>

libkml.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
include_once('libKML/views/Camera.php');
8787
include_once('libKML/views/LookAt.php');
8888
include_once('libKML/KMLBuilder.php');
89+
include_once('libKML/time/TimePrimitive.php');
90+
include_once('libKML/time/TimeSpan.php');
91+
include_once('libKML/time/TimeStamp.php');
8992

9093

9194
function parseKML($data) {

test/phpunit_test_time.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
require __DIR__ . '/../libkml.php';
4+
5+
class TimePrimitiveTest extends PHPUnit_Framework_TestCase
6+
{
7+
8+
const SAMPLE_KML = __DIR__ . '/sample-time.kml';
9+
10+
public function testKmlParsing()
11+
{
12+
// Checking if the document was correctly parsed.
13+
$kml_data = file_get_contents(self::SAMPLE_KML);
14+
$kml = KML::createFromText($kml_data);
15+
$features = $kml->getAllFeatures();
16+
$this->assertNotEmpty($kml);
17+
$folder = $kml->getFeature();
18+
$this->assertNotEmpty($folder);
19+
$document = $folder->getFeatures()[0];
20+
$this->assertNotEmpty($folder);
21+
$placemarks = $document->getFeatures();
22+
$this->assertNotEmpty($placemarks);
23+
24+
// Checking if the TimeStamp and TimeSpan are converted to xml correctly.
25+
foreach(array('TimeStamp', 'TimeSpan') as $i => $tag) {
26+
$str = $placemarks[$i]->__toString();
27+
$this->assertRegExp("/$tag/", $str);
28+
}
29+
}
30+
}

test/sample-time.kml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<kml xmlns="http://www.opengis.net/kml/2.2"
3+
xmlns:gx="http://www.google.com/kml/ext/2.2">
4+
5+
<Folder>
6+
7+
<name>Document inside a Folder and Placemark with TimeStamp</name>
8+
<open>1</open>
9+
<Style>
10+
<BalloonStyle>
11+
<textColor>ff000000</textColor>
12+
<bgColor>ffffffff</bgColor>
13+
<displayMode>default</displayMode>
14+
</BalloonStyle>
15+
</Style>
16+
17+
<Document>
18+
<name>gx:AnimatedUpdate example</name>
19+
20+
<Style id="pushpin">
21+
<IconStyle id="mystyle">
22+
<Icon>
23+
<href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
24+
<scale>1.0</scale>
25+
</Icon>
26+
</IconStyle>
27+
</Style>
28+
29+
<Placemark id="mountainpin1">
30+
<name>Pin on a mountaintop</name>
31+
<styleUrl>#pushpin</styleUrl>
32+
<TimeStamp><when>2009-07-28T17:32:43Z</when></TimeStamp>
33+
<Point>
34+
<coordinates>170.1435558771009,-43.60505741890396,0</coordinates>
35+
</Point>
36+
</Placemark>
37+
38+
<Placemark id="mountainpin2">
39+
<name>Pin on a mountaintop</name>
40+
<styleUrl>#pushpin</styleUrl>
41+
<TimeSpan>
42+
<begin>2009-07-28T17:32:43Z</begin>
43+
<end>2009-07-28T17:35:43Z</end>
44+
</TimeSpan>
45+
<Point>
46+
<coordinates>170.1435558771009,-43.60505741890396,0</coordinates>
47+
</Point>
48+
</Placemark>
49+
50+
<gx:Tour>
51+
<name>Play me!</name>
52+
53+
<gx:Playlist>
54+
55+
<gx:FlyTo>
56+
<gx:flyToMode>bounce</gx:flyToMode>
57+
<gx:duration>3</gx:duration>
58+
<Camera>
59+
<longitude>170.157</longitude>
60+
<latitude>-43.671</latitude>
61+
<altitude>9700</altitude>
62+
<heading>-6.333</heading>
63+
<tilt>33.5</tilt>
64+
</Camera>
65+
</gx:FlyTo>
66+
67+
<gx:AnimatedUpdate>
68+
<gx:duration>5</gx:duration>
69+
<Update>
70+
<targetHref></targetHref>
71+
<Change>
72+
<IconStyle targetId="mystyle">
73+
<scale>10.0</scale>
74+
</IconStyle>
75+
</Change>
76+
</Update>
77+
</gx:AnimatedUpdate>
78+
79+
<gx:Wait>
80+
<gx:duration>5</gx:duration>
81+
</gx:Wait>
82+
83+
</gx:Playlist>
84+
</gx:Tour>
85+
86+
</Document>
87+
88+
</Folder>
89+
</kml>

0 commit comments

Comments
 (0)