وحدة:Infobox mapframe
| This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
Usage
Module that automatically makes a mapframe suitable for an infobox automatically, if a page's linked Wikidata item has coordinates ([خطأ: الوظيفة "wdurl" غير موجودة. coordinate location (P625)]). Otherwise, an empty string is returned. The coordinates will be displayed as a point feature unless [خطأ: الوظيفة "wdurl" غير موجودة. OpenStreetMap relation ID (P402)] is specified on the Wikidata item.
Can be used from {{Infobox mapframe}}, or invoked directly by a template, or imported to another Lua module.
local p = {}
local function wdurl(id)
return 'https://www.wikidata.org/wiki/' .. id
end
-- Helper: sanitize string to number (returns nil if not valid number)
local function tonum(x)
if not x then return nil end
local n = tonumber(x)
return n
end
-- Main function
function p.autoWithCaption(frame)
local args = frame.args
local lat = tonum(args.latitude or args.lat)
local long = tonum(args.longitude or args.lon or args.long)
local caption = args.caption or "الموقع على الخريطة"
local marker = args["mapframe-marker"] or "marker"
if not (lat and long) then
return '<div class="error">خطأ: إحداثيات غير صالحة.</div>'
end
local zoom = tonumber(args.zoom) or 10
local width = args.width or "300"
local height = args.height or "200"
local framestyle = string.format("width:%spx; height:%spx", width, height)
-- خريطة Mapframe
local mapframe = string.format('<mapframe width="%s" height="%s" zoom="%d" latitude="%f" longitude="%f" text="%s" frameless/>',
width, height, zoom, lat, long, caption
)
-- التغليف
return string.format([[
<div class="mapframe-container" style="%s">
<div class="mapframe-caption" style="text-align: center; font-size: 90%%; margin-bottom: 0.3em;">%s</div>
%s
</div>
]], framestyle, caption, mapframe)
end
return p