legend.Param= line[6] or ''
local argnum,legendCount,title,1,0
if (legend.Text and legend.Text~='') then
titleHeight=15+(13.4*(select(2, string.gsub(legend.Text,"
", ""))))
end
local legendLine,legendGroup,legendY={},{},{}
while args['legendItem'..argnum] do -- assign legendLine, legendGroup, legendY for each dot
line,legendLine[legendCount] = extractItem(args['legendItem'..argnum] or '')
line=splitItem(line,3)
legendGroup[legendCount]=line[2] or argnum
if shapeList[legendGroup[legendCount]] then
maxWidth=math.max(tonumber(string.match(shapeList[legendGroup[legendCount]].shapeSize or '10','[%d]+')),maxWidth)
else maxWidth=math.max(tonumber(string.match(shapeList['1'].shapeSize or '10','[%d]+')),maxWidth)
end
maxWidth=maxWidth+1
if line[3] then
legendY[legendCount]=tonumber(string.match(line[3],'[%d]+'))
else legendY[legendCount] = 3+maxWidth*(legendCount-1)+titleHeight
-- if (legend.Text and legend.Text~='') then legendY[legendCount]=legendY[legendCount]+15 end
end
legendCount=legendCount+1
argnum=tostring(legendCount)
end
local w,h,r=getsize(legend.Size or '')
local x,y=getsize(legend.Pos or '')
local div=mw.html.create ('div')
div:css('position', 'absolute')
div:css('outline', ' solid'..getColor(legend.Color))
if r~=0 then div:css('-radius',tostring(r).."px") end
div
:css('top', y.."px")
:css('', x.."px")
:css('width', w.."px")
:css('height', h.."px")
:css('line-height','105%')
:css('background-color', getColor(legend.Background) )
:css('color','inherit')
if not string.find(legend.Param,'noshadow') then div:css('box-shadow', ' #33203335') end
div:tag( 'div' )
:css('position', 'absolute')
:css('top','')
:css('', (w/2).."px")
:css('width',(w-8)..'px')
:css('text-align', '')
:css('color', getColor(legend.Color))
:css('transform', 'translateX(-50%)')
:css('font-size','')
:wikitext(legend.Text)
:done
for lct=1,legendCount-1 do
--local t=legendGroup[lct]
local shape=shapeList[legendGroup[lct]] or shapeList['1']
local row={}
row.gridx=3+maxWidth/2
row.gridy=(legendY[lct] or 0) + 5
if shape.shape=='image:' then row.gridy=row.gridy+6 end
row.dx=0 row.dy=0
local legendShape= getshapetable(row,shape)
div:wikitext(legendShape)
:tag( 'div' )
:css('position', 'absolute')
:css('top',(legendY[lct] or 0)..'px')
:css('', (maxWidth+6)..'px')
:css('width', (w-maxWidth-6)..'px')
:css('text-align', '')
:css('line-height','103%')
:css('color', getColor(legend.Color))
:css('font-size','')
:wikitext(legendLine[lct])
:done
end
div:allDone
table.insert(result,tostring(div))
end  
function p._main ( args )
local result={}
local =mw.getCurrentFrame
local dotTable={}
local magVal,scaleVal = args.magnify,''
local origH,origW=maplist.height,maplist.width  
if magVal then --set up the values needed to magnify the top- portion of the map
magVal=tonumber(string.match(magVal or '0',"[%.%-?%d]+")) or 1
if magVal>1 and magVal <=2 then
maplist.height= round(maplist.height/magVal,0)
maplist.width=round(maplist.width/magVal,0)
scaleVal='transform: scale('..magVal..') translateY('..tostring((origH-maplist.height)/2)..'px);'
else magVal=1
end
--debugmsg('magVal='..magVal..', Magnify: H='..maplist.height..', ('..origH..'), W='..maplist.width..', ('..origW..'), scale='..scaleVal)
--debugmsg('top: '..tostring(((origW-maplist.width))/2)..'px;: '..tostring(0-((origW-maplist.width))/2)..'px; (alt top: '..tostring(((origH-maplist.height))/2)..'px;)')
end
-- set up the three nested div boxes (plus an extra if centered) to put the map plus title/caption area, in an appropriate on the page
if args.float=='' or args.float=='centre' then table.insert(result,'<div><div>')
elseif args.float=='' then table.insert(result,'<div>')
else table.insert(result,'<div>')
end
table.insert(result,'<div400")..'px;">')
if args.title then table.insert(result,'<div>'..args.title..'</div>') end
if magVal and magVal >1 and magVal<=2 then
table.insert(result,'<div>')
else
magVal=1
table.insert(result,'<div>')
end  
-- Create the basemap using mapframe
local mapframecontent=getmapframecontent(args,'basemap')
table.insert(result, :extensionTag{ name ='mapframe', content=mapframecontent, args={width=tostring(maplist.width), height=tostring(maplist.height),
zoom=tostring(maplist.zoom), longitude=tostring(maplist.lonbase), latitude=tostring(maplist.latbase), mapstyle=maplist.mapstyle, =true } } )  
--Add coverall box to block the unhelpful links from mapframe - which wouldn't include all the dots. Reinstate some links to osm and wikimedia
table.insert(result,'<div></div>')
--Add replacent hover-links for OpenStreetMap and maps terms and conditions
table.insert(result,'<div>')
table.insert(result,'</div>')
table.insert(result,'<div>')
table.insert(result,'</div>')  
-- Add scale-line
if not args.scalemark or args.scalemark~='0' then
local top=maplist.height-42
local =maplist.width-61-(tonumber(args.scalemark or '1'))
local minipos=string.lower(args.minimap or '') -- scalemark gets pushed if it would be behind the minimap
if minipos~=* and not(string.find(minipos,*) or string.find(minipos,'top') ) then
local offset=tonumber(args.scalemark or '1')-tonumber(args['mini-width'] or '60')
if offset<1 then =maplist.width-61-tonumber(args['mini-width'] or '60') end
end
if maplist.width- >216 then top=top+14 end -- shunt scaleline down if it is beyond the copyright stuff
local scalek,scalem=getScale(maplist.zoom, maplist.latbase, magVal)
local magReduce=''
table.insert(result,"<div style=\"display:inline-block; position: absolute; background-color: #111111")
table.insert(result,"; color:inherit; clip-path:path(nonzero, &#39;M0,8 l0,4 l20,0 l0,-4 l-0.3,0 l0,3.7 l-19.4,0 l0,-3.7 z&#39;) ")
table.insert(result,"; width:") -- path is a 20px20px box, and then rescales
if magVal==1 then
table.insert(result,"; top:"..tostring(top-1).."px")
table.insert(result,"; :"..tostring(+16).."px")
table.insert(result,"; height:; transform:scale("..tostring(2.5)..", "..tostring(1.5)..")")
else -- shrink the scalemark to compensate for magnification
table.insert(result,"; top:"..tostring(top-(magVal*0.28)).."px")
table.insert(result,"; :"..tostring(+(16*(magVal*1.15))).."px")
table.insert(result,"; height:; transform:scale("..tostring(2.5*(1/magVal))..", "..tostring(1.5*(1/magVal))..")")
magReduce= 'scale('..tostring(1/magVal)..')'
end
table.insert(result,"\"></div>")  
table.insert(result,'<div>'..scalek..'
'..scalem..'</div>')
end  
--Set up the shapeList and dotList tables, to provide data to go on the map
local sgNumbers,sgSortable={},{} --s1,s2
sgNumbers["1"]="1"
if args.useFormatStyle and args.useFormatStyle=='shortstyle' then
shapeList=ParseShapeTypes (shapeList,args,"1")
for argindex,argv in pairs(args) do -- build a list of all the numbered sg's that have been used
if string.find(argindex,"sg[a-f,n%d]+") == 1 then -- only look through the sga,sgb, sgc,sgd,sge,sgf and sgn args
local x=string.match(argindex,"[%d]+") -- find its number
if x and not sgNumbers[x] then sgNumbers[x]=x end -- only add if not already found
end
if string.find(argindex,"sg[a-f]H") == 1 and highlightNum then highlightOption=true end
end
for indx,sgnum in pairs(sgNumbers) do table.insert(sgSortable,sgnum) end
table.sort(sgSortable,lessthan) -- put the list in a sortable form
for k,v in pairs(sgSortable) do -- work through the sorted list, parsing each set of sg's in turn, from 1 upwards
shapeList=ParseShapeTypes (shapeList,args,v)
end
if highlightOption==true then shapeList=ParseShapeTypes (shapeList,args,'H') end
end
local dotList,dotresult,dotItemTable,dotGroupList={},{},{},{}
if (not args.useFormatStyle) or args.useFormatStyle=='standardstyle' then
local dotmax=0
for indx in pairs(args) do
if string.match(indx,'mark%-coord[%d]+') or string.match(indx,'lat[%d]+') then
dotmax=math.max(dotmax, tonumber(string.match(indx,"[%d]+")))
end
if (indx=='shapeH') or (indx=='shape-colorH') or (indx=='shape-outlineH') or (indx=='label-colorH') then highlightOption=true end
end
dotItemTable=tradstyleParseShapes(args,dotItemTable,dotmax)