Modul:Karte/Work: Unterschied zwischen den Versionen
Aus FürthWiki
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 24: | Zeile 24: | ||
-- =p.karte(mw.getCurrentFrame(), {pagename="Zum Adler", location="Restaurant Zum Adler, Fürth, Bayern, Deutschland"}) | -- =p.karte(mw.getCurrentFrame(), {pagename="Zum Adler", location="Restaurant Zum Adler, Fürth, Bayern, Deutschland"}) | ||
local t = "" | local t = "" | ||
local pagename = args["pagename"] or wik.pagename() -- nur zum | local geoobjects = {} | ||
local kategorien = {} | |||
local pagename = args["pagename"] or wik.pagename() -- nur zum Debuggen pagename vorgebbar | |||
-- geocode location and locationlist | -- geocode location and locationlist | ||
local minimum_one_geocode_ok = false -- Flag, dass mindestens ein geocode erfolgreich war | |||
local minimum_one_geocode_ok = false | |||
-- locationlist und location zusammenführen | -- locationlist und location zusammenführen | ||
local locations_merged = str.splitAndStrip(args["locationlist"] or "", ";") | local locations_merged = str.splitAndStrip(args["locationlist"] or "", ";") | ||
locations_merged:insert( | |||
(args["location"] or "") .. "~" .. | |||
(args["popuptitle"] or "") .. "~" .. | |||
(args["popuptext"] or "")) | |||
-- alle locations durchiterieren und für jedes ein subobject erstellen | -- alle locations durchiterieren und für jedes ein subobject erstellen | ||
for _, l in ipairs(locations_merged) do | for _, l in ipairs(locations_merged) do | ||
-- Aufteilung location ~ popuptitle ~ popuptext | -- Aufteilung location ~ popuptitle ~ popuptext | ||
l = str.split2(l, "~") | l = str.split2(l, "~") | ||
| Zeile 45: | Zeile 43: | ||
local popuptitle = str.strip(l[2] or "") | local popuptitle = str.strip(l[2] or "") | ||
local popuptext = str.strip(l[3] or "") | local popuptext = str.strip(l[3] or "") | ||
if location ~= "" then | if location ~= "" then | ||
geoobject_entry["Geolokation"] = location | local geoobject_entry = {["Geolokation"] = location} | ||
-- Prüfung Koordinate (Zahl) oder textuelle Objektlokation | |||
if | -- wenn Objektlokation und Ehemals, dann nicht auswerten | ||
if location:match("%d") == nil and -- Zahlerkennung | |||
com.isTrue(args["Ehemals"]) then | |||
kategorien["Hat Objektlokation, ist aber ehemaliges Objekt"] = true | |||
else | else | ||
-- location geocode | |||
local geocode = geocode(frame, location) | |||
if geocode ~= "Geocoding failed" then | |||
geoobject_entry["Geokoordinate"] = geocode | |||
if | |||
geoobject_entry["Geokoordinate"] = | |||
minimum_one_geocode_ok = true | minimum_one_geocode_ok = true | ||
end | else | ||
-- geocode nicht erfolgreich => SMW-DB nehmen | |||
kategorien["Hat Geo-Kodierungsfehler"] = true | |||
smw_geokoordinate = mw.smw.ask( | |||
"[[-Has subobject::" .. pagename .. "]]" .. | |||
end | "[[Geolokation::" .. location .. "]]" .. | ||
"|?Geokoordinate|limit=1") or {{}} | |||
smw_geokoordinate = smw_geokoordinate[1]["Geokoordinate"] | |||
if smw_geokoordinate ~= nil then -- SMW-DB Geokoordinate vorhanden? | |||
kategorien["Hat Geo-Kodierungsfehler, aber noch Geokoordinate in SMW-DB"] = true | |||
geoobject_entry["Geokoordinate"] = smw_geokoordinate | |||
minimum_one_geocode_ok = true | |||
end | |||
end -- if geocode ~= "Geocoding failed" then | |||
end -- if Zahlerkennung | |||
set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext) | |||
geoobjects:insert(geoobject_entry) | |||
end -- if location ~= "" then | |||
end -- for _, l in ipairs(locations_merged) do | |||
-- geocode lon/lat | -- geocode lon/lat | ||
| Zeile 88: | Zeile 85: | ||
geoobjects:insert(geoobject_entry) | geoobjects:insert(geoobject_entry) | ||
else | else | ||
kategorien["Hat Geo-Kodierungsfehler"] = true | |||
end | end | ||
end | end | ||
| Zeile 102: | Zeile 99: | ||
-- bisherige Vorlagen-Karte | -- bisherige Vorlagen-Karte | ||
t = t .. frame:expandTemplate{title = "Karte/Legacy", args = args} | t = t .. frame:expandTemplate{title = "Karte/Legacy", args = args} | ||
-- Kategorien setzen | |||
for _, k in pairs(kategorien) do | |||
t = t .. "[[Kategorie:" .. k .. "]]" | |||
end | |||
mw.logObject(t, "t") | mw.logObject(t, "t") | ||
Version vom 10. Dezember 2025, 14:07 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")
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")
-- Konsolenzeilen zum Debuggen:
-- =p.karte(mw.getCurrentFrame(), args)
-- =p.karte(mw.getCurrentFrame(), {pagename="Zum Adler", location="Restaurant Zum Adler, Fürth, Bayern, Deutschland"})
local t = ""
local geoobjects = {}
local kategorien = {}
local pagename = args["pagename"] or wik.pagename() -- nur zum Debuggen pagename vorgebbar
-- geocode location and locationlist
local minimum_one_geocode_ok = false -- Flag, dass mindestens ein geocode erfolgreich war
-- locationlist und location zusammenführen
local locations_merged = str.splitAndStrip(args["locationlist"] or "", ";")
locations_merged:insert(
(args["location"] or "") .. "~" ..
(args["popuptitle"] or "") .. "~" ..
(args["popuptext"] or ""))
-- alle locations durchiterieren und für jedes ein subobject erstellen
for _, l in ipairs(locations_merged) do
-- 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 "")
if location ~= "" then
local geoobject_entry = {["Geolokation"] = location}
-- Prüfung Koordinate (Zahl) oder textuelle Objektlokation
-- wenn Objektlokation und Ehemals, dann nicht auswerten
if location:match("%d") == nil and -- Zahlerkennung
com.isTrue(args["Ehemals"]) then
kategorien["Hat Objektlokation, ist aber ehemaliges Objekt"] = true
else
-- location geocode
local geocode = geocode(frame, location)
if geocode ~= "Geocoding failed" then
geoobject_entry["Geokoordinate"] = geocode
minimum_one_geocode_ok = true
else
-- geocode nicht erfolgreich => SMW-DB nehmen
kategorien["Hat Geo-Kodierungsfehler"] = true
smw_geokoordinate = mw.smw.ask(
"[[-Has subobject::" .. pagename .. "]]" ..
"[[Geolokation::" .. location .. "]]" ..
"|?Geokoordinate|limit=1") or {{}}
smw_geokoordinate = smw_geokoordinate[1]["Geokoordinate"]
if smw_geokoordinate ~= nil then -- SMW-DB Geokoordinate vorhanden?
kategorien["Hat Geo-Kodierungsfehler, aber noch Geokoordinate in SMW-DB"] = true
geoobject_entry["Geokoordinate"] = smw_geokoordinate
minimum_one_geocode_ok = true
end
end -- if geocode ~= "Geocoding failed" then
end -- if Zahlerkennung
set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
geoobjects:insert(geoobject_entry)
end -- if location ~= "" then
end -- for _, l in ipairs(locations_merged) do
-- 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 = geocode(frame, args["lat"] .. "," .. args["lon"])
if geocode ~= "Geocoding failed" then
local geoobject_entry = {["Geokoordinate"] = geocode}
set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
geoobjects:insert(geoobject_entry)
else
kategorien["Hat Geo-Kodierungsfehler"] = true
end
end
-- geoobjects setzen
mw.logObject(geoobjects, "geoobjects")
for _, o in ipairs(geoobjects) do
o["SubObjektTyp"] = "Geo"
local id = smw.subobjectIdCleaner(o["Geolokation"] or o["Geokoordinate"])
mw.smw.subobject(o, id)
end
-- bisherige Vorlagen-Karte
t = t .. frame:expandTemplate{title = "Karte/Legacy", args = args}
-- Kategorien setzen
for _, k in pairs(kategorien) do
t = t .. "[[Kategorie:" .. k .. "]]"
end
mw.logObject(t, "t")
return t
end
function geocode(frame, l)
return frame:callParserFunction(
"#geocode", {l, format="float", directional="no"})
end
function set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
if not com.isEmpty(popuptitle) then
geoobject_entry["KartePopupTitle"] = popuptitle
end
if not com.isEmpty(popuptext) then
geoobject_entry["KartePopupText"] = popuptext
end
end
return p