Template:Map Location: Difference between revisions

From HOPE Wiki
Lexicon (talk | contribs)
mNo edit summary
Lexicon (talk | contribs)
mNo edit summary
Line 1: Line 1:
local p = {}
<includeonly>{{#ifeq:{{{mode|}}}|geojson
|{{#invoke:MapLocation|geojson}}
|{{#invoke:MapLocation|infobox}}
}}</includeonly><noinclude>
Use this template on HOPE 26 map-location pages.


local categoryStyles = {
== Example ==
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)
<pre>
if value == nil then
{{Map Location
return ""
|name=The New Yorker Hotel
end
|lat=40.7527316
|lon=-73.9936287
|category=Hotel
|description=HOPE 26 conference hotel.
|hours=
|url=https://www.newyorkerhotel.com/
}}
</pre>


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


local function getArgs(frame)
; name
return frame:getParent().args
: Location name. Defaults to the page title.
end


local function getData(frame)
; lat
local args = getArgs(frame)
: Required latitude in decimal degrees.
local title = mw.title.getCurrentTitle()


local category = clean(args.category)
; lon
if category == "" then
: Required longitude in decimal degrees.
category = "Other"
end


local lat = tonumber(clean(args.lat))
; category
local lon = tonumber(clean(args.lon))
: Hotel, Conference, Food, Coffee, Transit, Pharmacy, Grocery, ATM, Shipping, Quiet, Hardware, Emergency, or Other.


return {
; description
name = clean(args.name) ~= "" and clean(args.name) or title.text,
: Short description displayed in the location box and map popup.
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)
; hours
local data = getData(frame)
: Optional operating-hours note.
local out = {}


table.insert(
; url
out,
: Optional official website.
'<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 />")
The template normally renders a location information box. Internal map-generation code can request GeoJSON with:
table.insert(out, "'''Category:''' " .. data.category .. "<br />")


if data.lat and data.lon then
<pre>
table.insert(
|mode=geojson
out,
</pre>
"'''Coordinates:''' " ..
</noinclude>
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:17, 9 July 2026

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, Conference, Food, Coffee, Transit, Pharmacy, Grocery, ATM, Shipping, Quiet, Hardware, Emergency, or Other.
description
Short description displayed in the location box and map popup.
hours
Optional operating-hours note.
url
Optional official website.

The template normally renders a location information box. Internal map-generation code can request GeoJSON with:

|mode=geojson