Módulo:Australian place map

Origem: Wikipédia, a enciclopédia livre.
-- This module implements the selection of the location map
-- in [[Predefinição:Info/Lugar australiano]]
require('Módulo:No globals')
local p = {}

local function isnotblank( s ) return s and s ~= '' end

local statenames = {
	sa = 'Austrália do Sul',
	vic = 'Victoria',
	nsw = 'Nova Gales do Sul',
	qld = 'Queensland',
	nt = 'Território do Norte',
	wa = 'Austrália Ocidental',
	tas = 'Tasmânia',
	act = 'Território da Capital da Austrália',
	jbt = 'Território da baía de Jervis',
	ni = 'Ilha Norfolk'
}
local mapwidths = {
	sa = 230,
	qld = 190,
	nt = 190,
	wa = 180,
	tas = 210,
	act = 180
}

function p.main(frame)
	local largs = frame:getParent().args
	local place_type = (largs.type or ''):lower()
	local map_name = largs.map_type or ''
	local map_type = (largs.map_type or 'auto'):lower()
	local state_abbr = (largs.state or ''):lower()
	local map_width = 270
	
	local lat_deg = largs.latitude or largs.latd or ''
	local lon_deg = largs.longitude or largs.longd or ''
	local lat_min = largs.latm or ''
	local lat_sec = largs.lats or ''
	local lat_dir = 'S'
	local lon_min = largs.longm or ''
	local lon_sec = largs.longs or ''
	local lon_dir = 'E'
	lat_deg = tonumber(lat_deg) and math.abs(tonumber(lat_deg)) or ''
	
	local coords = largs.coordinates or ''
	
	-- Default for LGAs is nomap
	-- Default for everywhere else is auto
	if map_type == '' or map_type == 'auto' then
		if place_type == 'lga' then
			map_type = 'nomap'
		else
			map_type = 'auto'
		end
	end
	-- Apply legacy parameters
	if isnotblank( largs.alternative_location_map ) then
		map_type = largs.alternative_location_map
		map_name = map_type
	elseif isnotblank( largs.force_national_map ) then
		map_type = 'national'
		map_name = 'Austrália'
	elseif isnotblank( largs.use_lga_map ) then
		map_type = 'lga'
	end
	-- Process the value in map_type 
	if map_type == 'state' or map_type == 'auto' or map_type == 'lga' then
		map_name = 'Austrália ' .. (statenames[state_abbr] or '')
		map_width = mapwidths[state_abbr] or 270
		if  map_type == 'lga' then
			map_name = map_name  .. ' ' .. (largs.lga or '')
			map_width = mapwidths[state_abbr] or 270
		end
	elseif map_type == 'national' or map_type == 'austrália' then
		map_name = 'Austrália'
	end
	
	-- Use (lat_deg, lon_deg) first, otherwise use coords
	if (lat_deg ~= '' and lon_deg ~= '') then
		coords = ''
	elseif (coords ~= '') then
		lat_deg, lat_min, lat_sec, lat_dir = '', '', '', ''
		lon_deg, lon_min, lon_sec, lon_dir = '', '', '', ''
	else
		map_type = 'nomap'
	end
	
	-- Finally build the map
	if map_type ~= 'nomap' then
		local caption = largs.pushpin_map_caption or ''
		
		if caption ~= '' then caption = '<small>' .. caption .. '</small>' end
		
		return frame:expandTemplate{
			title = 'Mapa de localização', 
			args = { 
				map_name,
				label = largs.name or '',
				relief = largs.relief or '',
				lat_deg = lat_deg,
				lat_min = lat_min,
				lat_sec = lat_sec,
				lat_dir = lat_dir,
				lon_deg = lon_deg,
				lon_min = lon_min,
				lon_sec = lon_sec,
				lon_dir = lon_dir,
				coordinates = coords,
				marksize = 6,
				position = largs.pushpin_label_position or '',
				float = 'center',
				caption = caption,
				border = 'infobox',
				width = map_width,
				alt = largs.map_alt or ''
			}
		}
	end
	return ''
end

return p