Modulo:Mapframe: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
aggiunta lettura coordinate da Wikidata |
m modulo no globals obsoleto |
||
(10 versioni intermedie di un altro utente non mostrate) | |||
Riga 1:
require('
local getArgs = require('Module:Arguments').getArgs
local mWikidata = require('Module:Wikidata')
Riga 10 ⟶ 11:
local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or ''
return string.format('<span class="error">%s</span>%s', msg, cat)
end
local function getLegenda(points, ncols)
local divStyle = {
['margin-top'] = '5px',
['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(' ')
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 sinottico = tonumber(args.sinottico) or 0
local colore = args.colore or '#b80000'
local simbolo = args.simbolo or '-number'
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 dsimbolo = 'medium'
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
}
-- =================================
-- popola la sequence points
-- =================================
if not args.dati then
local num = 1
if sinottico == 1 and args.lat1 == nil and args.lon1 == nil then
Riga 42 ⟶ 95:
dsimb = args['dim_simbolo' .. num] or dsimbolo, --dimensione del simbolo da mostrare
}
if
points[num].simb = '-number-' .. gruppo end
if points[num].lat > 85 or points[num].lat < -85 then
error(string.format('latitudine non valida per il punto %d', num), 2)
elseif
error(string.format('longitudine non valida per il punto %d', num), 2)
else
Riga 54 ⟶ 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
-- =================================
-- popola la table m_args
-- =================================
-- valore ingrandimento
if args.zoom then
m_args.zoom = tonumber(args.zoom)
elseif
if
m_args.zoom = 10 -- valore predefinito per singolo punto
if
m_args.zoom = 13 -- valore predefinito per sinottico con singolo punto
end
elseif
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 93 ⟶ 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
m_args.zoom = 10 -- valore default per singolo punto
else
Riga 101 ⟶ 143:
end
-- esclude didascalia per cornice = 0 e per sinottico = 1
if
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
if
m_args.longitude = points[1].lon
else
Riga 115 ⟶ 159:
if args.centro_lat then
m_args.latitude = tonumber(args.centro_lat)
elseif
if
m_args.latitude = points[1].lat
else
Riga 127 ⟶ 171:
end
-- =================================
-- popola la table m_dati
-- =================================
local m_dati
if
m_dati = args.dati
else
m_dati = { type = 'FeatureCollection', features = {} }
for i,
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 = {
}
}
end
m_dati = mw.text.jsonEncode(m_dati)
end
|