|
- // -----------------------------------------------------------------------------
- // --- Óíèâåðñàëüíûé àäàïòåð îò AnyGIS
- // -----------------------------------------------------------------------------
-
- // Ýòîò ñêðèïò ïðèçâàí óïðîñòèòü äîáàâëåíèå íîâûõ êàðò â SasPlanet.
- // Îí èçáàâèò íà÷èíàþùèõ ïîëüçîâàòåëåé îò íåîáõîäèìîñòè ïðîãðàììèðîâàòü íà Pascal,
- // ÷òîáû âíîñèòü èçìåíåíèÿ â ôàéë GetUrlScript.txt ïðè äîáàâëåíèè êàæäîé íîâîé êàðòû.
- // Òåïåðü ìîæíî ïðîñòî âñòàâëÿòü ïðèâû÷íûé URL ñ çàãëóøêàìè òèïà {x}, {y}, {z}
- // â ïîëå DefURLBase èç ôàéëà params.txt. Íà ïðèìåð, òàê:
- //
- // DefURLBase=http://{s:a,b,c}.tile.openstreetmap.org/{z}/{x}/{y}.png
-
-
- // Ñêðèïò ðàçðàáàòûâàëè Nnngrach è Erelen
-
-
-
-
- // --- Ñïèñîê äîñòóïíûõ ïàðàìåòðîâ äëÿ àâòîçàìåíû:
-
- // {x} Íîìåð òàéëà ïî îñè X. (Êàê â êàðòàõ OpenStreetMaps)
- // {y} Íîìåð òàéëà ïî îñè Y. (Êàê â êàðòàõ OpenStreetMaps)
- // {z} Óðîâåíü ïðèáëèæåíèÿ/çóìà. (Êàê â êàðòàõ OpenStreetMaps)
- // {q} Íîìåð òàéëà â ñèñòåìå QuadKey. (Êàê â êàðòàõ Bing)
- // {-y} Èíâåðòèðîâàííûé íîìåð òàéëà ïî îñè Y. (Êàê íà ñàéòå Nakarte)
- // {bbox} Êîîðäèíàòû ãðàíèö òàéëà. (Äëÿ WMS ñåðâåðîâ)
- // {timeStamp} Òåêóùåå âðåìÿ â ôîðìàòå UnixTime. (Äëÿ êàðò ñ ïðîáêàìè)
- // {z+1} Óðîâåíü çóìà. (Äëÿ êàðò, õðàíÿùèõñÿ â ôîðìàòå SasPlanet)
- // {x/1024} Íîìåð ïåðâîé ïîäïàïêè (Äëÿ êàðò, â ôîðìàòå SasPlanet)
- // {y/1024} Íîìåð âòîðîé ïîäïàïêè (Äëÿ êàðò, â ôîðìàòå SasPlanet)
- // {s:a,b,c} Áóêâà èëè öèôðà ñ íîìåðîì çåðêàëà ñåðâåðà.
- //  äàííîì ñëó÷àå - îäíà èç áóêâ (A,B,C), âûáðàííàÿ ðàíäîìíî.
-
-
-
- // Ñîâåò äëÿ íà÷èíàþùèõ: åñëè õîòèòå ðàçîáðàòüñÿ â ýòîì êîäå,
- // òî óäîáíåå âñåãî ÷èòàòü åãî ñ êîíöà.
-
- // Åùå îäèí ñîâåò: åñëè áóäåòå ïèñàòü ñâîè ñêðèïòû,
- // òî âûâîä â êîíñîëü (à òî÷íåå, â îêíî Debug Output ) äåëàåòñÿ òàê:
- //
- // writeLn('Hello Sas.Planet!');
-
-
-
-
-
-
-
-
- // -----------------------------------------------------------------------------
- // --- 4. Âñïîìîãàòåëüíûå ôóíêöèè
- // -----------------------------------------------------------------------------
-
- // --- Ïðîâåðèòü, ñîäåðæèò ëè îäíà ñòðîêà äðóãóþ?
- function isContains(findingText: string; inSourceText: string) : boolean;
- begin
- result := pos(findingText, inSourceText) <> 0;
- end;
-
-
- // --- Îêðóãëåíèå äî íóæíîãî êîëè÷åñòâà çíàêîâ ïîñëå çàïÿòîé
- // --- (ñòàíäàðòíûå ôóíêöèè îêðóãëåíèÿ ó ìåíÿ ïî÷åìó-òî íå çàðàáîòàëè)
- function roundFor(sourceNumber: Double ; digitAfterComma: integer) : string;
- var
- intPart, floatPart : integer;
- begin
- intPart := floor(sourceNumber);
- floatPart := floor( (sourceNumber - intPart) * round(intPower(10, digitAfterComma)) )
- result := intToStr(intPart) + '.' + intToStr(floatPart)
- end;
-
-
- // --- Âû÷èñëèòü íîìåð òàéëà â ñèñòåìå Quadkey (èñïîëüçóåòñÿ â êàðòàõ Bing)
- function getQuadkeyText(x: integer; y: integer; z: integer) : string;
- var
- i, q : byte;
- begin
- result:='';
- for i:=1 to z do begin
- q:=0;
- if x mod 2 = 1 then q := q + 1;
- if y mod 2 = 1 then q := q + 2;
- x := x div 2;
- y := y div 2;
- result := intToStr(q) + result;
- end;
- end;
-
-
-
-
- // -----------------------------------------------------------------------------
- // --- 3. Åñëè òðåáóåòñÿ, òî ïîäñòàâèòü èìÿ äëÿ çåðêàëà ñåðâåðà
- // --- íà ìåñòî çàãëóøêè òèïà {s: a,b,c}
- // -----------------------------------------------------------------------------
- type
- TSubst = record
- mask, val : string;
- end;
- TSubsts = record
- count : integer;
- s : array [0..15] of TSubst;
- end;
-
-
- function replaceServerName(url: string) : string;
- var
- s, ss : string;
- sarr : array [0..9] of string;
- sarr_l, p : integer;
-
- begin
- s := RegExprGetMatchSubStr(url, '\{[sS]:([^}]+)\}', 0);
- if s <> '' then begin
- ss := s;
- ss := StringReplace(ss, '{s:', '', [rfIgnoreCase]);
- ss := StringReplace(ss, '}', '', [rfIgnoreCase]);
- ss := ss + ',';
- sarr_l := 0;
- while ss <> '' do begin
- p := pos(',', ss);
- if p = 0 then p := length(ss);
- sarr[sarr_l] := copy(ss, 1, p-1);
- sarr_l := sarr_l + 1;
- delete(ss, 1, p);
- end;
- url := StringReplace(url, s, sarr[random(sarr_l)], []);
- end;
- Result := url;
- end;
-
-
-
-
- // -----------------------------------------------------------------------------
- // --- 2. Åñëè òðåáóåòñÿ, òî âû÷èñëèòü è ïîäñòàâèòü â øàáëîí URL àäðåñà
- // --- íóæíûå çíà÷åíèÿ íà ìåñòî çàãëóøåê òèïà {x}, {y}, {z}.
- // -----------------------------------------------------------------------------
- function replaceLeafletPlaceholders(urlTemplate: string; x: integer; y: integer; z: integer) : string;
- var
- options: tReplaceFlags;
- calculatedValue: string;
-
- begin
- options := [rfReplaceAll, rfIgnoreCase];
- result := urlTemplate;
-
- if isContains('{x}', result) then begin
- calculatedValue := intToStr(x);
- result := stringReplace( result, '{x}', calculatedValue, options)
- end;
-
- if isContains('{y}', result) then begin
- calculatedValue := intToStr(y);
- result := stringReplace( result, '{y}', calculatedValue, options)
- end;
-
- if isContains('{z}', result) then begin
- calculatedValue := intToStr(z-1);
- result := stringReplace( result, '{z}', calculatedValue, options)
- end;
-
- if isContains('{z+1}', result) then begin
- calculatedValue := intToStr(z);
- result := stringReplace( result, '{z+1}', calculatedValue, options)
- end;
-
- if isContains('{x/1024}', result) then begin
- calculatedValue := intToStr(x div 1024);
- result := stringReplace( result, '{x/1024}', calculatedValue, options)
- end;
-
- if isContains('{y/1024}', result) then begin
- calculatedValue := intToStr(y div 1024);
- result := stringReplace( result, '{y/1024}', calculatedValue, options)
- end;
-
- if isContains('{-y}', result) then begin
- calculatedValue := intToStr( round(intPower(2, z-1)) - 1 - y);
- result := stringReplace( result, '{-y}', calculatedValue, options)
- end;
-
- if isContains('{q}', result) then begin
- calculatedValue := getQuadkeyText(x, y, z);
- result := stringReplace( result, '{q}', calculatedValue, options)
- end;
-
- if isContains('{bbox}', result) then begin
- result := stringReplace( result, '{bbox}', '{Left},{Bottom},{Right},{Top}', options)
- result := stringReplace( result, '{Left}', roundFor(GetLMetr,8), options)
- result := stringReplace( result, '{Bottom}', roundFor(GetBMetr,8), options)
- result := stringReplace( result, '{Right}', roundFor(GetRMetr,8), options)
- result := stringReplace( result, '{Top}', roundFor(GetTMetr,8), options)
- // Äåëàþ çàìåíó â ïÿòü îïåðàöèé ïîòîìó, ÷òî ïðè ïîïûòêå
- // ñäåëàòü âñå îäíîé ñòðîêîé âîçíèêàåò îøèáêà.
- // Âîçìîæíî êàêîå-òî îãðàíè÷åíèå íà ïàìÿòü.
- end;
-
- if isContains('{timeStamp}', result) then begin
- calculatedValue := IntToStr(GetUnixTime);
- result := stringReplace( result, '{timeStamp}', calculatedValue, options)
- end;
- end;
-
-
-
-
- // -----------------------------------------------------------------------------
- // --- 1. Ñòàðò ñêðèïòà. Çàïóñòèòü âû÷èñëåíèå URL-àäðåñà òàéëà.
- // --- Ñêà÷àòü òàéë ïî ïîëó÷åííîìó URL.
- // -----------------------------------------------------------------------------
- begin
- resultURL := replaceLeafletPlaceholders(getURLBase, getX, getY, getZ);
- resultURL := replaceServerName(resultURL);
- end.
|