Modul:Karte

Aus FürthWiki

Version vom 9. Dezember 2025, 18:32 Uhr von HeikoBot (Diskussion | Beiträge) (+ subobjectIdCleaner())
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

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")
	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)
				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"])
		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"
		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