Módulo:Mapa cos celeste
Aparencia
[ máis información | ver o historial | | | ver as instrucións ]
Obxectivo
[editar a fonte]Módulo para crear mapas celestes.
[ máis información | ver o historial | | | ver as instrucións ]
Esta documentación está transcluída desde Módulo:Mapa cos celeste/uso. Os editores poden probar cambios no mesmo en Módulo:Mapa cos celeste/probas.
Por favor, engade as categorías na subpáxina de documentación e os interwikis no Wikidata. Ver as subpáxinas deste módulo.
Por favor, engade as categorías na subpáxina de documentación e os interwikis no Wikidata. Ver as subpáxinas deste módulo.
local getArgs = require('Module:Argumentos').getArgs
local mWikidata = require('Module:Wikidades')
local cfg = mw.loadData('Module:Mapa cos celeste/datos')
local errorCategory = '[[Categoría:Artigos con erros do módulo Mapa cos celeste]]'
local p = {}
local function errhandler(msg)
local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or ''
return string.format('<span class="error">%s</span>%s', msg, cat)
end
local function getX(map, long, marksize)
local dim = 250
return math.floor(dim * (math.fmod(long + 360 + map.spost_mer0, 360) / 360) - marksize / 2)
end
local function getY(map, lat, marksize)
local dim = 250
local ret = 0
if map.projection == 'equirectangular' then
-- projecció cilíndrica equidistant o equirectangular
ret = (dim * map.height / map.width) / 2 *
(-lat / map.max_lat) +
(dim * map.height / map.width) / 2 - marksize / 2
elseif map.projection == 'Mercator' then
-- pProjecció cilíndrica de Mercator
ret = (dim * map.height / map.width) / 2 *
(-math.log(math.tan(math.pi / 4 + lat * math.pi / 360))) /
math.log(math.tan(math.pi / 4 + map.max_lat * math.pi / 360)) +
(dim * map.height / map.width) / 2 - marksize / 2
elseif map.projection == 'Lambert' then
-- projecció cilíndrica equivalent de Lambert
ret = (dim * map.height / map.width) / 2 *
(-math.sin(lat * math.pi / 180) / math.sin(map.max_lat * math.pi / 180)) +
(dim * map.height / map.width) / 2 - marksize / 2
end
return math.floor(ret)
end
-- Afegeix la preposició davant del nom del cos celeste
local function prep(cos)
if cos == 'lúa' then
return 'da Lúa'
elseif mw.ustring.find(cos, "^[aàeèéiíoòóuú]") then
return 'd’' .. mw.language.getContentLanguage():ucfirst(cos)
end
return 'de ' .. mw.language.getContentLanguage():ucfirst(cos)
end
-- Per utilitzar des d'altres mòduls
function p._main(args)
-- paràmetres requerits: mapa, lat, long
if args.mapa or args[1] then
args.mapa = mw.ustring.lower(args.mapa or args[1])
else
error('mapa non especificado', 2)
end
args.mapa = cfg.aliases[args.mapa] or args.mapa -- àlies eventual
if not cfg.maps[args.mapa] then
error('mapa non dispoñible: ' .. args.mapa, 2)
end
-- recuperació de coordenades de Wikidata
args.lat = args.lat or mWikidata.claim({property = 'P625', formatting = 'latitude', editicon='false'}) or mWikidata.claim({property = 'P8981', formatting = 'latitude', editicon='false'})
args.long = args.long or mWikidata.claim({property = 'P625', formatting = 'longitude', editicon='false'}) or mWikidata.claim({property = 'P8981', formatting = 'longitude', editicon='false'})
if not args.lat then
error('latitude non especificada', 2)
elseif not tonumber(args.lat) then
error('a latitude non é numérica', 2)
elseif not args.long then
error('lonxitude non especificada', 2)
elseif not tonumber(args.long) then
error('a lonxitude non é numérica', 2)
end
local map = cfg.maps[args.mapa]
local caption = string.format('Mapa topográfico %s. Proxección %s. Área representada: %s.',
prep(args.mapa),
(map.projection == 'equirectangular' and '' or 'de ') .. map.projection,
map.range)
return mw.getCurrentFrame():expandTemplate {
title = 'Sobreposto',
args = {
base = map.image,
base_width = '250px',
base_caption = caption,
float = args.mark or 'DeepPink pog.svg',
float_width = (args.marksize or 15) .. 'px',
float_caption = args.nom or '',
x = getX(map, args.long, args.marksize or 15),
y = getY(map, args.lat, args.marksize or 15)
}
}
end
-- Punt d'entrada des de plantilla
function p.main(frame)
return select(2, xpcall(function()
return p._main(getArgs(frame, {parentOnly = true}))
end, errhandler))
end
return p