source: trunk/src/inc/KMLFile.class.php@ 7632

Last change on this file since 7632 was 7632, checked in by Pieter Naber, 16 years ago

Setting up a new and better KML file template with more options!

File size: 3.3 KB
RevLine 
[7627]1<?
2/*
3 * Project: NodeMap2.0
4 * File: KMLHandler.class.php
5 * Purpose: Creating of editing KML files
6 */
7
[7632]8define('PLACEMARK_GREEN', 'http://www.google.com/intl/en_us/mapfiles/ms/micons/green-dot.png');
9define('PLACEMARK_ORANGE', 'http://www.google.com/intl/en_us/mapfiles/ms/micons/orange-dot.png');
10define('PLACEMARK_RED', 'http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png');
11
[7627]12class KMLFile {
[7631]13 private $template = '
[7627]14 <?xml version="1.0" encoding="UTF-8"?>
15 <kml xmlns="http://www.opengis.net/kml/2.2">
[7632]16 <Document>
17 <name>Wireless Leiden Interactive Nodemap 2.0</name>
18 <open>1</open>
19 <description>Wireless Leiden Interactive Nodemap 2.0</description>
20 <Style id="greenArrowIcon">
21 <IconStyle>
22 <Icon>
23 <href>%PLACEMARK_GREEN%</href>
24 </Icon>
25 </IconStyle>
26 </Style>
27 <Style id="orangeArrowIcon">
28 <IconStyle>
29 <Icon>
30 <href>%PLACEMARK_ORANGE%</href>
31 </Icon>
32 </IconStyle>
33 </Style>
34 <Style id="redArrowIcon">
35 <IconStyle>
36 <Icon>
37 <href>%PLACEMARK_RED%</href>
38 </Icon>
39 </IconStyle>
40 </Style>
41 <Folder>
42 <name>Nodes</name>
43 <description>Nodes from the Wireless Leiden network</description>
44 <LookAt>
45 <longitude>52.161087</longitude>
46 <latitude>4.490153</latitude>
47 <altitude>0</altitude>
48 <heading>0</heading>
49 <tilt>0</tilt>
50 <range>500</range>
51 </LookAt>
52 %CONTENT%
53 </Folder>
54 </Document>
[7627]55 </kml>';
[7632]56
[7631]57 private $fileFirst = 'type,host_name,has_been_checked,check_execution_time,current_state,last_hard_state,last_check,problem_has_been_acknowledged';
58 private $fileContent = array('string', 'string', 'integer', 'double', 'integer', 'integer', 'integer', 'integer');
[7627]59
60 private $KMLPlacemarks = array();
61
62 /*
63 * Function: __construct (constructor)
64 * Parameters: -
65 * Function: Creating a new KMLFile
66 */
[7631]67 public function __construct() {
[7627]68 }
69
[7631]70 public function addPlacemark(KMLPlacemark $placemark) {
[7628]71 $this->KMLPlacemarks[] = $placemark;
72 }
73
[7631]74 public function toString() {
75 $toString = $this->template;
[7627]76
77 $placemarkString = '';
78 $placemarkCount = count($this->KMLPlacemarks);
79 for ($i = 0; $i < $placemarkCount; $i++) {
[7631]80 $placemarkString .= $this->KMLPlacemarks[$i]->toString();
[7627]81 }
82
[7632]83 $toString = str_replace('%PLACEMARK_GREEN%', PLACEMARK_GREEN, $toString);
84 $toString = str_replace('%PLACEMARK_ORANGE%', PLACEMARK_ORANGE, $toString);
85 $toString = str_replace('%PLACEMARK_RED%', PLACEMARK_RED, $toString);
[7631]86 $toString = str_replace('%CONTENT%', $placemarkString, $toString);
[7627]87
88 return $toString;
89 }
90
[7631]91 public function write($filename) {
[7627]92 // TODO: Write KMLFile to a KML file
93 }
[7631]94
95 public function parseFile($file) {
96 $fileContents = explode("\r\n", $nodeStatus->getFile());
97
98 if ($fileContents[0] != $this->fileFirst) {
99 // TODO: Better error description
100 trigger_error();
101 }
102
103 $lines = count($fileContents);
104 for ($i = 1; $i < count($lines); $i++) {
105 $lineContent = explode(',', $fileContents[$i]);
106
107 if (count($lineContent) != count($this->fileContent)) {
108 // TODO: Better error description
109 trigger_error();
110 }
111
112 // TODO: Process all lines and create KMLPlacemark objects we can add to a new KMLFile object
113 }
114 }
[7627]115}
116?>
Note: See TracBrowser for help on using the repository browser.