Modul:Karte/Work: Unterschied zwischen den Versionen

Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(25 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 dev = require("Modul:Development")
local wik = require("Modul:Wiki")
local wik = require("Modul:Wiki")
local smw = require("Modul:SMW")
local smw = require("Modul:SMW")
Zeile 8: Zeile 9:


function p.Karte(frame)
function p.Karte(frame)
local frame, pargs = dev.GetFrameAndParentArgs(frame)
-- nur die benötigten Argumente übernehmen
-- nur die benötigten Argumente übernehmen
local args = {"lat", "lon", "location", "locationlist", "geojson", "zoom",
local args = {"lat", "lon", "location", "locationlist", "geojson", "zoom",
"popuptitle", "popuptext", "box", "headline", "width", "height",
"popuptitle", "popuptext", "box", "headline", "width", "height", "Work"}
"noattr", "Work"}
local args = wik.getArgs(pargs, args)
local args = wik.getArgs(frame.args, args)
local t, _ = p.karte(frame, args)
local t, _ = p.karte(frame, args)
return t
return t
Zeile 40: Zeile 41:
geoobjects.geojson.url = "{{canonicalurl:" .. geoobjects.geojson.fullpagename .. "}}"
geoobjects.geojson.url = "{{canonicalurl:" .. geoobjects.geojson.fullpagename .. "}}"
geoobjects.geojson.exists = wik.pageExists(geoobjects.geojson.fullpagename)
geoobjects.geojson.exists = wik.pageExists(geoobjects.geojson.fullpagename)
mw.logObject(geoobjects.geojson, "geoobjects.geojson")


-- width/height
-- width/height
Zeile 76: Zeile 76:
  com.isTrue(args["Ehemals"]) then
  com.isTrue(args["Ehemals"]) then
kategorien["Hat Objektlokation, ist aber ehemaliges Objekt"] = true
kategorien["Hat Objektlokation, ist aber ehemaliges Objekt"] = true
else
else -- if args["lat"] == nil or args["lon"] == nil then -- to do: dieses if später rausschmeißen nach Aufbau nominatim.fuerthwiki.de
local geocode
local geocode = frame:callParserFunction("#geocode", location)
if args["lat"] == nil or args["lon"] == nil then -- to do: dieses if später rausschmeißen nach Aufbau nominatim.fuerthwiki.de
geocode = frame:callParserFunction("#geocode", frame, location) -- to do: behalten (mit local)
else -- to do: dieses if später rausschmeißen nach Aufbau nominatim.fuerthwiki.de
geocode = args["lat"] .. "," .. args["lon"] -- to do: dieses if später rausschmeißen nach Aufbau nominatim.fuerthwiki.de
end -- to do: dieses if später rausschmeißen nach Aufbau nominatim.fuerthwiki.de
if geocode ~= "Geocoding failed" then
if geocode ~= "Geocoding failed" then
geoobject_entry["Geokoordinate"] = geocode
geoobject_entry["Geokoordinate"] = geocode
Zeile 90: Zeile 85:
-- geocode nicht erfolgreich => SMW-DB-Eintrag nehmen
-- geocode nicht erfolgreich => SMW-DB-Eintrag nehmen
kategorien["Hat Geo-Kodierungsfehler"] = true
kategorien["Hat Geo-Kodierungsfehler"] = true
local smw_geokoordinate = mw.smw.ask(
local smw_geokoordinate = mw.smw.ask( -- SMW-Abfrage
"[[-Has subobject::" .. pagename .. "]]" ..
"[[-Has subobject::" .. pagename .. "]]" ..
"[[Geolokation::" .. location .. "]]" ..
"[[Geolokation::" .. location .. "]]" ..
Zeile 100: Zeile 95:
geoobject_entry["Quellangaben"] = "SMW-DB"
geoobject_entry["Quellangaben"] = "SMW-DB"
minimum_one_geocode_ok = true
minimum_one_geocode_ok = true
else
kategorien["Hat Geo-Kodierungsfehler und Geokoordinate nicht in SMW-DB vorhanden"] = true
end
end
end -- if geocode ~= "Geocoding failed" then
end -- if geocode ~= "Geocoding failed" then
Zeile 113: Zeile 110:
  args["lat"] ~= nil and args["lon"] ~= nil then
  args["lat"] ~= nil and args["lon"] ~= nil then
local geoobject_entry = {}
local geoobject_entry = {}
-- local geocode = frame:callParserFunction("#geocode", frame, args["lat"] .. "," .. args["lon"])
local geocode = frame:callParserFunction(
local geocode = args["lat"] .. "," .. args["lon"] -- to do: diesen Block später rausschmeißen und obigen aktivieren, wenn fertig
"#coordinates", args["lat"] .. "," .. args["lon"])
if geocode ~= "Geocoding failed" then
geoobject_entry["Geokoordinate"] = geocode
geoobject_entry["Geokoordinate"] = geocode
geoobject_entry["Quellangaben"] = "lat/lon"
geoobject_entry["Quellangaben"] = "lat/lon"
else
kategorien["Hat Geo-Kodierungsfehler"] = true
end
geoobject_entry["KartePopupTitle"] = popuptitle
geoobject_entry["KartePopupTitle"] = popuptitle
geoobject_entry["KartePopupText"] = popuptext
geoobject_entry["KartePopupText"] = popuptext
Zeile 146: Zeile 139:
for _, o in ipairs(geoobjects) do
for _, o in ipairs(geoobjects) do
o["SubObjektTyp"] = "Geo"
o["SubObjektTyp"] = "Geo"
local id = smw.subobjectIdCleaner(o["Geolokation"] or o["Geokoordinate"])
o["KartePopupTitle"] = nil -- brauchen nicht gespeichert werden
o["KartePopupText"] = nil
local id = "Geo " .. smw.subobjectIdCleaner(o["Geolokation"] or o["Geokoordinate"])
mw.smw.subobject(o, id)
mw.smw.subobject(o, id)
end
end
end
end


-- Karten-Argumente (display_map) erstellen
if not com.isTrue(args["nomap"]) then -- keine Karte anzeigen?
local map_args = { "", ["zoom"] = args["zoom"], -- gemeinsame settings
-- sondern nur geoobjects und SMW-DB
["width"] = args["width"], ["height"] = args["height"],
-- Karten-Argumente (display_map) erstellen
["enablefullscreen"] = "yes", ["resizable"] = "yes"}
local map_args = { "", ["zoom"] = args["zoom"], -- gemeinsame settings
-- geojson-Argument
["width"] = args["width"], ["height"] = args["height"],
if geoobjects.geojson.exists then
["enablefullscreen"] = "yes", ["resizable"] = "yes"}
map_args["geojson"] = geoobjects.geojson.pagename
-- geojson-Argument
if #geoobjects > 0 then
if geoobjects.geojson.exists then
kategorien["Hat geojson und location/lat/lon"] = true
map_args["geojson"] = geoobjects.geojson.pagename
if #geoobjects > 0 then
kategorien["Hat geojson und location/lat/lon"] = true
end
end
end
end
-- location/lat/lon-Argumente
-- location/lat/lon-Argumente
if not (geoobjects.geojson.exists and -- Pin-Anzeige deaktivieren, wenn GeoJson vorhanden und hide_loc_latlon=Ja
if not (geoobjects.geojson.exists and -- Pin-Anzeige deaktivieren, wenn GeoJson vorhanden und hide_loc_latlon=Ja
com.isTrue(args["hide_loc_latlon"])) then -- SMW-DB wird trotzdem geschrieben
com.isTrue(args["hide_loc_latlon"])) then -- SMW-DB wird trotzdem geschrieben
for _, o in ipairs(geoobjects) do
for _, o in ipairs(geoobjects) do
if o["Geokoordinate"] ~= nil then
if o["Geokoordinate"] ~= nil then
if map_args[1] ~= "" then
if map_args[1] ~= "" then
map_args[1] = map_args[1] .. ";"
map_args[1] = map_args[1] .. ";"
end
end
map_args[1] = map_args[1] .. o["Geokoordinate"]
map_args[1] = map_args[1] .. o["Geokoordinate"]
if o["KartePopupTitle"] ~= nil then
if o["KartePopupTitle"] ~= nil then
map_args[1] = map_args[1] .. "~" .. o["KartePopupTitle"]
map_args[1] = map_args[1] .. "~" .. o["KartePopupTitle"]
if o["KartePopupText"] ~= nil then
if o["KartePopupText"] ~= nil then
map_args[1] = map_args[1] .. "~" .. o["KartePopupText"]
map_args[1] = map_args[1] .. "~" .. o["KartePopupText"]
end
end
end
end
end
end
end
end
end
end
 
-- Karte (display_map)
-- Karte (display_map)
if map_args[1] ~= "" or map_args["geojson"] ~= nil then
if map_args[1] ~= "" or map_args["geojson"] ~= nil then
-- mw.logObject(map_args, "map_args")
-- mw.logObject(map_args, "map_args")
t = t .. frame:callParserFunction("#display_map", map_args)
t = t .. frame:callParserFunction("#display_map", map_args)
if geoobjects.geojson.arg ~= nil and map_args["geojson"] == nil then
if args["geojson"] ~= nil and map_args["geojson"] == nil then
t = t .. "<small>Karte [" .. geoobjects.geojson.url .. " " ..
t = t .. "<small>Karte [" .. geoobjects.geojson.url .. " " .. args["geojson"] .. "] nicht gefunden</small>"
geoobjects.geojson.arg .. "] nicht gefunden</small>"
end
else
if com.isTrue(args["form"]) then
t = t .. "Positionsangabe fehlt oder fehlende Karte<br>" ..
geoobjects.geojson.fullpagename ..
"<br>Bitte Position in Formular eintragen oder"
else
t = t .. "Breiten-/Längengrad (lat/lon) fehlt, Objekt-Lokation " ..
"(location) fehlt oder fehlende Karte<br>" ..
geoobjects.geojson.fullpagename
end
t = t .. "<br>[" .. geoobjects.geojson.url ..
" Hier klicken zum Anlegen der Karte<br>" ..
geoobjects.geojson.fullpagename ..
"].<br>Siehe auch [[Hilfe:Karten]]"
kategorien["Ohne Position"] = true
end
end
else
if com.isTrue(args["form"]) then
-- Box um Karte
t = t .. "Positionsangabe fehlt oder fehlende Karte<br>" .. geoobjects.geojson.fullpagename .. "<br>Bitte Position in Formular eintragen oder"
if com.isTrue(args["box"]) then
else
local headline = args["headline"] or geoobjects.geojson.arg or pagename
t = t .. "Breiten-/Längengrad (lat/lon) fehlt, Objekt-Lokation (location) fehlt oder fehlende Karte<br>" .. geoobjects.geojson.fullpagename
t = box.box{headline = headline, content = t, textalign = center}
end
end
t = t .. "<br>[" .. geoobjects.geojson.url .. " Hier klicken zum Anlegen der Karte<br>" .. geoobjects.geojson.fullpagename .. "].<br>Siehe auch [[Hilfe:Karten]]"
kategorien["Ohne Position"] = true
end


-- Box um Karte
end -- if not com.isTrue(args["nomap"]) then
if com.isTrue(args["box"]) then
local headline = args["headline"] or args["geojson"] or pagename
t = box.box{headline = headline, content = t, textalign = center}
end


-- Kategorien setzen
-- Kategorien setzen
Zeile 230: Zeile 237:
end
end
end
end
end
function p.kartenArgsVorhanden(args)
local argsVorhanden =
(not com.isEmpty(args["lat"]) and not com.isEmpty(args["lon"])) or
not com.isEmpty(args["location"]) or
not com.isEmpty(args["locationlist"]) or
not com.isEmpty(args["geojson"]) or
wik.pageExists("GeoJson:" .. wik.pagename()) or
com.isTrue(args["GeoJsonKarte"])
return argsVorhanden
end
end


return p
return p

Aktuelle Version vom 17. Dezember 2025, 14:48 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 dev = require("Modul:Development")
local wik = require("Modul:Wiki")
local smw = require("Modul:SMW")
local box = require("Modul:Box")

function p.Karte(frame)
	local frame, pargs = dev.GetFrameAndParentArgs(frame)
	-- nur die benötigten Argumente übernehmen
	local args = {"lat", "lon", "location", "locationlist", "geojson", "zoom",
		"popuptitle", "popuptext", "box", "headline", "width", "height", "Work"}
	local args = wik.getArgs(pargs, args)
	local t, _ = p.karte(frame, args)
	return t
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 kategorien = {}
	local attrlist = {}
	local geoobjects = {}
	local pagename = args["pagename"] or wik.pagename()							-- nur zum Debuggen pagename vorgebbar

	-- defaults setzen
	args["box"] = args["box"] or "Ja"
	args["zoom"] = args["zoom"] or "16"

	-- geojson-Angabe auswerten
	geoobjects.geojson = {}
	geoobjects.geojson.arg = args["geojson"]
	geoobjects.geojson.pagename = geoobjects.geojson.arg or pagename
	geoobjects.geojson.fullpagename = "GeoJson:" .. geoobjects.geojson.pagename
	geoobjects.geojson.url = "{{canonicalurl:" .. geoobjects.geojson.fullpagename .. "}}"
	geoobjects.geojson.exists = wik.pageExists(geoobjects.geojson.fullpagename)

	-- width/height
	if com.isTrue(args["box"]) or args["width"] == "auto" then
		args["width"] = nil														-- ohne width passt sich Karte eigenständig in Box ein
	elseif args["width"] == nil then
		args["width"] = "50%"													-- default bei keiner width-Angabe und keiner Box
	end
	if com.isTrue(args["box"]) or args["height"] == "auto" then
		args["height"] = nil													-- ohne height passt sich Karte eigenständig in Box ein
	elseif args["height"] == nil then
		args["height"] = "25%"													-- default bei keiner height-Angabe und keiner Box
	end

	-- 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. location kann auch Koordinate sein
			   com.isTrue(args["Ehemals"]) then
				kategorien["Hat Objektlokation, ist aber ehemaliges Objekt"] = true
			else -- if args["lat"] == nil or args["lon"] == nil then			-- to do: dieses if später rausschmeißen nach Aufbau nominatim.fuerthwiki.de
				local geocode = frame:callParserFunction("#geocode", 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-Eintrag nehmen
					kategorien["Hat Geo-Kodierungsfehler"] = true
					local smw_geokoordinate = mw.smw.ask(						-- SMW-Abfrage
						"[[-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
					else
						kategorien["Hat Geo-Kodierungsfehler und Geokoordinate nicht in SMW-DB vorhanden"] = true
					end
				end -- if geocode ~= "Geocoding failed" then
			end -- if Zahlerkennung
			geoobject_entry["KartePopupTitle"] = popuptitle
			geoobject_entry["KartePopupText"] = 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 
	   args["lat"] ~= nil and args["lon"] ~= nil then
		local geoobject_entry = {}
		local geocode = frame:callParserFunction(
			"#coordinates", args["lat"] .. "," .. args["lon"])
		geoobject_entry["Geokoordinate"] = geocode
		geoobject_entry["Quellangaben"] = "lat/lon"
		geoobject_entry["KartePopupTitle"] = popuptitle
		geoobject_entry["KartePopupText"] = popuptext
		table.insert(geoobjects, geoobject_entry)
	end

	-- Attribute setzen
	if not com.isTrue(args["noattr"]) then
		-- Geolokation/Geokoordinate setzen
		for _, o in ipairs(geoobjects) do										-- to do: obsolete, wenn sobobject genutzt
			setAttr(attrlist, "Geolokation", o["Geolokation"])					-- to do: obsolete, wenn sobobject genutzt
			setAttr(attrlist, "Geokoordinate", o["Geokoordinate"])				-- to do: obsolete, wenn sobobject genutzt
		end																		-- to do: obsolete, wenn sobobject genutzt
		-- GeoJson
		if geoobjects.geojson.exists then
			setAttr(attrlist, "GeoJson", geoobjects.geojson.fullpagename)
		end
		-- zoom
		setAttr(attrlist, "Zoomlevel", args["zoom"])
		-- normale Attribute setzen
--		mw.logObject(attrlist, "attrlist")
		mw.smw.set(attrlist)
		-- geoobjects als subobjects setzen
--		mw.logObject(geoobjects, "geoobjects")
		for _, o in ipairs(geoobjects) do
			o["SubObjektTyp"] = "Geo"
			o["KartePopupTitle"] = nil											-- brauchen nicht gespeichert werden
			o["KartePopupText"] = nil
			local id = "Geo " .. smw.subobjectIdCleaner(o["Geolokation"] or o["Geokoordinate"])
			mw.smw.subobject(o, id)
		end
	end

	if not com.isTrue(args["nomap"]) then										-- keine Karte anzeigen?
																				-- sondern nur geoobjects und SMW-DB
		-- Karten-Argumente (display_map) erstellen
		local map_args = { "", ["zoom"] = args["zoom"],							-- gemeinsame settings
			["width"] = args["width"], ["height"] = args["height"],
			["enablefullscreen"] = "yes", ["resizable"] = "yes"}
		-- geojson-Argument
		if geoobjects.geojson.exists then
			map_args["geojson"] = geoobjects.geojson.pagename
			if #geoobjects > 0 then
				kategorien["Hat geojson und location/lat/lon"] = true
			end
		end
		-- location/lat/lon-Argumente
		if not (geoobjects.geojson.exists and									-- Pin-Anzeige deaktivieren, wenn GeoJson vorhanden und hide_loc_latlon=Ja
				com.isTrue(args["hide_loc_latlon"])) then						-- SMW-DB wird trotzdem geschrieben
			for _, o in ipairs(geoobjects) do
				if o["Geokoordinate"] ~= nil then
					if map_args[1] ~= "" then
						map_args[1] = map_args[1] .. ";"
					end
					map_args[1] = map_args[1] .. o["Geokoordinate"]
					if o["KartePopupTitle"] ~= nil then
						map_args[1] = map_args[1] .. "~" .. o["KartePopupTitle"]
						if o["KartePopupText"] ~= nil then
							map_args[1] = map_args[1] .. "~" .. o["KartePopupText"]
						end
					end
				end
			end
		end
	
		-- Karte (display_map)
		if map_args[1] ~= "" or map_args["geojson"] ~= nil then
--			mw.logObject(map_args, "map_args")
			t = t .. frame:callParserFunction("#display_map", map_args)
			if geoobjects.geojson.arg ~= nil and map_args["geojson"] == nil then
				t = t .. "<small>Karte [" .. geoobjects.geojson.url .. " " ..
					geoobjects.geojson.arg .. "] nicht gefunden</small>"
			end
		else
			if com.isTrue(args["form"]) then
				t = t .. "Positionsangabe fehlt oder fehlende Karte<br>" ..
					geoobjects.geojson.fullpagename ..
					"<br>Bitte Position in Formular eintragen oder"
			else
				t = t .. "Breiten-/Längengrad (lat/lon) fehlt, Objekt-Lokation " ..
				"(location) fehlt oder fehlende Karte<br>" ..
				geoobjects.geojson.fullpagename
			end
			t = t .. "<br>[" .. geoobjects.geojson.url ..
				" Hier klicken zum Anlegen der Karte<br>" ..
				geoobjects.geojson.fullpagename ..
				"].<br>Siehe auch [[Hilfe:Karten]]"
			kategorien["Ohne Position"] = true
		end
	
		-- Box um Karte
		if com.isTrue(args["box"]) then
			local headline = args["headline"] or geoobjects.geojson.arg or pagename
			t = box.box{headline = headline, content = t, textalign = center}
		end

	end -- if not com.isTrue(args["nomap"]) then

	-- Kategorien setzen
	kategorien["Hat Karte"] = true
	-- Check "Hat Geolokation, aber keine Geokoordinate"
	for _, o in ipairs(geoobjects) do
		if o["Geolokation"] ~= nil and o["Geokoordinate"] == nil then
			kategorien["Hat Geolokation, aber keine Geokoordinate"] = true
		end
	end
	-- Kategorien nun setzen
	for k, _ in pairs(kategorien) do
		t = t .. "[[Kategorie:" .. k .. "]]"
	end

--	mw.logObject(t, "t")
	t = frame:preprocess(t)
	return t, geoobjects
end

function setAttr(attrlist, attr, val)
	if val ~= nil then
		if attrlist[attr] == nil then
			attrlist[attr] = {val}
		else
			table.insert(attrlist[attr], val)
		end
	end
end

function p.kartenArgsVorhanden(args)
	local argsVorhanden =
		(not com.isEmpty(args["lat"]) and not com.isEmpty(args["lon"])) or
		not com.isEmpty(args["location"]) or
		not com.isEmpty(args["locationlist"]) or
		not com.isEmpty(args["geojson"]) or
		wik.pageExists("GeoJson:" .. wik.pagename()) or
		com.isTrue(args["GeoJsonKarte"])
	return argsVorhanden
end

return p