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.

GetUrlScript.txt 2.4 KiB

54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
54 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. function GetCode(const url: AnsiString): Cardinal;
  2. var
  3. VResponseCode: Cardinal;
  4. VResponseHeader, VResponseData: AnsiString;
  5. begin
  6. Result := 1;
  7. if Assigned(Downloader) then begin
  8. VResponseHeader := '';
  9. VResponseData := '';
  10. VResponseCode := Downloader.DoHttpRequest(url, '', '', VResponseHeader, VResponseData);
  11. Result := VResponseCode;
  12. end;
  13. end;
  14. var
  15. BaseUrl: string;
  16. code: Cardinal;
  17. z_ok, z_no: integer;
  18. r: integer;
  19. begin
  20. ResultURL := '';
  21. z_ok := StrToIntDef(GetBefore(';', ScriptBuffer), 1); // Максимальный масштаб, который точно есть
  22. z_no := StrToIntDef(GetAfter(';', ScriptBuffer), 25); // Минимальный масштаб, которого точно нет
  23. // Масштаба нет - говорить не о чем
  24. if getz >= z_no then exit;
  25. // Выбор зеркала, если не указана версия
  26. if version = '' then
  27. r := random(3)
  28. else
  29. r := StrToInt(version);
  30. case r of
  31. 0: BaseUrl := GetURLBase;
  32. 1: BaseUrl := RegExprReplaceMatchSubStr(GetURLBase, 'http://91.237.82.95:8088', 'https://maps.melda.ru');
  33. 2: BaseUrl := RegExprReplaceMatchSubStr(GetURLBase, '91.237.82.95:8088/pub/genshtab', 't.caucasia.ru:80');
  34. end;
  35. // Проверяем наличие масштаба
  36. if getz > z_ok then begin
  37. code := GetCode(BaseUrl+'z'+inttostr(getz)+'/');
  38. // Внимание! Если сервер вернёт 403 - code почему-то будет 0. Так что выбор "404 или что-то иное"
  39. // Если дело дошло до проверки наличия масштаба - значит какая-то граница (z_ok / z_no) точно подвинется.
  40. if code = 404 then z_no := getz else z_ok := getz;
  41. // Сохраняем актуализированные границы для последующих вызовов
  42. ScriptBuffer := inttostr(z_ok) + ';' + inttostr(z_no);
  43. // Масштаба нет (о чём могли только что при проверке узнать) - говорить не о чем
  44. if getz >= z_no then exit;
  45. end;
  46. // Ок, качаем тайлик
  47. ResultURL:= BaseUrl+'z'+inttostr(getz)+'/'+inttostr(getx div 1024)+'/x'+inttostr(getx)+'/'+inttostr(gety div 1024)+'/y'+inttostr(gety)+'.jpg';
  48. end.