--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.local p =
local stadiumDatabase = require("Module:Football map/data") -- configuration module -- main function callable in Wikipedia via the #invoke command.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--p.getMapframeString = function(frame)
--get mapframe arguments from calling templates local parent = mw.getCurrentFrame:getParent --local mapParams = -- -- get JSON data for features to display local mapData = p.getStadiumJSON local mapString = ""
--mapString = '
mapString = ' mapString = mapString .. ' width=' .. math.floor(width) .. ' height=' .. math.floor(height) .. ' align=' .. align local zoom = parent.args['zoom'] --or "0" -- no longer set defaults (mapframe does automatically) local latitude = parent.args['latitude'] --or "0" local longitude = parent.args['longitude'] --or "0" --set if values, otherwise allow mapframe to set automatically (TODO check if longitude and latitude are independent) if zoom then mapString = mapString .. ' zoom=' .. zoom end if latitude then mapString = mapString .. ' latitude=' .. latitude end if longitude then mapString = mapString .. ' longitude=' .. longitude end mapString = mapString .. ' >' .. mapData .. '
end -- End the function.
--imageN=, |descriptionN=) (2) from values in the data module (i.e. Module:Football map/data) (3) from Wikidatap.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 = "" --get mapframe arguments from calling templates local parent = 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 -- local useWikidata = true local useModule = true if parent.args['wikidata'] then useWikidata = true; useModule = false end -- use wikidata or template data (no module data) if parent.args['moduledata'] then useModule = true; useWikidata = false end -- use module of template data (no wikidata) if parent.args['templatedata'] then useModule = false; useWikidata = false end -- only use template data -- default parameters for marker color, size and symbol (i.e. those without index suffix) local defaultMarker = local index=0 while index < maxNumber do index = index + 1 local stadiumID = "" -- (1) get stadium name stadiumName = parent.args['stadium'..tostring(index)] --or "" if not stadiumName then -- name from |stadiumN parameter, clubName = parent.args['club'..tostring(index)] or "" if clubName ~= "" then stadiumName, stadiumID = p.getStadiumFromClubName(clubName) end end -- if we have a valid stadium name (note:Lua has no continue statement) if stadiumName then local feature = local validFeatureData =true -- assume now and -- (2) get feature parameters from module or wikidata or both if useModule then -- get feature parameters from module data stadium list feature = p.getModuleData(frame, stadiumName) end if useWikidata and feature['name']
--check if current feature marker has specified color, size or symbol local featureMarker = -- if we have a stadium with valid coordinates if validFeatureData then --(4) construct the json for the features --mapData = mapStadium1 featureData = ' ' if index > 1 and mapData ~= "" then mapData = mapData .. ',' .. featureData else mapData = featureData end else --mapData = ' ' 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 -- local geoshape = parent.args['geoshape'..tostring(1)] or "" if geoshape ~= "" then mapData = mapData .. ',' .. geoshape -- assumes at least one stadium end -- add outer bracket to json if more than one element if index > 1 then mapData = '[' .. mapData .. ']' end return mapData end -- End the function.
--150px]]Tottenham Hotspur Football Club (1899-2017)", ' jsonString = jsonString .. ' "marker-symbol": "-number", "marker-size": "small", "marker-color": "dd50d0" } } ' --mapString = mapString .. '' jsonString = ' ' jsonString = ' ' str = '' .. jsonString .. '' --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 .-- 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".