79 line
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. 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, VRequestHeader: 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.com/tile/get_key/NAVIONICS_WEBAPP_P01/webapp.navionics.com?_=' + VTimeStamp + '123';
  47. VRequestHeader := 'Origin: https://webapp.navionics.com' + #13#10 + 'Referer: https://webapp.navionics.com/';
  48. VResponseHeader := '';
  49. VResponseData := '';
  50. VResponseCode := Downloader.DoHttpRequest(VRequestUrl, VRequestHeader, '', VResponseHeader, VResponseData);
  51. if VResponseCode = 200 then begin
  52. Result := VResponseData;
  53. ScriptBuffer := cNavTokenKey + Result + ';' + cTimeStampKey + VTimeStamp + ';';
  54. end;
  55. end;
  56. end;
  57. //******************************************************************************
  58. var
  59. VNavToken: AnsiString;
  60. begin
  61. VNavToken := GetNavToken;
  62. if VNavToken <> '' then begin
  63. ResultURL := GetURLBase + IntToStr(GetZ-1) + '/' + IntToStr(GetX) + '/' +
  64. IntToStr(GetY) + '?' + cReqParams + '&' + 'navtoken=' + VNavToken;
  65. end else begin
  66. ResultURL := '';
  67. end;
  68. end.