Die Dokumentation für dieses Modul kann unter Modul:Koordinaten/doc erstellt werden
local p = {}
-- Dezimal → Grad/Minuten/Sekunden
local function toDMS(decimal)
local abs_val = math.abs(decimal)
local deg = math.floor(abs_val)
local min_f = (abs_val - deg) * 60
local min = math.floor(min_f)
local sec = math.floor((min_f - min) * 60 * 100 + 0.5) / 100
return deg, min, sec
end
-- Sekunden mit deutschem Komma, 2 Nachkommastellen
local function fmtSec(sec)
return string.format('%.2f', sec):gsub('%.', ',')
end
function p.location(frame)
local args = frame.args
local lat_deg, lat_min, lat_sec, lat_dir
local lon_deg, lon_min, lon_sec, lon_dir
local url
-- DMS-Eingabe erkennen: param 4 = N oder S
if args[4] == 'N' or args[4] == 'S' then
lat_deg = tonumber(args[1]) or 0
lat_min = tonumber(args[2]) or 0
lat_sec = tonumber(args[3]) or 0
lat_dir = args[4]
lon_deg = tonumber(args[5]) or 0
lon_min = tonumber(args[6]) or 0
lon_sec = tonumber(args[7]) or 0
lon_dir = (args[8] == 'W') and 'W' or 'O'
url = string.format(
'https://sonicscrewdriver.mbr.mobi/mapjump/?params=%d_%d_%s_%s_%d_%d_%s_%s',
lat_deg, lat_min, tostring(lat_sec), args[4],
lon_deg, lon_min, tostring(lon_sec), args[8] or 'E'
)
else
local lat = tonumber(args[1])
local lon = tonumber(args[2])
if not lat or not lon then return '' end
lat_deg, lat_min, lat_sec = toDMS(lat)
lon_deg, lon_min, lon_sec = toDMS(lon)
lat_dir = lat >= 0 and 'N' or 'S'
lon_dir = lon >= 0 and 'O' or 'W'
url = string.format(
'https://sonicscrewdriver.mbr.mobi/mapjump/?lat=%s&lon=%s',
args[1], args[2]
)
end
local display = string.format(
'%d\194\176\194\160%d\226\128\178\194\160%s\226\128\179\194\160%s,\194\160%d\194\176\194\160%d\226\128\178\194\160%s\226\128\179\194\160%s',
lat_deg, lat_min, fmtSec(lat_sec), lat_dir,
lon_deg, lon_min, fmtSec(lon_sec), lon_dir
)
return string.format('[%s %s]', url, display)
end
return p