You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.3 KiB

  1. //******************************************************************************
  2. // LAYERS parameter: config_a_b_c
  3. // a = 1 for depth in meters, 2 for depth in feet, 3 for fathoms
  4. // b = 1 for 1 m safety depth (beginning of blue coloring) (unit equal to that set by a)
  5. // c = 0 for pristine Navionics charts, 1 for Sonar Charts
  6. //
  7. // TRANSPARENT parameter:
  8. // FALSE for non-layer
  9. // TRUE for layer
  10. //
  11. //******************************************************************************
  12. const
  13. cReqParams = 'LAYERS=config_1_1_0&TRANSPARENT=FALSE&theme=0';
  14. //******************************************************************************
  15. const
  16. cTTL = 24*60*60; // 24 hour
  17. function CheckTTL(const ATimeStamp: Integer): Boolean;
  18. begin
  19. Result := (cTTL div 2) > GetUnixTime - ATimeStamp;
  20. end;
  21. function GetNavToken: AnsiString;
  22. var
  23. VNavToken: AnsiString;
  24. VTimeStamp: Integer;
  25. VResponseCode: Cardinal;
  26. VResponseHeader, VResponseData: AnsiString;
  27. VRequestUrl, VRequestHeader: AnsiString;
  28. begin
  29. Result := '';
  30. Global.Lock;
  31. try
  32. if Global.Exists(0) and Global.Exists(1) then begin
  33. VNavToken := Global.GetVar(0);
  34. VTimeStamp := Global.GetVar(1);
  35. if (VNavToken <> '') and (VTimeStamp <> 0) and CheckTTL(VTimeStamp) then begin
  36. Result := VNavToken;
  37. end;
  38. end;
  39. if (Result = '') and Assigned(Downloader) then begin
  40. VRequestUrl := 'https://tile1.navionics.com/tile/get_key/Navionics_webapi_04041/maps.garmin.com';
  41. VRequestHeader := 'Origin: https://maps.garmin.com' + #13#10 + 'Referer: https://maps.garmin.com/';
  42. VResponseHeader := '';
  43. VResponseData := '';
  44. VResponseCode := Downloader.DoHttpRequest(VRequestUrl, VRequestHeader, '', VResponseHeader, VResponseData);
  45. if VResponseCode = 200 then begin
  46. Result := VResponseData;
  47. Global.SetVar(0, Result);
  48. Global.SetVar(1, GetUnixTime);
  49. end;
  50. end;
  51. finally
  52. Global.Unlock;
  53. end;
  54. end;
  55. //******************************************************************************
  56. var
  57. VNavToken: AnsiString;
  58. begin
  59. VNavToken := GetNavToken;
  60. if VNavToken <> '' then begin
  61. ResultURL := TemplateToUrl(GetURLBase) + '?' + cReqParams + '&' + 'navtoken=' + VNavToken;
  62. end else begin
  63. ResultURL := '';
  64. end;
  65. end.