Module:Location map: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
require('Module:No globals')
require('strict')


local p = {}
local p = {}
Line 103: Line 103:
-- Finds a parameter in a transclusion of {{Coord}}.
-- Finds a parameter in a transclusion of {{Coord}}.
local function coord2text(para,coord) -- this should be changed for languages which do not use Arabic numerals or the degree sign
local function coord2text(para,coord) -- this should be changed for languages which do not use Arabic numerals or the degree sign
local lat, long = mw.ustring.match(coord,'<span class="p%-latitude latitude">([^<]+)</span><span class="p%-longitude longitude">([^<]+)</span>')
if lat then
return tonumber(para == 'longitude' and long or lat)
end
local result = mw.text.split(mw.ustring.match(coord,'%-?[%.%d]+°[NS] %-?[%.%d]+°[EW]') or '', '[ °]')
local result = mw.text.split(mw.ustring.match(coord,'%-?[%.%d]+°[NS] %-?[%.%d]+°[EW]') or '', '[ °]')
if para == 'longitude' then result = {result[3], result[4]} end
if para == 'longitude' then result = {result[3], result[4]} end
if not tonumber(result[1]) or not result[2] then return error('Malformed coordinates value', 2) end
if not tonumber(result[1]) or not result[2] then
mw.log('Malformed coordinates value')
mw.logObject(para, 'para')
mw.logObject(coord, 'coord')
return error('Malformed coordinates value', 2)
end
return tonumber(result[1]) * hemisphereMultipliers[para][result[2]]
return tonumber(result[1]) * hemisphereMultipliers[para][result[2]]
end
end
Line 126: Line 135:
if args.AlternativeMap then
if args.AlternativeMap then
return args.AlternativeMap
return args.AlternativeMap
elseif args.relief and map('image1') ~= '' then
elseif args.relief then
return map('image1')
        local digits = mw.ustring.match(args.relief,'^[1-9][0-9]?$') or '1' -- image1 to image99
else
        if map('image' .. digits) ~= '' then
return map('image')
            return map('image' .. digits)
        end
end
end
    return map('image')
end
end


Line 162: Line 173:
         end
         end
     end
     end
local retval = frame:extensionTag{name = 'templatestyles', args = {src = 'Template:Location map/styles.css'}}
local retval = frame:extensionTag{name = 'templatestyles', args = {src = 'Module:Location map/styles.css'}}
if args.float == 'center' then
if args.float == 'center' then
retval = retval .. '<div class="center">'
retval = retval .. '<div class="center">'
end
end
if args.caption and args.caption ~= '' and args.border ~= 'infobox' then
if args.caption and args.caption ~= '' and args.border ~= 'infobox' then
retval = retval .. '<div class="locmap noviewer thumb '
retval = retval .. '<div class="locmap noviewer noresize thumb '
if args.float == '"left"' or args.float == 'left' then
if args.float == '"left"' or args.float == 'left' then
retval = retval .. 'tleft'
retval = retval .. 'tleft'
Line 198: Line 209:
local currentTitle = mw.title.getCurrentTitle()
local currentTitle = mw.title.getCurrentTitle()
retval = string.format(
retval = string.format(
'%s[[File:%s|%spx|%s%s]]',
'%s[[File:%s|%spx|%s%s|class=notpageimage]]',
retval,
retval,
image,
image,
Line 211: Line 222:
end
end
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]]</div>'
return retval .. '<div style="position:absolute;top:0;left:0">[[File:' .. args.overlay_image .. '|' .. width .. 'px|class=notpageimage]]</div>'
else
else
return retval
return retval
Line 230: Line 241:
retval = retval .. '<div style="padding-top:0.2em">'
retval = retval .. '<div style="padding-top:0.2em">'
else
else
retval = retval .. '<div style="font-size:90%;padding-top:3px">'
retval = retval .. '<div style="font-size:91%;padding-top:3px">'
end
end
retval = retval
retval = retval
Line 237: Line 248:
elseif args.caption ~= ''  then
elseif args.caption ~= ''  then
-- This is not the pipe trick. We're creating a link with no text on purpose, so that CSS can give us a nice image
-- This is not the pipe trick. We're creating a link with no text on purpose, so that CSS can give us a nice image
retval = retval .. '<div class="thumbcaption"><div class="magnify">[[:File:' .. getContainerImage(args, map) .. '| ]]</div>' .. args.caption .. '</div>'
retval = retval .. '<div class="thumbcaption"><div class="magnify">[[:File:' .. getContainerImage(args, map) .. '|class=notpageimage| ]]</div>' .. args.caption .. '</div>'
end
end


