Modulo:Mapframe: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
utilizzo della funzione "error", +categoria per errori, possibilità di essere usata da altro modulo
m modulo no globals obsoleto
 
(15 versioni intermedie di 2 utenti non mostrate)
Riga 1:
require('Module:No globalsstrict')
 
local getArgs = require('Module:Arguments').getArgs
local mWikidata = require('Module:Wikidata')
local errorCategory = '[[Categoria:Voci con errori del modulo Mapframe]]'
 
Riga 11 ⟶ 13:
end
 
local function agggetLegenda(tpoints, ...ncols)
local argsdivStyle = {...}
['margin-top'] = '5px',
for _, s in ipairs(args) do
['column-count'] = ncols,
table.insert(t, s)
['-moz-column-count'] = ncols,
end
['-webkit-column-count'] = ncols
}
local divNode = mw.html.create('div'):css(divStyle)
local currNum = 1
local currChar = 'A'
 
for _, point in ipairs(points) do
local pNode = mw.html.create('p')
:css('font-size', '90%')
:css('margin-top', '0')
local codeNode = mw.html.create('code')
:css('font-weight', 'bold')
:css('color', 'white')
:css('border-radius', '6px')
:css('border', '2px solid ' .. point.col)
:css('background', point.col)
if not point.simb then
codeNode:wikitext(' ')
elseif point.simb:find('-number') == 1 then
codeNode:wikitext(currNum)
currNum = currNum + 1
elseif point.simb:find('-letter') == 1 then
codeNode:wikitext(currChar)
currChar = ('ABCDEFGHIJKLMNOPQRSTUVWXYZA'):match(currChar .. '(.)')
elseif point.simb == '' then
else
codeNode
:css('padding-left', '0')
:css('padding-right', '0')
:css('background', 'white')
codeNode:wikitext(string.format('[[File:Maki2-%s-18.svg|18px]]', point.simb))
end
pNode:node(codeNode):wikitext(' ' .. point.nome)
divNode:node(pNode)
end
 
return tostring(divNode)
end
 
function p._mappa(args)
local points = {}
local geosinottico = tonumber(args.datisinottico) or -10
local colore = args.colore or '#b80000' --colore
local simbolo = args.simbolo or '-number' --simbolo
local gruppo = args.gruppo or ''
local autozoom = args.autozoom or 's'
local elenco = (args.elenco == '1' or args.elenco == '2') and args.elenco or nil
local cornice
local dsimbolo = 'medium'
if args.cornice then cornice = tonumber(args.cornice) or 1 else cornice = 1 end
local cornice = tonumber(args.cornice) or 1
local lat1, lat2, lon1, lon2 = 400, -400, 400, -400
local m_args = {
width = args.larghezza or (sinottico == 1 and 260 or 350),
height = args.altezza or (sinottico == 1 and 260 or 300),
align = args.allinea or (sinottico == 1 and 'center' or 'right'),
-- frameless con cornice = 0 o con sinottico = 1
frameless = (cornice == 0 or sinottico == 1) and 1 or nil
}
 
-- =================================
if geo == -1 then
-- popola la sequence points
-- =================================
if not args.dati then
local num = 1
if sinottico == 1 and args.lat1 == nil and args.lon1 == nil then
args.lat1 = mWikidata._getProperty({ 'P625', coord = 'latitude', n = 1 })
args.lon1 = mWikidata._getProperty({ 'P625', coord = 'longitude', n = 1 })
end
while args['nome' .. num] do
points[num] = {
nome = args['nome' .. num], -- nome del punto
desc = args['desc' .. num], -- descrizione del punto
lat = tonumber(args['lat' .. num]) or -400, --latitudine
lon = tonumber(args['lon' .. num]) or -400, --longitudine
col = args['colore' .. num] or colore, -- colore del punto
simb = args['simbolo' .. num] or simbolo, --simbolo da mostrare
dsimb = args['dim_simbolo' .. num] or dsimbolo, --dimensione del simbolo da mostrare
}
if (points[num].simb == '-number' and gruppo ~= '') then
points[num].simb = '-number-' .. gruppo end
end
if (points[num].lat > 85 or points[num].lat < -85) then
if points[num].lat > 85 or points[num].lat < -85 then
error(string.format('latitudine non valida per il punto %d', num), 2)
elseif (points[num].lon > 180 or points[num].lon < -180) then
error(string.format('longitudine non valida per il punto %d', num), 2)
else
Riga 51 ⟶ 109:
end
num = num + 1
end
-- non utilizza nessun simbolo con un solo punto e args.simbolo e args.simbolo1 non definiti
if #points == 1 and args.simbolo == nil and args.simbolo1 == nil then
points[1].simb = nil
end
end
 
