1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
//---------------------------------------------------------------------------
// gmview.c: google map view
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <mshtml.h>
#include "rtklib.h"
#include "gmview.h"
#define RTKLIB_GM_FILE L"rtklib_gmap.htm"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SHDocVw_OCX"
#pragma resource "*.dfm"
TGoogleMapView *GoogleMapView;
//---------------------------------------------------------------------------
__fastcall TGoogleMapView::TGoogleMapView(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TGoogleMapView::FormCreate(TObject *Sender)
{
UnicodeString url,exe,dir=L".";
wchar_t *p,*q;
exe=Application->ExeName; // exe directory
p=exe.c_str();
if ((q=wcsrchr(p,L'\\'))) {
dir=exe.SubString(1,q-p);
}
url=L"file://"+dir+L"\\"+RTKLIB_GM_FILE;
WebBrowser->Navigate(url.c_str());
}
//---------------------------------------------------------------------------
int __fastcall TGoogleMapView::GetState(void)
{
IHTMLDocument3 *doc=NULL;
IHTMLElement *ele1=NULL;
VARIANT var;
int state;
if (!WebBrowser->Document) return 0;
WebBrowser->Document->QueryInterface(IID_IHTMLDocument3,(void **)&doc);
if (!doc) return 0;
doc->getElementById(L"state",&ele1);
doc->Release();
if (!ele1) return 0;
VariantInit(&var);
if (ele1->getAttribute(L"value",0,&var)!=S_OK) {
VariantClear(&var);
return 0;
}
swscanf(var.bstrVal,L"%d",&state);
VariantClear(&var);
return state;
}
//---------------------------------------------------------------------------
void __fastcall TGoogleMapView::BtnCloseClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TGoogleMapView::BtnHomeClick(TObject *Sender)
{
ShowHome();
}
//---------------------------------------------------------------------------
void __fastcall TGoogleMapView::ShowHome(void)
{
ExecFunc("ShowHome()");
}
//---------------------------------------------------------------------------
void __fastcall TGoogleMapView::ClearMark(void)
{
ExecFunc("ClearMark()");
}
//---------------------------------------------------------------------------
void __fastcall TGoogleMapView::AddMark(double lat, double lon,
AnsiString title, AnsiString msg)
{
AnsiString f;
ExecFunc(f.sprintf("AddMark(%.7f,%.7f,\"%s\",\"%s\")",lat,lon,title,msg));
}
//---------------------------------------------------------------------------
void __fastcall TGoogleMapView::PosMark(double lat, double lon,
AnsiString title)
{
AnsiString f;
ExecFunc(f.sprintf("PosMark(%.7f,%.7f,\"%s\")",lat,lon,title));
}
//---------------------------------------------------------------------------
void __fastcall TGoogleMapView::HighlightMark(AnsiString title)
{
AnsiString f;
ExecFunc(f.sprintf("HighlightMark(\"%s\")",title));
}
//---------------------------------------------------------------------------
void __fastcall TGoogleMapView::ExecFunc(AnsiString func)
{
IHTMLWindow2 *win;
IHTMLDocument2 *doc=NULL;
VARIANT var;
HRESULT hr;
wchar_t func_w[1024]={0};
if (!WebBrowser->Document) return;
WebBrowser->Document->QueryInterface(IID_IHTMLDocument2,(void **)&doc);
if (!doc) return;
hr=doc->get_parentWindow(&win);
doc->Release();
if (hr!=S_OK) return;
VariantInit(&var);
::MultiByteToWideChar(CP_UTF8,0,func.c_str(),-1,func_w,512);
hr=win->execScript(func_w,L"javascript",&var);
VariantClear(&var);
}
//---------------------------------------------------------------------------
|