« Module:Carte » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
petit modification de l'ordre des cartes, pour qu'elle s'affichent de haut en bas suivant l'ordre de la chaîne indiquée dans |géolocalisation =
0x010D (discussion | contributions)
m autorise plusieurs points par carte, petites corrections
Ligne 2 : Ligne 2 :
local pointmod = require('Module:Carte/Points')
local pointmod = require('Module:Carte/Points')
local linguistic = require('Module:Linguistique')
local linguistic = require('Module:Linguistique')
local maintenance = ''
local function loaddata(name)
return require('Module:Carte/données/' .. mw.ustring.lower(name))
end


local function loaddata(name)  
local function addmaintenancecat(cat, sortkey) -- ajoute du texte à la string maintenance en cas de problème
return require('Module:Carte/données/' .. string.lower(name))
if mw.title.getCurrentTitle().namespace ~= 0 then
return
end
maintenance = maintenance .. '[[Category:' .. cat .. ']]'
end
end


Ligne 48 : Ligne 55 :


----------------------------------
----------------------------------
 
local function placepoint(mapdata, point) -- fonction d'aige pour buildmap point est une table contenant latitude, longitude, type de point...
local function buildmap(map, maptype, width, latitude, longitude, pointimage, caption) -- fonction d'aige pour buildmap
local latitude = point.latitude
if map == '-' then
local longitude = point.longitude
return
local pointsize = tostring(point.pointsize or '8')
end
local pointtype = point.pointtype or 'default'
local success, mapdata = pcall(loaddata, map)
local pointimage = pointmod[pointtype]
if not success or not mapdata.images then
if not pointimage then
addmaintenancecat('Page avec des données de géolocalisation non supportées')
pointimage = pointmod[pointtype]
addmaintenancecat('Page avec un modèle de point de carte non supporté')
end
end
local name = mapdata.name or '?'
-- analyse linguistique pour le texte de la carte
local datagender = mapdata.genre or ''
local gender = string.sub(datagender, 1, 1) -- ms = masculin-singulier, fp = féminin pluriel etc.
local number = string.sub(datagender, 2, 2)
local determiner = mapdata.determiner
local ofstring = linguistic.of(name, gender, number, determiner) -- restitue "de France" ou "du Japon"
local pointsize = tostring(8)
local ypos, xpos
local ypos, xpos
if mapdata.x and mapdata.y then -- pour les cartes complexes : calcul de la position à partir de formules en Wikicode dans les clés "x" et "y"
if mapdata.x and mapdata.y then -- pour les cartes complexes : calcul de la position à partir de formules en Wikicode dans les clés "x" et "y"
Ligne 93 : Ligne 91 :
:wikitext('[[Image:' .. pointimage .. ']]')
:wikitext('[[Image:' .. pointimage .. ']]')
:done()
:done()
return pointdiv
end
local function buildmap(map, maptype, width, pointtable, caption) -- fonction d'aige pour multimap
if map == '-' then
return
end
local success, mapdata = pcall(loaddata, map)
if not success or not mapdata.images then
addmaintenancecat('Page avec des données de géolocalisation non supportées')
end
local name = mapdata.name or '?'
-- analyse linguistique pour le texte de la carte
local datagender = mapdata.genre or ''
local gender = string.sub(datagender, 1, 1) -- ms = masculin-singulier, fp = féminin pluriel etc.
local number = string.sub(datagender, 2, 2)
local determiner = mapdata.determiner
local ofstring = linguistic.of(name, gender, number, determiner) -- restitue "de France" ou "du Japon"
local mapname = mapdata.name
local mapname = mapdata.name
local file
local file = mapdata.images[maptype] or mapdata.images['default'] or mapdata.images[1]
if type(mapdata.images) == 'string' then
if not file then
file = mapdata.images
file = mapdata.images['default']
else
file = mapdata.images[maptype] or mapdata.images[1] or mapdata.images['default']
end
end
local alt = 'voir sur la carte ' .. ofstring
local alt = 'voir sur la carte ' .. ofstring
local map = mw.html.create('div')
local map = mw.html.create('div')
:css{['text-align'] = 'center'}
:css{['text-align'] = 'center'}
:addClass("geobox")
:addClass("geobox")
:wikitext('<small>Géolocalisation sur la carte ' .. ofstring .. '</small>')
:wikitext('Localisation sur la carte ' .. ofstring)
:tag('table')
:tag('table')
:addClass('DebutCarte')
:addClass('DebutCarte')
Ligne 113 : Ligne 131 :
:tag('div')
:tag('div')
:css({position= 'relative', margin = "auto",})
:css({position= 'relative', margin = "auto",})
:wikitext('[[Fichier:' .. file .. '|' .. width .. 'px' .. '|' .. alt .. ']]' )
:wikitext('[[File:' .. file .. '|' .. width .. 'px' .. '|' .. alt .. ']]' )
:node(pointdiv)
:done()
for i, j in pairs(pointtable) do -- pour chque point à placer, do
:done()
map:node(placepoint(mapdata,j))
:done()
end
:done()
return map:done():done():done():done()
return map
end
end


