Modul:Koordinaten: Unterschied zwischen den Versionen
Erscheinungsbild
Koordinatenumrechnung Dezimal↔DMS mit deutschem Anzeigeformat (via create-page on MediaWiki MCP Server) |
mapjump-Parameter service=, link=, title= ergänzt; DMS2Decimal-Hilfsfunktion für spätere Vorlagen (via update-page on MediaWiki MCP Server) |
||
| Zeile 9: | Zeile 9: | ||
local sec = math.floor((min_f - min) * 60 * 100 + 0.5) / 100 | local sec = math.floor((min_f - min) * 60 * 100 + 0.5) / 100 | ||
return deg, min, sec | return deg, min, sec | ||
end | |||
-- DMS → Dezimal | |||
function p.dms2dec(frame) | |||
local args = frame.args | |||
local deg = tonumber(args[1]) or 0 | |||
local min = tonumber(args[2]) or 0 | |||
local sec = tonumber(args[3]) or 0 | |||
local dir = args[4] or 'N' | |||
local dec = deg + min / 60 + sec / 3600 | |||
if dir == 'S' or dir == 'W' then dec = -dec end | |||
return string.format('%.6f', dec) | |||
end | end | ||
| Zeile 14: | Zeile 26: | ||
local function fmtSec(sec) | local function fmtSec(sec) | ||
return string.format('%.2f', sec):gsub('%.', ',') | return string.format('%.2f', sec):gsub('%.', ',') | ||
end | |||
-- URL-Encode (nur das Nötigste für Titel) | |||
local function urlEncode(s) | |||
return s:gsub(' ', '+'):gsub('[^%w%+%-%.%_%~]', function(c) | |||
return string.format('%%%02X', string.byte(c)) | |||
end) | |||
end | |||
-- Mapjump-URL aufbauen | |||
local function buildUrl(base, params) | |||
local parts = {} | |||
for k, v in pairs(params) do | |||
if v and v ~= '' then | |||
table.insert(parts, k .. '=' .. v) | |||
end | |||
end | |||
table.sort(parts) | |||
return base .. '?' .. table.concat(parts, '&') | |||
end | end | ||
| Zeile 20: | Zeile 51: | ||
local lat_deg, lat_min, lat_sec, lat_dir | local lat_deg, lat_min, lat_sec, lat_dir | ||
local lon_deg, lon_min, lon_sec, lon_dir | local lon_deg, lon_min, lon_sec, lon_dir | ||
local | local url_params = {} | ||
-- Optionale mapjump-Parameter | |||
local service = args['service'] or args['dienst'] or '' | |||
local link = args['link'] or '' | |||
local title = args['title'] or args['titel'] or '' | |||
if service ~= '' then url_params['service'] = service end | |||
if link ~= '' then url_params['link'] = link end | |||
if title ~= '' then url_params['title'] = urlEncode(title) end | |||
-- DMS-Eingabe erkennen: param 4 = N oder S | -- DMS-Eingabe erkennen: param 4 = N oder S | ||
| Zeile 33: | Zeile 73: | ||
lon_dir = (args[8] == 'W') and 'W' or 'O' | lon_dir = (args[8] == 'W') and 'W' or 'O' | ||
url_params['params'] = string.format('%d_%d_%s_%s_%d_%d_%s_%s', | |||
lat_deg, lat_min, tostring(lat_sec), args[4], | lat_deg, lat_min, tostring(lat_sec), args[4], | ||
lon_deg, lon_min, tostring(lon_sec), args[8] or 'E' | lon_deg, lon_min, tostring(lon_sec), args[8] or 'E') | ||
else | else | ||
local lat = tonumber(args[1]) | local lat = tonumber(args[1]) | ||
| Zeile 48: | Zeile 86: | ||
lon_dir = lon >= 0 and 'O' or 'W' | lon_dir = lon >= 0 and 'O' or 'W' | ||
url_params['lat'] = args[1] | |||
url_params['lon'] = args[2] | |||
end | end | ||
local base_url = 'https://sonicscrewdriver.mbr.mobi/mapjump/' | |||
local url = buildUrl(base_url, url_params) | |||
local display = string.format( | local display = string.format( | ||
Aktuelle Version vom 2. April 2026, 15:04 Uhr
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
-- DMS → Dezimal
function p.dms2dec(frame)
local args = frame.args
local deg = tonumber(args[1]) or 0
local min = tonumber(args[2]) or 0
local sec = tonumber(args[3]) or 0
local dir = args[4] or 'N'
local dec = deg + min / 60 + sec / 3600
if dir == 'S' or dir == 'W' then dec = -dec end
return string.format('%.6f', dec)
end
-- Sekunden mit deutschem Komma, 2 Nachkommastellen
local function fmtSec(sec)
return string.format('%.2f', sec):gsub('%.', ',')
end
-- URL-Encode (nur das Nötigste für Titel)
local function urlEncode(s)
return s:gsub(' ', '+'):gsub('[^%w%+%-%.%_%~]', function(c)
return string.format('%%%02X', string.byte(c))
end)
end
-- Mapjump-URL aufbauen
local function buildUrl(base, params)
local parts = {}
for k, v in pairs(params) do
if v and v ~= '' then
table.insert(parts, k .. '=' .. v)
end
end
table.sort(parts)
return base .. '?' .. table.concat(parts, '&')
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_params = {}
-- Optionale mapjump-Parameter
local service = args['service'] or args['dienst'] or ''
local link = args['link'] or ''
local title = args['title'] or args['titel'] or ''
if service ~= '' then url_params['service'] = service end
if link ~= '' then url_params['link'] = link end
if title ~= '' then url_params['title'] = urlEncode(title) end
-- 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_params['params'] = string.format('%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_params['lat'] = args[1]
url_params['lon'] = args[2]
end
local base_url = 'https://sonicscrewdriver.mbr.mobi/mapjump/'
local url = buildUrl(base_url, url_params)
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