Modul:Mapshape

Aus Wikivoyage
Zur Navigation springen Zur Suche springen
Template-info.png Dokumentation für das Modul Mapshape[Ansicht] [Bearbeiten] [Versionsgeschichte] [Aktualisieren]

Anwendung

Der Modul wird direkt von der Vorlage {{Mapshape}} aufgerufen. Parameterbeschreibung siehe dort.

Benötigte weitere Module

Dieses Modul benötigt folgende weitere Module: FastWikidata • Mapshape/Params • MapshapeBase • MapshapeBase/i18n
Hinweise
-- getting a mapshape object

-- documentation
local Mapshape = {
	suite  = 'Mapshape',
	serial = '2020-05-28',
	item   = 65449536
}

-- module import
local mb = require( 'Module:MapshapeBase' )
local mi = require( 'Module:MapshapeBase/i18n' )
local mp = require( 'Module:Mapshape/Params' )
local fw = require( 'Module:FastWikidata' )

local ms = {
	entityId = nil,
	wikilang
}

local function getShape( args, frame )
	local colorId, description, fill, id, image, geojson, result, stroke, title
	ms.entityId = mw.wikibase.getEntityIdForCurrentPage()
	ms.wikiLang = mw.getContentLanguage():getCode()

	local tagArgs = {
		text = '',
		group = args.group,
		class = 'no-icon'
	}

	if args.page ~= '' then
		geojson = {
			type = 'ExternalData',
			service = 'page',
			title = mw.ustring.gsub( args.page, '[Dd]ata:', '' )
		}
	else
		-- getting first id
		id = mb.getFirstId( args.wikidata )

		-- getting color from first id
		stroke = args.stroke
		if stroke == '' then
			stroke = mb.getColor( id )
			if stroke == '' then
				stroke = mi.defaultStroke
			end
		end

		title = args.title
		description = args.description
		image = args.image
		-- getting title if only one id
		if id == args.wikidata then
			if title == '' then
				title = mb.getTitle( id )
			end
			title = mb.addLink( title, id, ms.entityId, ms.wikiLang )
			if args.type == 'geomask' then
				title = string.format( mi.geomask, title )
			end
			if description == '' and image == '' then
				image = mb.getImage( id )
			end
		else
			if title == '' then
				title = mw.title.getCurrentTitle().subpageText
			end
			if args.type == 'geomask' then
				title = string.format( mi.geomask, title )
			end
		end

		if description == '' and image ~= '' then
			description = '[[file:' .. image .. '|141px]]'
		end

		fill = mb.getParameter( args.fill, mi.defaultFill )
		geojson = {
			type = 'ExternalData',
			service = args.type,
			ids = args.wikidata,
			properties = {
				title = title,
				description = description,
				fill = fill,
				[ 'fill-opacity' ] = mb.getNumber( args.fillOpacity, mi.defaultFillOpacity ),
				stroke = stroke,
				[ 'stroke-width' ] = mb.getNumber( args.strokeWidth, mi.defaultStrokeWidth ),
				[ 'stroke-opacity' ] = mb.getNumber( args.strokeOpacity, mi.defaultStrokeOpacity )
			}
		}
	end
	
	result = frame:extensionTag( 'maplink', mw.text.jsonEncode( geojson ), tagArgs )
	if mw.title.getCurrentTitle().namespace == 0 then
		result = result .. fw.getCategories( mi.properties )
			.. mb.getCategories( mi.properties )
	end
	return result
end

function ms.show( frame )
	local args, errors =
		mb.checkParams( frame:getParent().args, mp, 'Mapshape', mi.msUnknown )
	args.type    = mb.getParameter( args.type, 'geomask' )
	args.group   = mb.getParameter( args.group, mi.group )
	if args.group:lower() == 'track' then
		args.group = mi.track
	end

	if args.wikidata == '' and args.page == '' then
		args.wikidata = mw.wikibase.getEntityIdForCurrentPage() or ''
		if args.wikidata == '' then
			return mi.msMissing .. errors
		end
	elseif args.wikidata ~= '' and args.page ~= '' then
		return mi.msTogether .. errors
	end

	return getShape( args, frame ) .. errors
end

return ms