Module:Infobox mapframe: Difference between revisions

Content deleted Content added
remove config["coordinates"], config["coord"]; leave note referencing talk page
update from sandbox: allow locally-specified coords to override Wikidata (per Template talk:Maplink#Template:Infobox power station/sandbox)
Line 1:
local mf = require('Module:Mapframe')
 
-- Trim whitespace from args, and remove empty args
function setCleanArgstrimArgs(argsTable)
local cleanArgs = {}
for key, val in pairs(argsTable) do
Line 49 ⟶ 50:
 
p._main = function(_config)
local-- `config` =is setCleanArgs(_config)the args passed to this module
local config = trimArgs(_config)
-- Use wikidata by default
local useWikidata = true
-- Do not use wikidata when coords are specified, unless explicitly set
if config.coord then
useWikidata = config.wikidata and true or false
end
-- Require wikidata item, or specified coords
local wikidataId = config.id or mw.wikibase.getEntityIdForCurrentPage()
if not (wikidataId) and not(config.coord) then
return ''
end
 
-- Require wikidatacoords item(specified withor coordsfrom wikidata), so somethingthat map will be centred somewhere
local hasCoordinates = hasWikidataProperty(wikidataId, 'P625') -- (P625 = coordinate ___location)
local hasCoordinates = hasWikidataProperty(wikidataId, 'P625') or config.coordinates or config.coord
if not hasCoordinates then
return ''
end
 
-- `args` is the arguments forwhich will be passed to the mapframe module
local args = {}
 
Line 94 ⟶ 106:
 
-- Shape
if useWikidata then
args.type = "shape"
args.type = "shape"
if config.id then args.id = config.id end
args["stroke-width"] = config["shape-stroke-width"] or config["stroke-width"] or "3"
args["stroke-color"] = config["shape-stroke-color"] or config["shape-stroke-colour"] or config["stroke-color"] or config["stroke-colour"] or "#FF0000"
end
 
-- Line
if useWikidata then
args.type2 = "line"
args.type2 = "line"
if config.id then args.id2 = config.id end
args["stroke-width2"] = config["line-stroke-width"] or config["stroke-width"] or "5"
args["stroke-color2"] = config["line-stroke-color"] or config["line-stroke-colour"] or config["stroke-color"] or config["stroke-colour"] or "#FF0000"
end
 
-- Point
local hasOsmRelationId = hasWikidataProperty(wikidataId, 'P402') -- P402 is OSM relation ID
local shouldShowPointMarker = not(hasOsmRelationId) or (config.marker and config.marker ~= 'none') or (config.coordinates or config.coord)
if shouldShowPointMarker then
local argNumber = useWikidata and "3" or ""
args["type".type3.argNumber] = "point"
if config.id then args.id3 = config.id end
if config.markerid then args["id".marker3.argNumber] = config.markerid end
if config.idcoord then args["coord".id3.argNumber] = config.idcoord end
args["marker-color3"] = config["marker-color"] or config["marker-colour"] or "#5E74F3"
if config.marker then args["marker"..argNumber] = config.marker end
args["marker-color3color"..argNumber] = config["marker-color"] or config["marker-colour"] or "#5E74F3"
end
local mapframe = mf._main(args)