« Module:Carte » : différence entre les versions
déplace la fonction de documentation vers Module:Carte/données |
correction équirectangulaire passant le 180°E, correction paramétrage de l'image du point |
||
Ligne 36 : | Ligne 36 : | ||
) / mapdata.iwidth | ) / mapdata.iwidth | ||
return val | return val | ||
end | |||
--longitude équirectangulaire | |||
local function equirecLong(longitude, mapdata) | |||
if mapdata.right < mapdata.left then | |||
mapdata.right = 360 - mapdata.right | |||
if longitude < 0 then longitude = 180 - longitude end | |||
end | |||
return 100 * (longitude - mapdata.left) / (mapdata.right - mapdata.left) | |||
end | end | ||
---------------------------------- | ---------------------------------- | ||
local function buildmap(map, maptype, width, latitude, longitude, | local function buildmap(map, maptype, width, latitude, longitude, pointimage, caption) -- fonction d'aige pour buildmap | ||
if map == '-' then | if map == '-' then | ||
return | return | ||
Ligne 49 : | Ligne 58 : | ||
end | end | ||
local name = mapdata.name or '?' | local name = mapdata.name or '?' | ||
-- analyse linguistique pour le texte de la carte | -- analyse linguistique pour le texte de la carte | ||
local datagender = mapdata.genre or '' | local datagender = mapdata.genre or '' | ||
Ligne 65 : | Ligne 68 : | ||
local pointsize = tostring(8) | local pointsize = tostring(8) | ||
local ypos, xpos | local ypos, xpos | ||
if mapdata.x and mapdata.y then | 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" | ||
ypos, xpos = mapdata.y, mapdata.x | ypos, xpos = mapdata.y, mapdata.x | ||
ypos = string.gsub(ypos, '$lat', tostring(latitude)) | ypos = string.gsub(ypos, '$lat', tostring(latitude)) | ||
ypos = string.gsub(ypos, '$long', tostring(longitude)) | ypos = string.gsub(ypos, '$long', tostring(longitude)) | ||
Ligne 77 : | Ligne 79 : | ||
elseif mapdata.projection == 'Projection équirectangulaire' then | elseif mapdata.projection == 'Projection équirectangulaire' then | ||
ypos = 100 * (latitude - mapdata.top) / (mapdata.bottom - mapdata.top) | ypos = 100 * (latitude - mapdata.top) / (mapdata.bottom - mapdata.top) | ||
xpos = | xpos = equirecLong(longitude, mapdata) | ||
elseif mapdata.projection == 'Projection conique avec DL' then | elseif mapdata.projection == 'Projection conique avec DL' then | ||
ypos = dllat(latitude, longitude, mapdata) | ypos = dllat(latitude, longitude, mapdata) | ||
Ligne 130 : | Ligne 132 : | ||
local latitude = params.latitude | local latitude = params.latitude | ||
local longitude = params.longitude | local longitude = params.longitude | ||
local pointtype = params.pointtype | |||
-- les cartes s'affichent en ordre inversé, remettre bien | -- les cartes s'affichent en ordre inversé, remettre bien | ||
local newlist = {} | local newlist = {} | ||
Ligne 146 : | Ligne 148 : | ||
local div = mw.html.create('div'):addClass('img_toogle') | local div = mw.html.create('div'):addClass('img_toogle') | ||
if not | if (not pointtype) then | ||
pointtype = default | |||
end | end | ||
pointimage = pointmod[pointtype] | |||
if not pointimage then pointimage = pointmod.default end -- + message d'erreur ? | |||
--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 |
Version du 29 décembre 2014 à 11:11
local p = {} local pointmod = require('Module:Carte/Points') local linguistic = require('Module:Linguistique')
local function loaddata(name) return require('Module:Carte/données/' .. string.lower(name)) 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 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 buildmap(map, maptype, width, latitude, longitude, pointimage, caption) -- fonction d'aige pour buildmap 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 pointsize = tostring(8) 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" ypos, xpos = mapdata.y, mapdata.x ypos = string.gsub(ypos, '$lat', tostring(latitude)) ypos = string.gsub(ypos, '$long', tostring(longitude)) ypos = tonumber(mw.ext.ParserFunctions.expr(ypos)) xpos = string.gsub(xpos, '$lat', tostring(latitude)) xpos = string.gsub(xpos, '$long', tostring(longitude)) xpos = tonumber(mw.ext.ParserFunctions.expr(xpos))
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 .. error(ypos .. ' ' .. xpos) 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() local mapname = mapdata.name local file if type(mapdata.images) == 'string' then file = mapdata.images else file = mapdata.images[maptype] or mapdata.images[1] or mapdata.images['default'] end local alt = 'voir sur la carte ' .. ofstring local map = mw.html.create('div') :css{['text-align'] = 'center'} :addClass("geobox") :wikitext('Géolocalisation 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 .. '' ) :node(pointdiv) :done() :done() :done() :done() return map end
function p.multimap(params) local maplist = params.maplist local width = params.width local latitude = params.latitude local longitude = params.longitude local pointtype = params.pointtype -- les cartes s'affichent en ordre inversé, remettre bien local newlist = {} for i, j in pairs(maplist) do table.insert(newlist, 1, j) end maplist = newlist
-- 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')
if (not pointtype) then pointtype = default end pointimage = pointmod[pointtype] if not pointimage then pointimage = pointmod.default end -- + message d'erreur ?
--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 local success, data = pcall(loaddata, j) if not success then return mw.getCurrentFrame():expandTemplate{ title = 'Infobox/Géolocalisation multiple/transition', args = {['géolocalisation'] = mapliststring, type = maptype, latitude = latitude, longitude = longitude }} .. end end for i, map in pairs(maplist) do local newmap = buildmap( map, maptype, width, latitude, longitude, pointimage, 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