Managed C++ Code to exercise ILayer and IMap
The following code was created in Visual Studio 2003 by starting with Windows Forms Project. I added 3 buttons Connect, Recenter, and AddLine I then added a refrence to the FalconView TLB by right clicking Refrences in the solution Explorer and sellecting Add Refrence. Then select the COM tab and scroll down to FVW.
Then add the following code to the project and compile.
- Sample_Managed_Cpp.zip: Sample Managed C++ aplication
#pragma once
namespace Sample_Managed_C
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
Interop::fvw::Layer* m_pLayer;
Interop::fvw::Map* m_pMap;
int m_LayerHandle;
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Button * Connect;
private: System::Windows::Forms::Button * Recenter;
private: System::Windows::Forms::Button * AddLine;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container * components;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->Connect = new System::Windows::Forms::Button();
this->Recenter = new System::Windows::Forms::Button();
this->AddLine = new System::Windows::Forms::Button();
this->SuspendLayout();
//
// Connect
//
this->Connect->Location = System::Drawing::Point(8, 16);
this->Connect->Name = S"Connect";
this->Connect->Size = System::Drawing::Size(120, 40);
this->Connect->TabIndex = 0;
this->Connect->Text = S"Connect";
this->Connect->Click += new System::EventHandler(this, Connect_Click);
//
// Recenter
//
this->Recenter->Location = System::Drawing::Point(8, 64);
this->Recenter->Name = S"Recenter";
this->Recenter->Size = System::Drawing::Size(120, 40);
this->Recenter->TabIndex = 1;
this->Recenter->Text = S"Recenter";
this->Recenter->Click += new System::EventHandler(this, Recenter_Click);
//
// AddLine
//
this->AddLine->Location = System::Drawing::Point(8, 112);
this->AddLine->Name = S"AddLine";
this->AddLine->Size = System::Drawing::Size(120, 40);
this->AddLine->TabIndex = 2;
this->AddLine->Text = S"Addline";
this->AddLine->Click += new System::EventHandler(this, AddLine_Click);
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 273);
this->Controls->Add(this->AddLine);
this->Controls->Add(this->Recenter);
this->Controls->Add(this->Connect);
this->Name = S"Form1";
this->Text = S"Form1";
this->ResumeLayout(false);
}
ConnectClick
private: System::Void Connect_Click(System::Object ''' sender, System::EventArgs ''' e)
{
try
{
m_pLayer = new Interop::fvw::LayerClass();
m_pLayer->RegisterWithMapServer("My Layer",(int)get_Handle(),this);
m_LayerHandle = m_pLayer->CreateLayer("My Sample Layer");
m_pMap = new Interop::fvw::MapClass();
}
catch (Exception* e)
{
Console::WriteLine("Exception Caught");
}
}
ReCenter
private: System::Void Recenter_Click(System::Object ''' sender, System::EventArgs ''' e)
{
const int CLIENT_MASK_LATITUDE = 1;
const int CLIENT_MASK_LONGITUDE = 2;
const int CLIENT_MASK_ROTATION = 4;
const int CLIENT_MASK_CATEGORY = 8;
const int CLIENT_MASK_SCALE = 16;
const int CLIENT_MASK_ZOOM = 32;
int zoom;
double lat;
double lon;
double rot;
int catagory;
int map;
int projection;
int result = m_pMap->GetMapDisplay(&lat, &lon, &rot, &catagory, &map, &zoom, &projection);
// set up mask to tell FalconView to change only Lat, Lon and Zoom
int mask = CLIENT_MASK_LATITUDE | CLIENT_MASK_LONGITUDE | CLIENT_MASK_ZOOM;
zoom = 200;
lat = 41.24463;
lon = -111.96034;
result = m_pMap->SetMapDisplay(lat,lon,0,catagory,map,zoom,mask,projection);
}
AddLine
private: System::Void AddLine_Click(System::Object ''' sender, System::EventArgs ''' e)
{
int result;
//red with dark grey background 3 pixels wide (solid)
result = m_pLayer->SetPen(m_LayerHandle, 255, 0, 0, 10, 10, 10, 0, 3, 0);
//great circle line
result = m_pLayer->SetLineType(m_LayerHandle, 2);
//line from N41.24 W111.97 to N 33.778 W 084.39
int LineHandle = m_pLayer->AddLine(m_LayerHandle, 41.24005, -111.97176, 33.77845, -84.39846, 0, 0);
}
};
}
-- Main.ChrisBailey - 07 Mar 2005
Attachments
-
Sample_Managed_Cpp.zip
(36.8 KB) - added by CarolynKnabel
18 months ago.
