13,401
edits
No edit summary |
No edit summary |
||
Line 7: | Line 7: | ||
local function round(n, decimals) | local function round(n, decimals) | ||
local pow = 10^(decimals or 0) | local pow = 10^(decimals or 0) | ||
return math.floor(n * pow + 0.5) / pow | |||
end | end | ||
Line 182: | Line 183: | ||
retval = retval .. '"><div style="position:relative;width:' .. width .. 'px' .. (args.border ~= 'none' and ';border:1px solid lightgray">' or '">') | retval = retval .. '"><div style="position:relative;width:' .. width .. 'px' .. (args.border ~= 'none' and ';border:1px solid lightgray">' or '">') | ||
else | else | ||
retval = retval .. '<div class="locmap" style="width:' .. width .. 'px;' | |||
if args.float == '"left"' or args.float == 'left' then | if args.float == '"left"' or args.float == 'left' then | ||
retval = retval .. 'float:left;clear:left' | retval = retval .. 'float:left;clear:left' | ||
Line 191: | Line 193: | ||
retval = retval .. 'float:right;clear:right' | retval = retval .. 'float:right;clear:right' | ||
end | end | ||
retval = retval .. '"><div style="width:' .. width .. 'px;padding:0"><div style="position:relative;width:' .. width .. 'px">' | |||
end | end | ||
local image = getContainerImage(args, map) | local image = getContainerImage(args, map) | ||
Line 315: | Line 318: | ||
elseif position == 'bottom' then -- specified bottom | elseif position == 'bottom' then -- specified bottom | ||
builder:addClass('pv'):cssText('top:' .. distance .. 'px;left:' .. (-label_width / 2) .. 'em') | builder:addClass('pv'):cssText('top:' .. distance .. 'px;left:' .. (-label_width / 2) .. 'em') | ||
elseif position == 'left' or (tonumber(x) > 70 and position ~= 'right') then -- specified left or autodetected to left | |||
builder:addClass('pl'):cssText('right:' .. distance .. 'px') | |||
else -- specified right or autodetected to right | else -- specified right or autodetected to right | ||
builder:addClass('pr'):cssText('left:' .. distance .. 'px') | builder:addClass('pr'):cssText('left:' .. distance .. 'px') | ||
Line 324: | Line 329: | ||
end | end | ||
return builder:done() | return builder:done() | ||
end | |||
local function getX(longitude, left, right) | |||
local width = (right - left) % 360 | |||
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 | |||
return 100 * distanceFromLeft / width | |||
end | |||
local function getY(latitude, top, bottom) | |||
return 100 * (top - latitude) / (top - bottom) | |||
end | end | ||
Line 375: | Line 397: | ||
-- error('Coordinates from [[Module:Coordinates]] and individual coordinates cannot both be provided') | -- error('Coordinates from [[Module:Coordinates]] and individual coordinates cannot both be provided') | ||
-- end | -- end | ||
longitude = coord2text('longitude', args.coordinates) | |||
latitude = coord2text('latitude', args.coordinates) | |||
elseif not longitude and not latitude and args.useWikidata then | |||
-- If they didn't provide either coordinate, try Wikidata. If they provided one but not the other, don't. | |||
local entity = mw.wikibase.getEntity() | |||
if entity and entity.claims and entity.claims.P625 and entity.claims.P625[1].mainsnak.snaktype == 'value' then | |||
local value = entity.claims.P625[1].mainsnak.datavalue.value | |||
longitude, latitude = value.longitude, value.latitude | |||
end | |||
if args.link and (currentTitle.namespace == 0) then | if args.link and (currentTitle.namespace == 0) then | ||
builder:wikitext('[[Category:Location maps with linked markers with coordinates from Wikidata]]') | builder:wikitext('[[Category:Location maps with linked markers with coordinates from Wikidata]]') | ||
end | end | ||
end | |||
if not longitude then | |||
error('No value was provided for longitude') | |||
elseif not latitude then | |||
error('No value was provided for latitude') | |||
end | end | ||
if currentTitle.namespace > 0 then | if currentTitle.namespace > 0 then | ||
Line 406: | Line 442: | ||
end | end | ||
end | end | ||
if map('x') ~= '' then | |||
x = tonumber(mw.ext.ParserFunctions.expr(map('x', { latitude, longitude }))) | |||
else | |||
x = tonumber(getX(longitude, map('left'), map('right'))) | |||
end | |||
if map('y') ~= '' then | |||
y = tonumber(mw.ext.ParserFunctions.expr(map('y', { latitude, longitude }))) | |||
else | |||
y = tonumber(getY(latitude, map('top'), map('bottom'))) | |||
end | |||
if (x < 0 or x > 100 or y < 0 or y > 100) and not args.outside then | |||
mw.log('Mark placed outside map boundaries without outside flag set. x = ' .. x .. ', y = ' .. y) | |||
local parent = frame:getParent() | |||
if parent then | |||
mw.log('Parent is ' .. parent:getTitle()) | |||
end | |||
mw.logObject(args, 'args') | |||
if currentTitle.namespace == 0 then | if currentTitle.namespace == 0 then | ||
local key = currentTitle.prefixedText | local key = currentTitle.prefixedText | ||
builder:wikitext('[[Category:Location maps with marks outside map and outside parameter not set|' .. key .. ' ]]') | builder:wikitext('[[Category:Location maps with marks outside map and outside parameter not set|' .. key .. ' ]]') | ||
end | end | ||
end | |||
local mark = args.mark or map('mark') | local mark = args.mark or map('mark') | ||
if mark == '' then | if mark == '' then |
edits