Line 280: Line 291:
end
end


local function markOuterDiv(x, y, imageDiv, labelDiv)
local function markOuterDiv(x, y, imageDiv, labelDiv, label_size)
return mw.html.create('div')
return mw.html.create('div')
:addClass('od')
:addClass('od')
:cssText('top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%')
:addClass('notheme') -- T236137
:cssText('top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%;font-size:' .. label_size .. '%')
:node(imageDiv)
:node(imageDiv)
:node(labelDiv)
:node(labelDiv)
Line 295: Line 307:
if marksize ~= 0 then
if marksize ~= 0 then
builder:wikitext(string.format(
builder:wikitext(string.format(
'[[File:%s|%dx%dpx|%s|link=%s%s]]',
'[[File:%s|%dx%dpx|%s|link=%s%s|class=notpageimage]]',
mark,
mark,
marksize,
marksize,
Line 312: Line 324:
end
end
local builder = mw.html.create('div')
local builder = mw.html.create('div')
:cssText('font-size:' .. label_size .. '%;width:' .. label_width .. 'em')
:cssText('width:' .. label_width .. 'em')
local distance = round(marksize / 2 + 1)
local distance = round(marksize / 2 + 1)
if position == 'top' then -- specified top
if position == 'top' then -- specified top
Line 427: Line 439:
builder:wikitext('[[Category:Location maps with different longitude and latitude precisions|Decimal]]')
builder:wikitext('[[Category:Location maps with different longitude and latitude precisions|Decimal]]')
end
end
end
if ((tonumber(args.lat_deg) or 0) < 0) and ((tonumber(args.lat_min) or 0) ~= 0 or (tonumber(args.lat_sec) or 0) ~= 0 or (args.lat_dir and args.lat_dir ~='')) then
builder:wikitext('[[Category:Location maps with negative degrees and minutes or seconds]]')
end
if ((tonumber(args.lon_deg) or 0) < 0) and ((tonumber(args.lon_min) or 0) ~= 0 or (tonumber(args.lon_sec) or 0) ~= 0 or (args.lon_dir and args.lon_dir ~= '')) then
builder:wikitext('[[Category:Location maps with negative degrees and minutes or seconds]]')
end
if (((tonumber(args.lat_min) or 0) < 0) or ((tonumber(args.lat_sec) or 0) < 0)) then
builder:wikitext('[[Category:Location maps with negative degrees and minutes or seconds]]')
end
if (((tonumber(args.lon_min) or 0) < 0) or ((tonumber(args.lon_sec) or 0) < 0)) then
builder:wikitext('[[Category:Location maps with negative degrees and minutes or seconds]]')
end
end
if args.skew or args.lon_shift or args.markhigh then
if args.skew or args.lon_shift or args.markhigh then
Line 470: Line 494:
local marksize = tonumber(args.marksize) or tonumber(map('marksize')) or 8
local marksize = tonumber(args.marksize) or tonumber(map('marksize')) or 8
local imageDiv = markImageDiv(mark, marksize, args.label or mw.title.getCurrentTitle().text, args.link or '', args.alt, args[2])
local imageDiv = markImageDiv(mark, marksize, args.label or mw.title.getCurrentTitle().text, args.link or '', args.alt, args[2])
local label_size = args.label_size or 91
local labelDiv
local labelDiv
if args.label and args.position ~= 'none' then
if args.label and args.position ~= 'none' then
labelDiv = markLabelDiv(args.label, args.label_size or 90, args.label_width or 6, args.position, args.background, x, marksize)
labelDiv = markLabelDiv(args.label, label_size, args.label_width or 6, args.position, args.background, x, marksize)
end
end
return builder:node(markOuterDiv(x, y, imageDiv, labelDiv))
return builder:node(markOuterDiv(x, y, imageDiv, labelDiv, label_size))
end
end


Autopatrolled, New page reviewers, Rollbackers
2,168

edits