Zum Inhalt springen

Modul:Mapshape

Aus Wikivoyage
Dokumentation für das Modul Mapshape[Ansicht] [Bearbeiten] [Versionsgeschichte] [Aktualisieren]

Anwendung

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

Versionsbezeichnung auf Wikidata: 2022-10-22 Ok!

Benötigte weitere Module

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

-- documentation
local Mapshape = {
	suite  = 'Mapshape',
	serial = '2022-10-22',
	item   = 65449536
}

-- module import
-- require( 'strict' )
local mi = require( 'Module:Mapshape utilities/i18n' )
local mp = require( 'Module:Mapshape/Params' )
local mu = require( 'Module:Mapshape utilities' )
local wu = require( 'Module:Wikidata utilities' )

-- module variable and administration
local ms = {
	moduleInterface = Mapshape
}

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

	local tagArgs = {
		text = '',
		group = mu.translateGroup( args.group ),
		class = 'no-icon'
	}

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

		-- getting color from first id
		stroke = args.stroke
		if stroke == '' then
			stroke = mu.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 = mu.getTitle( id )
			end
			title = mu.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 = mu.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 = mu.getParameter( args.fill, mi.defaultFill )
		geojson = {
			type = 'ExternalData',
			service = args.type,
			ids = args.wikidata,
			properties = {
				title = title,
				description = description,
				fill = fill,
				[ 'fill-opacity' ] = mu.getNumber( args.fillOpacity, mi.defaultFillOpacity ),
				stroke = stroke,
				[ 'stroke-width' ] = mu.getNumber( args.strokeWidth, mi.defaultStrokeWidth ),
				[ 'stroke-opacity' ] = mu.getNumber( args.strokeOpacity, mi.defaultStrokeOpacity )
			}
		}
	end
	
	local result = ''
	if next( geojson ) then
		result = frame:extensionTag( 'maplink', mw.text.jsonEncode( geojson ), tagArgs )
	end
	if mw.title.getCurrentTitle().namespace == 0 and mi.usePropertyCategs then
		result = result .. wu.getCategories( mi.properties )
			.. mu.getCategories( mi.properties )
	end
	return result
end

function ms.show( frame )
	local args, errors =
		mu.checkParams( frame:getParent().args, mp, 'Mapshape', mi.msUnknown )
	args.type  = mu.getParameter( args.type, 'geomask' )
	args.group = mu.checkGroup( args.group )

	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