Module:Infobox/Fonctions/Géolocalisation

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher

La documentation pour ce module peut être créée à Module:Infobox/Fonctions/Géolocalisation/doc

local coord = require('Module:Coordinates')
local wikidatamod = require('Module:Wikidata')
local p = {}
function p.coordinates(moduleparams)
	-- initialise les paramètres avec les valeurs du module d'infobox (moduleparams)
	if not moduleparams then moduleparams = {} end
	local globe = moduleparams.globe
	local displayinline = moduleparams.displayinline
	local displaytitle = moduleparams.displaytitle
	local displayformat = moduleparams.displayformat
	if not displaytitle then displaytitle = 'title' end -- displayinline et displaytitle sont des chaînes à utiliser dans le paramètre "display" de coord
	if not displayinline then displayinline = 'inline' end

	return function(localdata, item)
		
		-- vérifie qu'il faut afficher les coordonnées
		if localdata["géolocalisation"] == 'pas pertinent' or localdata['géolocalisation'] == 'non' then
			if not (localdata['coordonnées'] == 'oui') then
			return nil
		end end
		
		-- si paramètres donnés dans l'article, écrasent les autres
		if localdata['format coordonnées'] then
			displayformat = localdata['format coordonnées']
		end
		if localdata['coords en titre'] == 'oui' then
			local displaytitle = 'title'
		end
		if localdata['coords en titre'] == 'non' or  localdata['coords en titre'] == '-' then
			displaytitle = ''
		end
		if localdata['coords en en ligne'] == 'oui' then
			displayinline = 'inline'
		end
		if localdata['coords en en ligne'] == 'non' or localdata['coords en en ligne'] == '-' then
			displayinline = ''
		end	
		local displayplace = displaytitle .. ',' .. displayinline
		local latitude = localdata['latitude']
		local longitude = localdata['longitude']
		if localdata['globe'] then
			globe = localdata['globe']
		end
		local wikidata = localdata['wikidata'] or 'true'
		if displayinline == '' then
			return -- type: external text pour ne pas avoir de ligne vide en infobox
			{
			type = 'external text',
			maintenancecat = 'Page géolocalisable sans coordonnées paramétrées',
			sortkey = sortkey,
 			value =
 				function(localdata, item)
 					return coord._coord({latitude = latitude, longitude = longitude, displayformat = displayformat, display= displayplace, globe = globe, wikidata =wikidata})
 			end
 		}
 		else return
 			{
		type = 'mixed',
		label = 'Coordonnées',
		maintenancecat = 'Page géolocalisable sans coordonnées paramétrées',
		sortkey = sortkey,
 		value =
 			function(localdata, item)
 				return coord._coord({latitude = latitude, longitude = longitude, displayformat = displayformat, display= displayplace, globe = globe, wikidata =wikidata})
 			end
 		}	
	end end
end

function p.geoloc()
	return   {
		type = 'map',
		latitude = 'latitude',
		longitude = 'longitude',
		wikidata = function(localdata, item) return wikidatamod.getClaims{item = item, property = 'P625'} end,
		maps = function(localdata, item) if localdata['géolocalisation'] then return mw.text.split( localdata['géolocalisation'], '/', true ) end end
        }
 
end
return p