FANDOM


local p = {}
function p.maplocations( f )
  local args = f:getParent().args
  -- set default values (borderCoords are for top, right, bottom, left)
  local map, borderCoords, mapsize, markersize, markercolor, markericon, opacity, text, float = 'Map The Island.jpg', {t=7.2,r=92.8,b=92.8,l=7.2}, 300, 10, '#f40','', 1, '', ''
 
  -- get values from parameters
  if args.map ~= nil then
    map = args.map
    -- if map is the center, use its default borders
    if map == 'The Center Map.jpg' then
      borderCoords = {t=-2.0,r=100.0,b=100.0,l=0.0}
    end
    if map == 'Scorched Earth Map.jpg' then
      borderCoords = {t=0.0,r=100.0,b=100.0,l=0.0}
    end
  end
  if args.mapsize ~= nil then
    mapsize = args.mapsize
  end
  if args.markersize ~= nil then
    markersize = args.markersize
  end
  if args.markercolor ~= nil then
    markercolor = args.markercolor
  end
  if args.markericon ~= nil then
    markericon = args.markericon
  end
  if args.opacity ~= nil then
    opacity = args.opacity
  end
  if args.text ~= nil then
    text = args.text
  end
  if args.float ~= nil then
    float = args.float
  end
  if args.borderCoordT ~= nil then
    borderCoords.t = args.borderCoordT
  end
  if args.borderCoordR ~= nil then
    borderCoords.r = args.borderCoordR
  end
  if args.borderCoordB ~= nil then
    borderCoords.b = args.borderCoordB
  end
  if args.borderCoordL ~= nil then
    borderCoords.l = args.borderCoordL
  end
 
  -- variables for a single marker: lat, lon, ms (markersize), mc (markercolor), mt (markertext/title/tooltip), mis (markericons)
  local locations, lat, lon, ms, mc, mt, mis = {}, 0, 0, 0, '','', {}
  for _,l in ipairs(args) do
    ms = markersize
    mc = markercolor
    mis = {}
    mis[1] = markericon
    local parts,i = {},0
    for part in string.gmatch(l..',', "([^,]*),") do
      table.insert(parts,part:match "^%s*(.-)%s*$")
    end
 
    if #parts > 1 then
      lat = parts[1]
      lon = parts[2]
      mt = 'lat '..lat..', lon '..lon
      if #parts > 2 and string.len(parts[3])>0 then
        ms = parts[3]
      end
      if #parts > 3 and string.len(parts[4])>0 then
        mc = parts[4]
      end
      if #parts > 4 and string.len(parts[5])>0 then
        mt = parts[5]..'
'..mt
      end
      i=5
      while #parts > i do
        mis[i-4] = parts[i+1]
        i = i + 1
      end
      if #mis > 0 and string.len(mis[1]) > 0 then
        table.insert(locations,'<div style="position:absolute;line-height:0;left:'.. 100*((lon-borderCoords.l)/(borderCoords.r-borderCoords.l) - ms/(2*mapsize)) ..'%;top:'.. 100*((lat-borderCoords.t)/(borderCoords.b-borderCoords.t) - ms/(2*mapsize)) ..'%;padding:0;opacity:'..opacity..'" title="'..mt..'"><div style="position:absolute">[[File:'..table.concat(mis,'|'..ms..'px]]</div><div style="position:absolute">[[File:')..'|'..ms..'px]]</div></div>')
      else
        table.insert(locations,'<div style="position:absolute;line-height:0;left:'.. 100*((lon-borderCoords.l)/(borderCoords.r-borderCoords.l) - ms/(2*mapsize)) ..'%;top:'.. 100*((lat-borderCoords.t)/(borderCoords.b-borderCoords.t) - ms/(2*mapsize)) ..'%;padding:0;width:'..ms..'px;height:'..ms..'px;border-radius:50%;background-color:'..mc..';border:1px solid black;opacity:'..opacity..'" title="'..mt..'"></div>')
      end
    end
  end
  local subtitle = ''
  if text ~= '' then
    subtitle = '\n|-\n| align="middle" | '..text
  end
  return '{| class="wikitable" style="float:'..float..'"\n|-\n|<div class="noviewer" style="position: relative;width:'..mapsize..'px;height:'..mapsize..'px">'..table.concat(locations)..'[[File:'..map..'|'..mapsize..'px]]</div>'..subtitle..'\n|}'
end
return p