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 | ||
function p.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 | 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 | 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 | ||
return decimal | |||
return | |||
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. | 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 = | width = args.width | ||
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 | 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 | ||
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 | ||
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">') | ||
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:-' .. | 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 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 | local function getX(longitude, left, right) | ||
local | local width = (right - left) % 360 | ||
if | if width == 0 then | ||
width = 360 | |||
end | |||
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 | return 100 * distanceFromLeft / width | ||
end | end | ||
local function getY(latitude, top, bottom) | local function getY(latitude, top, bottom) | ||
return | 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 | ||
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 | 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 ' | return p.top(frame, args, map) .. body .. p.bottom(frame, args, map) .. (markhigh and '' or '') | ||
end | end | ||
return p | return p |