Module:GeoSetsNav
Appearance
From Wikimedia Commons, the free media repository
Lua
Documentation for this module may be created at Module:GeoSetsNav/doc
Code
local p = {} function p.renderMap(frame) -- Try to get parameters from the current frame; if empty, check the parent frame. local args = frame.args if not next(args) then args = frame:getParent().args end local markers = {} for k, v in pairs(args) do if k:match("^marker%d+$") then -- Expect each value in the format: lat,lon,label local lat, lon, label = v:match("^%s*([%-%.%d]+)%s*,%s*([%-%.%d]+)%s*,%s*(.+)%s*$") if lat and lon and label then table.insert(markers, { lat = lat, lon = lon, label = label }) end end end if #markers == 0 then return "No markers provided." end -- Build parameters for Template:Maplink. local params = {} params.frame = "yes" -- display the map in a frame params.plain = "no" -- include the surrounding frame (set to "yes" for no frame) params.zoom = args.zoom or "18" -- default zoom level; adjust as needed params["frame-width"] = args["frame-width"] or "800" -- default width if not set params["frame-height"] = args["frame-height"] or "600" -- default height if not set -- Function to convert a coordinate value (as string) into the expected format local function formatCoord(value, isLat) local num = tonumber(value) if not num then return nil end local absVal = tostring(math.abs(num)) local hemisphere = "" if isLat then hemisphere = num < 0 and "S" or "N" else hemisphere = num < 0 and "W" or "E" end return absVal .. "_" .. hemisphere end for i, marker in ipairs(markers) do local latStr = formatCoord(marker.lat, true) local lonStr = formatCoord(marker.lon, false) if not (latStr and lonStr) then -- Skip markers with invalid numeric coordinates. else local coordStr = latStr .. "_" .. lonStr -- e.g. "19.928323_N_43.938624_W" if i == 1 then params.type = "point" params.coord = coordStr params.title = marker.label else params["type" .. i] = "point" params["coord" .. i] = coordStr params["title" .. i] = marker.label end end end return frame:expandTemplate{ title = "Maplink", args = params } end return p