Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:MergedMap

From Wikipedia, the free encyclopedia

require('strict')
local pushpinModule = require ('Module:MergedMapGetPushPin')
local OSMModule = require ('Module:MergedMapGetOSM')
local im = require ('Module:InfoboxImage')
local imf3 = require ('Module:Infobox mapframe/sandbox3')
local infoboxImage = require('Module:InfoboxImage').InfoboxImage
local getArgs = require('Module:Arguments').getArgs

local p = {}

function p.parseCustomWikitext(customWikitext)
	-- infoboxImage will format an image if given wikitext containing an
	-- image, or else pass through the wikitext unmodified
	return infoboxImage({
		args = {
			image = customWikitext
		}
	})
end
function p.ltrim(s)
  return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end

function p.main(frame, args)
	local caption_list = {}
	local args = getArgs(frame)
	
	
	if args.useWikidata == nil then
		args.useWikidata = true
	end
	local maps = {}
	local mapNamesList = {}
	local queryString
	if args['mapQuery'] then
		queryString = args['mapQuery']
	elseif args[1] then
		queryString = args[1]
	end
	if queryString then
			queryString = p.ltrim (queryString) 
			for mapname in string.gmatch(queryString, '[^#]+') do
				if mapname == "OSM" then
					if args['mapframe-switcher'] == "zooms" then
						local OSMCustomText 
						if args['mapframe-zoom'] then 
							OSMCustomText = p.parseCustomWikitext('{{Infobox mapframe|id= ' .. args['mapframeId'] ..  ' |zoom = ' .. args['mapframe-zoom'] .. ' }}')
						else 
							OSMCustomText = p.parseCustomWikitext('{{Infobox mapframe|id= ' .. args['mapframeId'] ..  '}}')
						end
						OSMCustomText = frame:preprocess(OSMCustomText)
						maps[#maps + 1] =   '<div><div>OSM</div>' ..OSMCustomText .. '</div>' 
						mapNamesList[#mapNamesList + 1] = 'Show OpenStreetMap'

						local OSMCustomTextZoomIn = p.parseCustomWikitext('{{Infobox mapframe|id= ' .. args['mapframeId'] ..  '|zoom = 13}}')
						OSMCustomTextZoomIn = frame:preprocess(OSMCustomTextZoomIn)
						maps[#maps + 1] =  '<div><div>OSM</div>' .. OSMCustomTextZoomIn .. '</div>' 
						mapNamesList[#mapNamesList + 1] = 'Show OpenStreetMap in Zoom in' 

						local OSMCustomTextZoomOut = p.parseCustomWikitext('{{Infobox mapframe|id= ' .. args['mapframeId'] ..  '|zoom = 1}}')
						OSMCustomTextZoomOut = frame:preprocess(OSMCustomTextZoomOut)
						maps[#maps + 1] =  '<div><div>OSM</div>' .. OSMCustomTextZoomOut .. '</div>' 
						mapNamesList[#mapNamesList + 1] = 'Show OpenStreetMap in Zoom out' 
					else
						local OSMArgs = args
						--OSMArgs['mapframe-shape'] = 'yes'
						--frame.args['mapframe-wikidata'] = 'yes'
						--frame.args['mapframe-caption'] = args['mapframe-caption']
						for k,v in pairs(args) do frame.args[k] = v end
						maps[#maps + 1] = '<div><div>OSM</div>' .. OSMModule.main(frame, args) .. '</div>' 
						local count = 0
						for mapname in string.gmatch(queryString, '[^#]+') 
							do count = count + 1 end
						if count == 1 then
							if not args['mapframe-caption'] then
								mapNamesList[#mapNamesList + 1] = 'OpenStreetMap' 
							end 
						else
							mapNamesList[#mapNamesList + 1] = 'Show OpenStreetMap' 
						end
					end
				elseif string.match(mapname, "OSM%d") then
					local OSMCustomText = args[mapname]
					maps[#maps + 1] = '<div>' ..OSMCustomText .. '</div>' 
					local OSMNumeber = string.match(mapname, "%d")
					mapNamesList[#mapNamesList + 1] = args['OSM' .. OSMNumeber .. 'Caption'] or  mapname
				elseif string.match(mapname, "File%d") then
					local FileCustomText = args[mapname]
					maps[#maps + 1] = FileCustomText
					local FileNumeber = string.match(mapname, "%d")
					mapNamesList[#mapNamesList + 1] = args['File' .. FileNumeber .. 'Caption'] or  mapname
				elseif string.match(mapname, "customMap%d") then 
					local customMapText = args[mapname]
					
					local ImageURL = args[mapname]
					local imageArgs = {}
					imageArgs['image'] = ImageURL
					frame.args['image'] = ImageURL
					frame.args['maxsize'] = 270
					maps[#maps + 1] = '<div>' .. im.InfoboxImage (frame) .. '</div>'
					local CustomNumeber = string.match(mapname, "%d")
					local myString = 'Show satellite map'
					if tonumber(CustomNumeber) > 1 then
						myString = myString .. CustomNumeber
					end
					mapNamesList[#mapNamesList + 1] = args['customMap' .. CustomNumeber .. 'Caption'] or myString
				else
					
					local pushpinArgs = {}
					local pushpinMapName = mw.ustring.gsub(mapname, '^%s*(.-)%s*$', '%1')
		
					pushpinArgs[1] =  mapname

					for k,v in pairs(args) do pushpinArgs[k] = v end
					
					
					frame.args = pushpinArgs
					maps[#maps + 1] = '<div style= "text-align: left;">' .. pushpinModule.main(frame, args) .. '</div>'
					mapNamesList[#mapNamesList + 1] = 'Show in ' .. mapname
				end
			end
				
	end

	local root = mw.html.create('div'):addClass('switcher-container')
	
	for i =1, #maps do
			local span = root
				:tag('div')
					:wikitext(maps[i])
						:tag('span')
						:addClass('switcher-label')
						:wikitext(mapNamesList[i])
						:css('display', 'none')
			if i == 1 then
					span:attr('data-switcher-default', '')
			end
	end
	return '<div class="center"><div style = "width: 270px;">' ..  tostring(root) .. '</div></div>'
	
end
return p