Modulo:Mapframe: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m uniformati apici
m modulo no globals obsoleto
 
(16 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]]'
 
local p = {}
 
-- Error handler per xpcall, formatta l'errore.
local function agg(t, ...)
local args =function {...}errhandler(msg)
local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or ''
for _, s in ipairs(args) do
return string.format('<span class="error">%s</span>%s', msg, cat)
table.insert(t, s)
end
end
 
local function p.mappagetLegenda(framepoints, ncols)
local argsdivStyle = getArgs(frame){
['margin-top'] = '5px',
local err = '-'
['column-count'] = ncols,
['-moz-column-count'] = ncols,
['-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('&nbsp;')
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('&nbsp;' .. 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
err = string.format('latitudine non valida per il punto %d', num)
error(string.format('latitudine non valida per il punto %d', num), 2)
elseif (points[num].lon > 180 or points[num].lon<-180) then
elseif points[num].lon > 180 or points[num].lon < -180 then
err = string.format('longitudine non valida per il punto %d', num)
error(string.format('longitudine non valida per il punto %d', num), 2)
else
lat1 = math.min(lat1, points[num].lat)
Riga 46 ⟶ 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
 
-- =================================
if err == '-' then
-- popola la table m_args
local m_args = {}
-- =================================
m_args.width = args.larghezza or 350
-- valore ingrandimento
m_args.height = args.altezza or 300
if args.zoom then
m_args.align = args.allinea or 'right'
m_args.zoom = tonumber(args.zoom)
elseif not args.dati then
if cornice ~= 1 then m_args.frameless = 1 end
if #points == 1 then
 
m_args.zoom = 10 -- valore predefinito per singolo punto
if args.zoom then
if sinottico == 1 then
m_args.zoom = tonumber(args.zoom)
m_args.zoom = 13 -- valore predefinito per sinottico con singolo punto
elseif (geo == -1 and autozoom == 's') then
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)
Riga 66 ⟶ 135:
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 sinottico ~= 1 then
m_args.text = (args.didascalia or '') .. (elenco and getLegenda(points, elenco) or '')
end
 
if args.centro_lon then
if cornice == 1 and args.didascalia then m_args.text = args.didascalia end
m_args.longitude = tonumber(args.centro_lon)
 
if elseif not args.centro_londati then
if #points == 1 then
m_args.longitude = tonumber(args.centro_lon)
m_args.longitude = points[1].lon
elseif geo == -1 then
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
m_args.latitude = points[1].lat
else
local l1 = 1 - math.log(math.tan(math.pi * (1 + lat1 / 90) / 4)) / math.pi
local l2 = 1 - math.log(math.tan(math.pi * (1 + lat2 / 90) / 4)) / math.pi
Riga 90 ⟶ 169:
m_args.latitude = centroy
end
end
 
-- =================================
local m_dati
-- popola la table m_dati
if geo == -1 then
-- =================================
m_dati = { type = 'FeatureCollection', features = {} }
local m_dati
for i = 1, #points do
if args.dati then
m_dati.features[i] = {
typem_dati = 'Feature',args.dati
else
properties = {},
m_dati = { type = 'FeatureCollection', features = {} }
geometry = {
for i, point in ipairs(points) do
type = 'Point',
m_dati.features[i] = {
coordinates = { points[i].lon, points[i].lat }
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 = { point.lon, 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
if args.debug then
local mdebug = mw.text.jsonEncode(m_args)
return string.format('<pre>%s\n\n%s</pre>', mdebug, m_dati)
else
return mw.getCurrentFrame():extensionTag('mapframe', m_dati, m_args)
end
m_dati = mw.text.jsonEncode(m_dati)
end
 
if args.debug then
local mdebug = mw.text.jsonEncode(m_args)
return string.format('<pre>%s\n\n%s</pre>', mdebug, m_dati)
else
return mw.getCurrentFrame():extensionTag('mapframe', m_dati, m_args)
return err
end
end
 
-- Funzione per il template {{Mappa OSM}}.
function p.mappa(frame)
return select(2, xpcall(function()
return p._mappa(getArgs(frame, { parentOnly = true }))
end, errhandler))
end