Modulo:Maplink: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
Nessun oggetto della modifica
Riga 8:
function p.scala(frame)
local t = getArgs(frame)
local amnlat1, amxlat2, bmnlon1, bmxlon2 = 400, -400, 400, -400
local dimx = tonumber(t[1]) or 1 --larghezza
local dimy = tonumber(t[2]) or 1 --altezza
Riga 16:
vlr = tonumber(t[i])
if (i % 2 == 0) then --calcolo latitudine minima e massima
if (amnlat1 > vlr) then amnlat1 = vlr end
if (amxlat2 < vlr) then amxlat2 = vlr end
else --calcolo longitudine minima e massima
if (bmnlon1 > vlr) then bmnlon1 = vlr end
if (bmxlon2 < vlr) then bmxlon2 = vlr end
end
end
end
 
-- per evitare punti troppo vicini al margine
-- problemi con latitudine oltre 85°
local dx = 1.05*(bmx-bmn)
if ((lat2>85) or (lat1<-85)) then return 0 end
local dy = 1.05*(amx-amn)
 
-- calcola posizione rispetto a Web Mercator per griglia di lato 1
-- con fattore 1.10 per evitare punti troppo vicini al margine
local dx = 1.0510*(bmxlon2-bmnlon1)/360
local dy = 1.10*(math.log(math.tan( math.pi*(1 + lat2/90)/4)) - math.log(math.tan( math.pi*(1 + lat1/90)/4)))/(2*math.pi)
 
-- calcolo scale per coordinate
local scalax, scalay
if (dx == 0) then scalax = 18 else scalax = math.floor(-math.log(360/dx)/math.log(2)) end
if (dy == 0) then scalay = 18 else scalay = math.floor(-math.log(180/dy)/math.log(2)) end
local scala
if ((dx == 0) and (dy == 0)) then
Riga 40 ⟶ 46:
end
 
-- Calcola centro per singola coordinatalongitudine
-- esempio chiamata di funzione {{#invoke:Mappa OSM|centro|x1|x2|...}}
function p.centro(frame)
Riga 52 ⟶ 58:
end
return (mn+mx)/2
end
 
-- Calcola centro per latitudine
-- esempio chiamata di funzione {{#invoke:Mappa OSM|centro2|x1|x2|...}}
function p.centro2(frame)
local dyt = 1.05*getArgs(amx-amnframe)
local mn, mx = 400, -400
local xval
for i,v in ipairs(t) do
xval = tonumber(t[i])
if (mn > xval) then mn = xval end
if (mx < xval) then mx = xval end
end
local lat1 = 1-math.log(math.tan( math.pi*(1 + mn/90)/4))/math.pi
local lat2 = 1-math.log(math.tan( math.pi*(1 + mx/90)/4))/math.pi
local latm = (lat1+lat2)/2
local coord = (math.atan(math.exp(math.pi*(1-latm)))-math.pi/4)*360/math.pi
return coord
end