Modul:Karte/Work: Unterschied zwischen den Versionen
Aus FürthWiki
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 25: | Zeile 25: | ||
local minimum_one_geocode_ok = false | local minimum_one_geocode_ok = false | ||
if not com.isTrue(args["Ehemals"]) then | if not com.isTrue(args["Ehemals"]) then | ||
local | -- locationlist und location zusammenführen | ||
local locations_merged = str.splitAndStrip(args["locationlist"] or "", ";") | |||
if args["location"] ~= nil then | if args["location"] ~= nil then | ||
table.insert( | table.insert(locations_merged, args["location"] .. | ||
"~" .. (args["popuptitle"] or "") .. | |||
"~" .. (args["popuptext"] or "")) | |||
end | end | ||
for _, l in ipairs( | -- alle locations durchiterieren und für jedes ein subobject erstellen | ||
for _, l in ipairs(locations_merged) do | |||
local subobject_entry = {} | local subobject_entry = {} | ||
subobject_entry["Geolokation"] = | -- Aufteilung location ~ popuptitle ~ popuptext | ||
l = str.split2(l, "~") | |||
local location = str.strip(l[1] or "") | |||
local popuptitle = str.strip(l[2] or "") | |||
local popuptext = str.strip(l[3] or "") | |||
-- location geocode | |||
if location ~= "" then | |||
subobject_entry["Geolokation"] = location | |||
local geocode = frame:callParserFunction("#geocode", location) | |||
if geocode ~= "Geocoding failed" then | |||
subobject_entry["Geokoordinate"] = geocode | |||
minimum_one_geocode_ok = true | |||
end | |||
end | end | ||
-- popuptitle und popuptext ablegen | |||
if popuptitle ~= "" then | |||
subobject_entry["popuptitle"] = popuptitle | |||
end | |||
if popuptext ~= "" then | |||
subobject_entry["popuptext"] = popuptext | |||
end | |||
-- subobject in Liste aufnehmen | |||
table.insert(subobjects, subobject_entry) | table.insert(subobjects, subobject_entry) | ||
end | end | ||
| Zeile 60: | Zeile 80: | ||
-- bisherige Vorlagen-Karte | -- bisherige Vorlagen-Karte | ||
t = frame:expandTemplate{title = "Karte/Legacy", args = args} | t = t .. frame:expandTemplate{title = "Karte/Legacy", args = args} | ||
mw.logObject(t, "t") | mw.logObject(t, "t") | ||
Version vom 9. Dezember 2025, 16:30 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Karte/Work/Doku erstellt werden
p = {}
local com = require("Modul:Common")
local str = require("Modul:String")
local wik = require("Modul:Wiki")
function p.Karte(frame)
-- nur die benötigten Argumente übernehmen
local args = {
"lat", "lon", "location", "locationlist", "geojson", "geocode",
"zoom", "popuptitle", "popuptext",
"box", "headline", "width", "height",
"noattr", "form"}
args = wik.getArgs(frame.args, args)
return p.karte(frame, args)
end
function p.karte(frame, args)
mw.log("karte(frame, args)")
mw.logObject(args, "args")
local t = ""
-- geocode location and locationlist
local subobjects = {}
local minimum_one_geocode_ok = false
if not com.isTrue(args["Ehemals"]) then
-- locationlist und location zusammenführen
local locations_merged = str.splitAndStrip(args["locationlist"] or "", ";")
if args["location"] ~= nil then
table.insert(locations_merged, args["location"] ..
"~" .. (args["popuptitle"] or "") ..
"~" .. (args["popuptext"] or ""))
end
-- alle locations durchiterieren und für jedes ein subobject erstellen
for _, l in ipairs(locations_merged) do
local subobject_entry = {}
-- Aufteilung location ~ popuptitle ~ popuptext
l = str.split2(l, "~")
local location = str.strip(l[1] or "")
local popuptitle = str.strip(l[2] or "")
local popuptext = str.strip(l[3] or "")
-- location geocode
if location ~= "" then
subobject_entry["Geolokation"] = location
local geocode = frame:callParserFunction("#geocode", location)
if geocode ~= "Geocoding failed" then
subobject_entry["Geokoordinate"] = geocode
minimum_one_geocode_ok = true
end
end
-- popuptitle und popuptext ablegen
if popuptitle ~= "" then
subobject_entry["popuptitle"] = popuptitle
end
if popuptext ~= "" then
subobject_entry["popuptext"] = popuptext
end
-- subobject in Liste aufnehmen
table.insert(subobjects, subobject_entry)
end
end
-- geocode lon/lat
if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and args["lat"] ~= nil and args["lon"] ~= nil then
local geocode = frame:callParserFunction("#geocode", args["lat"] .. "," .. args["lon"])
if geocode ~= "Geocoding failed" then
local subobject_entry = {}
subobject_entry["Geokoordinate"] = geocode
one_geocode_ok = true
table.insert(subobjects, subobject_entry)
end
end
mw.logObject(subobjects, "subobjects")
-- subobjects setzen
for _, s in ipairs(subobjects) do
s["SubObjektTyp"] = "Geo"
mw.smw.subobject(s, s["Geolokation"] or s["Geokoordinate"])
end
-- bisherige Vorlagen-Karte
t = t .. frame:expandTemplate{title = "Karte/Legacy", args = args}
mw.logObject(t, "t")
return t
end
return p