//---------------------------------------------------------------------------

#include "FrmVmsCamF.h"
#include <vcl.h>
#include <Mshtml.h>
#include "ITSSkinF.h"
#include "ITSUtilF.h"
#include "XiMapUtilF.h"
#include "CDSTrafficGradeF.h"
#include "CDSFacilityF.h"
#include "CDSIncidentF.h"
#pragma hdrstop

#include "ITS00GEOF.h"
#include "ITS00G0MF.h"
#include "FrmCctvImgF.h"
#include "FrmCctvCamF.h"
#include "FrmVmsMsgF.h"
#include "FrmLinkInfoF.h"
#include "FrmGisSearchF.h"
#include "FrmMainF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxCheckBox"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#pragma link "cxGroupBox"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxMaskEdit"
#pragma link "cxProgressBar"
#pragma link "cxSpinEdit"
#pragma link "cxTextEdit"
#pragma link "dxGDIPlusClasses"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinCaramel"
#pragma link "dxSkinCoffee"
#pragma link "dxSkinDarkRoom"
#pragma link "dxSkinDarkSide"
#pragma link "dxSkinFoggy"
#pragma link "dxSkinGlassOceans"
#pragma link "dxSkiniMaginary"
#pragma link "dxSkinLilian"
#pragma link "dxSkinLiquidSky"
#pragma link "dxSkinLondonLiquidSky"
#pragma link "dxSkinMcSkin"
#pragma link "dxSkinMoneyTwins"
#pragma link "dxSkinOffice2007Black"
#pragma link "dxSkinOffice2007Blue"
#pragma link "dxSkinOffice2007Green"
#pragma link "dxSkinOffice2007Pink"
#pragma link "dxSkinOffice2007Silver"
#pragma link "dxSkinOffice2010Black"
#pragma link "dxSkinOffice2010Blue"
#pragma link "dxSkinOffice2010Silver"
#pragma link "dxSkinsCore"
#pragma link "dxSkinSeven"
#pragma link "dxSkinSharp"
#pragma link "dxSkinSilver"
#pragma link "dxSkinStardust"
#pragma link "GMClasses"
#pragma link "GMMap"
#pragma link "GMMapVCL"
#pragma link "GMLinkedComponents"
#pragma link "GMRectangle"
#pragma link "GMRectangleVCL"
#pragma link "GMGeoCode"
#pragma resource "*.dfm"

//---------------------------------------------------------------------------
TITS00GEO *ITS00GEO = NULL;

//---------------------------------------------------------------------------
__fastcall TITS00GEO::TITS00GEO(TComponent* Owner, TForm *ParentForm)
    : TForm(Owner)
{
    ::CoInitialize(NULL);
    ::OleInitialize(NULL);

    ITSSkin_Load(this);
    LoadLocalSkin();
    
    FRectangle = false;
    FRectangleIdx = 0;

    panRemark->Visible = false;
    
	//마우스 제어 플래그 초기화
    m_bMouseDown  = false;
    m_bMoveCenter = false;
    m_bCalcMode   = false;
    m_bCalcCont   = false;
	m_ptDown.x = m_ptDown.y = 0;

    LoadConfig();
}
//---------------------------------------------------------------------------

/*
 * 환경설정정보 로딩
 *
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TITS00GEO::LoadConfig()
{
#if 0
    TIniFile *pIniFile = NULL;
    String sIniFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".ini");
    String sCfgFile = ExtractFilePath(Application->ExeName) + "\\cfg\\" + sIniFile;

    try
    {
        try
        {
            pIniFile = new TIniFile(sCfgFile);

            // 표출이미지 로딩
            //LoadImageFile(pIniFile->ReadString("IMAGE", "CENTER", ""), ImgOffice);

            LoadImageFile(pIniFile->ReadString("IMAGE", "RSE_N",  ""), ImgRseN);
            LoadImageFile(pIniFile->ReadString("IMAGE", "RSE_C",  ""), ImgRseC);

            LoadImageFile(pIniFile->ReadString("IMAGE", "CCTV_N", ""), ImgCctvN);
            LoadImageFile(pIniFile->ReadString("IMAGE", "CCTV_C", ""), ImgCctvC);
            LoadImageFile(pIniFile->ReadString("IMAGE", "CCTV_M", ""), ImgCctvM);

            LoadImageFile(pIniFile->ReadString("IMAGE", "VMS_N",  ""), ImgVmsN);
            LoadImageFile(pIniFile->ReadString("IMAGE", "VMS_C",  ""), ImgVmsC);
            LoadImageFile(pIniFile->ReadString("IMAGE", "VMS_M",  ""), ImgVmsM);

            LoadImageFile(pIniFile->ReadString("IMAGE", "INC_01", ""), ImgInc01);
            LoadImageFile(pIniFile->ReadString("IMAGE", "INC_02", ""), ImgInc02);
            LoadImageFile(pIniFile->ReadString("IMAGE", "INC_03", ""), ImgInc03);
            LoadImageFile(pIniFile->ReadString("IMAGE", "INC_04", ""), ImgInc04);
        }
        __finally
        {
            if (pIniFile) delete pIniFile;
            pIniFile = NULL;
        }
    }
    catch(...)
    {
    }
#endif
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::LoadImageFile(String sImgFile, TImage *pImage)
{
    if (sImgFile.Trim() == "") return;

    try
    {
        ImgTemp->Picture->Assign(NULL);
        ImgTemp->Picture->LoadFromFile(sImgFile);
        pImage->Picture->Assign(pImage->Picture);

        ImgTemp->Picture->Assign(NULL);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

/*
 * 메인화면 FormDestroy시 호출되는 Method
 * Form의 자원이 해제 되기 이전에 반드시 이 Method가 호출된다.
 * 그러므로 최종적으로 자원을 해제 하고자 한다면 이곳에서 처리하는게 확실함.
 *  parameter
 *      Sender : Event를 보낸 객체
 *  return
 *      None
 */
