FANDOM


-- <pre>
-- IMPORTANT: This module should be considered UNSTABLE and not be used widely
-- until further testing/bugfixing
--[[----------------------------------------------------------------------------
	Module:CoordinateMap
		Used to display a map given a set of coordinates or page name
 
		Note that this module is INVOKE only. If you're looking for LUA usage,
		you probably want Module:TileMap, which this module utilizes.
 
		For documentation, see Template:CoordinateMap
----------------------------------------------------------------------------]]--
 
-- Constants -------------------------------------------------------------------
-- Map constants, only needs changing if the map is updated
local MAPS = mw.loadData('Module:CoordinateMap/data')
 
-- Metamodules -----------------------------------------------------------------
local Coordinates = require('Module:Coordinates')
local TileMap = require('Module:TileMap')
local yesno = require('Module:Yesno')
 
-- INVOKE function -------------------------------------------------------------
local CoordinateMap = {}
function CoordinateMap.main(frame)
	if not frame or not frame.args then
		error('CoordinateMap.main() couldn\'t find the frame. This is an '..
			'invoke function; if you\'re calling this function in LUA, you '..
			'probably want Module:TileMap instead')
	end
	local rargs = frame.args -- Raw args
	local args = { -- Clean(ish) args
		coords = rargs[1],
		map = string.lower(rargs[2] or ''),
		width = tonumber(rargs.width) or 250,
		height = tonumber(rargs.height) or 250,
		align = string.lower(rargs.align or ''),
		smw = (rargs.smw and rargs.smw ~= '') and rargs.smw or 'false'
	}
	-- Check coords are valid
	if not args.coords then -- no coords passed
		error('CoordinateMap requires either a page name or a set of '..
			' coordinates passed as the first parameter')
	end
	-- Check map is valid
	if not MAPS[args.map] then
		args.map = 'worldmap'
	end
	-- Parse coords
	local coords = Coordinates.create(args.coords, args.map, true)
	if not coords then
		error(string.format('Could not find location "%s". If it is '..
			'coordinates, make sure they are formed correctly. If it is a '..
			'page name, make sure there is a map on the target page with '..
			'smw=yes', args.coords))
	elseif coords.mapid and not MAPS[coords.mapid] then
		error(string.format('Invalid map name "%s" returned. If "%s" is a '..
			'page, ensure it has a valid map and does not have an erroneous '..
			'"Map name" SMW property set', coords.mapid, args.coords))
	end
 
	-- Create TileMap
	local tmap = TileMap.create(
		coords:pixel().x - args.width/2, -- xmin
		coords:pixel().y - args.height/2, -- ymin
		args.width, -- width
		args.height, -- height
		MAPS[coords.mapid] -- map data
	)
	-- Alignment
	if args.align == 'left' then
		tmap.container:addClass('tleft')
	elseif args.align == 'right' then
		tmap.container:addClass('tright')
	elseif args.align == 'center' then
		tmap.container:css('margin','0 auto')
	end
	-- Reticle
	tmap.container:tag('div')
		:addClass('tilemap-overlay')
		:css({
			position = 'absolute',
			border = '2px solid rgba(158,223,251,0.75)',
			['background-color'] = 'rgba(158,223,251,0.25)',
			height = '50px',
			width = '50px',
			margin = '-27px 0 0 -27px',
			top = '50%',
			left = '50%'
		})
	-- Only add SMW data if the map was not retrieved from SMW, and
	-- 'smw' arg is truthy--]]--
	if not coords.fromsmw and yesno(args.smw) then
		tmap.container:tag('div')
			:addClass('tilemap-smw')
			:css('display', 'none')
			:tag('pre')
				:wikitext(string.format(
					'[[Map coordinates::%s,%s]]\n[[Map name::%s]]',
					coords:pixel().x, coords:pixel().y, args.map)
				)
	end
 
	return tmap
end
 
return CoordinateMap

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.