Modul:Karte: Unterschied zwischen den Versionen

Aus FürthWiki

(+ subobjects)
(dummy-Änderung als Job-Trigger)
 
(7 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 3: Zeile 3:
local com = require("Modul:Common")
local com = require("Modul:Common")
local str = require("Modul:String")
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)
function p.karte(frame, args)
mw.log("karte(frame, args)")
mw.log("karte(frame, args)")
mw.logObject(args, "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 t = ""
local geoobjects = {}
local kategorien = {}
local pagename = args["pagename"] or wik.pagename() -- nur zum Debuggen pagename vorgebbar


if (args["lat"] ~= nil and args["lon"] ~= nil) or
-- geocode location and locationlist
args["location"] ~= nil or args["locationlist"] ~= nil or
local minimum_one_geocode_ok = false -- Flag, dass mindestens ein geocode erfolgreich war
args["geojson"] ~= nil then
-- locationlist und location zusammenführen
 
local locationlist = str.splitAndStrip(args["locationlist"] or "", ";")
-- geocode location and locationlist
table.insert(locationlist,
local subobjects = {}
(args["location"] or "") .. "~" ..
local minimum_one_geocode_ok = false
(args["popuptitle"] or "") .. "~" ..
if not com.isTrue(args["Ehemals"]) then
(args["popuptext"] or ""))
local loc = str.splitAndStrip(args["locationlist"] or "", ";")
-- alle locations durchiterieren und für jedes ein subobject erstellen
if args["location"] ~= nil then
for _, l in ipairs(locationlist) do
table.insert(loc, args["location"])
-- Aufteilung location ~ popuptitle ~ popuptext
end
l = str.split2(l, "~")
for _, l in ipairs(loc) do
local location = str.strip(l[1] or "")
local subobject_entry = {}
local popuptitle = str.strip(l[2] or "")
subobject_entry["Geolokation"] = l
local popuptext = str.strip(l[3] or "")
local geocode = frame:callParserFunction("#geocode", l)
if location ~= "" then
local geoobject_entry = {["Geolokation"] = location}
-- Prüfung Koordinate (Zahl) oder textuelle Objektlokation
-- wenn Objektlokation und Ehemals, dann nicht auswerten
if string.match(location, "%d") == nil and -- Keine-Zahl-Erkennung
  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
if geocode ~= "Geocoding failed" then
subobject_entry["Geokoordinate"] = geocode
geoobject_entry["Geokoordinate"] = geocode
geoobject_entry["Quellangaben"] = "location"
minimum_one_geocode_ok = true
minimum_one_geocode_ok = true
end
else
table.insert(subobjects, subobject_entry)
-- geocode nicht erfolgreich => SMW-DB nehmen
end
kategorien["Hat Geo-Kodierungsfehler"] = true
local 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 Geokoordinate in SMW-DB noch vorhanden"] = true
geoobject_entry["Geokoordinate"] = smw_geokoordinate
geoobject_entry["Quellangaben"] = "SMW-DB"
minimum_one_geocode_ok = true
end
end -- if geocode ~= "Geocoding failed" then
end -- if Zahlerkennung
set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
table.insert(geoobjects, geoobject_entry)
end -- if location ~= "" then
end -- for _, l in ipairs(locations_merged) do
 
-- geocode lon/lat, nur wenn location/locationlist nicht erfolgreich oder ehemals
if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and
  not com.isEmpty(args["lat"]) and not com.isEmpty(args["lon"]) then
local geoobject_entry = {}
local geocode = geocode(frame, args["lat"] .. "," .. args["lon"])
if geocode ~= "Geocoding failed" then
geoobject_entry["Geokoordinate"] = geocode
geoobject_entry["Quellangaben"] = "lat/lon"
else
kategorien["Hat Geo-Kodierungsfehler"] = true
end
end
set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
table.insert(geoobjects, geoobject_entry)
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}


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


t = frame:expandTemplate{title = "Karte", args = args}
-- Kategorien setzen
for k, _ in pairs(kategorien) do
t = t .. "[[Kategorie:" .. k .. "]]"
end
end


mw.logObject(t, "t")
mw.logObject(t, "t")
return t
return t
end
function geocode(frame, location)
return frame:callParserFunction(
"#geocode", {location, 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
end


return p
return p

Aktuelle Version vom 10. Dezember 2025, 18:27 Uhr

Unterseiten


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 locationlist = str.splitAndStrip(args["locationlist"] or "", ";")
	table.insert(locationlist,
		(args["location"] or "") .. "~" ..
		(args["popuptitle"] or "") .. "~" ..
		(args["popuptext"] or ""))
	-- alle locations durchiterieren und für jedes ein subobject erstellen
	for _, l in ipairs(locationlist) 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 string.match(location, "%d") == nil and -- Keine-Zahl-Erkennung
			   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
					geoobject_entry["Quellangaben"] = "location"
					minimum_one_geocode_ok = true
				else
					-- geocode nicht erfolgreich => SMW-DB nehmen
					kategorien["Hat Geo-Kodierungsfehler"] = true
					local 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 Geokoordinate in SMW-DB noch vorhanden"] = true
						geoobject_entry["Geokoordinate"] = smw_geokoordinate
						geoobject_entry["Quellangaben"] = "SMW-DB"
						minimum_one_geocode_ok = true
					end
				end -- if geocode ~= "Geocoding failed" then
			end -- if Zahlerkennung
			set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
			table.insert(geoobjects, geoobject_entry)
		end -- if location ~= "" then
	end -- for _, l in ipairs(locations_merged) do

	-- geocode lon/lat, nur wenn location/locationlist nicht erfolgreich oder ehemals
	if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and 
	   not com.isEmpty(args["lat"]) and not com.isEmpty(args["lon"]) then
		local geoobject_entry = {}
		local geocode = geocode(frame, args["lat"] .. "," .. args["lon"])
		if geocode ~= "Geocoding failed" then
			geoobject_entry["Geokoordinate"] = geocode
			geoobject_entry["Quellangaben"] = "lat/lon"
		else
			kategorien["Hat Geo-Kodierungsfehler"] = true
		end
		set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
		table.insert(geoobjects, geoobject_entry)
	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, location)
	return frame:callParserFunction(
		"#geocode", {location, 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