Module:Slippymap: Difference between revisions
Jump to navigation
Jump to search
Minh Nguyen (talk | contribs) (In case anyone #invoke:s this module directly) |
Minh Nguyen (talk | contribs) (Added missing fallback for when width is only nominally specified) Tags: Mobile edit Mobile web edit |
||
Line 16: | Line 16: | ||
options.width = "full" |
options.width = "full" |
||
elseif args.width then |
elseif args.width then |
||
options.width = tonumber(clean(args.width), 10) |
options.width = tonumber(clean(args.width), 10) or 400 |
||
else |
else |
||
options.width = 400 |
options.width = 400 |
Latest revision as of 16:57, 6 March 2023
This documentation is transcluded from Module:Slippymap/doc. (Edit | history)
Note to editors: Please don't categorize this template by editing it directly. Instead, place the category in its documentation page, in its "includeonly" section.
Note to editors: Please don't categorize this template by editing it directly. Instead, place the category in its documentation page, in its "includeonly" section.
Module for Template:Slippymap because it does not work with parser functions alone.
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