コンテンツにスキップ

モジュール:地図/高規格幹線道路

モジュールの解説[作成]
local root=require("Module:地図/高規格幹線道路/data")
local head={}
for k,v in ipairs({string.byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",1,-1)}) do
	head[v]=k-1
end
local tail={}
-- "*"が含まれることや"="が末尾以外に現れることからBase64ではない。何かしらの座標を符号化したものだろうが...
for k,v in ipairs({string.byte("==9xsy+===4ldYem5=8kUNIOVn/wcMEAFPfzvbLD=BJZt3jTHCGQg0.rXSKRWo*=7qiahp6===^2u1-==",1,-1)}) do
	if v~=string.byte("=") then
		tail[v]={(k-1)%9-4,math.floor((k-1)/9)-4}
	end
end
local function decodeHead(b,index)
	return head[b[index]]+64*(head[b[index+1]]+64*head[b[index+2]])
end
local function decode(s)
	local b={s:byte(1,-1)}
	local p={decodeHead(b,1),decodeHead(b,4)}
	local list={}
	table.insert(list,{p[1]*360/65536,p[2]*360*2/3/65536})
	for k,v in ipairs(b) do
		if k>=7 then
			local d=tail[v]
			p={p[1]+d[1],p[2]+d[2]}
			table.insert(list,{p[1]*360/65536,p[2]*360*2/3/65536})
		end
	end
	return list
end
return function(projection)
	local result={}
	for _,gp in ipairs(root) do
		for _,rt in ipairs(gp[2]) do
			table.insert(result,{
				getImcomplete=function()
					return rt[1]
				end,
				getType=function()
					return rt[2]
				end,
				getName=function(level)
					return level==1 and gp[1] or rt[3]
				end,
				getPath=function()
					local ss=""
					for _,line in ipairs(rt[4]) do
						local ps=projection.convertMulti(true,decode(line[1]))
						if #ps>=2 then
							local s=""
							for k,v in ipairs(ps) do
								s=s..string.format("%s%.1f %.1f",k==1 and "M" or "L",v[1],v[2])
							end
							ss=ss..s
						end
					end
					return ss
				end,
				getPointList=function()
					local list={}
					for _,line in ipairs(rt[4]) do
						local ps=decode(line[1])
						if #line==2 then
							for _,q in ipairs(line[2]) do
								table.insert(list,{q[2],q[3],projection.convert(ps[q[1]+1])})
							end
						end
					end
					return list
				end
			})
		end
	end
	return result
end