Module:Infobox mapframe: Difference between revisions

From Random Island Wiki
Jump to navigation Jump to search
>Evad37
(point, shape, and line)
>Evad37
(check that coords exist)
Line 1: Line 1:
local mf = require('Module:Mapframe/sandbox')
local mf = require('Module:Mapframe/sandbox')
function hasWikidataCoords(item_id)
if not(mw.wikibase.isValidEntityId(item_id)) or not(mw.wikibase.entityExists(item_id)) then
return false
end
local coordStatements = mw.wikibase.getBestStatements(item_id, 'P625')
if not coordStatements or #coordStatements == 0 then
return false
end
return true
end


local p = {}
local p = {}
Line 18: Line 29:
args.plain = "yes"
args.plain = "yes"
args["frame-width"] = args["frame-width"] or "270"
args["frame-width"] = args["frame-width"] or "270"
args.type = "point"
-- Shape
args.type2 = "shape"
args.type = "shape"
args["stroke-width2"] = "3"
args["stroke-width"] = "3"
args["stroke-color2"] = "#00ff00"
args["stroke-color"] = "#00ff00"
args.type3 = "line"
-- Line
args.type2 = "line"
if args.id then
if args.id then
args.id2 = args.id
args.id2 = args.id
args.id3 = args.id
end
-- Point
if hasWikidataCoords(args.id or mw.wikibase.getEntityIdForCurrentPage()) then
args.type3 = "point"
if args.id then
args.id3 = args.id
end
end
end



Revision as of 21:29, 10 May 2018

Documentation for this module may be created at Module:Infobox mapframe/doc

local mf = require('Module:Mapframe/sandbox')

function hasWikidataCoords(item_id)
	if not(mw.wikibase.isValidEntityId(item_id)) or not(mw.wikibase.entityExists(item_id)) then
		return false
	end
	local coordStatements = mw.wikibase.getBestStatements(item_id, 'P625')
	if not coordStatements or #coordStatements == 0 then
		return false
	end
	return true
end

local p = {}

p.main = function(frame)
	local parent = frame.getParent(frame)
	local parentArgs = parent.args

	-- convert parent args to standard table
	local args = {}
	for k, v in pairs(parentArgs) do
		args[k] = v
	end

	-- Some defaults/overrides for infobox presentation
	args.display = "inline"
	args.frame = "yes"
	args.plain = "yes"
	args["frame-width"] = args["frame-width"] or "270"
	-- Shape
	args.type = "shape"
	args["stroke-width"] = "3"
	args["stroke-color"] = "#00ff00"
	-- Line
	args.type2 = "line"
	if args.id then
		args.id2 = args.id
	end
	-- Point
	if hasWikidataCoords(args.id or mw.wikibase.getEntityIdForCurrentPage()) then
		args.type3 = "point"
		if args.id then
			args.id3 = args.id
		end
	end

	local mapframe = mf._main(args)
	return frame:preprocess(mapframe)
end

return p