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)
for argindex=1,dotmax do -- build a list of all the numbered coords or lat,lons that have been used
local x=tostring(argindex)
if args['mark-coord'..x] or (args['mark-lat'..x] and args['mark-lon'..x]) then
sgNumbers[x]=x -- add it to the list
end
end
else
for indx in pairs(args) do
if string.match(indx,'dot[%d]+') then table.insert(dotList,indx) end --add the index name for dot1, dot2 etc to dotList
end
table.sort(dotList,morethan)
for indx,dotName in pairs(dotList) do
dotresult=ParseData(args,string.match(dotName,'[%d]+') ) -- using each dot number, assign the settings for each dot to a dotresult item line
table.insert(dotItemTable,dotresult) -- and store that item line within the dotItemTable
end
end  
for arcVal = 65,91 do -- check through args looking for any arcs
local arcLetter=string.char(arcVal)
if args['arc-text'..arcLetter] or args['arc'..arcLetter] then
makeArcText(args,result,arcLetter)
end
end  
local dotdivs=''
local ddots=0
if dotItemTable[1] then
local ddots=(dotItemTable[1].lat or 0)+(dotItemTable[1].lon or 0)
end
local fgroup='F'..tostring(maplist.latbase+maplist.lonbase+ddots )
local FullscreenList={}
local addcomma=''
for i,dotitem in pairs(dotItemTable) do -- working throug each dot item, merge the dot and shape values into a full set of css text
local dotgroup= dotitem.group or "0"  
if dotitem.posType=='mark-line' and dotitem.markDest then --find destination xy values for any mark-lines
for n,v in pairs(dotItemTable) do
if v.code == dotitem.markDest then dotitem.gridx2=v.gridx dotitem.gridy2=v.gridy break end
end
end
local qtype=dotitem.group -- find which shape group each dot has been assigned
--debugmsg('dotgroup='..qtype..', sg='..(sgNumbers[qtype] or 'nil')..' , shapeList='..shapeList[qtype].shape)
if not sgNumbers[qtype] then qtype="0" end --shapeList[dotitem.group] will give access to the shape values for that dot
if highlightNum==dotitem.code and highlightOption==true and shapeList['H'] then
table.insert(result, getshapetable(dotitem,shapeList['H']))
else
table.insert(result, getshapetable(dotitem,shapeList[qtype])) -- Add the actual css instructions for each dot
end
if shapeList[dotgroup] and not string.find((dotitem.param1 or ''),'nomap') then -- only add if not excluded with 'nomap' labelText
local ftext=''
if dotitem.dotTag~=* and not string.match(dotitem.labelText or *,'[%d]') then ftext=stripdivs(dotitem.dotTag or '')..'
' end
if (dotitem.labelText ~= ftext) and dotitem.dotLink =='' then ftext=ftext..' '..stripdivs(dotitem.labelText)..'
' end
if (dotitem.dotLink) and (dotitem.dotLink ~='') then ftext=ftext..dotitem.dotLink..'
' end
if dotitem.imageName then ftext=ftext..'' end
table.insert(FullscreenList,1, makeFullscreenItem (string.gsub(ftext,"[\n]+"," "), dotitem.info,dotitem.lat,dotitem.lon,fgroup,shapeList[dotgroup].shapeColor)..addcomma )
addcomma=', '
end
-- makeFullscreenItem (itemtitle,itemdescription,lat,lon,group,itemcolor)
-- Always add to start of list, to reverse the sequence, and separate with commas except for first item, which is now at the end
end
if args.legendBox then makeLegendBox(result,args) end
if args.minimap or args['mini-locator'] then makeLocatorMap(args,result) end  
-- add tag link and details for fullscreen version
addcomma=''
if (mapframecontent or '[]') ~= '[]' then addcomma=',' end
mapframecontent=getmapframecontent(args,'fullscreen')
local contentstart='[ '..mapframecontent..addcomma..'{ "type": "FeatureCollection", "features": [ ' --extra features after first square bracket
local contentend=' ] } ]'
table.insert(result, '<div>')
table.insert(result, '<div>')
table.insert(result, :extensionTag{ name ='maplink', content=contentstart..table.concat(FullscreenList)..contentend, args={zoom=tostring(maplist.zoom+1),, ='1',
latitude=tostring(maplist.latbase), longitude=tostring(maplist.lonbase), --add invisble 'en-spaces' for tooltip
text='<div title="'..fullscreenlinktext..'">&nbsp;&nbsp;&nbsp;</div>'} } )
table.insert(result,'</div></div>') -- end of maplink -----  
-- add closing div for main map
table.insert(result,'</div>')  
-- collate caption material to go in the outer div class
local autocaption=string.lower(args['auto-caption'] or 'no')
local autoOff=autocaption:match("(%w+)(.*)") -- select the first word in autocaption and see if it is a negativeAnswer)
if args.caption or not negativeAnswer[autoOff] then
table.insert(result,'<div>')
if args.caption then table.insert(result,args.caption) end
end
local columns=tonumber(autoOff:match("[%d]+") or '1')
if columns>1 then columns=round(maplist.width/(columns*17), 0) end -- convert from em to px for historical reasons
--for k in pairs(dotList) do capchk=capchk..(args["dotlink"..k] or '') end  
local capchk=nil
local captionList = {}
for key, value in pairs(dotItemTable) do
-- only add an autocaption line if there is both a dotTag and a dotLink line available and it is not marked as nolist
if value.dotTag and value.dotTag~=* and (not string.find(value.param1 or *,'nolist')) and string.gsub(value.dotLink or *,"%s+","")~=* then
table.insert(captionList, {key = key, value = value})
capchk=true
end
end
if capchk and (not negativeAnswer[autoOff]) then
table.sort(captionList, function (a,b) return lessthan(string.match(a.value.dotTag,'[%w]+'), string.match(b.value.dotTag,'[%w]+')) end)
local myDivision = string.gsub((args.toggletext or toggletext), "%s+", "")
if string.find(autocaption,'collaps') then
table.insert(result,'<hr><div>'..(args.toggletext or toggletext)..'</div>')
if string.find(autocaption,'collapsed') then
table.insert(result,'<div id="mw-customcollapsible-'..myDivision..'">')
else
table.insert(result,'<div id="mw-customcollapsible-'..myDivision..'">')
end
end
if string.find(autocaption, 'columns=') then
columns=string.match(autocaption,'[%d]+',string.find(autocaption, 'columns=') )
end
table.insert(result,'<div>')  
table.sort(dotList,lessthan)
local nval,ngrp='','0'
for k,v in pairs(captionList) do
nval=string.match(v.value.dotTag,'[%w]+') -- find the first alphanumeric item in the dotTag
ngrp=v.value.group or '0'
if v.value.dotLink and v.value.dotLink~=* and nval and nval~=* then
local c1,c2
if nval==args.highlight then
c1,c2=checkColors(shapeList['H'].shapeColor)
else
c1,c2=checkColors(shapeList[ngrp].shapeColor)
end
table.insert(result,'<div>'..nval..'</div> '..v.value.dotLink..'
')
end
end
table.insert(result,'</div>') -- end for caption-content div
if string.find(autocaption,'collaps') then table.insert(result,'</div>') end -- end for toggle
end
if args.caption or not negativeAnswer[autoOff] then table.insert(result,'</div>') end -- end for whole caption
table.insert(result,'</div></div>') -- outer two frames
if args.float == '' or args.float=='centre' then table.insert(result,'</div>') end  
if args['show-new-format'] == 'hints' then -- provide a 'format hint panel' in the 'Preview Box'
local w="<small>Below are some template hints for the 'sga' compressed version, "
w=w..'. It can use these, instead of the more verbose parameter format. '
w=w..'Data is divided between a "ShapeGroup" and the "Dots", so that a single shapeGroup can be used for multiple dots on the map. '
previewMsg(w..'(nb. the "group" value can be the number or an assigned name of a shapeGroup)</small>')  
w='<small>: | dot(n)=group,lat,lon,dotTag | '
w=w..'dotlink=link/tooltip | dotlabel=label,position,dx,dy,param1,info | dotpic=filename
'
w=w.."(nb. param1 options include 'nolink' 'nolist' 'nomap' 'hemisphere-1' 'hemisphere+1', 'noline' - quotes not required, separate with spaces).
"
w=w..'| sga = Shape,Sizepx,Color,Angledeg | sgb= OutlineWidth,Color,Style | sgc=TextSize,Color,Angle,bold italic
'
w=w..'| sgd=TagSizepx,Color,Spacer,Angledeg | sge=LineWidth,Color,Style | sgf=TextSpacingpx,LineHeight%,Outlinepx,backgroundColor
'