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.

80 lines
2.7 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. //cTTL = 1;
  21. cNavTokenKey = 'NavToken=';
  22. cTimeStampKey = 'TimeStamp=';
  23. function CheckTTL(const ATimeStamp: AnsiString): Boolean;
  24. begin
  25. Result := ( (cTTL div 2) > GetUnixTime - StrToInt64Def(ATimeStamp, 0) );
  26. end;
  27. function GetNavToken: AnsiString;
  28. var
  29. VNavToken: AnsiString;
  30. VTimeStamp: AnsiString;
  31. VResponseCode: Cardinal;
  32. VResponseHeader, VResponseData: AnsiString;
  33. VRequestUrl, VRequestHeader: AnsiString;
  34. begin
  35. Result := '';
  36. if ScriptBuffer <> '' then begin
  37. VNavToken := GetBetween(ScriptBuffer, cNavTokenKey, ';');
  38. VTimeStamp := GetBetween(ScriptBuffer, cTimeStampKey, ';');
  39. if (VNavToken <> '') and (VTimeStamp <> '') and CheckTTL(VTimeStamp) then begin
  40. Result := VNavToken;
  41. end else begin
  42. ScriptBuffer := '';
  43. end;
  44. end;
  45. if (Result = '') and Assigned(Downloader) then begin
  46. VTimeStamp := IntToStr(GetUnixTime);
  47. VRequestUrl := 'https://backend.navionics.com/tile/get_key/NAVIONICS_WEBAPP_P01/webapp.navionics.com?_=' + VTimeStamp + '123';
  48. VRequestHeader := 'Origin: https://webapp.navionics.com' + #13#10 + 'Referer: https://webapp.navionics.com/';
  49. VResponseHeader := '';
  50. VResponseData := '';
  51. VResponseCode := Downloader.DoHttpRequest(VRequestUrl, VRequestHeader, '', VResponseHeader, VResponseData);
  52. if VResponseCode = 200 then begin
  53. Result := VResponseData;
  54. ScriptBuffer := cNavTokenKey + Result + ';' + cTimeStampKey + VTimeStamp + ';';
  55. end;
  56. end;
  57. end;
  58. //******************************************************************************
  59. var
  60. VNavToken: AnsiString;
  61. begin
  62. VNavToken := GetNavToken;
  63. if VNavToken <> '' then begin
  64. ResultURL := GetURLBase + IntToStr(GetZ-1) + '/' + IntToStr(GetX) + '/' +
  65. IntToStr(GetY) + '?' + cReqParams + '&' + 'navtoken=' + VNavToken;
  66. end else begin
  67. ResultURL := '';
  68. end;
  69. end.