「モジュール:Location map」の版間の差分

ナビゲーションに移動 検索に移動
en:Module:Location map 21:36, 2 June 2014‎(UTC)より
template>Frozen-mikan
(en:Module:Location_map 2014-04-16T03:06:56Z の版を複製。)
 
template>K-iczn
(en:Module:Location map 21:36, 2 June 2014‎(UTC)より)
1行目: 1行目:
require('Module:No globals')
local p = {}
local p = {}


local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs


local function round(n, digits)
function p.getMapParams(map, frame)
local mult = math.pow(10, digits)
return math.floor(n * mult + 0.5) / mult
end
 
local function getMapParams(map, frame)
if not map then
if not map then
error('The name of the location map definition to use must be specified', 2)
error('The name of the location map definition to use must be specified', 2)
20行目: 17行目:
if mapData[name] == nil then
if mapData[name] == nil then
return ''
return ''
elseif params and params[1] then
elseif params then
return mw.message.newRawMessage(tostring(mapData[name]), unpack(params)):plain()
return mw.message.newRawMessage(tostring(mapData[name]), unpack(params)):plain()
else
else
48行目: 45行目:
end
end
if not map then
if not map then
map = getMapParams(args[1], frame)
map = p.getMapParams(args[1], frame)
end
end
local params = {}
local params = {}
56行目: 53行目:
end
end
end
end
return map(args[2], params)
return map(args[2], #params and params)
end
end


64行目: 61行目:
}
}


local function decdeg(degrees, minutes, seconds, hemisphere, digits, decimal, direction)
local function decdeg(degrees, minutes, seconds, hemisphere, decimal, direction)
if not degrees then
if not degrees then
if not decimal then
if not decimal then
93行目: 90行目:
decimal = decimal * multiplier
decimal = decimal * multiplier
end
end
if not digits then
return decimal
digits = 7
elseif not tonumber(digits) then
error('The value "' .. digits .. '" provided for number of digits in ' .. direction .. ' is not valid', 2)
end
return round(decimal, digits)
end
end


106行目: 98行目:
end
end
if not map then
if not map then
map = getMapParams(args[1], frame)
map = p.getMapParams(args[1], frame)
end
end
local width
local width
if args.width then
if not args.width then
width = mw.ustring.gsub(args.width, 'px', '')
width = math.floor((args.default_width or 240) * (tonumber(map('defaultscale')) or 1) + 0.5)
elseif mw.ustring.sub(args.width, -2) == 'px' then
width = mw.ustring.sub(args.width, 1, -3)
else
else
width = round((args.default_width or 240) * (tonumber(map('defaultscale')) or 1), 0)
width = args.width
end
local retval = ''
if args.float == 'center' then
retval = retval .. '<div class="center">'
end
end
local retval = args.float == 'center' and '<div class="center">' or ''
if args.caption then
if args.caption then
retval = retval .. '<div class="thumb '
retval = retval .. '<div class="thumb '
127行目: 118行目:
retval = retval .. 'tright'
retval = retval .. 'tright'
end
end
retval = retval .. '"><div class="thumbinner" style="width:' .. (width + 2) .. 'px;'
retval = retval .. '"><div class="thumbinner" style="width:' .. (width + 2) .. 'px'
if args.border == 'none' then
if args.border == 'none' then
retval = retval .. 'border:none;'
retval = retval .. ';border:none'
elseif args.border then
elseif args.border then
retval = retval .. 'border-color:' .. args.border .. ';'
retval = retval .. ';border-color:' .. args.border
end
retval = retval .. '"><div style="position:relative;width:' .. width .. 'px'
if args.border ~= 'none' then
retval = retval .. ';border:1px solid lightgray'
end
end
retval = retval .. '">'
retval = retval .. '"><div style="position:relative;width:' .. width .. 'px' .. (args.border ~= 'none' and ';border:1px solid lightgray">' or '">')
else
else
retval = retval .. '<div style="width:' .. width .. 'px;'
retval = retval .. '<div style="width:' .. width .. 'px;'
161行目: 148行目:
retval = retval .. '[[File:' .. image .. '|' .. width .. 'px|' .. (args.alt or ((args.label or mw.title.getCurrentTitle().text) .. ' is located in ' .. map('name'))) .. ']]'
retval = retval .. '[[File:' .. image .. '|' .. width .. 'px|' .. (args.alt or ((args.label or mw.title.getCurrentTitle().text) .. ' is located in ' .. map('name'))) .. ']]'
if args.overlay_image then
if args.overlay_image then
retval = retval .. '<div style="position:absolute; top: 0; left: 0">[[File:' .. args.overlay_image .. '|' .. width .. 'px|link=File:' .. image .. ']]</div>'
return retval .. '<div style="position:absolute;top:0;left:0">[[File:' .. args.overlay_image .. '|' .. width .. 'px|link=File:' .. image .. ']]</div>'
else
return retval
end
end
return retval
end
end


171行目: 159行目:
end
end
if not map then
if not map then
map = getMapParams(args[1], frame)
map = p.getMapParams(args[1], frame)
end
end
local retval = ''
local retval = '</div><div ' .. (args.caption and 'class="thumbcaption">' or 'style="font-size:90%;padding-top:3px">')
retval = retval .. '</div><div ' .. (args.caption and 'class="thumbcaption"' or 'style="font-size:90%;padding-top:3px"') .. '>'
local caption = frame.args.caption or frame:getParent().args.caption
local caption = frame.args.caption or frame:getParent().args.caption
if caption and not args.caption_undefined then
if caption and not args.caption_undefined then
184行目: 171行目:
if args.float == 'center' then
if args.float == 'center' then
retval = retval .. '</div>'
retval = retval .. '</div>'
end
if args.caption_undefined then
retval = retval .. ''
end
end
return retval
return retval
193行目: 183行目:
end
end
if not map then
if not map then
map = getMapParams(args[1], frame)
map = p.getMapParams(args[1], frame)
end
end
return p.top(frame, args, map) .. (args.places or '') .. p.bottom(frame, args, map)
return p.top(frame, args, map) .. (args.places or '') .. p.bottom(frame, args, map)
203行目: 193行目:


