Module:Slippymap

From wikiNonStop
Module documentation
local p = {}

-- cleans input of excessive whitespace typically added by linebreaks and spaces
function clean(input)
	return input and #input > 0 and mw.text.trim(input) or nil
end

function p.slippymap(frame)
	local args = (frame:getParent() or frame).args
	
	local options = {}
	options.latitude = tonumber(clean(args.lat), 10) or 51.3432699
	options.longitude = tonumber(clean(args.lon), 10) or 0.52700328
	options.height = tonumber(clean(args.height), 10) or 400
	if clean(args.width) == "full" then
		options.width = "full"
	elseif args.width then
		options.width = tonumber(clean(args.width), 10) or 400
	else
		options.width = 400
	end
	options.zoom = tonumber(clean(args.zoom), 10) or 12
	options.align = clean(args.alignment) or "center"
	options.text = clean(args.text)
	
	local content = nil
	if clean(args.marker) ~= "no" then
		content = mw.text.jsonEncode {
			type = "Feature",
			geometry = {
				type = "Point",
				coordinates = {
					[0] = options.longitude,
					[1] = options.latitude,
				},
			},
		}
	end
	
	return frame:extensionTag {
		name = "mapframe",
		content = content,
		args = options,
	}
end

return p