Mòdul:Proves/Vriullop/Map
Aparença
< Mòdul:Proves | Vriullop
Podeu crear la pàgina d'ús per documentar aquest mòdul Lua. |
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p._tag(args)
local tagname = args.type or 'mapframe'
if tagname ~= 'maplink' and tagname ~= 'mapframe' then error('unknown type "' .. tagname .. '"') end
local geotype = args.geotype or 'Point'
local tagArgs = {
text = args.text,
zoom = tonumber(args.zoom) or 13,
latitude = tonumber(args.latitude),
longitude = tonumber(args.longitude)
}
if tagname == 'mapframe' then
tagArgs.width = args.width or 420
tagArgs.height = args.height or 420
end
local i = 1
local myfeatures = {}
while args[i .. '-latitude'] and args[i .. '-longitude'] do
myfeatures[i] = {}
myfeatures[i]['type'] = "Feature"
myfeatures[i]['geometry'] = {type = geotype, coordinates = {tonumber(args[i..'-longitude']), tonumber(args[i..'-latitude'])}}
myfeatures[i]['properties'] = {}
myfeatures[i]['properties']['title'] = args[i..'-title']
if args[i..'-image'] then
args[i..'-description'] = (args[i..'-description'] or '') .. '[[File:' .. args[i..'-image'] .. '|300px]]'
end
myfeatures[i]['properties']['description'] = args[i..'-description']
myfeatures[i]['properties']['marker-size'] = args[i..'-marker-size'] or args['marker-size']
myfeatures[i]['properties']['marker-symbol'] = args[i..'-marker-symbol'] or args['marker-symbol']
myfeatures[i]['properties']['marker-color'] = args[i..'-marker-color'] or args['marker-color']
myfeatures[i]['properties']['stroke'] = args[i..'-stroke'] or args['stroke']
myfeatures[i]['properties']['stroke-opacity'] = args[i..'-stroke-opacity'] or args['stroke-opacity']
myfeatures[i]['properties']['stroke-width'] = args[i..'-stroke-width'] or args['stroke-width']
myfeatures[i]['properties']['fill'] = args[i..'-fill'] or args['fill']
myfeatures[i]['properties']['fill-opacity'] = args[i..'-fill-opacity'] or args['fill-opacity']
i = i + 1
end
local geojson = {
type = "FeatureCollection",
features = myfeatures
}
if args.debug ~= nil then
local html = mw.html.create(tagname, not geojson and {selfClosing=true} or nil)
:attr(tagArgs)
if geojson then
html:wikitext( mw.text.jsonEncode(geojson, mw.text.JSON_PRETTY) )
end
return 'syntaxhighlight', tostring(html) .. mw.text.jsonEncode(args, mw.text.JSON_PRETTY), { lang = 'json' }
end
return tagname, geojson and mw.text.jsonEncode(geojson) or '', tagArgs
end
function p.tag(frame)
local args = getArgs(frame)
local tag, geojson, tagArgs = p._tag(args)
return frame:extensionTag(tag, geojson, tagArgs)
end
return p