| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | * Project: NodeMap2.0
|
|---|
| 4 | * File: KMLPlacemark.class.php
|
|---|
| 5 | * Purpose: Placemark used in KMLFile
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | define('LINE_BLACK', 'blackLine');
|
|---|
| 9 |
|
|---|
| 10 | class KMLLine {
|
|---|
| 11 | private $template = '
|
|---|
| 12 | <Placemark id="%ID%">
|
|---|
| 13 | <name>%NAME%</name>
|
|---|
| 14 | <description>
|
|---|
| 15 | <![CDATA[
|
|---|
| 16 | <img src="http://www.wirelessleiden.nl/sites/wirelessleiden.nl/files/garland-wl_logo.png" alt="Wireless Leiden" title="Wireless Leiden" style="float: right;"/>
|
|---|
| 17 | %DESCRIPTION%
|
|---|
| 18 | ]]>
|
|---|
| 19 | </description>
|
|---|
| 20 | <LookAt>
|
|---|
| 21 | <longitude>%LONGITUDE1%</longitude>
|
|---|
| 22 | <latitude>%LATITUDE1%</latitude>
|
|---|
| 23 | <altitude>0</altitude>
|
|---|
| 24 | <heading>0</heading>
|
|---|
| 25 | <tilt>0</tilt>
|
|---|
| 26 | <range>500</range>
|
|---|
| 27 | </LookAt>
|
|---|
| 28 | <styleUrl>%STYLE%</styleUrl>
|
|---|
| 29 | <LineString>
|
|---|
| 30 | <coordinates>
|
|---|
| 31 | %LONGITUDE1%, %LATITUDE1%, 0.
|
|---|
| 32 | %LONGITUDE2%, %LATITUDE2%, 0.
|
|---|
| 33 | </coordinates>
|
|---|
| 34 | </LineString>
|
|---|
| 35 | </Placemark>';
|
|---|
| 36 |
|
|---|
| 37 | private $id; // ID of the line
|
|---|
| 38 | private $name; // Name of the line
|
|---|
| 39 | private $description; // Description of the line
|
|---|
| 40 | private $style; // Style of the line
|
|---|
| 41 | private $longitude1; // Start longitude of line
|
|---|
| 42 | private $latitude1; // Start latitude of line
|
|---|
| 43 | private $longitude2; // End longitude of line
|
|---|
| 44 | private $latitude2; // End latitude of line
|
|---|
| 45 |
|
|---|
| 46 | /*
|
|---|
| 47 | * Function: __construct (constructor)
|
|---|
| 48 | * Description: Creating a new KMLLine
|
|---|
| 49 | * Parameters: -
|
|---|
| 50 | * Returns: -
|
|---|
| 51 | */
|
|---|
| 52 | function __construct() {
|
|---|
| 53 | $this->id = '';
|
|---|
| 54 | $this->name = '';
|
|---|
| 55 | $this->description = '';
|
|---|
| 56 | $this->longitude = 0;
|
|---|
| 57 | $this->latitude = 0;
|
|---|
| 58 | $this->style = LINE_BLACK;
|
|---|
| 59 | $this->longitude1 = 0;
|
|---|
| 60 | $this->latitude1 = 0;
|
|---|
| 61 | $this->longitude2 = 0;
|
|---|
| 62 | $this->latitude2 = 0;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | /*
|
|---|
| 66 | * Function: setID
|
|---|
| 67 | * Description: Setting the ID of the placemark
|
|---|
| 68 | * Parameters: string $newID
|
|---|
| 69 | * Returns: -
|
|---|
| 70 | */
|
|---|
| 71 | function setID($newID) {
|
|---|
| 72 | $this->id = $newID;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | /*
|
|---|
| 76 | * Function: setName
|
|---|
| 77 | * Description: Setting the name of the placemark
|
|---|
| 78 | * Parameters: string $newName
|
|---|
| 79 | * Returns: -
|
|---|
| 80 | */
|
|---|
| 81 | function setName($newName) {
|
|---|
| 82 | $this->name = $newName;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | /*
|
|---|
| 86 | * Function: getName
|
|---|
| 87 | * Description: Getting the name of the placemark
|
|---|
| 88 | * Parameters: -
|
|---|
| 89 | * Returns: The name of the placemark
|
|---|
| 90 | */
|
|---|
| 91 | function getName() {
|
|---|
| 92 | return $this->name;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | /*
|
|---|
| 96 | * Function: setDescription
|
|---|
| 97 | * Description: Setting the description of the placemark
|
|---|
| 98 | * Parameters: string $newDescription
|
|---|
| 99 | * Returns: -
|
|---|
| 100 | */
|
|---|
| 101 | function setDescription($newDescription) {
|
|---|
| 102 | $this->description = (string) $newDescription;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | /*
|
|---|
| 106 | * Function: setStyle
|
|---|
| 107 | * Description: Setting the style of the placemark
|
|---|
| 108 | * Parameters: string $newStyle
|
|---|
| 109 | * Returns: -
|
|---|
| 110 | */
|
|---|
| 111 | function setStyle($newStyle) {
|
|---|
| 112 | $this->style = (string) $newStyle;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | /*
|
|---|
| 116 | * Function: setLongitude1
|
|---|
| 117 | * Description: Setting the longitude1 of the placemark
|
|---|
| 118 | * Parameters: double $newLongitude
|
|---|
| 119 | * Returns: -
|
|---|
| 120 | */
|
|---|
| 121 | function setLongitude1($newLongitude) {
|
|---|
| 122 | $this->longitude1 = (double) $newLongitude;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | /*
|
|---|
| 126 | * Function: setLatitude1
|
|---|
| 127 | * Description: Setting the latitude1 of the placemark
|
|---|
| 128 | * Parameters: double $newLatitude
|
|---|
| 129 | * Returns: -
|
|---|
| 130 | */
|
|---|
| 131 | function setLatitude1($newLatitude) {
|
|---|
| 132 | $this->latitude1 = (double) $newLatitude;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | /*
|
|---|
| 136 | * Function: setLongitude2
|
|---|
| 137 | * Description: Setting the longitude2 of the placemark
|
|---|
| 138 | * Parameters: double $newLongitude
|
|---|
| 139 | * Returns: -
|
|---|
| 140 | */
|
|---|
| 141 | function setLongitude2($newLongitude) {
|
|---|
| 142 | $this->longitude2 = (double) $newLongitude;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | /*
|
|---|
| 146 | * Function: setLatitude2
|
|---|
| 147 | * Description: Setting the latitude2 of the placemark
|
|---|
| 148 | * Parameters: double $newLatitude
|
|---|
| 149 | * Returns: -
|
|---|
| 150 | */
|
|---|
| 151 | function setLatitude2($newLatitude) {
|
|---|
| 152 | $this->latitude2 = (double) $newLatitude;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | /*
|
|---|
| 156 | * Function: isConnected
|
|---|
| 157 | * Description: Check if it is really a line or just a dot
|
|---|
| 158 | * Parameters: -
|
|---|
| 159 | * Returns: true if the line is connected, otherwise false
|
|---|
| 160 | */
|
|---|
| 161 | function isConnected() {
|
|---|
| 162 | if (($this->latitude2 == 0) || ($this->longitude2 == 0)) {
|
|---|
| 163 | return false;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | // This is a line!
|
|---|
| 167 | return true;
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | /*
|
|---|
| 171 | * Function: toString
|
|---|
| 172 | * Description: Converts the content of this placemark to a KML valid string
|
|---|
| 173 | * Parameters: -
|
|---|
| 174 | * Returns: KML valid string
|
|---|
| 175 | */
|
|---|
| 176 | function toString() {
|
|---|
| 177 | $toString = $this->template;
|
|---|
| 178 |
|
|---|
| 179 | $toString = str_replace('%ID%', $this->id, $toString);
|
|---|
| 180 | $toString = str_replace('%NAME%', $this->name, $toString);
|
|---|
| 181 | $toString = str_replace('%DESCRIPTION%', $this->description, $toString);
|
|---|
| 182 | $toString = str_replace('%STYLE%', $this->style, $toString);
|
|---|
| 183 | $toString = str_replace('%LONGITUDE1%', $this->longitude1, $toString);
|
|---|
| 184 | $toString = str_replace('%LATITUDE1%', $this->latitude1, $toString);
|
|---|
| 185 | $toString = str_replace('%LONGITUDE2%', $this->longitude2, $toString);
|
|---|
| 186 | $toString = str_replace('%LATITUDE2%', $this->latitude2, $toString);
|
|---|
| 187 |
|
|---|
| 188 | return $toString;
|
|---|
| 189 | }
|
|---|
| 190 | }
|
|---|
| 191 | ?>
|
|---|