Модуль:Coord

Материал из Verum
Версия от 04:45, 12 марта 2023; Сабатэй (обсуждение | вклад) (оформление)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)
Перейти к навигации Перейти к поиску

Для документации этого модуля может быть создана страница Модуль:Coord/doc

local p = {}

function p.main( frame )
	local coord_line = frame.args['coord'] or ''		-- coord = "1/2/3.4/N/4/5/65,3/E"
	local scale		= frame.args['scale'] or 30000	-- scale = ширина (высота экрана) отображаемой местности в метрах
	local globe		= frame.args['globe'] or 'earth'	-- globe = небесное тело
	local type		= frame.args['type'] or 'landmark'	-- type =
	local service	= frame.args['service'] or ''		-- service = "G/Я/B/E/N/Э"
	local format	= frame.args['format'] or ''		-- format = "", "tech180", "tech360"
	local name		= frame.args['name'] or ''			-- name = название объекта

	local zoom   = 0 -- шкала увеличения, считается из scale
	local result = ""

	local coord = { ["lat"] = 0, ["lon"] = 0, ["lat_mod"] = 1, ["lat_text"] = "с. ш.", ["lon_mod"] = 1, ["lon_text"] = "в. д." }

	if coord_line:find("S") ~= nil then
		coord["lat_mod"] = -1
		coord["lat_text"] = "ю. ш."
	end

	if coord_line:find("W") ~= nil then
		coord["lon_mod"] = -1
	end

	coord_line = coord_line:gsub(",", ".")
	coord_line = coord_line:gsub("/[NSEW]", "")

	scale = tonumber(scale)
	if scale == nil then
		scale = 30000
	end

	i = 1;
	t = {}
	for value in string.gmatch(coord_line, "[^/]+") do
		t[i] = tonumber(value);
		i = i + 1;
	end

	if t[6] ~= nil then
		coord["lat"] = t[1] + t[2]/60 + t[3]/3600
		coord["lon"] = t[4] + t[5]/60 + t[6]/3600
	elseif t[4] ~= nil then
		coord["lat"] = t[1] + t[2]/60
		coord["lon"] = t[3] + t[4]/60
	elseif t[2] ~= nil then
		coord["lat"] = t[1]
		coord["lon"] = t[2]
	end

	coord["lat"] = string.format("%.4f", coord["lat"]) * coord["lat_mod"]
	coord["lon"] = string.format("%.4f", coord["lon"]) * coord["lon_mod"]

	if coord["lat"] > 90 or coord["lat"] < -90 or coord["lon"] >= 360 or coord["lon"] <= -360 then
		return "[[К: Ошибки: Coord: исправить: координаты]]"
	end

	coord["lon180"] = coord["lon"];
	if coord["lon"] > 180 then
		coord["lon180"] = coord["lon"] - 360
	elseif coord["lon"] <= -180 then
		coord["lon180"] = coord["lon"] + 360
	end

	if coord["lat"] < 0 then
		coord["lat_text"] = "ю. ш."
	end

	coord["lon360"] = coord["lon"]
	if coord["lon"] < 0 then
		coord["lon360"] = coord["lon"] + 360
	end

	if (format == "tech180") then
		return coord["lat"] .. "/" .. coord["lon180"]
	elseif (format == "tech360") then
		return coord["lat"] .. "/" .. coord["lon360"]
	end

	if globe:find("[А-я]") then -- перевод
		local globe_list_translate = {
			["Ариэль"]	= "Ariel",
			["Бенну"]	= "Bennu",
			["Венера"]	= "Venus",
			["Веста"]	= "Vesta",
			["Ганимед"]	= "Ganymede",
			["Гиперион"]= "Hyperion",
			["Деймос"]	= "Deimos",
			["Диона"]	= "Dione",
			["Европа"]	= "Europa",
			["Земля"]	= "Earth",
			["Ио"]		= "Io",
			["Каллисто"]= "Callisto",
			["Луна"]	= "Moon",
			["Марс"]	= "Mars",
			["Меркурий"]= "Mercury",
			["Мимас"]	= "Mimas",
			["Миранда"]	= "Miranda",
			["Оберон"]	= "Oberon",
			["Плутон"]	= "Pluto",
			["Рея"]		= "Rhea",
			["Рюгу"]	= "Ryugu",
			["Тефия"]	= "Tethys",
			["Титан"]	= "Titan",
			["Титания"]	= "Titania",
			["Тритон"]	= "Triton",
			["Умбриэль"]= "Umbriel",
			["Феба"]	= "Phoebe",
			["Фобос"]	= "Phobos",
			["Харон"]	= "Charon",
			["Церера"]	= "Ceres",
			["Энцелад"]	= "Enceladus",
			["Юпитер"]	= "Jupiter",
			["Япет"]	= "Iapetus"
			}

		globe = globe_list_translate[mw.ustring.gsub(globe, " %(.+", "")]

		if globe == nil then
			globe = "blank"
			result = result .. "[[К: Ошибки: Coord: исправить: globe]]"
		end
	end

	local globe_list_geohack = "/Ariel/Callisto/Ceres/Charon/Deimos/Dione/Earth/Enceladus/Europa/Ganymede/Hyperion/Iapetus/Io/Jupiter/Mars/Mercury/Mimas/Miranda/Moon/Oberon/Phobos/Phoebe/Pluto/Rhea/Tethys/Titan/Titania/Triton/Umbriel/Venus/Vesta/"

	if (globe_list_geohack:find('/' .. globe .. '/')) then
		result = '<span class="plainlinks nourlexpansion">[//geohack.toolforge.org/geohack.php?language=ru'
			.. '&pagename=' .. mw.ustring.gsub(name, " ", "_")
			.. '&params=' .. coord["lat"] .. '_N_' .. coord["lon360"] .. "_E"
			.. '_scale:' .. scale
			.. '_globe:' .. globe
			.. '_type:' .. type

		result = result .. " " .. tostring(coord["lat"]):gsub("[%.]", ","):gsub("[%-]", "") .. "° " .. coord["lat_text"] .. " " .. tostring(coord["lon360"]):gsub("[%.]", ",") .. "° " .. coord["lon_text"] .. "]</span>"
	else -- нет карты на Geohack, добавить локальный инструмент
		result = result .. tostring(coord["lat"]):gsub("[%.]", ","):gsub("[%-]", "") .. "° " .. coord["lat_text"] .. " " .. tostring(coord["lon360"]):gsub("[%.]", ",") .. "° " .. coord["lon_text"]
	end

	if service ~= "" then

		result = result .. ":<small>"

		if globe == "Earth" then
			for value in string.gmatch(service, "[^/]+") do
				if value == 'G' then
					result = result .. ' <span class="plainlinks noprint" title="Гибридная карта Гугла">[//maps.google.com/maps?'
						.. 'll=' ..  coord["lat"] .. ',' .. coord["lon180"]
						.. '&q=' ..  coord["lat"] .. ',' .. coord["lon180"]
						.. '&spn=' .. (scale / 1000000) .. ',' .. (scale / 1000000)
						.. '&t=h&hl=ru G]</span>'
				elseif value == 'Я' then
					result = result .. ' <span class="plainlinks noprint" title="Гибридная карта Яндекса">[//yandex.ru/maps/'
						.. '?ll=' .. coord["lon180"] .. ',' .. coord["lat"]
						.. '&pt=' .. coord["lon180"] .. ',' .. coord["lat"]
						.. '&spn=' .. (scale / 1000000) .. ',' .. (scale / 1000000)
						.. '&l=sat,skl Я]</span>'
				elseif value == 'E' then
					result = result .. ' <span class="plainlinks noprint" title="Снимки ESRI">[http://retromap.ru/04200913_z15_'
						.. coord["lat"] .. ',' .. coord["lon360"] .. ' E]</span>'
				elseif value == 'B' then
					result = result .. ' <span class="plainlinks noprint" title="Гибридная карта Bing">[//www.bing.com/maps?cp='
						.. coord["lat"] .. "~" .. coord["lon360"]
						.. '&style=h&v=2&sV=2&lvl=15 B]</span>'
				elseif value == 'N' then
					result = result .. ' <span class="plainlinks noprint data-checker" style="display:none" title="На карте">[//nakarte.me/#m=14/'
						.. coord["lat"] .. "/" .. coord["lon360"]
						.. '&l=T/N/J/F/K N]</span>'
				elseif value == 'Э' then
					result = result .. ' <span class="plainlinks noprint data-checker" style="display:none" title="Исторические карты на сайте «Это место»">[http://www.etomesto.ru/?y='
						.. coord["lat"] .. "&x=" .. coord["lon360"] .. ' Э]</span>'
				end
			end
		else
			for value in string.gmatch(service, "[^/]+") do

				if value == 'G' then
					globe_list_google = "/Callisto/Ceres/Charon/Dione/Earth/Enceladus/Europa/Ganymede/Iapetus/Io/Mars/Mercury/Mimas/Moon/Pluto/Rhea/Tethys/Titan/Venus/Vesta/"

					if (globe_list_google:find('/' .. globe .. '/')) then
						result = result .. ' <span class="plainlinks noprint" title="Снимки Google">[//www.google.com/maps/space/' .. globe:lower() .. '/@'
									.. coord["lat"] .. ',' .. coord["lon360"]
									.. ',' .. scale .. 'm G]</span>'

						if globe == "Mars" or globe == 'Moon' then
							if scale < 100000 then zoom = 9
							elseif scale < 1200000 then zoom = 8
							elseif scale < 2300000 then zoom = 7
							elseif scale < 3400000 then zoom = 6
							elseif scale < 4500000 then zoom = 5
							elseif scale < 5600000 then zoom = 4
							elseif scale < 6700000 then zoom = 3
							else zoom = 2
							end

							result = result .. ' <span class="plainlinks noprint" title="Снимки Google">[//www.google.com/' .. globe:lower()
								.. '/#lat=' ..  coord["lat"] .. '&lon=' .. coord["lon360"]
								.. '&zoom=' ..  zoom
								.. ' G3]</span>'
						end
					end
				elseif value == 'A' then

					if (globe == 'Mars') then
						result = result .. ' <span class="plainlinks noprint" title="Applied Coherent Technology">[//mars.quickmap.io/?extent='
						.. coord["lon360"] .. ',' .. (coord["lat"]-2) .. ',' .. coord["lon360"] .. ',' ..  (coord["lat"]+2)
						.. '&showGraticule=true A]</span>'
					elseif (globe == 'Mercury') then
						result = result .. ' <span class="plainlinks noprint" title="Applied Coherent Technology">[//mercury.quickmap.io/?extent='
						.. coord["lon360"] .. ',' .. (coord["lat"]-8) .. ',' .. coord["lon360"] .. ',' ..  (coord["lat"]+8)
						.. '&showGraticule=true A]</span>'
					elseif (globe == 'Moon') then
						result = result .. ' <span class="plainlinks noprint" title="Applied Coherent Technology">[//quickmap.lroc.asu.edu/?extent='
						.. coord["lon360"] .. ',' .. (coord["lat"]-8) .. ',' .. coord["lon360"] .. ',' ..  (coord["lat"]+8)
						.. '&showGraticule=true&proj=16 A]</span>'
					end

				elseif value == 'T' then
					if (globe == 'Mars') then -- планеты
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/mars/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=5&p=urn:ogc:def:crs:EPSG::104905 T]</span>'
					elseif (globe == 'Mercury') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/mercury/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=6&p=urn:ogc:def:crs:IAU2000::19900 T]</span>'
					elseif (globe == 'Venus') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/venus/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=5&p=urn:ogc:def:crs:IAU2000::29900 T]</span>'
					elseif (globe == 'Bennu') then -- иное
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/bennu/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=4&p=urn:ogc:def:crs:trek::bennu T]</span>'
					elseif (globe == 'Ceres') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[trek.nasa.gov/ceres/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=3&p=urn:ogc:def:crs:trek::ceres T]</span>'
					elseif (globe == 'Dione') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[https://trek.nasa.gov/dione/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=3&p=urn:ogc:def:crs:IAU2000::60400 T]</span>'
					elseif (globe == 'Enceladus') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/enceladus/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=4&p=urn:ogc:def:crs:::104929 T]</span>'
					elseif (globe == 'Europa') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/europa/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=3&p=urn:ogc:def:crs:IAU2000::50200 T]</span>'
					elseif (globe == 'Iapetus') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/iapetus/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=3&p=urn:ogc:def:crs:::60800 T]</span>'
					elseif (globe == 'Mimas') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/mimas/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=3&p=urn:ogc:def:crs:IAU2000::60100 T]</span>'
					elseif (globe == 'Moon') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/moon/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=5&p=urn:ogc:def:crs:EPSG::104903 T]</span>'
					elseif (globe == 'Phoebe') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/phoebe/ T]</span>'
					elseif (globe == 'Rhea') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/rhea/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=4&p=urn:ogc:def:crs:IAU2000::60500 T]</span>'
					elseif (globe == 'Ryugu') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/ryugu/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=2&p=urn:ogc:def:crs:trek::ryugu T]</span>'
					elseif (globe == 'Tethys') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/tethys/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=3&p=urn:ogc:def:crs:::60300 T]</span>'
					elseif (globe == 'Titan') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/titan/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=3&p=urn:ogc:def:crs:IAU2000::60600 T]</span>'
					elseif (globe == 'Vesta') then
						result = result .. ' <span class="plainlinks noprint" title="NASA Trek">[//trek.nasa.gov/venus/#v=0.1&x='
						.. coord["lon180"] .. '&y=' .. coord["lat"] .. '&z=5&p=urn:ogc:def:crs:IAU2000::29900 T]</span>'
					end
				end
			end
		end

		result = result .. "</small>"

	end

	return result
end

return p