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.

78 lines
2.6 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 = 10.00: for 10.00 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. // UGC parameter:
  12. // FALSE for pristine Navionics charts
  13. // TRUE for additinal user-generated content icons
  14. //******************************************************************************
  15. const
  16. cReqParams = 'LAYERS=config_1_10.00_0&TRANSPARENT=FALSE&UGC=FALSE';
  17. //******************************************************************************
  18. const
  19. cTTL = 24*60*60; // 24 hour
  20. cNavTokenKey = 'NavToken=';
  21. cTimeStampKey = 'TimeStamp=';
  22. function CheckTTL(const ATimeStamp: AnsiString): Boolean;
  23. begin
  24. Result := ( (cTTL div 2) > GetUnixTime - StrToInt64Def(ATimeStamp, 0) );
  25. end;
  26. function GetNavToken: AnsiString;
  27. var
  28. VNavToken: AnsiString;
  29. VTimeStamp: AnsiString;
  30. VResponseCode: Cardinal;
  31. VResponseHeader, VResponseData: AnsiString;
  32. VRequestUrl: AnsiString;
  33. begin
  34. Result := '';
  35. if ScriptBuffer <> '' then begin
  36. VNavToken := GetBetween(ScriptBuffer, cNavTokenKey, ';');
  37. VTimeStamp := GetBetween(ScriptBuffer, cTimeStampKey, ';');
  38. if (VNavToken <> '') and (VTimeStamp <> '') and CheckTTL(VTimeStamp) then begin
  39. Result := VNavToken;
  40. end else begin
  41. ScriptBuffer := '';
  42. end;
  43. end;
  44. if (Result = '') and Assigned(Downloader) then begin
  45. VTimeStamp := IntToStr(GetUnixTime);
  46. VRequestUrl := 'https://backend.navionics.io/tile/get_key/Navionics_internalpurpose_00001/webapiv2.navionics.com?_=' + VTimeStamp;
  47. VResponseHeader := '';
  48. VResponseData := '';
  49. VResponseCode := Downloader.DoHttpRequest(VRequestUrl, '', '', VResponseHeader, VResponseData);
  50. if VResponseCode = 200 then begin
  51. Result := VResponseData;
  52. ScriptBuffer := cNavTokenKey + Result + ';' + cTimeStampKey + VTimeStamp + ';';
  53. end;
  54. end;
  55. end;
  56. //******************************************************************************
  57. var
  58. VNavToken: AnsiString;
  59. begin
  60. VNavToken := GetNavToken;
  61. if VNavToken <> '' then begin
  62. ResultURL := GetURLBase + IntToStr(GetZ-1) + '/' + IntToStr(GetX) + '/' +
  63. IntToStr(GetY) + '?' + cReqParams + '&' + 'navtoken=' + VNavToken;
  64. end else begin
  65. ResultURL := '';
  66. end;
  67. end.