Module:MapLocations

From ARK Wiki
Jump to navigation Jump to search
Template-info.png Documentation

Displays a map with multiple markers at given coordinates

Parameters

all are optionally

Parameter default description
map Map The Island.jpg Filename of the map
mapsize 300 mapsize in px
markersize 10 markersize in px
markercolor #f30
markericon Filename of the default-icon
opacity 1 opacity of markers
text is displayed under the map
float where the map floats (left / right)
borderCoordT 7.2 Coords of Top
borderCoordR 92.8 Coords of Right
borderCoordB 92.8 Coords of Bottom
borderCoordL 7.2 Coords of Left

Locations are given as comma-separated-values and have to be in this order (only lat and lon are mandatory) lat,lon,markersize,markercolor,markertooltip,markericon[,markericon2[,markericon3...]]. Leave parameters empty for the default. E.g. write 20,50,,green for a green marker at 20-50 with the default size.

  • Commas are not allowed in the title-text (it breaks the format)
  • An equal-sign has to be written like {{=}}, a vertical bar / pipe has to be written like {{!}}.

Example

{{MapLocations|30,50|20,80,20}}
The Island Topographic Map.jpg
{{MapLocations|40,50|30,80|text=so many spots|80,50,30,yellow,I'm a yellow marker!|opacity=0.7|50,50,5|markercolor=green|mapsize=200|10,10,5}}
The Island Topographic Map.jpg
so many spots

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 = 'The Island Topographic Map.jpg', {t=0,r=100,b=100,l=0}, 300, 10, '#f40','', 1, '', ''

  -- get values from parameters
  if args.map ~= nil then
    map = args.map
    -- if the map is given as just the name, apply the default map-file
    if map == 'The Island' then map = 'The Island Topographic Map.jpg'
    elseif map == 'The Center' then map = 'The Center Topographic Map.jpg'
    elseif map == 'Scorched Earth' then map = 'Scorched Earth Topographic Map.jpg'
    elseif map == 'Ragnarok' then map = 'Ragnarok Topographic Map.jpg'
    elseif map == 'Aberration' then map = 'Aberration Topographic Map.jpg'
    end

    -- use the default borders of the chosen map
    if map == 'The Island Topographic Map.jpg' then
      borderCoords = {t=7.2,r=92.8,b=92.8,l=7.2}
    elseif map == 'The Center Topographic Map.jpg' then
      borderCoords = {t=-2.0,r=100.0,b=100.0,l=0.0}
    elseif map == 'Scorched Earth Topographic Map.jpg' then
      borderCoords = {t=0.0,r=100.0,b=100.0,l=0.0}
    elseif map == 'Ragnarok Topographic Map.jpg' then
      borderCoords = {t=11,r=89,b=89,l=11}
    elseif map == 'Ragnarok Ocean Topographic Map.jpg' then
      borderCoords = {t=-2.6,r=102.4,b=102.4,l=-2.6}
    elseif map == 'Ragnarok Map.png' then
      borderCoords = {t=0.0,r=100.0,b=100.0,l=0.0}
    elseif map == 'Aberration Topographic Map.jpg' then
      borderCoords = {t=7.2,r=92.8,b=92.8,l=7.2}
    end
  end
  if args.mapsize ~= nil then
    mapsize = args.mapsize
  end
  if args.markersize ~= nil and tonumber(args.markersize) ~= nil and tonumber(args.markersize) >= 0 then
    markersize = tonumber(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="mapLocations" 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