Modulo:Mapa ojeto cełeste

Da Wikipedia, l'ençiclopedia libara.



local getArgs = require('Module:Arguments').getArgs
local mWikidata = require('Module:Wikidades')
local cfg = mw.loadData('Module:Mapa ojeto cełeste/dati')
local errorCategory = ''
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
		--  
		ret = (dim * map.height / map.width) / 2 *
			  (-lat / map.max_lat) +
			  (dim * map.height / map.width) / 2 - marksize / 2
	elseif map.projection == 'Mercator' then
		--  
		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
		-- 
		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

-- 
local function prep(ojeto)
	if ojeto == 'luna' then
		return 'de ła Luna'
	elseif mw.ustring.find(ojeto, "^[aàeèéiíoòóuú]") then
		return 'd’' .. mw.language.getContentLanguage():ucfirst(ojeto)
	end
	return 'de ' .. mw.language.getContentLanguage():ucfirst(ojeto)
end

-- 
function p._main(args)
	-- mapa, lat, long
	if args.mapa or args[1] then
		args.mapa = mw.ustring.lower(args.mapa or args[1])
	else
		error('mapa no spesifegada', 2)
	end
	args.mapa = cfg.aliases[args.mapa] or args.mapa -- àlies eventual
	if not cfg.maps[args.mapa] then
		error('mapa no disponibile: ' .. args.mapa, 2)
	end
	
	--  
	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('latitùdene no spesifegada', 2)
	elseif not tonumber(args.lat) then
		error('la latitùdene no ła ze numèrega', 2)
	elseif not args.long then
		error('lonzitùdene no ła ze spesifegada', 2)
	elseif not tonumber(args.long) then
		error('la lonzitùdene no ła ze numèrega', 2)
	end
	
	local map = cfg.maps[args.mapa]
	local caption = string.format('Mapa topogràfega %s. Projesion %s. Àrea reprezentada: %s.',
						prep(args.mapa),
						(map.projection == 'equirectangular' and '' or 'de ') .. map.projection,
						map.range)
	
	return mw.getCurrentFrame():expandTemplate {
		title = 'Soraponesta',
		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

-- 
function p.main(frame)
	return select(2, xpcall(function()
		return p._main(getArgs(frame, {parentOnly = true}))
	end, errhandler))
end

return p
Traesto fora da Wikipèdia - L'ençiclopedia łìbara e cołaboradiva in łéngua Vèneta "https://vec.wikipedia.org/w/index.php?title=Modulo:Mapa_ojeto_cełeste&oldid=1081215"