Module:Infobox mapframe
Appearance
![]() | This module is rated as alpha. It is ready for third party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
Usage
Module that automatically makes a mapframe suitable for an infobox automatically, if a page's linked Wikidata item has coordinates (अक्षांस-देशांतर लोकेशन (P625)). Otherwise, an empty string is returned.
Can be used from {{Infobox mapframe}}, or invoked directly by a template, or imported to another Lua module.
local mf = require('Module:Mapframe/sandbox')
function hasWikidataCoords(item_id)
if not(mw.wikibase.isValidEntityId(item_id)) or not(mw.wikibase.entityExists(item_id)) then
return false
end
local coordStatements = mw.wikibase.getBestStatements(item_id, 'P625')
if not coordStatements or #coordStatements == 0 then
return false
end
return true
end
function getZoom(length_km)
-- max for zoom 2 is 6400km, for zoom 3 is 3200km, for zoom 4 is 1600km, etc
local zoom = math.floor(8 - (math.log10(length_km) - 2)/(math.log10(2)))
-- limit to values between 1 and 17
return math.max(1, math.min(17, zoom))
end
local p = {}
p.main = function(frame)
local parent = frame.getParent(frame)
local parentArgs = parent.args
-- convert parent args to standard table
local args = {}
for k, v in pairs(parentArgs) do
args[k] = v
end
-- Some defaults/overrides for infobox presentation
args.display = "inline"
args.frame = "yes"
args.plain = "yes"
args["frame-width"] = args["frame-width"] or "270"
if args.length_km then
args.zoom = getZoom(tonumber(args.length_km))
elseif args.area_km2 then
args.zoom = getZoom(math.sqrt(tonumber(args.area_km2)))
else
args.zoom = 10
end
-- Shape
args.type = "shape"
args["stroke-width"] = "6"
args["stroke-color"] = "#00ff00"
-- Line
args.type2 = "line"
args["stroke-width2"] = "3"
if args.id then
args.id2 = args.id
end
-- Point
if hasWikidataCoords(args.id or mw.wikibase.getEntityIdForCurrentPage()) then
args.type3 = "point"
if args.id then
args.id3 = args.id
end
end
local mapframe = mf._main(args)
return frame:preprocess(mapframe)
end
return p