Modul:Karte: Unterschied zwischen den Versionen

Aus FürthWiki

1.678 Bytes hinzugefügt ,  Gestern um 15:52
Weiterarbeit
(geocode format="float", directional="no". lat/lon mit popuptitle und popuptext)
(Weiterarbeit)
Zeile 20: Zeile 20:
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


-- geocode location and locationlist
-- geocode location and locationlist
local subobjects = {}
local minimum_one_geocode_ok = false -- Flag, dass mindestens ein geocode erfolgreich war
local minimum_one_geocode_ok = false
-- locationlist und location zusammenführen
if not com.isTrue(args["Ehemals"]) then
local locationlist = str.splitAndStrip(args["locationlist"] or "", ";")
-- locationlist und location zusammenführen
table.insert(locationlist,
local locations_merged = str.splitAndStrip(args["locationlist"] or "", ";")
(args["location"] or "") .. "~" ..
local location = str.strip(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
if location ~= "" then
table.insert(locations_merged, args["location"] ..
local geoobject_entry = {["Geolokation"] = location}
"~" .. (args["popuptitle"] or "") ..
-- Prüfung Koordinate (Zahl) oder textuelle Objektlokation
"~" .. (args["popuptext"] or ""))
-- wenn Objektlokation und Ehemals, dann nicht auswerten
end
if string.match(location, "%d") == nil and -- Keine-Zahl-Erkennung
-- alle locations durchiterieren und für jedes ein subobject erstellen
  com.isTrue(args["Ehemals"]) then
for _, l in ipairs(locations_merged) do
kategorien["Hat Objektlokation, ist aber ehemaliges Objekt"] = true
local subobject_entry = {}
else
-- Aufteilung location ~ popuptitle ~ popuptext
-- location geocode
l = str.split2(l, "~")
local geocode = geocode(frame, location)
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, format="float", directional="no"})
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
end
-- geocode nicht erfolgreich => SMW-DB nehmen
-- popuptitle und popuptext ablegen
kategorien["Hat Geo-Kodierungsfehler"] = true
if popuptitle ~= "" then
local smw_geokoordinate = mw.smw.ask(
subobject_entry["KartePopupTitle"] = popuptitle
"[[-Has subobject::" .. pagename .. "]]" ..
end
"[[Geolokation::" .. location .. "]]" ..
if popuptext ~= "" then
"|?Geokoordinate|limit=1") or {{}}
subobject_entry["KartePopupText"] = popuptext
smw_geokoordinate = smw_geokoordinate[1]["Geokoordinate"]
end
if smw_geokoordinate ~= nil then -- SMW-DB Geokoordinate vorhanden?
-- subobject in Liste aufnehmen
kategorien["Hat Geo-Kodierungsfehler, aber Geokoordinate in SMW-DB noch vorhanden"] = true
table.insert(subobjects, subobject_entry)
geoobject_entry["Geokoordinate"] = smw_geokoordinate
end
geoobject_entry["Quellangaben"] = "SMW-DB"
end
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
-- 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
if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and  
local geocode = frame:callParserFunction("#geocode", {args["lat"] .. "," .. args["lon"], format="float", directional="no"})
  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
if geocode ~= "Geocoding failed" then
local subobject_entry = {}
geoobject_entry["Geokoordinate"] = geocode
subobject_entry["Geokoordinate"] = geocode
geoobject_entry["Quellangaben"] = "lat/lon"
if popuptitle ~= "" then
else
subobject_entry["KartePopupTitle"] = popuptitle
kategorien["Hat Geo-Kodierungsfehler"] = true
end
if popuptext ~= "" then
subobject_entry["KartePopupText"] = popuptext
end
table.insert(subobjects, subobject_entry)
end
end
set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
table.insert(geoobjects, geoobject_entry)
end
end
-- subobjects setzen
-- geoobjects setzen
mw.logObject(subobjects, "subobjects")
mw.logObject(geoobjects, "geoobjects")
for _, s in ipairs(subobjects) do
for _, o in ipairs(geoobjects) do
s["SubObjektTyp"] = "Geo"
o["SubObjektTyp"] = "Geo"
local id = smw.subobjectIdCleaner(s["Geolokation"] or s["Geokoordinate"])
local id = smw.subobjectIdCleaner(o["Geolokation"] or o["Geokoordinate"])
mw.smw.subobject(s, id)
mw.smw.subobject(o, id)
end
end


-- bisherige Vorlagen-Karte
-- bisherige Vorlagen-Karte
t = t .. frame:expandTemplate{title = "Karte/Legacy", args = args}
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")
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