void __fastcall TITS00GEO::FormDestroy(TObject *Sender)
{
    try
    {
    }
    catch (...)
    {
    }

    ::OleUninitialize();
    ::CoUninitialize();
}
//---------------------------------------------------------------------------

/*
 * form을 보여줄때 호출되는 event 메서드이다.
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TITS00GEO::FormShow(TObject *Sender)
{
    Refresh();
    FormInit();
    Application->ProcessMessages();
    TmrShow->Enabled = true;
}
//---------------------------------------------------------------------------

/*
 * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
 * Form과 DataModule class를 delete시킨다.
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TITS00GEO::CommClose()
{
    //ITS00GEO = NULL;
    //::CoUninitialize();
}
//---------------------------------------------------------------------------

/*
 * Form의 초기화 작업을 수행한다.
 *  arguments
 *      void
 *  return
 *      void
 */
bool __fastcall TITS00GEO::FormInit()
{
    //memset((char*)&m_PrevExt, 0x00, sizeof(m_PrevExt));
    memset((char*)&m_ExtQ,    0x00, sizeof(m_ExtQ));
    m_ExtQ.bExtent = true;
    m_ExtQ.userIdx = 0;
    m_ExtQ.currIdx = 0;

    return true;
}
//---------------------------------------------------------------------------

/*
 * Form의 Skin 초기화 작업을 수행한다.
 *  arguments
 *      void
 *  return
 *      void
 */
