FRAME_GoogleMapF.cpp 14 KB

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