Ir para o conteúdo

Módulo:Mapframe

Wikimedia Brasil

A documentação para este módulo pode ser criada em Módulo:Mapframe/doc

local p = {}

local function splitcoord (frame)
	local coord = frame.args.coord or frame.args.coordenadas
	
	local lat,NS_aux,lon,EW_aux = string.match(coord,"(.*)%s*(%a),%s*(.*)%s*(%a)")
	local la1,la2,la3 = string.match(lat,"(%d+)°(%d+)'(%d*%.?%d+)\"")
	local lo1,lo2,lo3 = string.match(lon,"(%d+)°(%d+)'(%d*%.?%d+)\"")
	
	local NS,EW = 1,1
	if NS_aux=="S" then NS = -1 end
	if EW_aux=="W" then EW = -1 end
	
	latitude = NS*(tonumber(la1) + tonumber(la2)/60 + tonumber(la3)/3600)
	longitude = EW*(tonumber(lo1) + tonumber(lo2)/60 + tonumber(lo3)/3600)
	return latitude,longitude
end
	
p.coord_to_dec = function(frame)
	local coord = frame.args.coord or frame.args[1]
	
	local lat,NS_aux,lon,EW_aux = string.match(coord,"(.*)%s*(%a),%s*(.*)%s*(%a)")
	local la1,la2,la3 = string.match(lat,"(%d+)°(%d+)'(%d*%.?%d+)\"")
	local lo1,lo2,lo3 = string.match(lon,"(%d+)°(%d+)'(%d*%.?%d+)\"")
	
	local NS,EW = 1,1
	if NS_aux=="S" then NS = -1 end
	if EW_aux=="W" then EW = -1 end
	
	latitude = NS*(tonumber(la1) + tonumber(la2)/60 + tonumber(la3)/3600)
	longitude = EW*(tonumber(lo1) + tonumber(lo2)/60 + tonumber(lo3)/3600)
	return latitude..','..longitude
end

p.mapframe = function(frame)
	local out = {}
	local tracado = frame.args["traçado"]
	local cor_fundo = frame.args.cor_fundo
	local qid = frame.args.qid
	local titulo = frame.args["título"]
	local descricao = frame.args["descrição"]
	local marcadortipo = frame.args.marcador_tipo
	local marcadortamanho = frame.args.marcador_tamanho
	local marcadorcor = frame.args.marcador_cor
	local latitude, longitude = splitcoord(frame)
	
	local width = frame.args.width or frame.args.tamanho
	local height = frame.args.height or frame.args.tamanho
	local zoom = frame.args.zoom or 14
	local legenda = frame.args.legenda
	local posicao = frame.args["posição"]
	if posicao == "right" or posicao == "direita" or posicao == "d" or posicao == "r" then posicao = "right" end
	if posicao == "left" or posicao == "esquerda" or posicao == "e" or posicao == "l" then posicao = "left" end
	if posicao == "center" or posicao == "centro" or posicao == "c" then posicao = "center" end
	
	local contorno = frame.args.contorno
	local marcador = frame.args.marcador
	
	if not contorno or contorno ~= "não" then
		if tracado then local text_tracado = ", \"stroke-width\": "..tostring(tracado) end
		if cor_fundo then local text_cor_fundo = ", \"properties\":{\"fill\": \""..cor_fundo.."\", \"stroke\": \""..cor_fundo.."\""..text_tracado.."}" end
		if qid then local text_qid = "{\"type\": \"ExternalData\",\"service\": \"geoshape\",\"ids\": \""..qid.."\""..text_cor_fundo.." }" end
		
		out[#out+1] = text_qid
	end
	local out_sub = {}
	
	if not marcador or marcador ~= "não" then
		if titulo then text_title = "\"title\": \""..titulo.."\"" end
		if descricao then text_description = "\"description\": \""..descricao.."\"" end
		if marcadortipo then text_marker_symbol = "\"marker-symbol\": \""..string.lower(marcadortipo).."\"" end
		if marcadortamanho then text_marker_size = "\"marker-size\": \""..marcadortamanho.."\"" end
		if marcadorcor then text_marker_color = "\"marker-color\": \""..marcadorcor.."\"" end
		
		out_sub[#out_sub+1] = "\"properties\": {"..table.concat({text_title, text_description, text_marker_symbol, text_marker_size, text_marker_color}, ", ").."}"
		
		if latitude and longitude then
			out_sub[#out_sub+1] = "\"geometry\": { \"type\": \"Point\", \"coordinates\": ["..longitude..", "..latitude.."]".."}"
		end
		
		if #out_sub > 0 then
			out[#out+1] = "{ \"type\": \"Feature\", "..table.concat(out_sub,", ").."}"
		end
	end
	
	if #out > 0 then
		local map_content = "["..table.concat(out,", ").."]"
		return frame:preprocess("<mapframe width="..width.." height="..height.." zoom="..zoom.." text=\""..legenda.."\" longitude="..longitude.." latitude="..latitude.." align=\""..posicao.."\">"..map_content.."</mapframe>")
	end
end


return p