#ifndef KML_HPP
#define KML_HPP

#include "../JuceLibraryCode/JuceHeader.h"
#include "IHttp.hpp"
#include "IKml.hpp"

class Kml : public IKml, public IHttpListener
{
public:
	Kml(const char *pDocRoot);
	~Kml(void);

	void createNetworkLinkFile(String const &filename, String const &hostIp);
	void setAltitudeMode(String const &modeString);
	void setPathColor(String const &colorString);
	void setCameraAltitude(float alt_meters);
	void setCameraTilt(float tilt_deg);
	void setCameraAutoHeading(bool enable);
	void setCameraAutoRoll(bool enable);
	void setCameraFlyToView(bool enable);
	
private:
	CriticalSection m_lock;
	ScopedPointer<XmlElement> m_pKml;
	XmlElement *m_pTrackPlaceMark;
	char m_path[1024];
	const char *m_docRoot;
	String m_altitudeModeString;
	String m_pathColorString;
	float m_cameraAlt;
	float m_cameraTilt;
	bool m_cameraAutoHeading;
	bool m_cameraAutoRoll;
	bool m_cameraFlyToView;
	FlightData m_flightData;
	void create();
	void destroy();
	const char* getPath();
	void updateFlightData(FlightData const &flightData);
	void update(FlightData const &flightData);
	void exportKml(const char *pPath);
	void exportKmz(const char *pPath);
	void updatePlane();
	void updateTrack();
	void onUpdate(const char *pPath, ViewFormat const &viewFormat);
	
	XmlElement* createNetworkLinkControl();
	XmlElement* createPlane();
	XmlElement* createTrack();
};

#endif // !KML_HPP
