Modul:Karte/Work: Unterschied zwischen den Versionen

Aus FürthWiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 29: Zeile 29:
local geoobjects = {}
local geoobjects = {}
local minimum_one_geocode_ok = false
local minimum_one_geocode_ok = false
if not com.isTrue(args["Ehemals"]) then
-- 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 "", ";")
local location = str.strip(args["location"] 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 geoobject_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 "")
-- Prüfung Koordinate (Zahl) oder textuelle Objektlokation
-- wenn Objektlokation und Ehemals, dann nicht auswerten
if location ~= "" and
  string.match(location, "%d") == nil and
  com.isTrue(args["Ehemals"]) then
location = ""
t = t .. "[[Kategorie:Hat Objektlokation, ist aber ehemaliges Objekt]]"
end
-- location geocode
if location ~= "" then
if location ~= "" then
table.insert(locations_merged, args["location"] ..
geoobject_entry["Geolokation"] = location
"~" .. (args["popuptitle"] or "") ..
local geocode = geocode(frame, location)
"~" .. (args["popuptext"] or ""))
if geocode ~= "Geocoding failed" then
end
geoobject_entry["Geokoordinate"] = geocode
-- alle locations durchiterieren und für jedes ein subobject erstellen
minimum_one_geocode_ok = true
for _, l in ipairs(locations_merged) do
else
local geoobject_entry = {}
t = t .. "[[Kategorie:Hat Geo-Kodierungsfehler]]"
-- Aufteilung location ~ popuptitle ~ popuptext
smw_geokoordinate = mw.smw.ask(
l = str.split2(l, "~")
"[[-Has subobject::" .. pagename .. "]]" ..
local location = str.strip(l[1] or "")
"[[Geolokation::" .. location .. "]]" ..
local popuptitle = str.strip(l[2] or "")
"|?Geokoordinate|limit=1")
local popuptext = str.strip(l[3] or "")
if smw_geokoordinate ~= nil and
-- location geocode
smw_geokoordinate[1]["Geokoordinate"] ~= nil then
if location ~= "" then
t = t .. "[[Kategorie:Hat Geo-Kodierungsfehler, aber noch Geokoordinate in SMW-DB]]"
geoobject_entry["Geolokation"] = location
geoobject_entry["Geokoordinate"] =
local geocode = frame:callParserFunction(
smw_geokoordinate[1]["Geokoordinate"]
"#geocode", {location, format="float", directional="no"})
if geocode ~= "Geocoding failed" then
geoobject_entry["Geokoordinate"] = geocode
minimum_one_geocode_ok = true
minimum_one_geocode_ok = true
else
smw_geokoordinate = mw.smw.ask(
"[[-Has subobject::" .. pagename .. "]]" ..
"[[Geolokation::" .. location .. "]]" ..
"|?Geokoordinate|limit=1")
if smw_geokoordinate ~= nil and
smw_geokoordinate[1]["Geokoordinate"] ~= nil then
geoobject_entry["Geokoordinate"] =
smw_geokoordinate[1]["Geokoordinate"]
minimum_one_geocode_ok = true
end
end
end
end
end
-- popuptitle und popuptext ablegen
if popuptitle ~= "" then
geoobject_entry["KartePopupTitle"] = popuptitle
end
if popuptext ~= "" then
geoobject_entry["KartePopupText"] = popuptext
end
-- subobject in Liste aufnehmen
table.insert(geoobjects, geoobject_entry)
end
end
geoobject_entry["KartePopupTitle"] = popuptitle
geoobject_entry["KartePopupText"] = popuptext
geoobjects:insert(geoobject_entry)
end
end


-- geocode lon/lat
-- geocode lon/lat
if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and args["lat"] ~= nil and args["lon"] ~= nil then
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"})
local geocode = geocode(frame, args["lat"] .. "," .. args["lon"])
if geocode ~= "Geocoding failed" then
if geocode ~= "Geocoding failed" then
local geoobject_entry = {}
local geoobject_entry = {["Geokoordinate"] = geocode}
geoobject_entry["Geokoordinate"] = geocode
geoobject_entry["KartePopupTitle"] = popuptitle
if popuptitle ~= "" then
geoobject_entry["KartePopupText"] = popuptext
geoobject_entry["KartePopupTitle"] = popuptitle
geoobjects:insert(geoobject_entry)
end
if popuptext ~= "" then
geoobject_entry["KartePopupText"] = popuptext
end
table.insert(geoobjects, geoobject_entry)
end
end
end
end
Zeile 108: Zeile 104:
mw.logObject(t, "t")
mw.logObject(t, "t")
return 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)
end
end


return p
return p

Version vom 10. Dezember 2025, 12:06 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 pagename = args["pagename"] or wik.pagename()							-- nur zum Debugging pagename vorgebbar

	-- geocode location and locationlist
	local geoobjects = {}
	local minimum_one_geocode_ok = false
	-- 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 geoobject_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 "")
		-- Prüfung Koordinate (Zahl) oder textuelle Objektlokation
		-- wenn Objektlokation und Ehemals, dann nicht auswerten
		if location ~= "" and 
		   string.match(location, "%d") == nil and 
		   com.isTrue(args["Ehemals"]) then
				location = ""
			t = t .. "[[Kategorie:Hat Objektlokation, ist aber ehemaliges Objekt]]"
		end
		-- location geocode
		if location ~= "" then
			geoobject_entry["Geolokation"] = location
			local geocode = geocode(frame, location)
			if geocode ~= "Geocoding failed" then
				geoobject_entry["Geokoordinate"] = geocode
				minimum_one_geocode_ok = true
			else
				t = t .. "[[Kategorie:Hat Geo-Kodierungsfehler]]"
				smw_geokoordinate = mw.smw.ask(
					"[[-Has subobject::" .. pagename .. "]]" ..
					"[[Geolokation::" .. location .. "]]" ..
					"|?Geokoordinate|limit=1")
				if smw_geokoordinate ~= nil and 
					smw_geokoordinate[1]["Geokoordinate"] ~= nil then
					t = t .. "[[Kategorie:Hat Geo-Kodierungsfehler, aber noch Geokoordinate in SMW-DB]]"
					geoobject_entry["Geokoordinate"] =
						smw_geokoordinate[1]["Geokoordinate"]
					minimum_one_geocode_ok = true
				end
			end
		end
		geoobject_entry["KartePopupTitle"] = popuptitle
		geoobject_entry["KartePopupText"] = popuptext
		geoobjects:insert(geoobject_entry)
	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 = geocode(frame, args["lat"] .. "," .. args["lon"])
		if geocode ~= "Geocoding failed" then
			local geoobject_entry = {["Geokoordinate"] = geocode}
			geoobject_entry["KartePopupTitle"] = popuptitle
			geoobject_entry["KartePopupText"] = popuptext
			geoobjects:insert(geoobject_entry)
		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}

	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)
end

return p