Module:Football map
![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
coordinate location (P625) (see uses)
home venue (P115) (see uses)
image (P18) (see uses)
occupant (P466) (see uses)
maximum capacity (P1083) (see uses)
Overview
This module is used with the template {{football map}} to simplify creation of maps with the <mapframe> tag provided by the Kartographer extension.
The template takes the same parameters as <mapframe> and adds a number of markers using a series of |stadiumN parameters that are used to general the JSON data for the markers. The stadium data is either taken from an internal list or using Wikidata for the coordinates.
Examples:
- Template:Football map/demo — stadia of London football clubs (using data from module list)
- Template:Football map/demo2— stadia for the Russia World Cup in 2018 (using data supplied in template)
- Template:Football map/demo3 — a selection of English stadia (using a mixture of all three data sources)
- Template:Football map/demo4 — a map of the stadia in List of football stadiums in England (using Wikidata for data parameters)
- Template:Football map/demo5 — a list of clubs and their stadium for the 2018-19 Premier League season (using Wikidata for data parameters)
- User:Jts1882/maps/stadiums — a user test page with some mapframe related information and some more examples
Usage
{{#invoke:Football map|function_name}}
Template documentation
coordinate location (P625) (see uses)
home venue (P115) (see uses)
image (P18) (see uses)
occupant (P466) (see uses)
maximum capacity (P1083) (see uses)
This template uses <mapframe>...</mapframe>
to display interactive maps of football stadia, using data supplied from the template, from Wikidata, and/or from lists defined in module subpages. The markers for each stadium have a popup
window with information on the stadium (e.g. image, description, capacity, etc.).
Usage
The simplest use of the template requires the basic mapframe parameters and a list of football stadiums or football clubs.
Parameters
Mapframe parameters
|width=
and|height=
— set the dimensions of the map on the page|align=
— sets the position on the page (left, right, center)|latitude=
and|longitude=
— the coordinates of the map centre|zoom=
— a zoom factor with a value between 0 (whole world) to 19 (very local). See examples for typical values|text=
— a description of the map displayed as a footer.|frameless=
— to produce a frameless map (e.g. for an infobox).
For more further information see Kartographer extension.
Stadium and club lists
A Mapframes
map can display markers for a number of geographical features, or a football stadia for this template. It takes the data in JSON format, but this template creates the JSON data from the parameters in the template. At its simplest, it needs a list of stadia or clubs set with the following parameters.
|stadiumN=
— a list of stadia with index N. The name must point to a valid Wikipedia page title.|clubN=
— a list of football clubs with index N. Wikidata is used to get the name of the home stadium.
Stadia and clubs can be mixed, but each index can only be used once. The maximum index is currently 200.
See below for more on customising the markers.
Sources of data
Each marker needs the coordinates for its location. These can be provided in the template or got automatically from a list maintained in the module or from Wikidata. Parameters provided by the template have priority, followed those in the module lists and Wikidata.
|wikidata=
— makes Wikidata the first choice for data source. Values can be overridden by those set in the template parameters.|moduledata=
— makes the lists of data in the module the first choice for data source. Values can be overridden by those set in the template parameters.|templatedata=
— only uses data provided by the template.|latitudeN=
and|longitudeN=
— the coordinates of each stadium with the index specified|imageN=
— an image to display in the popup, entered in the form File:The Hive Stadium 3.jpg|descriptionN=
a description to display in the popup. This can contain any wiki markup, within reason.
Markers
The default markers:
|size=
— the size of the marker (small, medium, large )|color=
— the color of the marker (red, green, #0050d0, etc.)|symbol=
— the marker can take numbers, letters or custom symbols- use
-number
to number the markers (default) - use
-letter
to use a sequence of letters in the markers - use
soccer
,museum
, etc. to use a custom symbol (see mw:Help:Extension:Kartographer/IconsList of icons for more)
- use
The markers for any feature can be customised using a parameter with the index matching the feature name:
|sizeN=
— the size of the marker (small, medium, large). This is particularly useful for showing two stadia very close together (e.g. Goodison and Anfield), when making the one behind larger and/or on in front small makes them both easier to resolve. There is no control over the relative positions, which are set by<mapframe>...</mapframe>
(more northerly ones first)|colorN=
— the color of the marker (red, green, #0050d0, etc.)|symbolN=
— the marker can take numbers, letters or custom symbols.
Examples
Using data from module list
Using data supplied in template
Lua error at line 163: attempt to index local 'statements' (a nil value).
Using Wikidata for data parameters
Lua error at line 163: attempt to index local 'statements' (a nil value).
Using Wikidata for data parameters
Using a mixture of all three data sources
Lua error at line 163: attempt to index local 'statements' (a nil value).
Using Wikidata for data parameters
Lua error at line 163: attempt to index local 'statements' (a nil value).
-- All Lua modules on Wikipedia must begin by defining a variable that will hold their
-- externally accessible functions. They can have any name and may also hold data.
local p = {}
p.stadia = {
-- stadium name , latitude, longitude
{ "White Hart Lane", 51.603333, -0.065833 },
{ "Northumberland Development Project", 51.60475, -0.066417 },
{ "Wembley Stadium", 51.555833, -0.279722 },
{ "Emirates Stadium", 51.555, -0.108611 },
{ "Arsenal Stadium", 51.557778, -0.102778 },
{ "Stamford Bridge", 51.481667, -0.191111 },
{ "London Stadium", 51.538611, -0.016389 },
{ "Boleyn Ground", 51.531944, 0.039444 },
{ "Craven Cottage", 51.475, -0.221667 },
{ "The Valley (London)", 51.486389, 0.036389 },
{ "Selhurst Park", 51.398333, -0.085556},
{ "Kingsmeadow", 51.405083, -0.281944},
{ "Vicarage Road", 51.649836, -0.401486},
{ "The Hive Stadium", 51.602599, -0.291785},
{ "Loftus Road", 51.509167, -0.232222},
{ "Griffin Park", 51.488183, -0.302639},
{ "Brisbane Road", 51.56015, -0.012658},
{ "The Den", 51.485953, -0.05095},
{ "The Old Den", 51.480883, -0.048175},
{ "Wembley Stadium (1923)", 51.555556, -0.279722},
{ "x", 51, 0}
}
p.clubs = {
{ "Tottenham Hotspur F.C.", "White Hart Lane", 1899, 2017},
{ "Tottenham Hotspur F.C.", "Northumberland Development Project", 2018, -1 },
{ "Arsenal F.C.", "Emirates Stadium", 2006, -1 },
{ "Arsenal F.C.", "Arsenal Stadium", 1913, 2006 },
{ "Chelsea F.C.", "Stamford Bridge", -1, -1 },
{ "West Ham United F.C.", "London Stadium", 2016, -1 },
{ "West Ham United F.C.", "Boleyn Ground", 1904, 2016 },
{ "Fulham F.C.", "Craven Cottage", -1, -1 },
{ "Charlton Athletic F.C.", "The Valley (London)", -1, -1 },
{ "Crystal Palace F.C.", "Selhurst Park", -1, -1},
{ "A.F.C. Wimbledon", "Kingsmeadow", -1, -1},
{ "Watford F.C.", "Vicarage Road", -1, -1},
{ "Barnet F.C.", "The Hive Stadium", -1, -1},
{ "Queens Park Rangers F.C.", "Loftus Road", -1, -1},
{ "Brentford F.C.", "Griffin Park", -1, -1},
{ "Leyton Orient F.C.", "Brisbane Road", -1, -1},
{ "Millwall F.C.", "The Den", 1993, -1},
{ "Millwall F.C.", "The Old Den", 1910, 1993},
{ "England national team", "Wembley", 2007, -1 },
{ "England national team", "Wembley Stadium (1923)", 1923, 2002}
}
p.aliases = {
-- name of wikipedia article, alias
{"Northumberland Development Project", "New White Hart Lane"},
{"Arsenal Stadium", "Highbury"},
{"London Stadium", "Olympic Stadium"},
{"Boleyn Ground", "Upton Park"}
}
-- Add a function to the variable. These are callable in Wikipedia via the #invoke command.
-- "frame" will contain the data that Wikipedia sends this function when it is called.
p.hello = function(frame)
-- Declare a local variable and assign data to it.
local str = "Hello World!"
--str = '<table><tr><td>Hello</td><td>World</td></tr><tr><td>in HTML</td><td>table</td></tr></table>'
--str = p.getMapframeString()
str = p.getTestJSONstring()
-- Quit this function and send the information in "str" back to Wikipedia.
-- The "print" function is not allowed, so all output is accomplished via
-- returning strings in this fashion.
return str
end -- End the function.
-- main function
p.main = function(frame)
str = p.getMapframeString()
return frame:preprocess(str) -- the mapframe needs to be preprocessed!!!!!
end -- End the function.
--[[ function to construct mapframe string
The appropriate string with JSON between mapframe elements is generated correctly (test a copy),
but it is displaces as the string rather than embedding the map
i.e. it is not behaving like normal HTML
]]
p.getMapframeString = function(frame)
--mapString = '<mapframe text="London football stadia" width=800 height=650 align=left zoom=11 latitude=51.530 longitude=-0.16 >'
mapWidth = mw.getCurrentFrame():getParent().args['width'] or "400"
mapHeight = mw.getCurrentFrame():getParent().args['height'] or "300"
mapLatitude = mw.getCurrentFrame():getParent().args['latitude'] or "51.5"
mapLongitude = mw.getCurrentFrame():getParent().args['longitude'] or "-0.15"
mapAlign = mw.getCurrentFrame():getParent().args['align'] or "right"
mapText = mw.getCurrentFrame():getParent().args['text'] or ""
mapZoom = mw.getCurrentFrame():getParent().args['zoom'] or "9"
mapData = p.getStadiumJSON()
local mapString = ""
if mapData ~= "" then
mapString = '<mapframe text="' .. mapText ..'" width=' .. mapWidth .. ' height=' .. mapHeight
mapString = mapString .. ' align=' .. mapAlign .. ' zoom=' .. mapZoom
mapString =mapString .. ' latitude=' .. mapLatitude .. ' longitude=' .. mapLongitude .. ' >'
mapString = mapString .. mapData .. '</mapframe>'
end
return mapString
end -- End the function.
-- function to construct JSON string
p.getStadiumJSON = function(frame)
-- now we need to iterate through the stadiumN parameters and get data for the feature markers
local maxNumber = 50 -- maximum number looked for
local mapData = ""
local stadiumName = ""
local index=0
while index < maxNumber do
index = index + 1
stadiumName = mw.getCurrentFrame():getParent().args['stadium'..tostring(index)] or ""
local featureName=""
local featureData=""
local featureDescription=""
local featureLongitude=0
local featureLatitude=0
local stadiumText = mw.getCurrentFrame():getParent().args['text'..tostring(index)] or ""
local stadiumImage = mw.getCurrentFrame():getParent().args['image'..tostring(index)] or ""
-- if we have retrieved a name from the |stadiumN parameter
if stadiumName ~= "" then
-- check the stadium list for name match
for _, params in pairs( p.stadia ) do
if stadiumName==params[1] then
featureName=params[1]
featureLongitude = params[3]
featureLatitude = params[2]
-- we have a match from the list
break
end
end
end
-- if featureName set, we now have a stadium name match and coordinates from the stadium index list
-- but what if the name doesn't match? Here we could seek info from wikiData
if stadiumName ~= "" and featureName == "" then
-- have a look in wikidata
local WikidataId = mw.wikibase.getEntityIdForTitle(stadiumName)
local item = mw.wikibase.getEntity(WikidataId)
local statements = item:getBestStatements('P625')[1] --coordinate location
local datavalue = statements.mainsnak.datavalue.value
-- TODO must add some error checking here
-- add data for unindexed stadium
featureName=stadiumName
featureLatitude = statements.mainsnak.datavalue.value.latitude
featureLongitude = statements.mainsnak.datavalue.value.longitude
--featureDescription = "coordinate testing: " .. datavalue.latitude .. ', ' .. datavalue.longitude
end
if featureName ~= "" then
featureDescription = stadiumImage .. stadiumText
--mapData = mapStadium1
featureData = '{ "type": "Feature", "geometry": { "type": "Point", "coordinates": ['
.. featureLongitude .. ',' .. featureLatitude .. '] }, "properties": { "title": "' .. featureName
.. '", "description": "'..featureDescription..'", "marker-symbol": "soccer", "marker-size": "medium", "marker-color": "0050d0" } } '
if index > 1 then
mapData = mapData .. ',' .. featureData
else
mapData = featureData
end
else
--mapData = '{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [-0.066417, 51.60475] }, "properties": { "title": "White Hart Lane (default)", "description": "Stadium of Tottenham Hotspur F.C.", "marker-symbol": "soccer", "marker-size": "large", "marker-color": "0050d0" } } '
end
end -- end while loop
if index > 1 then
mapData = '[' .. mapData .. ']'
end
return mapData
end -- End the function.
-- function to construct JSON string for WHL in London map
p.getTestJSONstring = function(frame)
return '{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [-0.066417, 51.60475] }, "properties": { "title": "White Hart Lane", "description": "Stadium of Tottenham Hotspur F.C.", "marker-symbol": "soccer", "marker-size": "large", "marker-color": "0050d0" } } '
end -- End the function.
-- function to construct JSON string
p.getJSONstring = function(frame)
local stadiumName = mw.getCurrentFrame():getParent().args['stadium1'] or "default name"
local str=stadiumName
local jsonString = '{ "type": "Feature", '
jsonString = jsonString .. ' "geometry": { "type": "Point", "coordinates": [-0.065833, 51.603333] }, '
jsonString = jsonString .. ' "properties": { "title": "[[White Hart Lane]]", '
jsonString = jsonString .. ' "description": "[[File:White Hart Lane Aerial.jpg|150px]]Tottenham Hotspur Football Club (1899-2017)", '
jsonString = jsonString .. ' "marker-symbol": "-number", "marker-size": "small", "marker-color": "dd50d0" } } '
--mapString = mapString .. '</mapframe>'
jsonString = '{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [-0.066417, 51.60475] }, "properties": { "title": "[[Northumberland Development Project]]", "description": "[[File:NDProject2015.jpg|100px]]", "marker-symbol": "soccer", "marker-size": "large", "marker-color": "0050d0" } } '
jsonString = '{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [-0.066417, 51.60475] }, "properties": { "title": "title", "description": "description", "marker-symbol": "soccer", "marker-size": "large", "marker-color": "0050d0" } } '
str = '<nowiki>' .. jsonString .. '</nowiki>'
--str = jsonString
return str
end -- End the function.
-- All modules end by returning the variable containing its functions to Wikipedia.
return p
-- We can now use this module by calling {{#invoke: HelloWorld | hello }}.
-- The #invoke command begins with the module's name, in this case "HelloWorld",
-- then takes the name of one of its functions as an argument, in this case "hello".