« Module:Infobox/Fonctions/Géolocalisation » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
ajoute option référence géolocalisation
0x010D (discussion | contributions)
fonctions de test
Ligne 122 : Ligne 122 :
   
   
end
end
local function coordcoretest(moduleparams)
local globe = moduleparams.globe
local displayinline = moduleparams.displayinline
local displaytitle = moduleparams.displaytitle
local displayformat = moduleparams.displayformat
if (not displaytitle and not distantitem) then displaytitle = 'title' end -- displayinline et displaytitle sont des chaînes à utiliser dans le paramètre "display" de coord
--distantitem veut dire que le sujet de l'infobox ne correspond pas au sujet de l'article
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' and not (localdata['coordonnées'] == 'oui') then
return nil
end
-- si paramètres donnés dans l'article, écrasent les autres
if localdata['format coordonnées'] then
displayformat = localdata['format coordonnées']
end
displaytitle = 'title'
if localdata['infoboxrank'] == 'secondary' then
displaytitle = ''
end
if localdata['coords en titre'] == 'oui' then
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'
local val = coord._coord({latitude = latitude, longitude = longitude, displayformat = displayformat, display= displayplace, globe = globe, wikidata =wikidata})
if val and not localdata['latitude'] then
val = wikidatamod.addLinkback(val, item, 'P625')
end
if val and latitude and longitude and localdata['référence géolocalisation'] then
val = val .. ' ' .. localdata['référence géolocalisation']
end
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 = val
}
else
return  '<center><small>' .. val .. '</center></small>'
end
end
end
function p.coordinatestest(moduleparams)
-- initialise les paramètres avec les valeurs du module d'infobox (moduleparams)
if not moduleparams then moduleparams = {} end
return {
type = 'mixed',
-- label = 'Coordonnées',
maintenancecat = 'Page géolocalisable sans coordonnées paramétrées',
sortkey = sortkey,
value = coordcore(moduleparams)
}
end
return p
return p

Version du 10 mars 2015 à 08:39

local coord = require('Module:Coordinates') local wikidatamod = require('Module:Wikidata') local p = {}


local p = {} function p.country(country, label, flagdate, size) -- à faire : gestion des dates, mapping Wikidata/modèles, peut-être mettre une partie de la fonction dans un module séparé return function(localdata, item) if localdata['pays'] then -- priorité aux données locales country = localdata['pays'] end local countrymodule = require('Module:Country data') country = countrymodule.standarddisplay(country) local wikidatacountry = wikidatamod.formatAndCat{ item = item, property = 'P17', displayformat = function(snak) local id = 'Q' .. snak.datavalue.value['numeric-id'] local formattedval, success if snak.snaktype == 'value' then formattedval, success = countrymodule.standarddisplay(id) end if success then return formattedval else return wikidatamod.formatSnak(snak) end end } return { type = 'mixed', label = 'Pays', value = function() return country end, wikidata = function() return wikidatacountry end } end end

local function coordcore(moduleparams) local globe = moduleparams.globe local displayinline = moduleparams.displayinline local displaytitle = moduleparams.displaytitle local displayformat = moduleparams.displayformat if (not displaytitle and not distantitem) then displaytitle = 'title' end -- displayinline et displaytitle sont des chaînes à utiliser dans le paramètre "display" de coord --distantitem veut dire que le sujet de l'infobox ne correspond pas au sujet de l'article 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' and not (localdata['coordonnées'] == 'oui') then return nil end

-- si paramètres donnés dans l'article, écrasent les autres if localdata['format coordonnées'] then displayformat = localdata['format coordonnées'] end

displaytitle = 'title' if localdata['infoboxrank'] == 'secondary' then displaytitle = end if localdata['coords en titre'] == 'oui' then 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' local val = coord._coord({latitude = latitude, longitude = longitude, displayformat = displayformat, display= displayplace, globe = globe, wikidata =wikidata}) if val and latitude and longitude and localdata['référence géolocalisation'] then val = val .. ' ' .. localdata['référence géolocalisation'] end

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 = val
		}
	else 
		return val
	end
	end

end function p.coordinates(moduleparams) -- initialise les paramètres avec les valeurs du module d'infobox (moduleparams) if not moduleparams then moduleparams = {} end return { type = 'mixed', label = 'Coordonnées', maintenancecat = 'Page géolocalisable sans coordonnées paramétrées', sortkey = sortkey,

		value = coordcore(moduleparams)
		}	

end

function p.geoloc(maplist) return { type = 'map', latitude = 'latitude', class = "infobox_v3", longitude = 'longitude', wikidata = function(localdata, item) return wikidatamod.getClaims{item = item, property = 'P625'} end, maps = 'géolocalisation'

    }

end

local function coordcoretest(moduleparams) local globe = moduleparams.globe local displayinline = moduleparams.displayinline local displaytitle = moduleparams.displaytitle local displayformat = moduleparams.displayformat if (not displaytitle and not distantitem) then displaytitle = 'title' end -- displayinline et displaytitle sont des chaînes à utiliser dans le paramètre "display" de coord --distantitem veut dire que le sujet de l'infobox ne correspond pas au sujet de l'article 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' and not (localdata['coordonnées'] == 'oui') then return nil end

-- si paramètres donnés dans l'article, écrasent les autres if localdata['format coordonnées'] then displayformat = localdata['format coordonnées'] end

displaytitle = 'title' if localdata['infoboxrank'] == 'secondary' then displaytitle = end if localdata['coords en titre'] == 'oui' then 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' local val = coord._coord({latitude = latitude, longitude = longitude, displayformat = displayformat, display= displayplace, globe = globe, wikidata =wikidata}) if val and not localdata['latitude'] then val = wikidatamod.addLinkback(val, item, 'P625') end if val and latitude and longitude and localdata['référence géolocalisation'] then val = val .. ' ' .. localdata['référence géolocalisation'] end

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 = val
		}
	else 

return '

' .. val .. '

'

	end
	end

end

function p.coordinatestest(moduleparams) -- initialise les paramètres avec les valeurs du module d'infobox (moduleparams) if not moduleparams then moduleparams = {} end return { type = 'mixed', -- label = 'Coordonnées', maintenancecat = 'Page géolocalisable sans coordonnées paramétrées', sortkey = sortkey,

		value = coordcore(moduleparams)
		}	

end

return p