Modul:Karte

Aus FürthWiki

Version vom 9. Dezember 2025, 14:17 Uhr von HeikoBot (Diskussion | Beiträge) (Karte() mit wik.getArgs)

Unterseiten


p = {}

local com = require("Modul:Common")
local str = require("Modul:String")
local wik = require("Modul:Wiki")

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
		local loc = str.splitAndStrip(args["locationlist"] or "", ";")
		if args["location"] ~= nil then
			table.insert(loc, args["location"])
		end
		for _, l in ipairs(loc) do
			local subobject_entry = {}
			subobject_entry["Geolokation"] = l
			local geocode = frame:callParserFunction("#geocode", l)
			if geocode ~= "Geocoding failed" then
				subobject_entry["Geokoordinate"] = geocode
				minimum_one_geocode_ok = true
			end
			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"
		mw.smw.subobject(s, s["Geolokation"] or s["Geokoordinate"])
	end

	-- bisherige Vorlagen-Karte
	t = frame:expandTemplate{title = "Karte/Legacy", args = args}

	mw.logObject(t, "t")
	return t
end

return p