FRAME_GoogleMapF.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "ITSSkinF.h"
  5. #include "ITSUtilF.h"
  6. #pragma hdrstop
  7. #include "FRAME_GoogleMapF.h"
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma link "GMClasses"
  11. #pragma link "GMMap"
  12. #pragma link "GMMapVCL"
  13. #pragma link "GMLinkedComponents"
  14. #pragma link "GMMarker"
  15. #pragma link "GMMarkerVCL"
  16. #pragma link "cxCheckBox"
  17. #pragma link "cxButtons"
  18. #pragma link "cxContainer"
  19. #pragma link "cxControls"
  20. #pragma link "cxEdit"
  21. #pragma link "cxGraphics"
  22. #pragma link "cxLabel"
  23. #pragma link "cxLookAndFeelPainters"
  24. #pragma link "cxLookAndFeels"
  25. #pragma link "dxSkinBlack"
  26. #pragma link "dxSkinBlue"
  27. #pragma link "dxSkinCaramel"
  28. #pragma link "dxSkinCoffee"
  29. #pragma link "dxSkinDarkRoom"
  30. #pragma link "dxSkinDarkSide"
  31. #pragma link "dxSkinFoggy"
  32. #pragma link "dxSkinGlassOceans"
  33. #pragma link "dxSkiniMaginary"
  34. #pragma link "dxSkinLilian"
  35. #pragma link "dxSkinLiquidSky"
  36. #pragma link "dxSkinLondonLiquidSky"
  37. #pragma link "dxSkinMcSkin"
  38. #pragma link "dxSkinMoneyTwins"
  39. #pragma link "dxSkinOffice2007Black"
  40. #pragma link "dxSkinOffice2007Blue"
  41. #pragma link "dxSkinOffice2007Green"
  42. #pragma link "dxSkinOffice2007Pink"
  43. #pragma link "dxSkinOffice2007Silver"
  44. #pragma link "dxSkinOffice2010Black"
  45. #pragma link "dxSkinOffice2010Blue"
  46. #pragma link "dxSkinOffice2010Silver"
  47. #pragma link "dxSkinsCore"
  48. #pragma link "dxSkinSeven"
  49. #pragma link "dxSkinSharp"
  50. #pragma link "dxSkinSilver"
  51. #pragma link "dxSkinStardust"
  52. #pragma resource "*.dfm"
  53. TFRAMEGoogleMap *FRAMEGoogleMap;
  54. //---------------------------------------------------------------------------
  55. __fastcall TFRAMEGoogleMap::TFRAMEGoogleMap(TComponent* Owner)
  56. : TFrame(Owner)
  57. {
  58. ITSSkin_Load((TForm*)this);
  59. LoadLocalSkin();
  60. FOnDrawFacilityClick = NULL;
  61. FOnZoomChangeClick = NULL;
  62. memset((char*) & FPrev, 0x00, sizeof(FPrev));
  63. memset((char*) & FExtent, 0x00, sizeof(FExtent));
  64. FExtent.Extent = true;
  65. FExtent.TotCnt = 0;
  66. FExtent.CurIdx = 0;
  67. FMapZoom = g_GisInfo.nZoomLevel;
  68. FBaseZoom = FMapZoom;
  69. GMMap1->RequiredProp->Zoom = FBaseZoom;
  70. GMMap1->RequiredProp->Center->Lat = g_GisInfo.dCenterX;
  71. GMMap1->RequiredProp->Center->Lng = g_GisInfo.dCenterY;
  72. FMapTypeId = mtTERRAIN;
  73. LblZoom->Caption = "Zoom: " + String(FMapZoom) + " ";
  74. FCenLatLng = new TLatLng(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng);
  75. FMapBounds = new TLatLngBounds(0, 0, 0, 0);
  76. FCenterLat = GMMap1->RequiredProp->Center->Lat;
  77. FCenterLng = GMMap1->RequiredProp->Center->Lng;
  78. //LoadGisMap();
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TFRAMEGoogleMap::LoadLocalSkin()
  82. {
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TFRAMEGoogleMap::LoadGisMap()
  86. {
  87. if (!GMMap1->Active)
  88. {
  89. try {
  90. if (ImgLoading->Picture->Graphic->ClassName() == "TGIFImage")
  91. ((TGIFImage *)ImgLoading->Picture->Graphic)->Animate = true;
  92. Application->ProcessMessages();
  93. ImgLoading->Visible = true;
  94. } catch(...) {}
  95. GMMap1->Active = true;
  96. }
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TFRAMEGoogleMap::SetLinkLevel(int ALinkLevel)
  100. {
  101. FLinkLevel = ALinkLevel;
  102. }
  103. //---------------------------------------------------------------------------
  104. void __fastcall TFRAMEGoogleMap::ShowHideTrafficLayer(bool AShow)
  105. {
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TFRAMEGoogleMap::SelectObjectByPos(double dPosX, double dPosY, bool bArrow/*=false*/)
  109. {
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TFRAMEGoogleMap::SelectObjectByPos()
  113. {
  114. }
  115. //---------------------------------------------------------------------------
  116. bool __fastcall TFRAMEGoogleMap::SelectLinkByPos(int X, int Y, String &ALinkId)
  117. {
  118. return false;
  119. }
  120. //---------------------------------------------------------------------------
  121. bool __fastcall TFRAMEGoogleMap::GetLevelLinkId(int ALinkLevel, String &sLinkId, int X, int Y)
  122. {
  123. return false;
  124. }
  125. //---------------------------------------------------------------------------
  126. int __fastcall TFRAMEGoogleMap::GetLayerIndex()
  127. {
  128. return 0;
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TFRAMEGoogleMap::SelGisItem(int AType, String AId)
  132. {
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TFRAMEGoogleMap::OnCloseQuery(bool &CanClose)
  136. {
  137. }
  138. //---------------------------------------------------------------------------
  139. bool __fastcall TFRAMEGoogleMap::AddExtentQ(double ALat, double ALng, int FZoom)
  140. {
  141. TMapExtent *pExt = &FExtent.extent[FExtent.TotCnt];
  142. pExt->Lat = ALat;
  143. pExt->Lng = ALng;
  144. pExt->Zoom = (short)FZoom;
  145. if (FPrev.Lat == pExt->Lat && FPrev.Lng == pExt->Lng && FPrev.Zoom == pExt->Zoom)
  146. {
  147. return false;
  148. }
  149. // MAPDEBUG("AddExtentQ: " + String(FExtent.TotCnt));
  150. FPrev.Lat = pExt->Lat;
  151. FPrev.Lat = pExt->Lng;
  152. FPrev.Zoom = pExt->Zoom;
  153. FExtent.TotCnt++;
  154. if (FExtent.TotCnt >= D_EXT_QUEUE_SIZE)
  155. {
  156. FExtent.TotCnt = D_EXT_QUEUE_SIZE;
  157. memcpy((char*) & FExtent.extent[0], (char*) & FExtent.extent[1], sizeof(TMapExtent) * D_EXT_QUEUE_SIZE);
  158. }
  159. FExtent.CurIdx = FExtent.TotCnt - 1;
  160. if (FExtent.TotCnt > 1)
  161. {
  162. // BtnZoomPrev->Enabled = true;
  163. }
  164. return true;
  165. }
  166. //---------------------------------------------------------------------------
  167. /*!
  168. * @fn TFRMFC090000::PrevExtentQ
  169. * @brief PrevExtentQ
  170. * @param void
  171. * @return bool 결과
  172. */
  173. bool __fastcall TFRAMEGoogleMap::PrevExtentQ()
  174. {
  175. FExtent.Extent = false;
  176. if (FExtent.CurIdx <= 0)
  177. {
  178. FExtent.CurIdx = 0;
  179. return false;
  180. }
  181. FExtent.CurIdx--;
  182. if (FExtent.CurIdx == 0)
  183. {
  184. // BtnZoomPrev->Enabled = false;
  185. }
  186. try
  187. {
  188. TMapExtent *pExt = &FExtent.extent[FExtent.CurIdx];
  189. if (GMMap1->Active)
  190. {
  191. GMMap1->SetCenter(pExt->Lat, pExt->Lng);
  192. GMMap1->RequiredProp->Zoom = (int)pExt->Zoom;
  193. }
  194. // BtnZoomNext->Enabled = true;
  195. }
  196. catch(...)
  197. {
  198. }
  199. return true;
  200. }
  201. //---------------------------------------------------------------------------
  202. bool __fastcall TFRAMEGoogleMap::NextExtentQ()
  203. {
  204. FExtent.Extent = false;
  205. if (FExtent.CurIdx >= FExtent.TotCnt - 1)
  206. {
  207. FExtent.CurIdx = FExtent.TotCnt - 1;
  208. return false;
  209. }
  210. FExtent.CurIdx++;
  211. if (FExtent.CurIdx == FExtent.TotCnt - 1)
  212. {
  213. // BtnZoomNext->Enabled = false;
  214. }
  215. try
  216. {
  217. TMapExtent *pExt = &FExtent.extent[FExtent.CurIdx];
  218. if (GMMap1->Active)
  219. {
  220. GMMap1->SetCenter(pExt->Lat, pExt->Lng);
  221. GMMap1->RequiredProp->Zoom = (int)pExt->Zoom;
  222. }
  223. // BtnZoomPrev->Enabled = true;
  224. }
  225. catch(...)
  226. {
  227. }
  228. return true;
  229. }
  230. //---------------------------------------------------------------------------
  231. void __fastcall TFRAMEGoogleMap::WebBrowser1DownloadComplete(TObject *Sender)
  232. {
  233. // 웹페이지 스크롤바 없애기
  234. #if 0
  235. try
  236. {
  237. Variant vBody;
  238. Variant vObj = WebBrowser1->OleObject;
  239. String strDocCompatMode = vObj.OlePropertyGet("document").OlePropertyGet("compatMode");
  240. if (SameText(strDocCompatMode, "CSS1Compat"))
  241. vBody = vObj.OlePropertyGet("Document").OlePropertyGet("documentElement");
  242. else
  243. vBody = vObj.OlePropertyGet("Document").OlePropertyGet("body");
  244. vBody.OlePropertyGet("style").OlePropertySet("overflow", "hidden");
  245. }
  246. catch(Exception &e)
  247. {
  248. }
  249. #endif
  250. }
  251. //---------------------------------------------------------------------------
  252. void __fastcall TFRAMEGoogleMap::GMMap1AfterPageLoaded(TObject *Sender, bool First)
  253. {
  254. if (First)
  255. {
  256. GMMap1->DoMap();
  257. GMMap1->Tag = 1;
  258. PnlToolbar->Enabled = true;
  259. ImgLoading->Visible = false;
  260. try {
  261. if (ImgLoading->Picture->Graphic->ClassName() == "TGIFImage")
  262. ((TGIFImage *)ImgLoading->Picture->Graphic)->Animate = false;
  263. } catch(...) {}
  264. }
  265. }
  266. //---------------------------------------------------------------------------
  267. void __fastcall TFRAMEGoogleMap::GMMap1BoundsChanged(TObject *Sender, TLatLngBounds *NewBounds)
  268. {
  269. if (FMapBounds)
  270. {
  271. FMapBounds->SW->Lat = NewBounds->SW->Lat;
  272. FMapBounds->SW->Lng = NewBounds->SW->Lng;
  273. FMapBounds->NE->Lat = NewBounds->NE->Lat;
  274. FMapBounds->NE->Lng = NewBounds->NE->Lng;
  275. }
  276. }
  277. //---------------------------------------------------------------------------
  278. void __fastcall TFRAMEGoogleMap::GMMap1ZoomChanged(TObject *Sender, int NewZoom)
  279. {
  280. FMapZoom = NewZoom;
  281. try
  282. {
  283. int nLineWidth;
  284. if (FMapZoom > 14)
  285. nLineWidth = 5;
  286. else
  287. nLineWidth = 3;
  288. #if 0
  289. if (nLineWidth == FLineWidth)
  290. return;
  291. FLineWidth = nLineWidth;
  292. try
  293. {
  294. GMPolyline1->Map = NULL;
  295. int nPolylines = GMPolyline1->Count;
  296. for (int ii = nPolylines - 1; ii >= 0; ii--)
  297. {
  298. TPolyline *pTmpLine = GMPolyline1->Items[ii];
  299. pTmpLine->StrokeWeight = FLineWidth;
  300. }
  301. }
  302. __finally
  303. {
  304. GMPolyline1->Map = GMMap1;
  305. }
  306. #endif
  307. if (FExtent.Extent)
  308. {
  309. AddExtentQ(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng, NewZoom);
  310. }
  311. FExtent.Extent = true;
  312. }
  313. catch(...)
  314. {
  315. }
  316. LblZoom->Caption = "Zoom: " + String(FMapZoom) + " ";;
  317. if (FOnZoomChangeClick) FOnZoomChangeClick(Sender);
  318. }
  319. //---------------------------------------------------------------------------
  320. void __fastcall TFRAMEGoogleMap::GMMap1DragEnd(TObject *Sender)
  321. {
  322. if (FExtent.Extent)
  323. {
  324. AddExtentQ(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng, GMMap1->RequiredProp->Zoom);
  325. }
  326. FExtent.Extent = true;
  327. }
  328. //---------------------------------------------------------------------------
  329. void __fastcall TFRAMEGoogleMap::BtnMapToJpgClick(TObject *Sender)
  330. {
  331. try
  332. {
  333. if (GMMap1->Active)
  334. {
  335. SaveDialog1->FileName = Now().FormatString("YYYYMMDDHHNNSS") + ".jpg";
  336. if (SaveDialog1->Execute())
  337. {
  338. GMMap1->SaveToJPGFile(SaveDialog1->FileName);
  339. }
  340. }
  341. } catch(Exception &e) { }
  342. }
  343. //---------------------------------------------------------------------------
  344. void __fastcall TFRAMEGoogleMap::BtnMoveMapToCenterClick(TObject *Sender)
  345. {
  346. // 지도 중앙으로 이동
  347. try
  348. {
  349. if (GMMap1->Active)
  350. {
  351. int nZoom = GMMap1->VisualProp->ZoomCtrl->Position;
  352. GMMap1->SetCenter(FCenLatLng);
  353. if (FExtent.Extent)
  354. {
  355. AddExtentQ(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng, GMMap1->RequiredProp->Zoom);
  356. }
  357. FExtent.Extent = true;
  358. }
  359. } catch(Exception &e) { }
  360. }
  361. //---------------------------------------------------------------------------
  362. void __fastcall TFRAMEGoogleMap::BtnMoveDefBoundsClick(TObject *Sender)
  363. {
  364. // 지도 기본영역으로 이동
  365. try
  366. {
  367. if (GMMap1->Active)
  368. {
  369. GMMap1->SetCenter(FCenLatLng);
  370. GMMap1->RequiredProp->Zoom = FBaseZoom;
  371. if (FExtent.Extent)
  372. {
  373. AddExtentQ(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng, GMMap1->RequiredProp->Zoom);
  374. }
  375. FExtent.Extent = true;
  376. }
  377. } catch(Exception &e) { }
  378. }
  379. //---------------------------------------------------------------------------
  380. void __fastcall TFRAMEGoogleMap::BtnZoomInClick(TObject *Sender)
  381. {
  382. try
  383. {
  384. if (GMMap1->Active)
  385. {
  386. GMMap1->RequiredProp->Zoom = FMapZoom + 1;
  387. }
  388. } catch(Exception &e) { }
  389. }
  390. //---------------------------------------------------------------------------
  391. void __fastcall TFRAMEGoogleMap::BtnZoomOutClick(TObject *Sender)
  392. {
  393. try
  394. {
  395. if (GMMap1->Active)
  396. {
  397. if (FMapZoom > 0)
  398. {
  399. GMMap1->RequiredProp->Zoom = FMapZoom - 1;
  400. }
  401. }
  402. } catch(Exception &e) { }
  403. }
  404. //---------------------------------------------------------------------------
  405. void __fastcall TFRAMEGoogleMap::BtnZoomPrevClick(TObject *Sender)
  406. {
  407. PrevExtentQ();
  408. }
  409. //---------------------------------------------------------------------------
  410. void __fastcall TFRAMEGoogleMap::BtnZoomNextClick(TObject *Sender)
  411. {
  412. NextExtentQ();
  413. }
  414. //---------------------------------------------------------------------------
  415. void __fastcall TFRAMEGoogleMap::GMMap1CenterChanged(TObject *Sender, TLatLng *LatLng,
  416. double X, double Y)
  417. {
  418. FCenterLat = LatLng->Lat;
  419. FCenterLng = LatLng->Lng;
  420. }
  421. //---------------------------------------------------------------------------
  422. void __fastcall TFRAMEGoogleMap::RemoveMarker(TGMMarker *AMarker)
  423. {
  424. TGMMarker *pObjMarker = (TGMMarker*)AMarker;
  425. try
  426. {
  427. pObjMarker->Map = NULL;
  428. int nObjs = pObjMarker->Count;
  429. for (int ii = nObjs - 1; ii >= 0; ii--)
  430. {
  431. pObjMarker->Items[ii]->Visible = false;
  432. pObjMarker->Delete(ii);
  433. }
  434. pObjMarker->Clear();
  435. }
  436. catch(Exception &e)
  437. {
  438. }
  439. }
  440. //---------------------------------------------------------------------------
  441. void __fastcall TFRAMEGoogleMap::ChkDrawGisClick(TObject *Sender)
  442. {
  443. if (FOnDrawFacilityClick) FOnDrawFacilityClick(Sender);
  444. }
  445. //---------------------------------------------------------------------------