function p.multimap(params)
function p.multimap(params)
local maplist = params.maplist
local maplist = params.maplist
local maptype = params.maptype -- à retravailler pour quand on veut la même région, mais avec plusieurs types de carte
local width = params.width
local width = params.width
local latitude = params.latitude
if not pointtable then -- pointtable est la liste des points à placer, mais lorsqu'il n'y a qu'un seul point, on peut avoir des paramètres distinctions : 
local longitude = params.longitude
pointtable = {{latitude = params.latitude, longitude = params.longitude, pointtype = params.pointtype}}
local pointtype = params.pointtype
end
 
-- traitement de la largeur
-- traitement de la largeur
if width and tonumber(width) then
if width and tonumber(width) then
Ligne 136 : Ligne 153 :
end-- si pas un nombre, erreur ?
end-- si pas un nombre, erreur ?
local div =  mw.html.create('div'):addClass('img_toogle')
local div =  mw.html.create('div'):addClass('img_toogle')
if (not pointtype) then
pointtype = default
end
pointimage = pointmod[pointtype]
if not pointimage then pointimage = pointmod.default end -- + message d'erreur ?
-- met la carte à afficher par défaut à la fin, pour qu'elle soit affichée en premier
-- met la carte à afficher par défaut à la fin, pour qu'elle soit affichée en premier
Ligne 147 : Ligne 158 :
table.remove(maplist, 1)
table.remove(maplist, 1)
--transition: appel aux [[Modèle:Géolocalisation/]] n en l'absence de données dans le module
--transition: appel aux [[Modèle:Géolocalisation/]] n en l'absence de données dans le module
local mapliststring = table.concat(maplist, '/')
for i, j in pairs(maplist) do
for i, j in pairs(maplist) do
local success, data = pcall(loaddata, j)  
local success, data = pcall(loaddata, j)  
if not success then
if not success then
local mapliststring = table.concat(maplist, '/')
return mw.getCurrentFrame():expandTemplate{ title = 'Infobox/Géolocalisation multiple/transition', args = {['géolocalisation'] = mapliststring, type = maptype, latitude = latitude, longitude = longitude }}
return mw.getCurrentFrame():expandTemplate{ title = 'Infobox/Géolocalisation multiple/transition', args = {['géolocalisation'] = mapliststring, type = maptype, latitude = latitude, longitude = longitude }}
.. '[[Catégorie:Page avec des données de géolocalisation non supportées]]'
.. '[[Catégorie:Page avec des données de géolocalisation non supportées]]'
end
end
end
end
 
for i, j in pairs(maplist) do
for i, map in pairs(maplist) do
local newmap = buildmap( j, maptype, width, pointtable, caption)
local newmap = buildmap( map, maptype, width, latitude, longitude, pointimage, caption)
div:node(newmap)
div:node(newmap)
end
end

Version du 31 décembre 2014 à 08:47

local p = {} local pointmod = require('Module:Carte/Points') local linguistic = require('Module:Linguistique') local maintenance = local function loaddata(name) return require('Module:Carte/données/' .. mw.ustring.lower(name)) end

local function addmaintenancecat(cat, sortkey) -- ajoute du texte à la string maintenance en cas de problème if mw.title.getCurrentTitle().namespace ~= 0 then return end maintenance = maintenance .. end

-- 'Projection conique avec DL' local function dllat(latitude, longitude, mapdata) -- conique avec DL local val = 100* (mapdata.y0 + ( mapdata.iheight/2 - mapdata.y0 ) * (1 - mapdata.t * (latitude - mapdata.centrallat) * (0.01745329252 + 0.00000177219231 * (latitude - mapdata.centrallat) ^2) )* ( 1- 0.00015230871 * (longitude-mapdata.centrallong) ^2 * mapdata.s^2) ) / mapdata.iheight

return val end local function dllong(latitude, longitude, mapdata) local val = 100 * ( ( (mapdata.x0 or (mapdata.iwidth/2)) + ( mapdata.iheight/2 - mapdata.y0 ) * ( 1 -mapdata.t * (latitude-mapdata.centrallat) * ( 0.01745329252 + 0.00000177219231 * (latitude-mapdata.centrallat) * (latitude-mapdata.centrallat) ) ) * (longitude-mapdata.centrallong) * mapdata.s * (0.01745329252 - 0.000000886096156 * (longitude-(mapdata.centrallong)) * (longitude-(mapdata.centrallong)) * mapdata.s^2 ) ) ) / mapdata.iwidth return val end

--longitude équirectangulaire local function equirecLong(longitude, mapdata) if mapdata.right < mapdata.left then -- si la carte passe le méridien 180 mapdata.right = 360 - mapdata.right if longitude < 0 then longitude = 180 - longitude end end return 100 * (longitude - mapdata.left) / (mapdata.right - mapdata.left) end


