Jump to content

Module:Geonotice map

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Legoktm (talk | contribs) at 01:47, 14 August 2022 (new module). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local countries = {
	GB = "Q145"
}

local p = {}

function p.main()
	local data = mw.text.jsonDecode(mw.title.new("Wikipedia:Geonotice/list.json"):getContent())
	local geojson = {}
	for name, info in pairs(data) do
		local properties = {
			title = name,
			description = info.text .. "<br>(Start: " .. info.begin .. ", end: " .. info["end"] .. ")"
		}
		local feature
		if info.country ~= nil then
			feature = {
				type = "ExternalData",
				service = "geoshape",
				ids = countries[info.country],
				properties = properties
			}
		else
			feature = {
				type = "Feature",
				properties = properties,
				geometry = {
					type = "Polygon",
					coordinates = { {
						{ info.corners[1][2], info.corners[1][1] },
						{ info.corners[2][2], info.corners[1][1] },
						{ info.corners[2][2], info.corners[2][1] },
						{ info.corners[1][2], info.corners[2][1] },
						{ info.corners[1][2], info.corners[1][1] }
					} }
				}
			}
		end
		table.insert(geojson, feature)
	end
	return '<mapframe width="full" height="500">' .. mw.text.jsonEncode(geojson) .. '</mapframe>'
end

return p