<?php
/*
 * Project: NodeMap2.0
 * File: KMLPlacemark.class.php
 * Purpose: Placemark used in KMLFile
 */

define('PLACEMARK_GREEN', 'greenArrowIcon');
define('PLACEMARK_ORANGE', 'orangeArrowIcon');
define('PLACEMARK_RED', 'redArrowIcon');

class KMLPlacemark {
	private $template = '
		<Placemark id="%ID%">
			<name>%NAME%</name>
			<description>
				<![CDATA[
					<img src="http://www.wirelessleiden.nl/sites/wirelessleiden.nl/files/garland-wl_logo.png" alt="Wireless Leiden" title="Wireless Leiden" style="float: right;"/>
					%DESCRIPTION%
				]]>
			</description>
			<LookAt>
				<longitude>%LONGITUDE%</longitude>
				<latitude>%LATITUDE%</latitude>
				<altitude>0</altitude>
				<heading>0</heading>
				<tilt>0</tilt>
				<range>500</range>
			</LookAt>
			<styleUrl>%STYLE%</styleUrl>
			<Point>
				<altitudeMode>relativeToGround</altitudeMode>
				<coordinates>%LONGITUDE%,%LATITUDE%</coordinates>
			</Point>
		</Placemark>';

	private $id;					// ID of the node
	private $name;					// Name of the node
	private $descriptionLocation;	// Location information of the node
	private $descriptionStatus;		// Status information of the node
	private $longitude;				// Longitude of the node
	private $latitude;				// Latitude of the node
	private $style;					// Style of the placemark

	/*
	 * Function: __construct (constructor)
	 * Description: Creating a new KMLFile
	 * Parameters: -
	 * Returns: -
	 */
	function __construct() {
		$this->id = '';
		$this->name = '';
		$this->descriptionLocation = '';
		$this->descriptionStatus = '';
		$this->longitude = 0;
		$this->latitude = 0;
		$this->style = 'orangeArrowIcon';
	}

	/*
	 * Function: setID
	 * Description: Setting the ID of the placemark
	 * Parameters: string $newID
	 * Returns: -
	 */
	function setID($newID) {
		$this->id = $newID;
	}

	/*
	 * Function: setName
	 * Description: Setting the name of the placemark
	 * Parameters: string $newName
	 * Returns: -
	 */
	function setName($newName) {
		$this->name = $newName;
	}

	/*
	 * Function: getName
	 * Description: Getting the name of the placemark
	 * Parameters: -
	 * Returns: The name of the placemark
	 */
	function getName() {
		return $this->name;
	}

	/*
	 * Function: setDescriptionLocation
	 * Description: Setting the location description of the placemark
	 * Parameters: string $newDescriptionLocation
	 * Returns: -
	 */
	function setDescriptionLocation($newDescriptionLocation) {
		$this->descriptionLocation = (string) $newDescriptionLocation;
	}

	/*
	 * Function: setDescriptionStatus
	 * Description: Setting the status description of the placemark
	 * Parameters: string $newDescriptionStatus
	 * Returns: -
	 */
	function setDescriptionStatus($newDescriptionStatus) {
		$this->descriptionStatus = (string) $newDescriptionStatus;
	}

	/*
	 * Function: setLongitude
	 * Description: Setting the longitude of the placemark
	 * Parameters: string $newLongitude
	 * Returns: -
	 */
	function setLongitude($newLongitude) {
		$this->longitude = (double) $newLongitude;
	}

	/*
	 * Function: setLatitude
	 * Description: Setting the latitude of the placemark
	 * Parameters: string $newLatitude
	 * Returns: -
	 */
	function setLatitude($newLatitude) {
		$this->latitude = (double) $newLatitude;
	}

	/*
	 * Function: setStyle
	 * Description: Setting the style of the placemark
	 * Parameters: string $newStyle
	 * Returns: -
	 */
	function setStyle($newStyle) {
		$this->style = (string) $newStyle;
	}

	/*
	 * Function: toString
	 * Description: Converts the content of this placemark to a KML valid string
	 * Parameters: -
	 * Returns: KML valid string
	 */
	function toString() {
		$toString = $this->template;

		$toString = str_replace('%ID%', $this->id, $toString);
		$toString = str_replace('%NAME%', $this->name, $toString);
		$toString = str_replace('%DESCRIPTION%', $this->descriptionLocation . $this->descriptionStatus, $toString);
		$toString = str_replace('%LONGITUDE%', $this->longitude, $toString);
		$toString = str_replace('%LATITUDE%', $this->latitude, $toString);
		$toString = str_replace('%STYLE%', $this->style, $toString);
		
		return $toString;
	}
}
?>