Module:Football map
- coordinate location (P625) (see uses )
- home venue (P115) (see uses )
- image (P18) (see uses )
- occupant (P466) (see uses )
- maximum capacity (P1083) (see uses )
Overview
[edit ]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
[edit ]{{#invoke:Football map|function_name}}
Template documentation
[edit ]- 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 stadiums, 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
[edit ]The simplest use of the template requires the basic mapframe parameters and a list of football stadiums or football clubs.
Parameters
[edit ]Mapframe parameters
[edit ]|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
[edit ]A Mapframes map can display markers for a number of geographical features, or a football stadium 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 stadiums or clubs set with the following parameters.
|stadiumN=— a list of stadiums 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.
Stadiums 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
[edit ]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
[edit ]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
-numberto number the markers (default) - use
-letterto 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 stadiums 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
[edit ]Using data from module list
[edit ]Using data supplied in template
[edit ]Using Wikidata for data parameters
[edit ]Using Wikidata for data parameters
[edit ]Using a mixture of all three data sources
[edit ]Using Wikidata for data parameters
[edit ]Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.
--require('strict') -- 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. localp={} localstadiumDatabase=require("Module:Football map/data")-- configuration module -- main function callable in Wikipedia via the #invoke command. p.main=function(frame) str=p.getMapframeString() returnframe:preprocess(str)-- the mapframe needs to be preprocessed!!!!! end-- End the function. --[[ function to construct mapframe string --]] p.getMapframeString=function(frame) --get mapframe arguments from calling templates localparent=mw.getCurrentFrame():getParent() --[[local mapParams = { width = parent.args['width'] or "400", height = parent.args['height'] or "300", latitude = parent.args['latitude'] or "51.5", longitude = parent.args['longitude'] or "-0.15", align = parent.args['align'] or "right", text = parent.args['text'] or "", zoom = parent.args['zoom'] or "9" }--]] -- get JSON data for features to display localmapData=p.getStadiumJSON() localmapString="" --mapString = '<mapframe text="London football stadia" width=800 height=650 align=left zoom=11 latitude=51.530 longitude=-0.16 >' ifmapData~=""then mapString='<mapframe' ifparent.args['frameless']then-- don't and text as this overrides frameless parameter mapString=mapString..' frameless' else mapString=mapString..' text="'..(parent.args['text']or"")..'"' end -- set width and height using noth parameters, one parameter assuming 4:3 aspect ratio, or defaults localaspect=4/3 localwidth=parent.args['width']--or "400" localheight=parent.args['height']or(widthor300)/aspect--or "300" width=widthorheight*aspect-- if width null, use height localalign=parent.args['align']or"right" mapString=mapString..' width='..math.floor(width)..' height='..math.floor(height)..' align='..align localzoom=parent.args['zoom']--or "0" -- no longer set defaults (mapframe does automatically) locallatitude=parent.args['latitude']--or "0" locallongitude=parent.args['longitude']--or "0" --set if values, otherwise allow mapframe to set automatically (TODO check if longitude and latitude are independent) ifzoomthenmapString=mapString..' zoom='..zoomend iflatitudethenmapString=mapString..' latitude='..latitudeend iflongitudethenmapString=mapString..' longitude='..longitudeend mapString=mapString..' >'..mapData..'</mapframe>'-- add data and close tag --[[mapString = mapString ..' width=' .. (parent.args['width'] or "400" ) .. ' height=' .. (parent.args['height'] or "300") .. ' align=' .. (parent.args['align'] or "right") .. ' zoom=' .. (parent.args['zoom'] or "9" ) .. ' latitude=' .. (parent.args['latitude'] or "51.5") .. ' longitude=' .. (parent.args['longitude'] or "-0.15") .. ' >' .. mapData .. '</mapframe>' ]] else mapString="No data for map" end returnmapString end-- End the function. --[[ function to construct JSON format data for markers on map. The information for each marker (coordinate, description and image for popup, etc) can be set in several ways (in order of priority): (1) using arguments in the template (|imageN=, |descriptionN=) (2) from values in the data module (i.e. Module:Football map/data) (3) from Wikidata ]] p.getStadiumJSON=function(frame) -- now we need to iterate through the stadiumN parameters and get data for the feature markers localmaxNumber=200-- maximum number looked for localmapData="" localstadiumName="" localclubName="" --get mapframe arguments from calling templates localparent=mw.getCurrentFrame():getParent() --[[There are three ways of getting data about the stadium features (1) from a list in the module subpages (2) from wikidata (3) from the parameters in the template (these always override other) By default The parameters useWikiData, useModule restrict use of source --]] localuseWikidata=true localuseModule=true ifparent.args['wikidata']thenuseWikidata=true;useModule=falseend-- use wikidata or template data (no module data) ifparent.args['moduledata']thenuseModule=true;useWikidata=falseend-- use module of template data (no wikidata) ifparent.args['templatedata']thenuseModule=false;useWikidata=falseend-- only use template data -- default parameters for marker color, size and symbol (i.e. those without index suffix) localdefaultMarker={color=parent.args['color']or"0050d0", size=parent.args['size']or"medium", symbol=parent.args['symbol']or"soccer"} localindex=0 whileindex<maxNumberdo index=index+1 localstadiumID="" -- (1) get stadium name stadiumName=parent.args['stadium'..tostring(index)]--or "" ifnotstadiumNamethen-- name from |stadiumN parameter, clubName=parent.args['club'..tostring(index)]or"" ifclubName~=""then stadiumName,stadiumID=p.getStadiumFromClubName(clubName) end end -- if we have a valid stadium name (note:Lua has no continue statement) ifstadiumNamethen localfeature={name="",alias="",latitude=0,longitude=0,description="",image="",valid=false} localvalidFeatureData=true-- assume now and -- (2) get feature parameters from module or wikidata or both ifuseModulethen-- get feature parameters from module data stadium list feature=p.getModuleData(frame,stadiumName) end ifuseWikidataandfeature['name']==""then-- get feature parameters from wikidata feature=p.getDataFromWikiData(stadiumName,stadiumID) ifnotfeature['valid']thenvalidFeatureData=falseend-- no valid coordinates end ---------------------------------------------------- -- (3) data from template parameters will override those obtainied from a module table or wikidata localtemplateArgs={ latitude=parent.args['latitude'..tostring(index)],--or 0, longitude=parent.args['longitude'..tostring(index)],--or 0, description=parent.args['description'..tostring(index)],--or "", image=parent.args['image'..tostring(index)]--or "" } iftemplateArgs['latitude']andtemplateArgs['longitude']then-- if both explicitly set feature['latitude']=templateArgs['latitude'] feature['longitude']=templateArgs['longitude'] feature['name']=stadiumName-- as we have valid coordinates validFeatureData=true end -- use specified description and image if provided iftemplateArgs['description']then feature['description']=templateArgs['description'] end iftemplateArgs['image']then feature['image']=templateArgs['image']-- priority for image from template argument end iffeature['image']~=""thenfeature['image']='[['..mw.text.encode(feature['image'])..']]'end -- wikilink - use redirect if alias iffeature['alias']~=''then feature['name']='[['..feature['name']..'|'..feature['alias']..']]' else feature['name']='[['..feature['name']..']]' end ifclubName~=""then --feature['name'] = '[[' .. clubName .. ']] (' .. feature['name'] ..')' ifstadiumName~=""then feature['description']='[['..stadiumName..']]. '..feature['description'] end feature['name']='[['..clubName..']]' end iffeature['image']~=""then feature['description']=feature['image']..feature['description'] end --check if current feature marker has specified color, size or symbol localfeatureMarker={ color=parent.args['color'..tostring(index)]ordefaultMarker['color'], symbol=parent.args['symbol'..tostring(index)]ordefaultMarker['symbol'], size=parent.args['size'..tostring(index)]ordefaultMarker['size']} -- if we have a stadium with valid coordinates ifvalidFeatureDatathen --(4) construct the json for the features --mapData = mapStadium1 featureData='{ "type": "Feature", ' ..' "geometry": { "type": "Point", "coordinates": [' ..feature['longitude']..',' ..feature['latitude'] ..'] }, ' ..' "properties": { "title": "'..feature['name']..'", ' ..'"description": "'..feature['description']..'", ' ..'"marker-symbol": "'..featureMarker['symbol']..'", ' ..'"marker-size": "'..featureMarker['size']..'", ' ..'"marker-color": "'..featureMarker['color']..'" } ' ..' } ' ifindex>1andmapData~=""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-- if valid parameters end-- end if stadiumName end-- end while loop --[[ (5) check for external data (geoshape) TODO add more than index=1 and generalise for any json feature --]] localgeoshape=parent.args['geoshape'..tostring(1)]or"" ifgeoshape~=""then mapData=mapData..','..geoshape-- assumes at least one stadium end -- add outer bracket to json if more than one element ifindex>1then mapData='['..mapData..']' end returnmapData end-- End the function. --[[-------------------------------Retrieve information from wikidata------------------------- statements of interest (datavalue element) item = mw.wikibase.getEntity(WikidataId), statements = item:getBestStatements('P625')[1] "claims": P625 coordinate location (value.longitude/latitude) "P625":[{ "mainsnake": { ... "datavalue": { "value": {"latitude": 51.4, "longitude": -0.19] ... statements.mainsnak.datavalue.value.latitude P18 image on commons (value, "File:value") "P18":[{ "mainsnake": { ... "datavalue": { "value": "Stamford Bridge Clear Skies.JPG" P466 occupant (value.id) (use ) P1083 capacity (value.amount) "P1083":[{ "mainsnake": { ... "datavalue": { "value": { "amount" : "+41875" ... P571 inception (value), P576 demolished (value) P1566 GeoNames ID (value, "geonames.org/value") P84 architect P137 operator, P127 owned by P31 (instance of) Q483110 (stadium) "P18":[{ "mainsnake": { ... "datavalue": { "value": { "id": "Q483110" however also sports venue, olympic stadium, association football stadium P159 headquarters location (for football club) e..g. London qualifier property: coordinates(P625) page title on enwiki mw.wikibase.getSitelink( itemId ) - gets local version "sitelink": { "enwiki": { "title": "Stamford Bridge (stadium)" ERROR NOTE there was an error is caused when a supposed stadium redirected to page with no coordinates e.g Fortress Stadium, Bromley was redirecting to Bromley F.C., this had a valid Wiki ID and item but no coordinates 1. it is handled by setting wd['valid'] when there are valid coordinates 2. an alternative would We could check it is a stadium if P31 (instance of ) Q483110 (stadium) --]] p.getDataFromWikiData=function(stadiumName,stadiumID) localwd={name="",latitude="",longitude="",description="",image="",alias="",valid=false} -- get wikidata id corresponding to wikipedia stadium page localWikidataId=mw.wikibase.getEntityIdForTitle(stadiumName) ifWikidataIdandmw.wikibase.isValidEntityId(WikidataId)then-- valid id localitem=mw.wikibase.getEntity(WikidataId) ifnotitemthenreturnwdend-- will test for wiki localenwikiTitle=mw.wikibase.getSitelink(WikidataId)-- name of local Wikipedia page localwikidataTitle=mw.wikibase.getLabel(WikidataId)-- name of Wikidata page ifenwikiTitleandwikidataTitleandenwikiTitle~=wikidataTitlethen wd['alias']=wikidataTitle wd['name']=stadiumName else wd['name']=stadiumName end -- get coordinates localstatements=item:getBestStatements('P625')[1]--coordinate location ifstatements~=nilthen-- check cordinates available localcoord=statements.mainsnak.datavalue.value iftype(coord.latitude)=='number'andtype(coord.longitude)=='number'then -- add coordinate data from wikidata for unindexed stadium wd['latitude']=coord.latitude wd['longitude']=coord.longitude wd['valid']=true end end --get image statements=item:getBestStatements('P18')[1]--image ifstatements~=nilthen wd['image']='File:'..statements.mainsnak.datavalue.value end -- get occupants --TODO check for multi-occupancy statements=item:getBestStatements('P466')[1]--occupant (i.e football club) ifstatements~=nilthen localclubID=statements.mainsnak.datavalue.value.id ifclubIDthen localclubName=mw.wikibase.getLabel(clubID) wd['description']='<small>Home ground of '..clubName..'</small>' end end -- get capacity statements=item:getBestStatements('P1083')[1]--mcapacity ifstatements~=nilthen localcapacity=tonumber(statements.mainsnak.datavalue.value.amount) ifcapacitythen wd['description']=wd['description']..'<small> (capacity: '..capacity..')</small>' end end end returnwd end ---------------------------------------------- p.getStadiumFromClubName=function(clubName) -- let us assume the club name has a wikipedia page with the extact same name localwdId=mw.wikibase.getEntityIdForTitle(clubName) ifwdIdandmw.wikibase.isValidEntityId(wdId)then-- if valid id localitem=mw.wikibase.getEntity(wdId) mw.logObject(mw.wikibase.getBestStatements('Q18721','P115')) --local statements = mw.wikibase.getBestStatements( 'Q18721', 'P115' )[1] localstatements=item:getBestStatements('P115')[1]--home venue ifstatements~=nilthen-- check cordinates available localstadiumID=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 localstadiumName=mw.wikibase.getLabel(stadiumID) --stadiumName = clubName -- if the marker is to be labelled with club name localenwikiTitle=mw.wikibase.getSitelink(stadiumID) returnenwikiTitle,stadiumID --return stadiumName, stadiumID end end return"" end -------------------------------------------------------------------------------- p.getModuleData=function(frame,stadiumName) localfeature={} feature['name']="" --feature['data'] = "" feature['alias']="" feature['description']="" feature['image']="" -- check the module stadium list for name match -- set feature parameters from the module data for_,paramsinpairs(stadiumDatabase.stadia)do ifstadiumName==params[1]then-- if we have a match from the list feature['name']=params[1] feature['latitude']=params[2] feature['longitude']=params[3] feature['alias']=params[4] feature['description']=params[5] feature['image']=params[6] break end end returnfeature end -- 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) localstadiumName=mw.getCurrentFrame():getParent().args['stadium1']or"default name" localstr=stadiumName localjsonString='{ "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 returnstr end-- End the function. -- All modules end by returning the variable containing its functions to Wikipedia. returnp -- 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".