local function markImageDiv(mark, marksize, label, link, alt, title)
local function markImageDiv(mark, marksize, label, link, alt, title)
local retval = '<div style="position:relative;text-align:center;left:-' .. round(marksize / 2, 0) .. 'px;top:-' .. round(marksize / 2, 0) .. 'px;width:' .. marksize .. 'px;font-size:' .. marksize .. 'px;line-height:0"'
local retval = '<div style="position:relative;text-align:center;left:-' .. math.floor(marksize / 2 + 0.5) .. 'px;top:-' .. math.floor(marksize / 2 + 0.5) .. 'px;width:' .. marksize .. 'px;font-size:' .. marksize .. 'px;line-height:0"' .. (title and (' title="' .. title .. '">') or '>')
if title then
retval = retval .. ' title="' .. title .. '"'
end
retval = retval .. '>'
if marksize ~= 0 then
if marksize ~= 0 then
retval = retval .. '[[File:' .. mark .. '|' .. marksize .. 'x' .. marksize .. 'px|' .. label .. '|link=' .. link
retval = retval .. '[[File:' .. mark .. '|' .. marksize .. 'x' .. marksize .. 'px|' .. label .. '|link=' .. link
236行目: 222行目:
end
end


local function getX(longitude, latitude, lon_dir, left, right, top, bottom, crosses180, skew, lon_shift)
local function getX(longitude, left, right)
local crosses180_correction = crosses180 and lon_dir == 'W' and (-36000/(left - right)) or 0
local width = (right - left) % 360
if skew then
if width == 0 then
local lat_ratio = (top - latitude)/(top - bottom)
width = 360
local skew_factor = (1 - skew) * lat_ratio + skew
end
longitude = (longitude - 0.5 * (right + left) + lon_shift) * skew_factor + 0.5 * (right + left) - lon_shift
local distanceFromLeft = (longitude - left) % 360
-- the distance needed past the map to the right equals distanceFromLeft - width. the distance needed past the map to the left equals 360 - distanceFromLeft. to minimize page stretching, go whichever way is shorter
if distanceFromLeft - width / 2 >= 180 then
distanceFromLeft = distanceFromLeft - 360
end
end
return round(crosses180_correction + 100 * (longitude - left) / (right - left), 1)
return 100 * distanceFromLeft / width
end
end


local function getY(latitude, top, bottom)
local function getY(latitude, top, bottom)
return round(100 * (top - latitude) / (top - bottom), 1)
return 100 * (top - latitude) / (top - bottom)
end
end


255行目: 244行目:
end
end
if not map then
if not map then
map = getMapParams(args[1], frame)
map = p.getMapParams(args[1], frame)
end
local x, y, longitude, latitude
longitude = decdeg(args.lon_deg, args.lon_min, args.lon_sec, args.lon_dir, args.long, 'longitude')
latitude = decdeg(args.lat_deg, args.lat_min, args.lat_sec, args.lat_dir, args.lat, 'latitude')
local retval = ''
if args.skew or args.lon_shift or (map('skew') ~= '') or (map('lat_skew') ~= '') or (map('crosses180') ~= '') then
retval = retval .. ''
end
end
local x, y, longitude, latitide
longitude = decdeg(args.lon_deg, args.lon_min, args.lon_sec, args.lon_dir, nil, args.long, 'longitude')
latitude = decdeg(args.lat_deg, args.lat_min, args.lat_sec, args.lat_dir, nil, args.lat, 'latitude')
if map('x') ~= '' then
if map('x') ~= '' then
x = frame:callParserFunction('#expr', map('x', { latitude, longitude }))
x = frame:callParserFunction('#expr', map('x', { latitude, longitude }))
else
else
x = getX(longitude, latitude, args.lon_dir, map('left'), map('right'), map('top'), map('bottom'), map('crosses180') ~= '', tonumber(args.skew or map('skew')), args.lon_shift or 0)
x = getX(longitude, map('left'), map('right'))
end
end
if map('y') ~= '' then
if map('y') ~= '' then
278行目: 271行目:
divContent = divContent .. markLabelDiv(args.label, args.label_size or 90, args.label_width or 6, args.position, args.background, x)
divContent = divContent .. markLabelDiv(args.label, args.label_size or 90, args.label_width or 6, args.position, args.background, x)
end
end
return markOuterDiv(x, y, divContent)
return retval .. markOuterDiv(x, y, divContent)
end
end


289行目: 282行目:
end
end
if not map then
if not map then
map = getMapParams(args[1], frame)
map = p.getMapParams(args[1], frame)
end
end
return p.top(frame, args, map) .. p.mark(frame, args, map) .. p.bottom(frame, args, map)
return p.top(frame, args, map) .. p.mark(frame, args, map) .. p.bottom(frame, args, map)
348行目: 341行目:
end
end
if not map then
if not map then
map = getMapParams(args[1], frame)
map = p.getMapParams(args[1], frame)
end
end
local marks = {}
local marks = {}
378行目: 371行目:
end
end
args.label = nil -- there is no global label
args.label = nil -- there is no global label
return p.top(frame, args, map) .. body .. p.bottom(frame, args, map) .. (markhigh and '[[Category:Location map many using markhigh parameter]]' or '')
return p.top(frame, args, map) .. body .. p.bottom(frame, args, map) .. (markhigh and '' or '')
end
end


return p
return p
匿名利用者

案内メニュー