void __fastcall TITS00GEO::LoadLocalSkin()
{
    //PnlMenu->ParentColor = false;
    //PnlMenu->Color = 0x00FF9D62;
    PnlTrf00->ParentColor = false;
    PnlTrf00->Color = clSilver;
    PnlTrf01->ParentColor = false;
    PnlTrf01->Color = clLime;
    PnlTrf02->ParentColor = false;
    PnlTrf02->Color = clYellow;
    PnlTrf03->ParentColor = false;
    PnlTrf03->Color = clRed;

    /*
    *  GIS Command button skin
    */
    TImage *pImgZoomIn_n;
    TImage *pImgZoomIn_c;
    TImage *pImgCenter_n;
    TImage *pImgCenter_c;
    TImage *pImgPrev_c;
    TImage *pImgPrev_n;
    TImage *pImgSel_n;
    TImage *pImgSel_c;
    TImage *pImgDist_n;
    TImage *pImgCircle_c;
    TImage *pImgCircle_n;
    TImage *pImgDist_c;
    TImage *pImgStnd_n;
    TImage *pImgSave_c;
    TImage *pImgSave_n;
    TImage *pImgStnd_c;
    TImage *pImgZoomOut_n;
    TImage *pImgZoomOut_c;
    TImage *pImgPan_c;
    TImage *pImgPan_n;
    TImage *pImgNext_n;
    TImage *pImgNext_c;
    TImage *pImgBoundary_c;
    TImage *pImgBoundary_n;
    TImage *pImgSquare_n;
    TImage *pImgSquare_c;
    TImage *pImgFull_c;
    TImage *pImgFull_n;
    TImage *pImgRefresh_n;
    TImage *pImgRefresh_c;
    TImage *pImgPrint_c;
    TImage *pImgPrint_n;

    int nSkin = 1;
	switch (nSkin)
	{
    case 10:
        pImgZoomIn_n = ImgZoomIn_c;
        pImgZoomIn_c = ImgZoomIn_n;
        pImgZoomOut_n = ImgZoomOut_c;
        pImgZoomOut_c = ImgZoomOut_n;
        pImgCenter_n = ImgCenter_c;
        pImgCenter_c = ImgCenter_n;
        pImgPan_c = ImgPan_n;
        pImgPan_n = ImgPan_c;
        pImgPrev_c = ImgPrev_n;
        pImgPrev_n = ImgPrev_c;
        pImgNext_n = ImgNext_c;
        pImgNext_c = ImgNext_n;
        pImgBoundary_c = ImgBoundary_n;
        pImgBoundary_n = ImgBoundary_c;
        pImgSel_n = ImgSel_c;
        pImgSel_c = ImgSel_n;
        pImgDist_n = ImgDist_c;
        pImgDist_c = ImgDist_n;
        pImgSquare_n = ImgSquare_c;
        pImgSquare_c = ImgSquare_n;
        pImgCircle_c = ImgCircle_n;
        pImgCircle_n = ImgCircle_c;
        pImgFull_c = ImgFull_n;
        pImgFull_n = ImgFull_c;
        pImgStnd_n = ImgStnd_c;
        pImgStnd_c = ImgStnd_n;
        pImgRefresh_n = ImgRefresh_c;
        pImgRefresh_c = ImgRefresh_n;
        pImgPrint_c = ImgPrint_n;
        pImgPrint_n = ImgPrint_c;
        pImgSave_c = ImgSave_n;
        pImgSave_n = ImgSave_c;
        break;
	case 1: case 2: case 3: case 0:
	case 4: case 5: default:
        pImgZoomIn_n = ImgZoomIn_n;
        pImgZoomIn_c = ImgZoomIn_c;
        pImgZoomOut_n = ImgZoomOut_n;
        pImgZoomOut_c = ImgZoomOut_c;
        pImgCenter_n = ImgCenter_n;
        pImgCenter_c = ImgCenter_c;
        pImgPan_c = ImgPan_c;
        pImgPan_n = ImgPan_n;
        pImgPrev_c = ImgPrev_c;
        pImgPrev_n = ImgPrev_n;
        pImgNext_n = ImgNext_n;
        pImgNext_c = ImgNext_c;
        pImgBoundary_c = ImgBoundary_c;
        pImgBoundary_n = ImgBoundary_n;
        pImgSel_n = ImgSel_n;
        pImgSel_c = ImgSel_c;
        pImgDist_n = ImgDist_n;
        pImgDist_c = ImgDist_c;
        pImgSquare_n = ImgSquare_n;
        pImgSquare_c = ImgSquare_c;
        pImgCircle_c = ImgCircle_c;
        pImgCircle_n = ImgCircle_n;
        pImgFull_c = ImgFull_c;
        pImgFull_n = ImgFull_n;
        pImgStnd_n = ImgStnd_n;
        pImgStnd_c = ImgStnd_c;
        pImgRefresh_n = ImgRefresh_n;
        pImgRefresh_c = ImgRefresh_c;
        pImgPrint_c = ImgPrint_c;
        pImgPrint_n = ImgPrint_n;
        pImgSave_c = ImgSave_c;
        pImgSave_n = ImgSave_n;
        break;
    }

    try
    {
        ImgZoomIn->NormalPicture->Assign(pImgZoomIn_n->Picture);
        ImgZoomIn->Picture->Assign(pImgZoomIn_n->Picture);
        ImgZoomIn->TogglePicture->Assign(pImgZoomIn_c->Picture);
        ImgZoomIn->ClickedPicture->Assign(pImgZoomIn_n->Picture);
        ImgZoomOut->NormalPicture->Assign(pImgZoomOut_n->Picture);
        ImgZoomOut->Picture->Assign(pImgZoomOut_n->Picture);
        ImgZoomOut->TogglePicture->Assign(pImgZoomOut_c->Picture);
        ImgZoomOut->ClickedPicture->Assign(pImgZoomOut_n->Picture);
        ImgCenter->NormalPicture->Assign(pImgCenter_n->Picture);
        ImgCenter->Picture->Assign(pImgCenter_n->Picture);
        ImgCenter->TogglePicture->Assign(pImgCenter_c->Picture);
        ImgCenter->ClickedPicture->Assign(pImgCenter_n->Picture);
        ImgPan->NormalPicture->Assign(pImgPan_n->Picture);
        ImgPan->Picture->Assign(pImgPan_n->Picture);
        ImgPan->TogglePicture->Assign(pImgPan_c->Picture);
        ImgPan->ClickedPicture->Assign(pImgPan_n->Picture);
        ImgPrev->NormalPicture->Assign(pImgPrev_n->Picture);
        ImgPrev->Picture->Assign(pImgPrev_n->Picture);
        ImgPrev->TogglePicture->Assign(pImgPrev_c->Picture);
        ImgPrev->ClickedPicture->Assign(pImgPrev_n->Picture);
        
        ImgNext->NormalPicture->Assign(pImgNext_n->Picture);
        ImgNext->Picture->Assign(pImgNext_n->Picture);
        ImgNext->TogglePicture->Assign(pImgNext_c->Picture);
        ImgNext->ClickedPicture->Assign(pImgNext_n->Picture);

        ImgPrev->Cursor = crHandPoint;
        ImgNext->Cursor = crHandPoint;

        ImgBoundary->NormalPicture->Assign(pImgBoundary_n->Picture);
        ImgBoundary->Picture->Assign(pImgBoundary_n->Picture);
        ImgBoundary->TogglePicture->Assign(pImgBoundary_c->Picture);
        ImgBoundary->ClickedPicture->Assign(pImgBoundary_n->Picture);
        ImgSel->NormalPicture->Assign(pImgSel_n->Picture);
        ImgSel->Picture->Assign(pImgSel_n->Picture);
        ImgSel->TogglePicture->Assign(pImgSel_c->Picture);
        ImgSel->ClickedPicture->Assign(pImgSel_n->Picture);
        ImgDist->NormalPicture->Assign(pImgDist_n->Picture);
        ImgDist->Picture->Assign(pImgDist_n->Picture);
        ImgDist->TogglePicture->Assign(pImgDist_c->Picture);
        ImgDist->ClickedPicture->Assign(pImgDist_n->Picture);
        ImgSquare->NormalPicture->Assign(pImgSquare_n->Picture);
        ImgSquare->Picture->Assign(pImgSquare_n->Picture);
        ImgSquare->TogglePicture->Assign(pImgSquare_c->Picture);
        ImgSquare->ClickedPicture->Assign(pImgSquare_n->Picture);
        ImgCircle->NormalPicture->Assign(pImgCircle_n->Picture);
        ImgCircle->Picture->Assign(pImgCircle_n->Picture);
        ImgCircle->TogglePicture->Assign(pImgCircle_c->Picture);
        ImgCircle->ClickedPicture->Assign(pImgCircle_n->Picture);
        ImgFull->NormalPicture->Assign(pImgFull_n->Picture);
        ImgFull->Picture->Assign(pImgFull_n->Picture);
        ImgFull->TogglePicture->Assign(pImgFull_c->Picture);
        ImgFull->ClickedPicture->Assign(pImgFull_n->Picture);
        ImgStnd->NormalPicture->Assign(pImgStnd_n->Picture);
        ImgStnd->Picture->Assign(pImgStnd_n->Picture);
        ImgStnd->TogglePicture->Assign(pImgStnd_c->Picture);
        ImgStnd->ClickedPicture->Assign(pImgStnd_n->Picture);
        ImgRefresh->NormalPicture->Assign(pImgRefresh_n->Picture);
        ImgRefresh->Picture->Assign(pImgRefresh_n->Picture);
        ImgRefresh->TogglePicture->Assign(pImgRefresh_c->Picture);
        ImgRefresh->ClickedPicture->Assign(pImgRefresh_n->Picture);
        ImgPrint->NormalPicture->Assign(pImgPrint_n->Picture);
        ImgPrint->Picture->Assign(pImgPrint_n->Picture);
        ImgPrint->TogglePicture->Assign(pImgPrint_c->Picture);
        ImgPrint->ClickedPicture->Assign(pImgPrint_n->Picture);
        ImgSave->NormalPicture->Assign(pImgSave_n->Picture);
        ImgSave->Picture->Assign(pImgSave_n->Picture);
        ImgSave->TogglePicture->Assign(pImgSave_c->Picture);
        ImgSave->ClickedPicture->Assign(pImgSave_n->Picture);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::TmrShowTimer(TObject *Sender)
{
    TmrShow->Enabled = false;
    Application->ProcessMessages();
    LoadGisMap();

    Application->ProcessMessages();
    UpdateFacilityStatus();

    Application->ProcessMessages();
    UpdateIncidentStatus();
}
//---------------------------------------------------------------------------

/*
 * 지도데이터 로드 및 프로그램 초기화 작업 수행
 *  arguments
 *
 *  return
 *
 */
void __fastcall TITS00GEO::LoadGisMap()
{
    try
    {
        try
        {
            // 지도로딩 상태바 표출
            GMMap1->Active = true;

            FVehRect = GMVehRect->Items[0];
            FVehBounds = new TLatLngBounds(0, 0, 0, 0);

            PnlProgress->Left = (this->Width  - PnlProgress->Width)  / 2;
            PnlProgress->Top  = (this->Height - PnlProgress->Height) / 2;
            PnlProgress->Top -= 50;
            PnlProgress->Visible = true;

            PbLoadMap->Properties->Text = "전자지도 표출색상 정보 로딩 중...";
            Application->ProcessMessages();
            PbLoadMap->Position = 50;

            PbLoadMap->Position = 100;
            PbLoadMap->Properties->Text = "전자지도 로딩 중...";
            Application->ProcessMessages();

            m_nMapLevel = GMMap1->RequiredProp->Zoom;
            LblZoomLevel->Caption = String(GMMap1->RequiredProp->Zoom);

            //xsrvrMap->SetFullExtent(DDRect(g_GisInfo.dRightBottomX, g_GisInfo.dLeftTopX, g_GisInfo.dRightBottomY, g_GisInfo.dLeftTopY));
            // start client

            pmuControlGisClick((TObject*)pmuMove);  // 전자지도 마우스이벤트를 이동으로 설정
        }
        catch (...)
        {
        }
    }
    __finally
    {
        PnlProgress->Visible = false;
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::SetGisTrafficColor()
{
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::GisMenuCheckClear()
{
	pmuZoomIn->Checked  = false;
	pmuZoomOut->Checked = false;
	pmuMove->Checked    = false;
	pmuIconSel->Checked = false;
	pmuCalLen->Checked = false;
	pmuCalArea->Checked = false;
	pmuRadius->Checked = false;
    pmuMoveCenter->Checked = false;
    pmuGisDefault->Checked = false;
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::pmuGisCalcClick(TObject *Sender)
{
	TMenuItem *pMenu = (TMenuItem *)Sender;
    //SetMapOperation((TXiMapOperation)pMenu->Tag);
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::pmuControlGisClick(TObject *Sender)
{
    TMenuItem *pMenu = (TMenuItem*)Sender;
    
    //SetMapOperation((TXiMapOperation)pMenu->Tag);
}
//---------------------------------------------------------------------------

#if 0
/*
 * 지도제어 설정
 *  arguments
 *
 *  return
 *
 */
void __fastcall TITS00GEO::SetMapOperation(TXiMapOperation nMapOper)
{
	GisMenuCheckClear();

    m_bMoveCenter = false;
    m_bCalcMode   = false;
    m_bCalcCont   = false;
}
//---------------------------------------------------------------------------
#endif

void __fastcall TITS00GEO::MnuLayerSettingClick(TObject *Sender)
{
    Application->ProcessMessages();
    ShowLayerEditForm();
}
//---------------------------------------------------------------------------

/*
 * 레이어편집 설정창 표출
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TITS00GEO::ShowLayerEditForm()
{
}
//---------------------------------------------------------------------------

#if 0
/*
 * 전자지도의 영역을 설정한다.
 *  arguments
 *      double : left 영역
 *      double : top 영역
 *      double : right 영역
 *      double : bottom 영역
 *  return
 *      void
 */
void __fastcall TITS00GEO::SetExtent(TDDRect &curRc)
{
}
//---------------------------------------------------------------------------
#endif

#if 0
/*
 * 지도 영역 이동 함수. 현재 영역을 영역이동 큐에 추가한다.
 * 다음 버튼을 비활성 시킨다.
 *  arguments
 *  return
 *      void
 */
bool __fastcall TITS00GEO::AddExtentQ(TDDRect &curRc)
{
#if 0
    TDDRect *pExt = &m_ExtQ.extent[m_ExtQ.userIdx];
    memcpy((char*)pExt, (char*)&curRc, sizeof(curRc));

    if (m_PrevExt.MinX == pExt->MinX &&
        m_PrevExt.MinY == pExt->MinY &&
        m_PrevExt.MaxX == pExt->MaxX &&
        m_PrevExt.MaxY == pExt->MaxY)
    {
        return false;
    }

    memcpy((char*)&m_PrevExt, pExt, sizeof(m_PrevExt));

    if (m_ExtQ.userIdx >= D_EXT_QUEUE_SIZE)
    {
        m_ExtQ.userIdx = D_EXT_QUEUE_SIZE;

        memcpy((char *)&m_ExtQ.extent[0], (char *)&m_ExtQ.extent[1], sizeof(TDDRect)*D_EXT_QUEUE_SIZE);
    }
    else
    {
        m_ExtQ.userIdx++;
    }

    m_ExtQ.currIdx = m_ExtQ.userIdx-1;
#endif

    return true;
}
//---------------------------------------------------------------------------
#endif

/*
 * 지도 영역 이동 함수. 이전 영역으로 이동
 * 이동 범위에 따라 이전/다음 버튼을 활성/비활성 시킨다.
 *  arguments
 *  return
 *      void
 */
bool __fastcall TITS00GEO::PrevExtentQ()
{
#if 0
    m_ExtQ.bExtent = false;

    if (m_ExtQ.currIdx <= 0)
    {
        m_ExtQ.currIdx = 0;
        return false;
    }

    m_ExtQ.currIdx--;

    TDDRect *pExt = &m_ExtQ.extent[m_ExtQ.currIdx];

    SetExtent(*pExt);
#endif

    return true;
}
//---------------------------------------------------------------------------

/*
 * 지도 영역 이동 함수. 다음 영역으로 이동
 * 이동 범위에 따라 이전/다음 버튼을 활성/비활성 시킨다.
 *  arguments
 *  return
 *      void
 */
bool __fastcall TITS00GEO::NextExtentQ()
{
#if 0
    m_ExtQ.bExtent = false;

    if (m_ExtQ.currIdx >= m_ExtQ.userIdx-1)
    {
        m_ExtQ.currIdx = m_ExtQ.userIdx-1;
        return false;
    }

    m_ExtQ.currIdx++;

    TDDRect *pExt = &m_ExtQ.extent[m_ExtQ.currIdx];

    SetExtent(*pExt);
#endif

    return true;
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ImgPrevClick(TObject *Sender)
{
    PrevExtentQ();    
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ImgNextClick(TObject *Sender)
{
    NextExtentQ();    
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ChkTrafficLayerClick(TObject *Sender)
{
    SetTrfLayerShow(ChkTrafficLayer->Checked);    
}
//---------------------------------------------------------------------------

/*
 * 소통정보 레이어 보기 숨기기
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TITS00GEO::SetTrfLayerShow(bool bShow)
{
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ChkToolTipClick(TObject *Sender)
{
    if (!ChkToolTip->Checked)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::TmrSelectTimer(TObject *Sender)
{
    TmrSelect->Enabled = false;
    ImgSelect->Visible = false;
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::SelectObjectByPos(double dPosX, double dPosY, bool bArrow/*=false*/)
{
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::SelectObjectByPos()
{
    TPoint ptTmp;

    //ImgSelect->Parent = xclntMap;
    ImgSelect->Visible = false;
    TmrSelect->Enabled = false;
    TmrSelect->Interval = 3000;

    //ptTmp = xclntMap->RealToScreen(m_ptSelect);

    ImgSelect->Left = ptTmp.x - (ImgSelect->Width/2);
    ImgSelect->Top  = ptTmp.y - (ImgSelect->Height)-10;
    TmrSelect->Enabled = true;
    ImgSelect->Visible = true;
}
//---------------------------------------------------------------------------

String __fastcall TITS00GEO::GetLinkLayerName()
{
    if (m_nMapLevel < 3 || m_nMapLevel > 7) return "no_map";
}
//---------------------------------------------------------------------------

bool __fastcall TITS00GEO::SelectLinkById(int ALinkLevel, String sId, bool bHide/*=false*/)
{
    bool bResult = false;
    String sLinkLyrName = "";
    int    nLyrIndex    = -1;


    return bResult;
}
//---------------------------------------------------------------------------

bool __fastcall TITS00GEO::SelectLinkByPos(int X, int Y)
{
    String sLinkId;

    return false;
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::TmrLinkSelectTimer(TObject *Sender)
{
    TmrLinkSelect->Enabled = false;
}
//---------------------------------------------------------------------------

/*
 * 링크레이어 도움말 표출
 *  arguments
 *  return
 *      void
 */
bool __fastcall TITS00GEO::GetLevelLinkId(int ALinkLevel, String &sLinkId, int X, int Y)
{
    String sLinkLyrName = "";
    int    nLyrIndex    = -1;

    sLinkId = "";

    return false;
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::MnuSetStdAreaClick(TObject *Sender)
{
    Application->ProcessMessages();

    if (Application->MessageBox(L"현재 영역을 표준영역으로 지정하시겠습니까?", L"확인",
                                MB_YESNO|MB_ICONQUESTION) != IDYES)
    {
        return;
    }


    TIniFile *pIniFile = NULL;
    String sIniFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".ini");
    String sCfgFile = ExtractFilePath(Application->ExeName) + "\\cfg\\" + sIniFile;

    try
    {
        try
        {
            pIniFile = new TIniFile(sCfgFile);

#if 0
            TDDRect rc = xclntMap->GetViewExtent();

            pIniFile->WriteString("MAP", "LEFTTOPX",     String(rc.MaxX));
            pIniFile->WriteString("MAP", "LEFTTOPY",     String(rc.MaxY));
            pIniFile->WriteString("MAP", "RIGHTBOTTOMX", String(rc.MinX));
            pIniFile->WriteString("MAP", "RIGHTBOTTOMY", String(rc.MinY));


            g_GisInfo.dLeftTopX     = rc.MaxX;
            g_GisInfo.dLeftTopY     = rc.MaxY;
            g_GisInfo.dRightBottomX = rc.MinX;
            g_GisInfo.dRightBottomY = rc.MinY;
#endif
        }
        __finally
        {
            if (pIniFile) delete pIniFile;
            pIniFile = NULL;
        }
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::SetTrafficInfo(bool bFlag)
{
    bool alivethread = false;

}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::RefreshMapTraffic()
{
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ChkDrawIncidentClick(TObject *Sender)
{
    UpdateIncidentStatus();
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ChkDrawGisClick(TObject *Sender)
{
    UpdateFacilityStatus();
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ShowLinkDetailInfo(String sLinkId, int nLinkLevel)
{
    try
    {
        if (FrmLinkInfo == NULL)
        {
            FrmLinkInfo = new TFrmLinkInfo(Application);
        }
        FrmLinkInfo->Show();
        FrmLinkInfo->ShowLinkInfo(sLinkId, nLinkLevel);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ChkGisSearchClick(TObject *Sender)
{
    try
    {
        if (ChkGisSearch->Checked)
        {
            if (FrmGisSearch == NULL)
            {
                FrmGisSearch = new TFrmGisSearch(this);
                //FrmGisSearch->Parent = this;
            }
            FrmGisSearch->Show();
        }
        else
        {
            if (FrmGisSearch)
            {
                if (FrmGisSearch->m_bClose == false)
                {
                    FrmGisSearch->Close();
                }
            }
        }   
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::FormClose(TObject *Sender, TCloseAction &Action)
{
    CommClose();
    //ITS00GEO = NULL;
    Action = caFree;    
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::panRemarkMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
    TcxGroupBox *pGroup = (TcxGroupBox*)Sender;
	ReleaseCapture();
	pGroup->Perform(WM_SYSCOMMAND, 0xf012, 0);
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ChkViewExamplePropertiesChange(TObject *Sender)
{
    panRemark->Visible = ChkViewExample->Checked;
}
//---------------------------------------------------------------------------

/*
 * 시설물의 상태에 따라 이미지를 전자지도에 표출한다.(XiClient->CCTVIconList)
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TITS00GEO::UpdateFacilityStatus()
{
static String sStatusMsg[3] = { "정상", "이상", "모름", };

    int nStatus = 0;
    TItsFacility *pFacility;

	//xclntMap->ClearCCTVEvent(true);

    if (ChkDrawCtv->Checked)
    {
        try
        {
            ItsFacilityManager->FCctvLists.Lock();
            FOR_STL(TItsCctv *, pObj, ItsFacilityManager->FCctvLists)
            {
                nStatus = 2;
                pFacility = ItsFacilityManager->FLists.Find(pObj->CCTV_CTLR_ID);
                if (pFacility)
                {
                    if (pFacility->CommStatus == "CMS0") nStatus = 0;
                    else
                    if (pFacility->CommStatus == "CMS1") nStatus = 1;
                }

                try {
                String sTitle = "▶▶CCTV 정보◀◀|CCTV ID : " + pObj->CCTV_CTLR_ID + "|명칭 : " + pObj->ISTL_LCTN_NM + "|상태 : " + sStatusMsg[nStatus];
                //xclntMap->ADDCCTVEvent(DDPoint(pObj->X_CRDN.ToDouble(), pObj->Y_CRDN.ToDouble()), pObj->CCTV_CTLR_ID, "CCTV", sTitle, nStatus+1, 1, 7);
                } catch(...) { }
            }
        }
        __finally
        {
            ItsFacilityManager->FCctvLists.UnLock();
        }
    }

    if (ChkDrawVms->Checked)
    {
        try
        {
            ItsFacilityManager->FVmsLists.Lock();
            FOR_STL(TItsVms *, pObj, ItsFacilityManager->FVmsLists)
            {
                nStatus = 2;
                pFacility = ItsFacilityManager->FLists.Find(pObj->VMS_CTLR_ID);
                if (pFacility)
                {
                    if (pFacility->CommStatus == "CMS0") nStatus = 0;
                    else
                    if (pFacility->CommStatus == "CMS1") nStatus = 1;
                }

                try {
                String sTitle = "▶▶VMS 정보◀◀|VMS ID : " + pObj->VMS_CTLR_ID + "|명칭 : " + pObj->VMS_NM + "|상태 : " + sStatusMsg[nStatus];
                //xclntMap->ADDCCTVEvent(DDPoint(pObj->X_CRDN.ToDouble(), pObj->Y_CRDN.ToDouble()), pObj->VMS_CTLR_ID, "VMS", sTitle, nStatus+4, 1, 7);
                } catch(...) { }
            }
        }
        __finally
        {
            ItsFacilityManager->FVmsLists.UnLock();
        }
    }

    if (ChkDrawRse->Checked)
    {
        try
        {
            ItsFacilityManager->FRseLists.Lock();
            FOR_STL(TItsRse *, pObj, ItsFacilityManager->FRseLists)
            {
                nStatus = 2;
                pFacility = ItsFacilityManager->FLists.Find(pObj->RSEID);
                if (pFacility)
                {
                    if (pFacility->CommStatus == "CMS0") nStatus = 0;
                    else
                    if (pFacility->CommStatus == "CMS1") nStatus = 1;
                }

                try {
                String sTitle = "▶▶RSE 정보◀◀|RSE ID : " + pObj->RSEID + "|명칭 : " + pObj->LOCATION + "|상태 : " + sStatusMsg[nStatus];
                //xclntMap->ADDCCTVEvent(DDPoint(pObj->COORDX.ToDouble(), pObj->COORDY.ToDouble()), pObj->RSEID, "RSE", sTitle, nStatus+7, 1, 7);
                } catch(...) { }
            }
        }
        __finally
        {
            ItsFacilityManager->FRseLists.UnLock();
        }
    }

	//xclntMap->ReDraw();
}
//---------------------------------------------------------------------------

/*
 * 돌발 상태에 따라 이미지를 전자지도에 표출한다.(XiClient->ADDAccEvent)
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TITS00GEO::UpdateIncidentStatus()
{
static String sStatusMsg[5] = { "사고", "공사", "행사", "기상", "기타", };

    int nStatus = 0;

    //xclntMap->ClearAccEvent(true);

    if (ChkDrawIncident->Checked)
    {
        try
        {
            ItsIncidentManager->FLists.Lock();
            FOR_STL(TItsIncident *, pObj, ItsIncidentManager->FLists)
            {
                if (pObj->INCD_PRGR_STEP_CD == "ISS2")
                {
                    nStatus = 4;
                    if (pObj->INCD_TYPE_CLSF_CD == "1") nStatus = 0;
                    else
                    if (pObj->INCD_TYPE_CLSF_CD == "2") nStatus = 1;
                    else
                    if (pObj->INCD_TYPE_CLSF_CD == "3") nStatus = 2;
                    else
                    if (pObj->INCD_TYPE_CLSF_CD == "4") nStatus = 3;

                    String sTitle = "▶▶돌발 정보◀◀|돌발 ID : " + pObj->INCD_OCRR_ID + "|제목 : " + pObj->INCD_TITL + "|유형 : " + sStatusMsg[nStatus];
                    sTitle += "|돌발등록시각: " + ITSUtil_StrToTime(pObj->RGST_DT) + "|돌발시작시각: " + ITSUtil_StrToTime(pObj->FINCD_STRT_DT);
                    sTitle += "|돌발종료시각: " + ITSUtil_StrToTime(pObj->INCD_END_PRAR_DT);
                    //xclntMap->ADDAccEvent(DDPoint(pObj->X_CRDN.ToDouble(), pObj->Y_CRDN.ToDouble()), pObj->INCD_OCRR_ID, sTitle, sTitle, "", nStatus+10, false, 1, 7);
                }
            }
        }
        __finally
        {
            ItsIncidentManager->FLists.UnLock();
        }
    }
	//xclntMap->ReDraw();
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::pmuFacilityPopup(TObject *Sender)
{
    TPopupMenu *pMenu = (TPopupMenu*)Sender;
    if (pMenu->Tag == 0)
    {
        MnuCctvId->Caption = "[CCTV] " + FSelId;
    }
    else
    if (pMenu->Tag == 1)
    {
        MnuVmsId->Caption = "[VMS] " + FSelId;
    }
    else
    if (pMenu->Tag == 2)
    {
        MnuRseId->Caption = "[RSE] " + FSelId;
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::mnuFacilityPingClick(TObject *Sender)
{
    TMenuItem *pMenu = (TMenuItem*)Sender;

    String sIp;
    Application->ProcessMessages();
    if (pMenu->Tag >= 11 && 15 >= pMenu->Tag)
    {
        String sIp;
        TItsCctv *pObj = ItsFacilityManager->FCctvLists.Find(FSelId);
        if (pObj)
        {
            switch(pMenu->Tag)
            {
            case 12: sIp = pObj->CCTV_CAPT_IP.Trim(); break;
            case 13: sIp = pObj->CCTV_ENCD_IP.Trim(); break;
            case 14: sIp = pObj->STRM_SVR_IP.Trim();  break;
            case 15: sIp = pObj->CCTV_FIBR_IP.Trim(); break;
            case 11:
            default: sIp = pObj->CCTV_CTLR_IP.Trim(); break;
            }
        }
    }
    else
    if (pMenu->Tag >= 21 && 22 >= pMenu->Tag)
    {
        String sIp;
        TItsVms *pObj = ItsFacilityManager->FVmsLists.Find(FSelId);
        if (pObj)
        {
            switch(pMenu->Tag)
            {
            case 22: sIp = pObj->WEB_CMRA_IP.Trim(); break;
            case 21:
            default: sIp = pObj->VMS_CTLR_IP.Trim(); break;
            }
        }
    }
    else
    if (pMenu->Tag == 2)
    {
        TItsRse *pObj = ItsFacilityManager->FRseLists.Find(FSelId);
        if (pObj) sIp = pObj->RSEIP.Trim();
    }

    if (sIp.IsEmpty())
    {
        Application->MessageBox(L"IP Address 정보가 없습니다.\r\nIP Address 정보를 확인하세요.",
                                L"네크워크 연결확인", MB_OK|MB_ICONERROR|MB_APPLMODAL);
        return;
    }
    ITSUtil_NetworkPing(sIp);
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::mnuStopImageClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ITS00G0M->ScreenToClient(pt);
    ShowCctvStopImage(FSelId, pt);
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::mnuCctvCamClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ITS00G0M->ScreenToClient(pt);
    ShowCctvCamera(FSelId, pt);
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::mnuVmsMsgClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ITS00G0M->ScreenToClient(pt);
    ShowVmsMessage(FSelId, pt);
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::mnuVmsCamClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ITS00G0M->ScreenToClient(pt);
    ShowVmsCamera(FSelId, pt);
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ShowCctvStopImage(String AId, TPoint pt)
{
    TItsCctv *pObj = ItsFacilityManager->FCctvLists.Find(AId);
    if (!pObj) return;

    try {
        if (pObj->FData1)
        {
            TFrmCctvImg *pForm = (TFrmCctvImg *)pObj->FData1;
            pForm->SetFocus();
            pForm->LoadStopImage();
        }
        else
        {
            TFrmCctvImg *pForm = new TFrmCctvImg(ITS00G0M);
            pForm->Parent = ITS00G0M;

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;
            pForm->FObj = pObj;
            pObj->FData1 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ShowCctvCamera(String AId, TPoint pt)
{
    TItsCctv *pObj = ItsFacilityManager->FCctvLists.Find(AId);
    if (!pObj) return;

    try {
        if (pObj->FData2)
        {
            TFrmCctvCam *pForm = (TFrmCctvCam *)pObj->FData2;
            pForm->SetFocus();
        }
        else
        {
            TFrmCctvCam *pForm = new TFrmCctvCam(ITS00G0M);
            pForm->Parent = ITS00G0M;

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;
            pForm->FObj = pObj;
            pObj->FData2 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ShowVmsMessage(String AId, TPoint pt)
{
    TItsVms *pObj = ItsFacilityManager->FVmsLists.Find(FSelId);
    if (!pObj) return;

    try {
        if (pObj->FData1)
        {
            TFrmVmsMsg *pForm = (TFrmVmsMsg *)pObj->FData1;
            pForm->SetFocus();
        }
        else
        {
            TFrmVmsMsg *pForm = new TFrmVmsMsg(ITS00G0M, pObj);
            pForm->Parent = ITS00G0M;

            int nHG = pForm->ClientHeight - pForm->PnlVmsMsgDisp->Height;
            int nWG = pForm->ClientWidth  - pForm->PnlVmsMsgDisp->Width;

#if 0
            pForm->ClientHeight = nHG + pObj->Height;
            pForm->ClientWidth  = nWG + pObj->Width;
#endif

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;
            pForm->FObj = pObj;
            pObj->FData1 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ShowVmsCamera(String AId, TPoint pt)
{
    TItsVms *pObj = ItsFacilityManager->FVmsLists.Find(FSelId);
    if (!pObj) return;

    try {
        if (pObj->FData2)
        {
            TFrmVmsCam *pForm = (TFrmVmsCam *)pObj->FData2;
#if 0
            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }
            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;
#endif
            pForm->SetFocus();
        }
        else
        {
            TFrmVmsCam *pForm = new TFrmVmsCam(ITS00G0M, pObj);
            pForm->Parent = ITS00G0M;

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;
            pForm->FObj = pObj;
            pObj->FData2 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::GMMap1AfterPageLoaded(TObject *Sender, bool First)
{
    if (First)
    {
        GMMap1->DoMap();
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::WebBrowser1DocumentComplete(TObject *ASender, const IDispatch *pDisp, OleVariant &URL)
{
    try {
        Variant vBody;
        Variant vObj = WebBrowser1->OleObject;
        String strDocCompatMode = vObj.OlePropertyGet("document").OlePropertyGet("compatMode");
        if (SameText(strDocCompatMode, "CSS1Compat"))
            vBody = vObj.OlePropertyGet("Document").OlePropertyGet("documentElement");
        else
            vBody = vObj.OlePropertyGet("Document").OlePropertyGet("body");

        vBody.OlePropertyGet("style").OlePropertySet("overflow", "hidden");
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::GMMap1ZoomChanged(TObject *Sender, int NewZoom)
{
    m_nMapLevel = NewZoom;
    LblZoomLevel->Caption = String(NewZoom);
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::ImgStndClick(TObject *Sender)
{
    if (FRectangle)
    {
        // 사각형 그리기 끝내기
        FRectangle = false;
        FRectangleIdx = 0;
    }
    else
    {
        FRectangle = true;
        FRectangleIdx = 0;
    }

    if (ImgStnd->Tag == 13)
    {
        GMMap1->NonVisualProp->Options = (GMMap1->NonVisualProp->Options >> Draggable);
        GMMap1->NonVisualProp->Options = (GMMap1->NonVisualProp->Options >> ScrollWheel);
        GMMap1->DoMap();
        ImgStnd->Tag = 20;
    }
    else
    {
        FVehRect->Visible = false;
        GMMap1->NonVisualProp->Options = (GMMap1->NonVisualProp->Options << Draggable);
        GMMap1->NonVisualProp->Options = (GMMap1->NonVisualProp->Options << ScrollWheel);
        GMMap1->DoMap();
        ImgStnd->Tag = 13;
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::GMMap1Click(TObject *Sender, TLatLng *LatLng, double X, double Y)
{
    if (FRectangle && FRectangleIdx == 0)
    {
        FVehRect->Visible = true;
        Edit1->Text = LatLng->LatToStr(GMMap1->Precision);
        Edit2->Text = LatLng->LngToStr(GMMap1->Precision);

        FVehRect->Bounds->NE->Lat = LatLng->Lat;
        FVehRect->Bounds->NE->Lng = LatLng->Lng;
        FVehRect->Bounds->SW->Lat = LatLng->Lat;
        FVehRect->Bounds->SW->Lng = LatLng->Lng;

        FRectangleIdx = 1;

        Memo1->Lines->Add(Edit1->Text + "  " + Edit2->Text);
    }
    else
    if (FRectangle && FRectangleIdx == 1)
    {
        Edit1->Text = LatLng->LatToStr(GMMap1->Precision);
        Edit2->Text = LatLng->LngToStr(GMMap1->Precision);

        if (LatLng->Lng > FVehRect->Bounds->NE->Lng)
        {
            FVehRect->Bounds->SW->Lat = FVehRect->Bounds->NE->Lat;
            FVehRect->Bounds->SW->Lng = FVehRect->Bounds->NE->Lng;

            FVehRect->Bounds->NE->Lat = LatLng->Lat;
            FVehRect->Bounds->NE->Lng = LatLng->Lng;
        }
        else
        {
            FVehRect->Bounds->SW->Lat = LatLng->Lat;
            FVehRect->Bounds->SW->Lng = LatLng->Lng;
        }

        Memo1->Lines->Add(Edit1->Text + "  " + Edit2->Text);

        FRectangle = false;
        FRectangleIdx = 0;
        //FVehRect->Visible = false;
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::GMMap1MouseMove(TObject *Sender, TLatLng *LatLng, double X, double Y)
{
return;
    if (FRectangle && FRectangleIdx == 1)
    {
        if (LatLng->Lng > FVehRect->Bounds->NE->Lng)
        {
            FVehRect->Bounds->SW->Lat = FVehRect->Bounds->NE->Lat;
            FVehRect->Bounds->SW->Lng = FVehRect->Bounds->NE->Lng;

            FVehRect->Bounds->NE->Lat = LatLng->Lat;
            FVehRect->Bounds->NE->Lng = LatLng->Lng;
        }
        else
        {
            FVehRect->Bounds->SW->Lat = LatLng->Lat;
            FVehRect->Bounds->SW->Lng = LatLng->Lng;
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::FormCreate(TObject *Sender)
{
    //Application->OnMessage = WebMessageHandler;
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::WebMessageHandler(TMsg &Msg, bool &Handled)
{
    if (Msg.hwnd == WebBrowser1->Handle)
    {
        if (FRectangle)
        {
            if (Msg.message == WM_LBUTTONDOWN)
            {
                Handled = true;
            }
            else
            if (Msg.message == WM_LBUTTONUP)
            {

                Handled = true;
            }
        }
    }

#if 0
    Handled = IsDialogMessage(WebBrowser1->Handle, &Msg) == true;
    if (!Handled || WebBrowser1->Busy) return;

    if (FRectangle)
    {
        if (Msg.message == WM_LBUTTONDOWN)
        {
            //Handled = true;
        }
        else
        if (Msg.message == WM_LBUTTONUP)
        {

            //Handled = true;
        }
    }
#endif
}
//---------------------------------------------------------------------------

void __fastcall TITS00GEO::GMVehRectMouseUp(TObject *Sender, TLatLng *LatLng, int Index, TLinkedComponent *LinkedComponent)
{
    if (Index == 0)
    {
        Memo1->Lines->Add("job completed");
    }
}
//---------------------------------------------------------------------------

