Template:Map Location: Difference between revisions

From HOPE Wiki
Lexicon (talk | contribs)
mNo edit summary
Lexicon (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
<includeonly>
{{#cargo_store:
_table=MapLocations
|Name={{{name|{{PAGENAME}}}}}
|Location={{{lat|}}},{{{lon|}}}
|Category={{{category|Other}}}
|Description={{{description|}}}
|Hours={{{hours|}}}
|URL={{{url|}}}
}}


local categoryStyles = {
{{#invoke:MapLocation|infobox}}
Hotel = {
</includeonly>
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)
<noinclude>
if value == nil then
{{#cargo_declare:
return ""
_table=MapLocations
end
|Name=String
|Location=Coordinates
|Category=String
|Description=Text
|Hours=String
|URL=URL
}}


return mw.text.trim(tostring(value))
Use this template on HOPE 26 map-location pages.
end


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


local function getData(frame)
<pre>
local args = getArgs(frame)
{{Map Location
local title = mw.title.getCurrentTitle()
|name=The New Yorker Hotel
|lat=40.7527316
|lon=-73.9936287
|category=Hotel
|description=HOPE 26 conference hotel.
|hours=
|url=https://www.newyorkerhotel.com/
}}
</pre>


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


local lat = tonumber(clean(args.lat))
; name
local lon = tonumber(clean(args.lon))
: Location name. Defaults to the page title.


return {
; lat
name = clean(args.name) ~= "" and clean(args.name) or title.text,
: Required latitude in decimal degrees.
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)
; lon
local data = getData(frame)
: Required longitude in decimal degrees.
local out = {}


table.insert(
; category
out,
: Hotel, Food, Coffee, Transit, Pharmacy, Grocery, ATM, Shipping, Quiet, Hardware, Emergency, or Other.
'<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 />")
; description
table.insert(out, "'''Category:''' " .. data.category .. "<br />")
: Short description for the location page and map popup.


if data.lat and data.lon then
; hours
table.insert(
: Optional hours or availability note.
out,
"'''Coordinates:''' " ..
tostring(data.lat) .. ", " .. tostring(data.lon) .. "<br />"
)
else
table.insert(out, "'''Coordinates:''' Missing or invalid<br />")
end


if data.description ~= "" then
; url
table.insert(
: Optional official website.
out,
</noinclude>
"'''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

Latest revision as of 22:34, 9 July 2026


{{#cargo_declare:

_table=MapLocations
|Name=String
|Location=Coordinates
|Category=String
|Description=Text
|Hours=String
|URL=URL

}}

Use this template on HOPE 26 map-location pages.

Example

{{Map Location
 |name=The New Yorker Hotel
 |lat=40.7527316
 |lon=-73.9936287
 |category=Hotel
 |description=HOPE 26 conference hotel.
 |hours=
 |url=https://www.newyorkerhotel.com/
}}

Fields

name
Location name. Defaults to the page title.
lat
Required latitude in decimal degrees.
lon
Required longitude in decimal degrees.
category
Hotel, Food, Coffee, Transit, Pharmacy, Grocery, ATM, Shipping, Quiet, Hardware, Emergency, or Other.
description
Short description for the location page and map popup.
hours
Optional hours or availability note.
url
Optional official website.