Template:Map Location: Difference between revisions
creating map data template |
mNo edit summary |
||
| Line 1: | Line 1: | ||
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, | |||
'<div class="hope-map-location" ' .. | |||
'style="border:1px solid #aaa; padding:0.75em; ' .. | |||
'margin:0.75em 0; max-width:32em;">' | |||
) | |||
table.insert(out, "'''" .. data.name .. "'''<br />") | |||
table.insert(out, "'''Category:''' " .. data.category .. "<br />") | |||
if data.lat and data.lon then | |||
table.insert( | |||
out, | |||
"'''Coordinates:''' " .. | |||
tostring(data.lat) .. ", " .. tostring(data.lon) .. "<br />" | |||
) | |||
else | |||
table.insert(out, "'''Coordinates:''' Missing or invalid<br />") | |||
end | |||
if data.description ~= "" then | |||
table.insert( | |||
out, | |||
"'''Description:''' " .. data.description .. "<br />" | |||
) | |||
end | |||
if data.hours ~= "" then | |||
table.insert( | |||
out, | |||
"'''Hours:''' " .. data.hours .. "<br />" | |||
) | |||
end | |||
if data.url ~= "" then | |||
table.insert( | |||
out, | |||
"'''Website:''' [" .. data.url .. " Official website]<br />" | |||
) | |||
end | |||
table.insert(out, "</div>") | |||
table.insert(out, "[[Category:HOPE 26 Map Locations]]") | |||
table.insert( | |||
out, | |||
"[[Category:HOPE 26 " .. data.category .. "]]" | |||
) | |||
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 | |||
Revision as of 22:15, 9 July 2026
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, "" )
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
