Modul:Karte: Unterschied zwischen den Versionen

136 Bytes hinzugefügt ,  Gestern um 14:17
Karte() mit wik.getArgs
(+ Karte())
(Karte() mit wik.getArgs)
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")


function p.Karte(frame)
function p.Karte(frame)
return p.karte(frame, frame.args)
-- 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
end


Zeile 13: Zeile 21:
local t = ""
local t = ""


if (args["lat"] ~= nil and args["lon"] ~= nil) or
-- geocode location and locationlist
args["location"] ~= nil or args["locationlist"] ~= nil or
local subobjects = {}
args["geojson"] ~= nil then
local minimum_one_geocode_ok = false
 
if not com.isTrue(args["Ehemals"]) then
-- geocode location and locationlist
local loc = str.splitAndStrip(args["locationlist"] or "", ";")
local subobjects = {}
if args["location"] ~= nil then
local minimum_one_geocode_ok = false
table.insert(loc, args["location"])
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
end
 
for _, l in ipairs(loc) do
-- geocode lon/lat
local subobject_entry = {}
if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and args["lat"] ~= nil and args["lon"] ~= nil then
subobject_entry["Geolokation"] = l
local geocode = frame:callParserFunction("#geocode", args["lat"] .. "," .. args["lon"])
local geocode = frame:callParserFunction("#geocode", l)
if geocode ~= "Geocoding failed" then
if geocode ~= "Geocoding failed" then
local subobject_entry = {}
subobject_entry["Geokoordinate"] = geocode
subobject_entry["Geokoordinate"] = geocode
one_geocode_ok = true
minimum_one_geocode_ok = true
table.insert(subobjects, subobject_entry)
end
end
table.insert(subobjects, subobject_entry)
end
end
mw.logObject(subobjects, "subobjects")
end
 
-- subobjects setzen
-- geocode lon/lat
for _, s in ipairs(subobjects) do
if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and args["lat"] ~= nil and args["lon"] ~= nil then
s["SubObjektTyp"] = "Geo"
local geocode = frame:callParserFunction("#geocode", args["lat"] .. "," .. args["lon"])
mw.smw.subobject(s, s["Geolokation"] or s["Geokoordinate"])
if geocode ~= "Geocoding failed" then
local subobject_entry = {}
subobject_entry["Geokoordinate"] = geocode
one_geocode_ok = true
table.insert(subobjects, subobject_entry)
end
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/Legacy", args = args}
-- bisherige Vorlagen-Karte
end
t = frame:expandTemplate{title = "Karte/Legacy", args = args}


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