<<back

Code Sample 1 - test API functions.

A demo is provided to demonstrate the API and serve as a base for your application. Download full source code and executable here.

The demo places QuakeMap view (Camera) in Seattle area and ensures color imagery is used. Every click on the "Start / Single" button raises the Camera 20 meters. Clicking "Loop 20" button does it 20 times. Clicking "Pass File" button makes QuakeMap open a GPX, LOC, ZIP or GPZ file (download sample file here (GPZ) or here (ZIP)).

This demo allows you to create waypoints, vehicles, switch map style, move vehicles around etc.

This is how some of the code (C#) looks like:

		private double altMeters = 500.0d;

		private void startButton_Click(object sender, System.EventArgs e)
		{
			step();
		}

		private void step()
		{
			string strCmd = "/lat=47.55|/lon=-122.135|/map=color|/elev=" + altMeters;

			traceLabel.Text = "Camera at " + altMeters + " meters";
	
			altMeters+= 20.0d;

			try
			{
				qmApiLib.CommandMappingEngine(strCmd);
			}
			catch (Exception exc)
			{
				traceLabel.Text = exc.Message;
			}
		}

		private Thread m_workerThread = null;

		private void loopButton_Click(object sender, System.EventArgs e)
		{
			m_workerThread =	new Thread( new ThreadStart(doWork1));
			m_workerThread.IsBackground = true;	// terminate with the main process
			m_workerThread.Name = "Worker";
			m_workerThread.Priority = ThreadPriority.BelowNormal;
			m_workerThread.Start();
		}

		private void doWork1()
		{
			for (int i=0; i < 20 ;i++)
			{
				Thread.Sleep(1000);
				step();
			}
		}

		/// 
		/// make QuakeMap open a file and zoom into it
		/// 
		/// 
		/// 
		private void fileButton_Click(object sender, System.EventArgs e)
		{
			try
			{
				string strCmd = "/map=aerial";
				qmApiLib.CommandMappingEngine(strCmd);

				strCmd = fileTextBox.Text;
				qmApiLib.CommandMappingEngine(strCmd);
			}
			catch (Exception exc)
			{
				traceLabel.Text = exc.Message;
			}
		}

		/// 
		/// Create 20 waypoints and keep them in view
		/// 
		/// 
		/// 
		private void createWptButton_Click(object sender, System.EventArgs e)
		{
			m_workerThread =	new Thread( new ThreadStart(doWork2));
			m_workerThread.IsBackground = true;	// terminate with the main process
			m_workerThread.Name = "Worker";
			m_workerThread.Priority = ThreadPriority.BelowNormal;
			m_workerThread.Start();
		}

		private void doWork2()
		{
			try
			{
				// first make sure we are at a good altitude:
				string strCmd = "/map=aerial|/elev=6000";
				qmApiLib.CommandMappingEngine(strCmd);
				
				qmApiLib.resetZoom();		// prepare for a zoom into whole set of waypoints created below

				// now create 20 waypoints:
				for (int i=0; i < 20 ;i++)
				{
					CreateInfo ci = new CreateInfo();

					ci.lng = -117.123 + ( i / 100.0d);
					ci.lat = 34.123 + ( i / 100.0d);
					ci.name = "GC" + i;
					ci.urlName = "Waypoint" + i;
					ci.type = "geocache";				// "waypoint"
					ci.typeExtra = (i % 2 == 0) ? "Geocache" : "Geocache Found";		// "Hospital"
					ci.url = "http://www.ntsb.gov/ntsb/brief.asp?ev_id=20001212X22305";
					ci.source = "My API Demo";

					bool keepInView = true;

					traceLabel.Text = "Creating Waypoint" + i;

					qmApiLib.createWaypoint(ci, keepInView);

					Thread.Sleep(1000);		// just to have a visual effect of following the points as they are created
				}

				// perform zoom into the whole set of  zoom rectangle:
				// qmApiLib.doZoom();
			}
			catch (Exception exc)
			{
				traceLabel.Text = exc.Message;
			}
		}

Click here to see Sample 2 - an NTSB data importer.