Modul:Koordinaten: Unterschied zwischen den Versionen

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 url
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 = string.format(
url_params['params'] = string.format('%d_%d_%s_%s_%d_%d_%s_%s',
'https://sonicscrewdriver.mbr.mobi/mapjump/?params=%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 = string.format(
url_params['lat'] = args[1]
'https://sonicscrewdriver.mbr.mobi/mapjump/?lat=%s&lon=%s',
url_params['lon'] = args[2]
args[1], 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(