-- =================================
local m_args = {}
-- popola la table m_args
m_args.width = args.larghezza or 350
-- =================================
m_args.height = args.altezza or 300
-- valore ingrandimento
m_args.align = args.allinea or 'right'
if cornice ~= 1 then m_args.frameless = 1 end
 
if args.zoom then
m_args.zoom = tonumber(args.zoom)
elseif (geonot == -1 and autozoom == 's')args.dati then
if #points == 1 then
local dx = 1.1 * (lon2 - lon1) / 360
m_args.zoom = 10 -- valore predefinito per singolo punto
local dy = 1.1 * (math.log(math.tan(math.pi * (1 + lat2 / 90) / 4)) - math.log(math.tan( math.pi * (1 + lat1 / 90) / 4))) / (2 * math.pi)
if sinottico == 1 then
m_args.zoom = 13 -- valore predefinito per sinottico con singolo punto
end
elseif autozoom == 's' then -- calcola zoom automaticamente
local dx = 1.1 * (lon2 - lon1) / 360
local dy = 1.1 * (math.log(math.tan(math.pi * (1 + lat2 / 90) / 4)) - math.log(math.tan( math.pi * (1 + lat1 / 90) / 4))) / (2 * math.pi)
 
local scalax, scalay
if dx == 0 then scalax = 18 else scalax = math.floor(-math.log(dx) / math.log(2)) end
if dy == 0 then scalay = 18 else scalay = math.floor(-math.log(dy) / math.log(2)) end
if (dx == 0 and dy == 0) then
m_args.zoom = 10 -- valore default per singolo punto
else
m_args.zoom = math.max(0, math.min(18, scalax, scalay))
end
end
end
-- esclude didascalia per cornice = 0 e per sinottico = 1
 
if cornice == 1 and args.didascalia then m_args.textsinottico ~= args.didascalia1 endthen
m_args.text = (args.didascalia or '') .. (elenco and getLegenda(points, elenco) or '')
end
 
if args.centro_lon then
m_args.longitude = tonumber(args.centro_lon)
elseif geonot == -1args.dati then
if #points == 1 then
m_args.longitude = (lon1 + lon2) / 2
m_args.longitude = points[1].lon
else
m_args.longitude = (lon1 + lon2) / 2
end
end
 
if args.centro_lat then
m_args.latitude = tonumber(args.centro_lat)
elseif (geonot == -1)args.dati then
if #points == 1 then
local l1 = 1 - math.log(math.tan(math.pi * (1 + lat1 / 90) / 4)) / math.pi
m_args.latitude = points[1].lat
local l2 = 1 - math.log(math.tan(math.pi * (1 + lat2 / 90) / 4)) / math.pi
else
local centroy = (l1 + l2) / 2
centroy local l1 = (1 - math.atanlog(math.exptan(math.pi * (1 -+ centroy)))lat1 -/ math.pi90) / 4) * 360) / math.pi
local l2 = 1 - math.log(math.tan(math.pi * (1 + lat2 / 90) / 4)) / math.pi
m_args.latitude = centroy
local centroy = (l1 + l2) / 2
centroy = (math.atan(math.exp(math.pi * (1 - centroy))) - math.pi / 4) * 360 / math.pi
m_args.latitude = centroy
end
end
 
-- =================================
-- popola la table m_dati
-- =================================
local m_dati
if geo == -1args.dati then
m_dati = args.dati
else
m_dati = { type = 'FeatureCollection', features = {} }
for i, =point 1,in #ipairs(points) do
m_dati.features[i] = {
type = 'Feature',
properties = {},
['marker-symbol'] = point.simb,
['marker-color'] = point.col,
['marker-size'] = point.dsimb,
title = point.nome,
description = point.desc
},
geometry = {
type = 'Point',
coordinates = { points[i]point.lon, points[i]point.lat }
}
}
m_dati.features[i].properties['marker-symbol'] = points[i].simb
m_dati.features[i].properties['marker-color'] = points[i].col
m_dati.features[i].properties.title = points[i].nome
end
m_dati = mw.text.jsonEncode(m_dati)
else
m_dati = frame:preprocess(geo)
end
 
Riga 124 ⟶ 206:
end
 
-- Funzione per il template {{MapframeMappa OSM}}.
function p.mappa(frame)
return select(2, xpcall(function()