Modul:Karte: Unterschied zwischen den Versionen
(logObject) Markierung: Zurückgesetzt |
(geocode format="float", directional="no". lat/lon mit popuptitle und popuptext) |
||
| (7 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
p = {} | p = {} | ||
function p.karte(args) | local com = require("Modul:Common") | ||
mw.log("karte(args)") | local str = require("Modul:String") | ||
local wik = require("Modul:Wiki") | |||
local smw = require("Modul:SMW") | |||
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") | mw.logObject(args, "args") | ||
local t = "" | local t = "" | ||
if (args[" | |||
args["location"] ~ | -- 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 "", ";") | |||
local location = str.strip(args["location"] or "") | |||
if location ~= "" 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, format="float", directional="no"}) | |||
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["KartePopupTitle"] = popuptitle | |||
end | |||
if popuptext ~= "" then | |||
subobject_entry["KartePopupText"] = popuptext | |||
end | |||
-- subobject in Liste aufnehmen | |||
table.insert(subobjects, subobject_entry) | |||
end | |||
end | end | ||
-- mw.logObject(t, "t") | |||
-- 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"], format="float", directional="no"}) | |||
if geocode ~= "Geocoding failed" then | |||
local subobject_entry = {} | |||
subobject_entry["Geokoordinate"] = geocode | |||
if popuptitle ~= "" then | |||
subobject_entry["KartePopupTitle"] = popuptitle | |||
end | |||
if popuptext ~= "" then | |||
subobject_entry["KartePopupText"] = popuptext | |||
end | |||
table.insert(subobjects, subobject_entry) | |||
end | |||
end | |||
-- subobjects setzen | |||
mw.logObject(subobjects, "subobjects") | |||
for _, s in ipairs(subobjects) do | |||
s["SubObjektTyp"] = "Geo" | |||
local id = smw.subobjectIdCleaner(s["Geolokation"] or s["Geokoordinate"]) | |||
mw.smw.subobject(s, id) | |||
end | |||
-- bisherige Vorlagen-Karte | |||
t = t .. frame:expandTemplate{title = "Karte/Legacy", args = args} | |||
mw.logObject(t, "t") | |||
return t | return t | ||
end | end | ||
return p | return p | ||
Aktuelle Version vom 9. Dezember 2025, 21:22 Uhr
p = {}
local com = require("Modul:Common")
local str = require("Modul:String")
local wik = require("Modul:Wiki")
local smw = require("Modul:SMW")
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 "", ";")
local location = str.strip(args["location"] or "")
if location ~= "" 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, format="float", directional="no"})
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["KartePopupTitle"] = popuptitle
end
if popuptext ~= "" then
subobject_entry["KartePopupText"] = 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"], format="float", directional="no"})
if geocode ~= "Geocoding failed" then
local subobject_entry = {}
subobject_entry["Geokoordinate"] = geocode
if popuptitle ~= "" then
subobject_entry["KartePopupTitle"] = popuptitle
end
if popuptext ~= "" then
subobject_entry["KartePopupText"] = popuptext
end
table.insert(subobjects, subobject_entry)
end
end
-- subobjects setzen
mw.logObject(subobjects, "subobjects")
for _, s in ipairs(subobjects) do
s["SubObjektTyp"] = "Geo"
local id = smw.subobjectIdCleaner(s["Geolokation"] or s["Geokoordinate"])
mw.smw.subobject(s, id)
end
-- bisherige Vorlagen-Karte
t = t .. frame:expandTemplate{title = "Karte/Legacy", args = args}
mw.logObject(t, "t")
return t
end
return p