FRAME_GoogleMapF.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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 "cxButtons"
  12. #pragma link "cxCheckBox"
  13. #pragma link "cxContainer"
  14. #pragma link "cxControls"
  15. #pragma link "cxEdit"
  16. #pragma link "cxGraphics"
  17. #pragma link "cxLabel"
  18. #pragma link "cxLookAndFeelPainters"
  19. #pragma link "cxLookAndFeels"
  20. #pragma link "dxSkinBlack"
  21. #pragma link "dxSkinBlue"
  22. #pragma link "dxSkinsCore"
  23. #pragma link "GMClasses"
  24. #pragma link "GMLinkedComponents"
  25. #pragma link "GMMap"
  26. #pragma link "GMMapVCL"
  27. #pragma link "GMMarker"
  28. #pragma link "GMMarkerVCL"
  29. #pragma resource "*.dfm"
  30. TFRAMEGoogleMap *FRAMEGoogleMap;
  31. //---------------------------------------------------------------------------
  32. __fastcall TFRAMEGoogleMap::TFRAMEGoogleMap(TComponent* Owner)
  33. : TFrame(Owner)
  34. {
  35. LangTrans->Translate(this, ITSDb_GetConnection());
  36. //ITSSkin_Load((TForm*)this);
  37. LoadLocalSkin();
  38. FOnDrawFacilityClick = NULL;
  39. FOnZoomChanged = NULL;
  40. FOnBoundsChanged = NULL;
  41. FOnAfterPageLoaded = NULL;
  42. FOnFirstPageLoaded = NULL;
  43. FIsFirst = false;
  44. FIsDragginStart = false;
  45. FIsDragginEnd = false;
  46. FIsDragging = false;
  47. FMapStart = false;
  48. memset((char*) & FPrev, 0x00, sizeof(FPrev));
  49. memset((char*) & FExtent, 0x00, sizeof(FExtent));
  50. FExtent.Extent = true;
  51. FExtent.TotCnt = 0;
  52. FExtent.CurIdx = 0;
  53. FMapZoom = g_GisInfo.nZoomLevel;
  54. FBaseZoom = FMapZoom;
  55. GMMap1->APIKey = g_GisInfo.sApiKey;
  56. GMMap1->RequiredProp->Zoom = FBaseZoom;
  57. GMMap1->RequiredProp->Center->Lat = g_GisInfo.dCenterX;
  58. GMMap1->RequiredProp->Center->Lng = g_GisInfo.dCenterY;
  59. FMapTypeId = mtHYBRID; //mtTERRAIN, mtROADMAP, mtSATELLITE, mtTERRAIN, mtOSM
  60. PnlZoom->Caption = "Zoom: " + String(FMapZoom) + " ";
  61. FCenLatLng = new TLatLng(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng);
  62. FMapBounds = new TLatLngBounds(0, 0, 0, 0);
  63. FCenterLat = GMMap1->RequiredProp->Center->Lat;
  64. FCenterLng = GMMap1->RequiredProp->Center->Lng;
  65. TMarker *pMarker = GMMarker1->Items[0];
  66. if (pMarker == NULL)
  67. pMarker = GMMarker1->Items[0];
  68. if (pMarker)
  69. {
  70. pMarker->Icon = g_sImageDir + "pos.png";
  71. }
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TFRAMEGoogleMap::LoadLocalSkin()
  75. {
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TFRAMEGoogleMap::LoadGisMap()
  79. {
  80. if (!GMMap1->Active)
  81. {
  82. GMMap1->Active = true;
  83. }
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TFRAMEGoogleMap::SetLinkLevel(int ALinkLevel)
  87. {
  88. FLinkLevel = ALinkLevel;
  89. }
  90. //---------------------------------------------------------------------------
  91. void __fastcall TFRAMEGoogleMap::ShowHideTrafficLayer(bool AShow)
  92. {
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TFRAMEGoogleMap::SelectObjectByPos(double dPosX, double dPosY, bool bArrow/*=false*/)
  96. {
  97. TMarker *pMarker = GMMarker1->Items[0];
  98. if (pMarker == NULL)
  99. pMarker = GMMarker1->Items[0];
  100. if (!pMarker) return;
  101. TmrSelect->Enabled = false;
  102. pMarker->Visible = false;
  103. pMarker->Position->Lat = dPosY; // dLat;
  104. pMarker->Position->Lng = dPosX; // dLng;
  105. pMarker->CenterMapTo();
  106. pMarker->CenterMapToMarker();
  107. pMarker->Animation->OnDrop = false;
  108. pMarker->Animation->OnDrop = true;
  109. pMarker->Visible = true;
  110. if (FExtent.Extent)
  111. {
  112. //AddExtentQ(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng, GMMap1->RequiredProp->Zoom);
  113. //AddExtentQ(dPosY, dPosX, GMMap1->RequiredProp->Zoom);
  114. }
  115. //FExtent.Extent = true;
  116. TmrSelect->Enabled = true;
  117. }
  118. //---------------------------------------------------------------------------
  119. bool __fastcall TFRAMEGoogleMap::SelectLinkByPos(int X, int Y, String &ALinkId)
  120. {
  121. return false;
  122. }
  123. //---------------------------------------------------------------------------
  124. bool __fastcall TFRAMEGoogleMap::GetLevelLinkId(int ALinkLevel, String &sLinkId, int X, int Y)
  125. {
  126. return false;
  127. }
  128. //---------------------------------------------------------------------------
  129. int __fastcall TFRAMEGoogleMap::GetLayerIndex()
  130. {
  131. return 0;
  132. }
  133. //---------------------------------------------------------------------------
  134. void __fastcall TFRAMEGoogleMap::SelGisItem(int AType, String AId)
  135. {
  136. }
  137. //---------------------------------------------------------------------------
  138. void __fastcall TFRAMEGoogleMap::OnCloseQuery(bool &CanClose)
  139. {
  140. }
  141. //---------------------------------------------------------------------------
  142. bool __fastcall TFRAMEGoogleMap::AddExtentQ(double ALat, double ALng, int FZoom)
  143. {
  144. TMapExtent *pExt = &FExtent.extent[FExtent.TotCnt];
  145. pExt->Lat = ALat;
  146. pExt->Lng = ALng;
  147. pExt->Zoom = (short)FZoom;
  148. if (FPrev.Lat == pExt->Lat && FPrev.Lng == pExt->Lng && FPrev.Zoom == pExt->Zoom)
  149. {
  150. return false;
  151. }
  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::GMMap1AfterPageLoaded(TObject *Sender, bool First)
  234. {
  235. if (First)
  236. {
  237. FMapStart = true;
  238. GMMap1->DoMap();
  239. GMMap1->Tag = 1;
  240. PnlToolbar->Enabled = true;
  241. if (FOnFirstPageLoaded) FOnFirstPageLoaded(Sender);
  242. }
  243. if (FExtent.Extent)
  244. {
  245. AddExtentQ(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng, GMMap1->RequiredProp->Zoom);
  246. }
  247. FExtent.Extent = true;
  248. FIsFirst = First;
  249. if (GMMap1->Active)
  250. {
  251. if (FOnAfterPageLoaded) FOnAfterPageLoaded(Sender);
  252. }
  253. }
  254. //---------------------------------------------------------------------------
  255. void __fastcall TFRAMEGoogleMap::GMMap1BoundsChanged(TObject *Sender, TLatLngBounds *NewBounds)
  256. {
  257. if (FMapBounds)
  258. {
  259. FMapBounds->SW->Lat = NewBounds->SW->Lat;
  260. FMapBounds->SW->Lng = NewBounds->SW->Lng;
  261. FMapBounds->NE->Lat = NewBounds->NE->Lat;
  262. FMapBounds->NE->Lng = NewBounds->NE->Lng;
  263. }
  264. }
  265. //---------------------------------------------------------------------------
  266. void __fastcall TFRAMEGoogleMap::GMMap1ZoomChanged(TObject *Sender, int NewZoom)
  267. {
  268. FMapZoom = NewZoom;
  269. try
  270. {
  271. int nLineWidth;
  272. if (FMapZoom > 14)
  273. nLineWidth = 5;
  274. else
  275. nLineWidth = 3;
  276. #if 0
  277. if (nLineWidth == FLineWidth)
  278. return;
  279. FLineWidth = nLineWidth;
  280. try
  281. {
  282. GMPolyline1->Map = NULL;
  283. int nPolylines = GMPolyline1->Count;
  284. for (int ii = nPolylines - 1; ii >= 0; ii--)
  285. {
  286. TPolyline *pTmpLine = GMPolyline1->Items[ii];
  287. pTmpLine->StrokeWeight = FLineWidth;
  288. }
  289. }
  290. __finally
  291. {
  292. GMPolyline1->Map = GMMap1;
  293. }
  294. #endif
  295. if (FExtent.Extent)
  296. {
  297. //AddExtentQ(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng, NewZoom);
  298. }
  299. //FExtent.Extent = true;
  300. }
  301. catch(...)
  302. {
  303. }
  304. PnlZoom->Caption = "Zoom: " + String(FMapZoom) + " ";;
  305. if (FOnZoomChanged) FOnZoomChanged(Sender);
  306. }
  307. //---------------------------------------------------------------------------
  308. void __fastcall TFRAMEGoogleMap::GMMap1DragEnd(TObject *Sender)
  309. {
  310. if (FExtent.Extent)
  311. {
  312. //AddExtentQ(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng, GMMap1->RequiredProp->Zoom);
  313. }
  314. //FExtent.Extent = true;
  315. FIsDragginStart = false;
  316. FIsDragginEnd = true;
  317. }
  318. //---------------------------------------------------------------------------
  319. void __fastcall TFRAMEGoogleMap::GMMap1DragStart(TObject *Sender)
  320. {
  321. FIsDragginEnd = false;
  322. FIsDragginStart = true;
  323. FIsDragging = true;
  324. }
  325. //---------------------------------------------------------------------------
  326. void __fastcall TFRAMEGoogleMap::BtnMapToJpgClick(TObject *Sender)
  327. {
  328. try
  329. {
  330. if (GMMap1->Active)
  331. {
  332. SaveDialog1->FileName = Now().FormatString("YYYYMMDDHHNNSS") + ".jpg";
  333. if (SaveDialog1->Execute())
  334. {
  335. GMMap1->SaveToJPGFile(SaveDialog1->FileName);
  336. }
  337. }
  338. } catch(Exception &e) { }
  339. }
  340. //---------------------------------------------------------------------------
  341. void __fastcall TFRAMEGoogleMap::BtnMoveMapToCenterClick(TObject *Sender)
  342. {
  343. // 지도 중앙으로 이동
  344. try
  345. {
  346. if (GMMap1->Active)
  347. {
  348. int nZoom = GMMap1->VisualProp->ZoomCtrl->Position;
  349. GMMap1->SetCenter(FCenLatLng);
  350. if (FExtent.Extent)
  351. {
  352. //AddExtentQ(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng, GMMap1->RequiredProp->Zoom);
  353. //AddExtentQ(FCenLatLng->Lat, FCenLatLng->Lng, GMMap1->RequiredProp->Zoom);
  354. }
  355. //FExtent.Extent = true;
  356. }
  357. } catch(Exception &e) { }
  358. }
  359. //---------------------------------------------------------------------------
  360. void __fastcall TFRAMEGoogleMap::BtnMoveDefBoundsClick(TObject *Sender)
  361. {
  362. // 지도 기본영역으로 이동
  363. try
  364. {
  365. if (GMMap1->Active)
  366. {
  367. GMMap1->SetCenter(FCenLatLng);
  368. GMMap1->RequiredProp->Zoom = FBaseZoom;
  369. if (FExtent.Extent)
  370. {
  371. //AddExtentQ(GMMap1->RequiredProp->Center->Lat, GMMap1->RequiredProp->Center->Lng, GMMap1->RequiredProp->Zoom);
  372. //AddExtentQ(FCenLatLng->Lat, FCenLatLng->Lng, GMMap1->RequiredProp->Zoom);
  373. }
  374. //FExtent.Extent = true;
  375. }
  376. } catch(Exception &e) { }
  377. }
  378. //---------------------------------------------------------------------------
  379. void __fastcall TFRAMEGoogleMap::BtnZoomInClick(TObject *Sender)
  380. {
  381. try
  382. {
  383. if (GMMap1->Active)
  384. {
  385. GMMap1->RequiredProp->Zoom = FMapZoom + 1;
  386. }
  387. } catch(Exception &e) { }
  388. }
  389. //---------------------------------------------------------------------------
  390. void __fastcall TFRAMEGoogleMap::BtnZoomOutClick(TObject *Sender)
  391. {
  392. try
  393. {
  394. if (GMMap1->Active)
  395. {
  396. if (FMapZoom > 0)
  397. {
  398. GMMap1->RequiredProp->Zoom = FMapZoom - 1;
  399. }
  400. }
  401. } catch(Exception &e) { }
  402. }
  403. //---------------------------------------------------------------------------
  404. void __fastcall TFRAMEGoogleMap::BtnZoomPrevClick(TObject *Sender)
  405. {
  406. FExtent.Extent = false;
  407. PrevExtentQ();
  408. }
  409. //---------------------------------------------------------------------------
  410. void __fastcall TFRAMEGoogleMap::BtnZoomNextClick(TObject *Sender)
  411. {
  412. FExtent.Extent = false;
  413. NextExtentQ();
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TFRAMEGoogleMap::GMMap1CenterChanged(TObject *Sender, TLatLng *LatLng, 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::TmrSelectTimer(TObject *Sender)
  442. {
  443. TmrSelect->Enabled = false;
  444. TMarker *pMarker = GMMarker1->Items[0];
  445. if (pMarker == NULL)
  446. pMarker = GMMarker1->Items[0];
  447. if (pMarker)
  448. {
  449. pMarker->Visible = false;
  450. }
  451. }
  452. //---------------------------------------------------------------------------
  453. void __fastcall TFRAMEGoogleMap::WebBrowser1DocumentComplete(TObject *ASender, const IDispatch *pDisp,
  454. OleVariant &URL)
  455. {
  456. // 웹페이지 스크롤바 없애기
  457. #if 0
  458. try
  459. {
  460. Variant vBody;
  461. Variant vObj = WebBrowser1->OleObject;
  462. String strDocCompatMode = vObj.OlePropertyGet("document").OlePropertyGet("compatMode");
  463. if (SameText(strDocCompatMode, "CSS1Compat"))
  464. vBody = vObj.OlePropertyGet("Document").OlePropertyGet("documentElement");
  465. else
  466. vBody = vObj.OlePropertyGet("Document").OlePropertyGet("body");
  467. vBody.OlePropertyGet("style").OlePropertySet("overflow", "hidden");
  468. }
  469. catch(Exception &e)
  470. {
  471. }
  472. #endif
  473. }
  474. //---------------------------------------------------------------------------
  475. void __fastcall TFRAMEGoogleMap::GMMap1MouseMove(TObject *Sender, TLatLng *LatLng,
  476. double X, double Y)
  477. {
  478. FLat = LatLng->Lat;
  479. FLng = LatLng->Lng;
  480. }
  481. //---------------------------------------------------------------------------
  482. void __fastcall TFRAMEGoogleMap::BtnIconSelectClick(TObject *Sender)
  483. {
  484. lblGap3->Caption = BtnIconSelect->SpeedButtonOptions->Down ? "S" : "";
  485. }
  486. //---------------------------------------------------------------------------