local function placepoint(mapdata, point) -- fonction d'aige pour buildmap point est une table contenant latitude, longitude, type de point... local latitude = point.latitude local longitude = point.longitude local pointsize = tostring(point.pointsize or '8') local pointtype = point.pointtype or 'default' local pointimage = pointmod[pointtype] if not pointimage then pointimage = pointmod[pointtype] addmaintenancecat('Page avec un modèle de point de carte non supporté') end local ypos, xpos if mapdata.x and mapdata.y then -- pour les cartes complexes : calcul de la position à partir de formules en Wikicode dans les clés "x" et "y" xpos = mapdata.x(latitude, longitude) ypos = mapdata.y(latitude, longitude)

elseif mapdata.projection == 'Projection équirectangulaire' then ypos = 100 * (latitude - mapdata.top) / (mapdata.bottom - mapdata.top) xpos = equirecLong(longitude, mapdata) elseif mapdata.projection == 'Projection conique avec DL' then ypos = dllat(latitude, longitude, mapdata) xpos = dllong(latitude, longitude, mapdata) else return "système cartographique non supporté" end if (ypos > 100) or (xpos) > 100 or (ypos < 0) or (xpos < 0) then return .. 'les coordonnées inquées sont hors de la carte de géolocalisation demandée' end local htmlheight = tostring(ypos) .. '%' local htmlwidth = tostring(xpos) .. '%'

local pointdiv = mw.html.create('div') :css{position = 'absolute', border = 'none', top = htmlheight, left = htmlwidth} :tag('div') :css{position = 'absolute', top = '-4px', left = '-4px', ['line-height'] = '0', width = '8px'} :wikitext('Fichier:' .. pointimage .. '') :done()

return pointdiv end

local function buildmap(map, maptype, width, pointtable, caption) -- fonction d'aige pour multimap if map == '-' then return end local success, mapdata = pcall(loaddata, map) if not success or not mapdata.images then addmaintenancecat('Page avec des données de géolocalisation non supportées') end local name = mapdata.name or '?'

-- analyse linguistique pour le texte de la carte local datagender = mapdata.genre or local gender = string.sub(datagender, 1, 1) -- ms = masculin-singulier, fp = féminin pluriel etc. local number = string.sub(datagender, 2, 2) local determiner = mapdata.determiner local ofstring = linguistic.of(name, gender, number, determiner) -- restitue "de France" ou "du Japon"

local mapname = mapdata.name local file = mapdata.images[maptype] or mapdata.images['default'] or mapdata.images[1] if not file then file = mapdata.images['default'] end local alt = 'voir sur la carte ' .. ofstring

local map = mw.html.create('div') :css{['text-align'] = 'center'} :addClass("geobox") :wikitext('Localisation sur la carte ' .. ofstring) :tag('table') :addClass('DebutCarte') :attr({border="0", cellspacing="0", cellpadding="0"}) :css({margin = '0', border = 'none', padding = '0'}) :tag('tr') :tag('td') :tag('div') :css({position= 'relative', margin = "auto",}) :wikitext('' .. alt .. '' )

for i, j in pairs(pointtable) do -- pour chque point à placer, do map:node(placepoint(mapdata,j)) end return map:done():done():done():done() end

function p.multimap(params) local maplist = params.maplist local maptype = params.maptype -- à retravailler pour quand on veut la même région, mais avec plusieurs types de carte local width = params.width if not pointtable then -- pointtable est la liste des points à placer, mais lorsqu'il n'y a qu'un seul point, on peut avoir des paramètres distinctions : pointtable = Modèle:Latitude = params.latitude, longitude = params.longitude, pointtype = params.pointtype end -- traitement de la largeur if width and tonumber(width) then width = tonumber(width) else width = 280 end-- si pas un nombre, erreur ? local div = mw.html.create('div'):addClass('img_toogle')

-- met la carte à afficher par défaut à la fin, pour qu'elle soit affichée en premier table.insert(maplist, maplist[1]) table.remove(maplist, 1)

	--transition: appel aux Modèle:Géolocalisation/ n en l'absence de données dans le module

for i, j in pairs(maplist) do local success, data = pcall(loaddata, j) if not success then local mapliststring = table.concat(maplist, '/') return mw.getCurrentFrame():expandTemplate{ title = 'Infobox/Géolocalisation multiple/transition', args = {['géolocalisation'] = mapliststring, type = maptype, latitude = latitude, longitude = longitude }} .. end end for i, j in pairs(maplist) do local newmap = buildmap( j, maptype, width, pointtable, caption) div:node(newmap) end return div end

function p.map(frame) local args = frame.args -- utilisation du franaçs args.maplist = mw.text.split( args.carte, '/', true) return p.multimap(args) end return p