Template:Map Location

From HOPE Wiki
Revision as of 22:15, 9 July 2026 by Lexicon (talk | contribs)

local p = {}

local categoryStyles = { Hotel = { symbol = "lodging", color = "#7b1fa2" }, Conference = { symbol = "star", color = "#d32f2f" }, Food = { symbol = "restaurant", color = "#e65100" }, Coffee = { symbol = "cafe", color = "#795548" }, Transit = { symbol = "rail", color = "#1565c0" }, Pharmacy = { symbol = "pharmacy", color = "#2e7d32" }, Grocery = { symbol = "grocery", color = "#558b2f" }, ATM = { symbol = "bank", color = "#00695c" }, Shipping = { symbol = "post", color = "#455a64" }, Quiet = { symbol = "library", color = "#5d4037" }, Hardware = { symbol = "hardware", color = "#616161" }, Emergency = { symbol = "hospital", color = "#c62828" }, Other = { symbol = "marker", color = "#555555" } }

local function clean(value) if value == nil then return "" end

return mw.text.trim(tostring(value)) end

local function getArgs(frame) return frame:getParent().args end

local function getData(frame) local args = getArgs(frame) local title = mw.title.getCurrentTitle()

local category = clean(args.category) if category == "" then category = "Other" end

local lat = tonumber(clean(args.lat)) local lon = tonumber(clean(args.lon))

return { name = clean(args.name) ~= "" and clean(args.name) or title.text, lat = lat, lon = lon, category = category, description = clean(args.description), hours = clean(args.hours), url = clean(args.url), page = title.prefixedText } end

function p.infobox(frame) local data = getData(frame) local out = {}

table.insert( out,

'

'

)

table.insert(out, "" .. data.name .. "
") table.insert(out, "Category: " .. data.category .. "
")

if data.lat and data.lon then table.insert( out, "Coordinates: " .. tostring(data.lat) .. ", " .. tostring(data.lon) .. "
" ) else table.insert(out, "Coordinates: Missing or invalid
") end

if data.description ~= "" then table.insert( out, "Description: " .. data.description .. "
" ) end

if data.hours ~= "" then table.insert( out, "Hours: " .. data.hours .. "
" ) end

if data.url ~= "" then table.insert( out, "Website: [" .. data.url .. " Official website]
" ) end

table.insert(out, "

")

table.insert(out, "") table.insert( out, "" )

return table.concat(out, "\n") end

function p.geojson(frame) local data = getData(frame)

if not data.lat or not data.lon then return "" end

local style = categoryStyles[data.category] or categoryStyles.Other

local description = data.description

if data.hours ~= "" then if description ~= "" then description = description .. " " end description = description .. "Hours: " .. data.hours end

local feature = { type = "Feature", properties = { title = data.name, description = description, ["marker-symbol"] = style.symbol, ["marker-color"] = style.color }, geometry = { type = "Point", coordinates = { data.lon, data.lat } } }

return mw.text.jsonEncode(feature) end

return p