Module:MapLocation
From HOPE Wiki
Documentation for this module may be created at Module:MapLocation/doc
local p = {}
local function esc(s)
if s == nil then return "" end
s = tostring(s)
s = s:gsub("\\", "\\\\")
s = s:gsub('"', '\\"')
s = s:gsub("\n", " ")
return s
end
function p.infobox(frame)
local a = frame:getParent().args
local name = a.name or mw.title.getCurrentTitle().text
local lat = a.lat or ""
local lon = a.lon or ""
local category = a.category or "Other"
local description = a.description or ""
local hours = a.hours or ""
local url = a.url or ""
local out = {}
table.insert(out, '<div class="hope-map-location" style="border:1px solid #aaa; padding:0.75em; margin:0.75em 0; max-width:32em;">')
table.insert(out, "'''" .. name .. "'''<br />")
table.insert(out, "'''Category:''' " .. category .. "<br />")
table.insert(out, "'''Coordinates:''' " .. lat .. ", " .. lon .. "<br />")
if description ~= "" then table.insert(out, "'''Description:''' " .. description .. "<br />") end
if hours ~= "" then table.insert(out, "'''Hours:''' " .. hours .. "<br />") end
if url ~= "" then table.insert(out, "'''Website:''' [" .. url .. " Link]<br />") end
table.insert(out, '</div>')
table.insert(out, '[[Category:HOPE 26 Map Locations]]')
table.insert(out, '[[Category:HOPE 26 ' .. category .. ']]')
return table.concat(out, "\n")
end
function p.geojson(frame)
local a = frame:getParent().args
local name = a.name or mw.title.getCurrentTitle().text
local lat = a.lat or ""
local lon = a.lon or ""
local category = a.category or "Other"
local description = a.description or ""
if lat == "" or lon == "" then return "" end
return string.format([[
{
"type": "Feature",
"properties": {
"title": "%s",
"description": "%s",
"marker-symbol": "marker",
"marker-color": "%s"
},
"geometry": {
"type": "Point",
"coordinates": [%s, %s]
}
}]], esc(name), esc(description), esc(category), lon, lat)
end
return p
