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
Using Wikidata for data parameters
Using Wikidata for data parameters
Using a mixture of all three data sources
Using Wikidata for data parameters
--require('Module:No globals')
-- 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 = {}
local stadiumDatabase = require( "Module:Football map/data" ) -- configuration module
-- 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!"
-- 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 = 200 -- maximum number looked for
local mapData = ""
local stadiumName = ""
local clubName = ""
-- default parameters for marker color, size and symbol (i.e. those without index suffix)
local markerColor = mw.getCurrentFrame():getParent().args['color'] or "0050d0"
local markerSize = mw.getCurrentFrame():getParent().args['size'] or "medium"
local markerSymbol = mw.getCurrentFrame():getParent().args['symbol'] or "soccer"
local index=0
while index < maxNumber do
index = index + 1
stadiumName = mw.getCurrentFrame():getParent().args['stadium'..tostring(index)] or ""
local stadiumID = ""
local featureName = ""
local featureData = ""
local featureAlias = ""
local featureDescription = ""
local featureImage = ""
local wdDescription = ""
local wdImage = ""
-- if we have retrieved a name from the |stadiumN parameter
if stadiumName ~= "" then
-- check the stadium list for name match
for _, params in pairs( stadiumDatabase.stadia ) do
if stadiumName == params[1] then -- if we have a match from the list
featureName = params[1]
featureLatitude = params[2]
featureLongitude = params[3]
featureAlias = params[4]
featureDescription = params[5]
featureImage = '[[' .. params[6] .. ']]'
break
end
end
else --end
-- if we have no name from the |stadiumN parameter, try the |clubN parameter
--if stadiumName == "" then
clubName = mw.getCurrentFrame():getParent().args['club'..tostring(index)] or ""
-- let us assume the club name has a wikipedia page with the extact same name
local wdId = mw.wikibase.getEntityIdForTitle(clubName)
if wdId and mw.wikibase.isValidEntityId( wdId ) then -- if valid id
local item = mw.wikibase.getEntity(wdId)
mw.logObject( mw.wikibase.getBestStatements( 'Q18721', 'P115' ) )
--local statements = mw.wikibase.getBestStatements( 'Q18721', 'P115' )[1]
local statements = item:getBestStatements('P115')[1] --home venue
if statements ~= nil then -- check cordinates available
stadiumID = statements.mainsnak.datavalue.value.id
-- P115 doesn't seem to have the stadium name (P115 is type "Item")
--- other properties (e.g. stadium name) would need to be got from the ID
stadiumName = mw.wikibase.getLabel( stadiumID )
--stadiumName = clubName -- if the marker is to be labelled with club name
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)
if stadiumID ~= "" then -- use stadium ID obtained for |clubN
WikidataId = stadiumID
-- currently stadiumName holds the club name
--stadiumName = stadiumName .. '(' .. mw.wikibase.getLabel( stadiumID ) .. ')'
end
if WikidataId and mw.wikibase.isValidEntityId( WikidataId ) then -- valid id
local item = mw.wikibase.getEntity(WikidataId)
--[[ statements of interest (datavalue element)
P635 coordinate location (value.longitude/latitude)
P18 image on commons (value, "File:value")
P466 occupant (value.id) (use )
P571 inception (value), P576 demolished (value)
P1566 GeoNames ID (value, "geonames.org/value")
]]
local statements = item:getBestStatements('P625')[1] --coordinate location
if statements ~= nil then -- check cordinates available
local coord = statements.mainsnak.datavalue.value
if type(coord.latitude) == 'number' and type(coord.longitude) == 'number' then
-- add coordinate data from wikidata for unindexed stadium
featureName = stadiumName
featureLatitude = coord.latitude
featureLongitude = coord.longitude
end
end
statements = item:getBestStatements('P18')[1] --image
if statements ~= nil then
wdImage = "[[File:" .. statements.mainsnak.datavalue.value .. "]]"
end
wdDescription = " "
end
end
-- use specificed coordinates if provided (overriding above)
local latitude = mw.getCurrentFrame():getParent().args['latitude'..tostring(index)] or 0
local longitude = mw.getCurrentFrame():getParent().args['longitude'..tostring(index)] or 0
if latitude ~= 0 and longitude ~= 0 then -- if both explicitly set
featureLatitude = latitude
featureLongitude= longitude
featureName = stadiumName -- in case an location without wikipedia presence
end
if featureName ~= "" then
--check if current feature marker has specified color, size or symbol
local color = mw.getCurrentFrame():getParent().args['color'..tostring(index)] or markerColor
local symbol = mw.getCurrentFrame():getParent().args['symbol'..tostring(index)] or markerSymbol
local size = mw.getCurrentFrame():getParent().args['size'..tostring(index)] or markerSize
-- use specified description and image if provided
local argDescription = mw.getCurrentFrame():getParent().args['description'..tostring(index)] or ""
local argImage = mw.getCurrentFrame():getParent().args['image'..tostring(index)] or ""
if argDescription ~= "" then
featureDescription = argDescription
else
featureDescription = wdDescription
end
if argImage ~= "" then
featureImage = '[[' .. argImage .. ']]' -- priority for image from template argument
else
if featureImage == "" then -- if not set by data, use wikidata image
featureImage = wdImage
end
end
featureName = '[[' .. featureName .. ']]'
if clubName ~= "" then featureName = '[[' .. clubName .. ']] (' .. featureName ..')' end
if featureImage ~= "" then featureDescription = featureImage .. featureDescription end
--mapData = mapStadium1
featureData = '{ "type": "Feature", "geometry": { "type": "Point", "coordinates": ['
.. featureLongitude .. ',' .. featureLatitude .. '] }, "properties": { "title": "'
.. featureName .. '", "description": "'..featureDescription
..'", "marker-symbol": "' .. symbol .. '", "marker-size": "' .. size .. '", "marker-color": "' .. color .. '" } } '
if index > 1 and mapData ~= "" 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".