Jump to content

Module:Australian place map

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 16:07, 4 March 2017. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- This module implements the selection of the location map
-- in [[Template:Infobox Australian place]]
local p = {}

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

local statenames = {
	sa = 'South Australia',
	vic = 'Victoria',
	nsw = 'New South Wales',
	qld = 'Queensland',
	nt = 'Northern Territory',
	wa = 'Western Australia',
	tas = 'Tasmania',
	act = 'Australian Capital Territory',
	jbt = 'Jervis Bay Territory',
	ni = 'Norfolk Island'
}
local mapwidths = {
	sa = 230,
	qld = 190,
	nt = 190,
	wa = 180,
	tas = 210,
	act = 180
}

function p.main(frame)
	local args = frame:getParent().args
	local place_type = (args.type or ''):lower()
	local map_type = args.map_type or 'auto'
	local map_width = 270
	
	local lat_deg = args.latd or args.latitude or ''
	local lon_deg = args.longd or args.longitude or ''
	local lat_min = args.latm or ''
	local lat_sec = args.lats or ''
	local lat_dir = 'S'
	local lon_min = args.longm or ''
	local lon_sec = args.longs or ''
	local lon_dir = 'E'
	lon_deg = tonumber(lon_deg) and math.abs(tonumber(lon_deg)) or ''
	
	local coords = args.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( args.alternative_location_map ) then
		map_type = args.alternative_location_map
	elseif isnotblank( args.force_national_map ) then
		map_type = 'Australia'
	elseif isnotblank( args.use_lga_map ) then
		map_type = 'lga'
	end
	-- Process the value in map_type 
	if map_type:lower() == 'state' or map_type:lower() == 'auto' then
		local state_name = statenames[(args.state or ''):lower()] or ''
		map_type = 'Australia ' .. state_name
		map_width = mapwidths[(args.state or ''):lower()] or 270
	elseif map_type:lower() == 'lga' then
		local state_name = statenames[(args.state or ''):lower()] or ''
		map_type = 'Australia ' .. state_name .. ' ' .. (args.lga or '')
		map_width = mapwidths[(args.state or ''):lower()] or 270
	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:lower() ~= 'nomap' then
		local caption = args.pushpin_map_caption or ''
		
		if caption ~= '' then caption = '<small>' .. caption .. '</small>' end
		
		return frame:expandTemplate{
			title = 'Location map', 
			args = { 
				map_type,
				label = args.name or '',
				relief = args.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 = args.pushpin_label_position or '',
				float = 'center',
				caption = caption,
				border = 'infobox',
				width = map_width,
				alt = args.map_alt or ''
			}
		}
	end
	return ''
end

return p