Module:Location map: Difference between revisions
m
1 revision imported from templatewiki:Module:Location_map
(expand tracking) |
m (1 revision imported from templatewiki:Module:Location_map) |
||
Line 28:
else
return mapData[name]
end▼
end▼
elseif mw.title.new('Template:Location map ' .. map).exists then
local cache = {}
if type(frame) ~= 'table' or type(frame.expandTemplate) ~= 'function' then
error('A frame must be provided when using a legacy location map')
end▼
return function(name, params)
return frame:expandTemplate{title = 'Location map ' .. map, args = { name, unpack(params) }}
else
if name == nil then
return 'Template:Location map ' .. map
elseif cache[name] == nil then
cache[name] = frame:expandTemplate{title = 'Location map ' .. map, args = { name }}
end▼
return cache[name]
end
end
else
error('Unable to find the specified location map definition
end
end
Line 103 ⟶ 120:
-- 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
▲ if lat then
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 not tonumber(result[1]) or not result[2] then return error('Malformed coordinates value', 2) end
return tonumber(result[1]) * hemisphereMultipliers[para][result[2]]
end
Line 171 ⟶ 179:
end
end
local retval =
if args.caption and args.caption ~= '' and args.border ~= 'infobox' then
retval = retval .. '<div class="
if args.float == '"left"' or args.float == 'left' then
retval = retval .. 'tleft'
Line 192 ⟶ 197:
retval = retval .. '"><div style="position:relative;width:' .. width .. 'px' .. (args.border ~= 'none' and ';border:1px solid lightgray">' or '">')
else
retval = retval .. '<div
if args.float == '"left"' or args.float == 'left' then
retval = retval .. 'float:left;clear:left'
Line 205 ⟶ 210:
end
local image = getContainerImage(args, map)
retval = string.format(
'%s[[File:%s|%spx|%s%s]]',
Line 211 ⟶ 215:
image,
width,
args.alt or ((args.label or
args.maplink and ('|link=' .. args.maplink) or ''
)
if args.caption and args.caption ~= '' then
if
retval = retval .. '[[Category:Pages using location map with a double number sign in the caption]]'
end
Line 234 ⟶ 238:
end
local retval = '</div>'
if not args.caption or args.border == 'infobox' then
if args.border then
retval = retval .. '<div
else
retval = retval .. '<div style="font-size:
end
retval = retval
.. (args.caption or (args.label or
.. '</div>'
elseif args.caption ~= '' then
Line 263 ⟶ 267:
end
mw.logObject(args, 'args')
▲ retval = retval .. '[[Category:Location maps with removed parameters|caption_undefined]]'
▲ end
end
if map('skew') ~= '' or map('lat_skew') ~= '' or map('crosses180') ~= '' or map('type') ~= '' then
mw.log('Removed parameter used in map definition ' .. map())
▲ local key = (map('skew') ~= '' and 'skew' or '') ..
(map('lat_skew') ~= '' and 'lat_skew' or '') ..
(map('crosses180') ~= '' and 'crosses180' or '') ..
(map('type') ~= '' and 'type' or '')
▲ end
end
if string.find(map('name'), '|', 1, true) then
mw.log('Pipe used in name of map definition ' .. map())
▲ retval = retval .. '[[Category:Location maps with a name containing a pipe]]'
▲ end
end
if args.float == 'center' then
Line 291 ⟶ 289:
local function markOuterDiv(x, y, imageDiv, labelDiv)
return mw.html.create('div')
:cssText('position:absolute;top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%')▼
▲ :cssText('top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%')
:node(imageDiv)
:node(labelDiv)
Line 299 ⟶ 296:
local function markImageDiv(mark, marksize, label, link, alt, title)
local builder = mw.html.create('div')
:cssText('position:absolute;left:-' .. round(marksize / 2) .. 'px;top:-' .. round(marksize / 2) .. 'px;line-height:0')▼
▲ :cssText('left:-' .. round(marksize / 2) .. 'px;top:-' .. round(marksize / 2) .. 'px')
:attr('title', title)
if marksize ~= 0 then
Line 318 ⟶ 314:
local function markLabelDiv(label, label_size, label_width, position, background, x, marksize)
if tonumber(label_size) == 0 then
return mw.html.create('div'):
end
local builder = mw.html.create('div')
:cssText('font-size:' .. label_size .. '%;line-height:110%;position:absolute;width:' .. label_width .. 'em')
local distance = round(marksize / 2 + 1)
local spanCss
if position == 'top' then -- specified top
builder
elseif position == 'bottom' then -- specified bottom
builder
elseif position == 'left' or (tonumber(x) > 70 and position ~= 'right') then -- specified left or autodetected to left
builder
spanCss = 'float:right'
else -- specified right or autodetected to right
builder
spanCss = 'float:left'
end
builder = builder:tag('
:cssText('padding:1px')
:cssText(spanCss)
:wikitext(label)
if background then
Line 398 ⟶ 399:
end
local builder = mw.html.create()▼
if args.coordinates then
-- Temporarily removed to facilitate infobox conversion. See [[Wikipedia:Coordinates in infoboxes]]
Line 414 ⟶ 413:
local value = entity.claims.P625[1].mainsnak.datavalue.value
longitude, latitude = value.longitude, value.latitude
▲ end
builder:wikitext('[[Category:Location maps with linked markers with coordinates from Wikidata]]') ▼
end
end
Line 424 ⟶ 420:
error('No value was provided for latitude')
end
▲ local builder = mw.html.create()
builder:wikitext('[[Category:Location maps with negative degrees and minutes or seconds]]')▼
end
if args.skew or args.lon_shift or args.markhigh then
Line 456 ⟶ 439:
end
mw.logObject(args, 'args')
▲
▲ (args.markhigh and 'markhigh' or '')
end
if map('x') ~= '' then
Line 480 ⟶ 461:
end
mw.logObject(args, 'args')
local key = frame:preprocess('{{FULLPAGENAME}}')
▲ builder:wikitext('[[Category:Location maps with
end
local mark = args.mark or map('mark')
Line 493 ⟶ 472:
local labelDiv
if args.label and args.position ~= 'none' then
labelDiv = markLabelDiv(args.label, args.label_size or
end
return builder:node(markOuterDiv(x, y, imageDiv, labelDiv))
|