Modul:Karte/Work: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| (56 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") | ||
local box = require("Modul:Box") | local box = require("Modul:Box") | ||
local logOn = true -- loggings an/aus | |||
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"} | ||
local args = wik.getArgs(pargs, args) | |||
local args = wik.getArgs( | |||
local t, _ = p.karte(frame, args) | local t, _ = p.karte(frame, args) | ||
return t | return t | ||
| Zeile 18: | Zeile 21: | ||
function p.karte(frame, args) | function p.karte(frame, args) | ||
if logOn then | |||
mw.log("karte(frame, args)") | |||
end | |||
logObject(args, "args") | |||
local t = "" | local t = "" | ||
local kategorien = {} | local kategorien = {} | ||
| Zeile 36: | Zeile 38: | ||
geoobjects.geojson = {} | geoobjects.geojson = {} | ||
geoobjects.geojson.arg = args["geojson"] | geoobjects.geojson.arg = args["geojson"] | ||
geoobjects.geojson.pagename = geoobjects.geojson.arg or pagename | geoobjects.geojson.pagename = geoobjects.geojson.arg or pagename -- oder implizite GeoJson mit gleichem Seitennamen | ||
geoobjects.geojson.fullpagename = "GeoJson:" .. geoobjects.geojson.pagename | geoobjects.geojson.fullpagename = "GeoJson:" .. geoobjects.geojson.pagename | ||
geoobjects.geojson.url = "{{canonicalurl:" .. geoobjects.geojson.fullpagename .. "}}" | geoobjects.geojson.url = | ||
"{{canonicalurl:" .. geoobjects.geojson.fullpagename .. "}}" -- über diese kommt man schneller dazu, eine neue GeoJson-Karte anzulegen | |||
geoobjects.geojson.exists = wik.pageExists(geoobjects.geojson.fullpagename) | geoobjects.geojson.exists = wik.pageExists(geoobjects.geojson.fullpagename) | ||
geoobjects.geojson.missing = | |||
(geoobjects.geojson.arg ~= nil and not geoobjects.geojson.exists) | |||
-- width/height | -- width/height | ||
| Zeile 53: | Zeile 58: | ||
end | end | ||
-- geocode location and locationlist | -- geocode location and locationlist -- zerlegt locationlist und versucht geocode zu jeder location | ||
local minimum_one_geocode_ok = false -- Flag, dass mindestens ein geocode erfolgreich war | local minimum_one_geocode_ok = false -- Flag, dass mindestens ein geocode erfolgreich war | ||
-- locationlist und location zusammenführen | -- locationlist in table splitten und mit location zusammenführen | ||
local locationlist = str.splitAndStrip(args["locationlist"] or "", ";") | local locationlist = {} | ||
table.insert(locationlist, | if args["locationlist"] ~= nil then | ||
locationlist = str.splitAndStrip(args["locationlist"] or "", ";") | |||
end | |||
if args["location"] ~= nil then -- location hinzufügen | |||
-- alle locations durchiterieren und für jedes ein subobject erstellen | table.insert(locationlist, args["location"] .. "~" .. | ||
(args["popuptitle"] or "") .. "~" .. (args["popuptext"] or "")) -- ein leeres ~ ~ wird später wieder bereinigt | |||
end | |||
-- alle locations durchiterieren und für jedes ein geoobject (später subobject) erstellen | |||
for _, l in ipairs(locationlist) do | for _, l in ipairs(locationlist) do | ||
-- Aufteilung location ~ popuptitle ~ popuptext | -- Aufteilung location ~ popuptitle ~ popuptext bzw. l[1] ~ l[2] ~ l[3] | ||
l = str.split2(l, "~") | l = str.split2(l, "~") | ||
local location = str. | local location = str.nilStrip(l[1]) | ||
local | if location ~= nil then | ||
-- location auswerten | |||
local geoobject_entry = {["Geolokation"] = location, | |||
["KartePopupTitle"] = str.nilStrip(l[2]), | |||
["KartePopupText"] = str.nilStrip(l[3])} | |||
-- Prüfung Koordinate (Zahl) oder textuelle Objektlokation | -- Prüfung Koordinate (Zahl) oder textuelle Objektlokation | ||
-- wenn Objektlokation und Ehemals, dann nicht auswerten | -- wenn textuelle Objektlokation und Ehemals, dann nicht auswerten, | ||
if string.match(location, "%d") == nil and -- Keine-Zahl | -- weil diese in OSM nicht mehr vorhanden sind | ||
if string.match(location, "%d") == nil and -- textuellen location (Keine Koordinaten-Zahl)? | |||
com.isTrue(args["Ehemals"]) then | com.isTrue(args["Ehemals"]) then | ||
kategorien["Hat Objektlokation, ist aber ehemaliges Objekt"] = true | kategorien["Hat textuelle Objektlokation, ist aber ehemaliges Objekt"] = true | ||
else | |||
local geocode = frame:callParserFunction("#geocode", location) | local geocode = frame:callParserFunction("#geocode", location) | ||
if geocode ~= "Geocoding failed" then | if geocode ~= "Geocoding failed" then -- erfolgreiches geocode | ||
geoobject_entry["Geokoordinate"] = geocode | geoobject_entry["Geokoordinate"] = geocode -- Koordinate übernehmen | ||
geoobject_entry["Quellangaben"] = "location" | geoobject_entry["Quellangaben"] = "location" | ||
minimum_one_geocode_ok = true | minimum_one_geocode_ok = true | ||
| Zeile 85: | Zeile 95: | ||
kategorien["Hat Geo-Kodierungsfehler"] = true | kategorien["Hat Geo-Kodierungsfehler"] = true | ||
local smw_geokoordinate = mw.smw.ask( -- SMW-Abfrage | local smw_geokoordinate = mw.smw.ask( -- SMW-Abfrage | ||
"[[-Has subobject::" .. pagename .. "]]" .. | "[[-Has subobject::" .. pagename .. "]]" .. -- liefert nil, wenn nix gefunden | ||
"[[SubObjektTyp::Geo]]" .. | |||
"[[Geolokation::" .. location .. "]]" .. | "[[Geolokation::" .. location .. "]]" .. | ||
"|?Geokoordinate|limit=1") or {{}} | "|?Geokoordinate|limit=1") or {{}} -- deswegen {{}} | ||
smw_geokoordinate = smw_geokoordinate[1]["Geokoordinate"] | smw_geokoordinate = smw_geokoordinate[1]["Geokoordinate"] -- 1. Ergebnis (limit=1) | ||
if smw_geokoordinate ~= nil then -- SMW-DB Geokoordinate vorhanden? | if smw_geokoordinate ~= nil then -- SMW-DB Geokoordinate vorhanden? | ||
kategorien["Hat Geo-Kodierungsfehler, aber Geokoordinate in SMW-DB noch vorhanden"] = true | kategorien["Hat Geo-Kodierungsfehler, aber Geokoordinate in SMW-DB noch vorhanden"] = true | ||
geoobject_entry["Geokoordinate"] = smw_geokoordinate | geoobject_entry["Geokoordinate"] = smw_geokoordinate -- SMW-DB-Koordinate übernehmen (beibehalten) | ||
geoobject_entry["Quellangaben"] = "SMW-DB" | geoobject_entry["Quellangaben"] = "SMW-DB" | ||
minimum_one_geocode_ok = true | minimum_one_geocode_ok = true | ||
else | else -- geocode und SMW-DB-Abfrage nicht erfolgreich | ||
kategorien["Hat Geo-Kodierungsfehler und Geokoordinate nicht in SMW-DB vorhanden"] = true | kategorien["Hat Geo-Kodierungsfehler und Geokoordinate nicht in SMW-DB vorhanden"] = true | ||
geoobject_entry["Quellangaben"] = "geocode error" | |||
end | end | ||
end -- if geocode ~= "Geocoding failed" then | end -- if geocode ~= "Geocoding failed" then | ||
end -- if | end -- if textuellen location (Keine Koordinaten-Zahl)? | ||
table.insert(geoobjects, geoobject_entry) | table.insert(geoobjects, geoobject_entry) | ||
end -- if location ~= | end -- if location ~= nil then | ||
end -- for _, l in ipairs( | end -- for _, l in ipairs(locationlist) do | ||
-- | -- lon/lat, nur wenn location/locationlist nicht erfolgreich oder Ehemals | ||
if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and | if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and | ||
args["lat"] ~= nil and args["lon"] ~= nil then | args["lat"] ~= nil and args["lon"] ~= nil then | ||
local | local geokoordinate = frame:callParserFunction( -- lat/lon-Angabe in Default-Format konvertieren und prüfen | ||
"#coordinates", args["lat"] .. "," .. args["lon"]) | |||
if string.find(geokoordinate, "error") == nil then -- Fehlermeldung enthält kein "error" | |||
local geoobject_entry = { | |||
geoobject_entry["Geokoordinate"] = | ["Geokoordinate"] = geokoordinate, | ||
["Quellangaben"] = "lat/lon", | |||
["KartePopupTitle"] = str.nilStrip(args["popuptitle"]), | |||
["KartePopupText"] = str.nilStrip(args["popuptext"])} | |||
table.insert(geoobjects, geoobject_entry) | |||
else | else | ||
kategorien["Hat | kategorien["Hat fehlerhafte Koordinate"] = true | ||
end | end | ||
end | end | ||
logObject(geoobjects, "geoobjects") | |||
-- Attribute setzen | -- Attribute setzen | ||
if not com.isTrue(args["noattr"]) then | if not com.isTrue(args["noattr"]) then -- kann per noattr deaktiviert werden | ||
-- | -- Geokoordinate setzen (zusätzlich zu den subobjects für div. Karten-Queries) | ||
for _, o in ipairs(geoobjects) do | for _, o in ipairs(geoobjects) do | ||
setAttr(attrlist, "Geokoordinate", o["Geokoordinate"]) | |||
setAttr(attrlist, "Geokoordinate", o["Geokoordinate"]) | end | ||
end | |||
-- GeoJson | -- GeoJson | ||
if geoobjects.geojson.exists then | if geoobjects.geojson.exists then | ||
| Zeile 135: | Zeile 146: | ||
-- zoom | -- zoom | ||
setAttr(attrlist, "Zoomlevel", args["zoom"]) | setAttr(attrlist, "Zoomlevel", args["zoom"]) | ||
-- normale Attribute setzen | -- jetzt "normale" Attribute setzen | ||
logObject(attrlist, "attrlist") | |||
mw.smw.set(attrlist) | mw.smw.set(attrlist) | ||
-- geoobjects als subobjects setzen | -- geoobjects als subobjects setzen | ||
for _, o in ipairs(geoobjects) do | for _, o in ipairs(geoobjects) do | ||
o["SubObjektTyp"] = "Geo" | local id = "Geo " .. | ||
smw.subobjectIdCleaner(o["Geolokation"] or o["Geokoordinate"]) | |||
mw.smw.subobject( | local attrlist = { ["SubObjektTyp"] = "Geo", | ||
["Geolokation"] = o["Geolokation"], | |||
["Geokoordinate"] = o["Geokoordinate"], | |||
["Quellangaben"] = o["Quellangaben"]} | |||
logObject(id, "id (subobject)") | |||
logObject(attrlist, "attrlist (subobject)") | |||
mw.smw.subobject(attrlist, id) | |||
end | end | ||
end | end | ||
-- Karten-Argumente (display_map) erstellen | -- Karte anzeigen | ||
if not com.isTrue(args["nomap"]) then -- keine Karte anzeigen oder nur geoobjects und SMW-DB? | |||
-- Anwendung: Faktenbox, aber mit eigener Karten-Darstellung z.B. Straße | |||
-- Karten-Argumente (display_map) erstellen | |||
local map_args = { "", ["zoom"] = args["zoom"], -- gemeinsame settings und erstmal leere locationlist | |||
["width"] = args["width"], ["height"] = args["height"], -- map_args[1] = "" | |||
["enablefullscreen"] = "yes", ["resizable"] = "yes"} | |||
-- geojson-Argument | |||
if geoobjects.geojson.exists then | |||
map_args["geojson"] = geoobjects.geojson.pagename | |||
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 -- Anwendung: Es soll GeoJson-Karte aber ohne die location/lat/lon-Nadeln angezeigt werden | |||
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"] | |||
-- PopUp-Text und -Titel | |||
if o["KartePopupTitle"] ~= nil then | |||
map_args[1] = map_args[1] .. "~" .. o["KartePopupTitle"] | |||
if o["KartePopupText"] ~= nil then -- keine Text ohne Titel | |||
map_args[1] = map_args[1] .. "~" .. o["KartePopupText"] | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
-- Karte (display_map) | |||
logObject(map_args, "map_args") | |||
-- | if map_args[1] ~= "" or map_args["geojson"] ~= nil then -- wenn locationlist oder geojson vorhanden | ||
t = t .. frame:callParserFunction("#display_map", map_args) | |||
if geoobjects.geojson.missing then | |||
t = t .. "< | t = t .. "<small>Karte [" .. geoobjects.geojson.url .. " " .. | ||
geoobjects.geojson.arg .. "] nicht gefunden. </small>" | |||
end | |||
-- Fehlermeldung bei geocode-Fehler | |||
if kategorien["Hat Geo-Kodierungsfehler"] then | |||
t = t .. "<small>Geo-Kodierungsfehler: Objekt(e) nicht gefunden. </small>" | |||
end | |||
elseif kategorien["Hat Geo-Kodierungsfehler"] then | |||
t = t .. "Geo-Kodierungsfehler: Objekt(e) nicht gefunden." | |||
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["Hat keine Positionsangabe"] = true | |||
end | end | ||
if com.isTrue(args[" | -- Box um Karte | ||
if com.isTrue(args["box"]) then | |||
local headline = args["headline"] -- Box-Überschrift | |||
t = t | if headline == nil and geoobjects.geojson.exists then | ||
headline = geoobjects.geojson.pagename | |||
end | |||
t = box.box{headline = headline, content = t, textalign = center} | |||
end | end | ||
-- | end -- if not com.isTrue(args["nomap"]) then | ||
-- Kategorien setzen | -- Kategorien setzen | ||
| Zeile 207: | Zeile 243: | ||
kategorien["Hat Geolokation, aber keine Geokoordinate"] = true | kategorien["Hat Geolokation, aber keine Geokoordinate"] = true | ||
end | end | ||
end | |||
-- Check "Hat geojson und location/lat/lon" | |||
if geoobjects.geojson.exists and #geoobjects > 0 then | |||
kategorien["Hat geojson und location/lat/lon"] = true | |||
end | end | ||
-- Kategorien nun setzen | -- Kategorien nun setzen | ||
for k, _ in pairs(kategorien) do | logObject(kategorien, "kategorien") | ||
if wik.namespace() == "" then | |||
for k, _ in pairs(kategorien) do | |||
t = t .. "[[Kategorie:" .. k .. "]]" | |||
end | |||
end | end | ||
logObject(t, "t") | |||
t = frame:preprocess(t) | t = frame:preprocess(t) | ||
return t, geoobjects | return t, geoobjects | ||
| Zeile 237: | Zeile 280: | ||
com.isTrue(args["GeoJsonKarte"]) | com.isTrue(args["GeoJsonKarte"]) | ||
return argsVorhanden | return argsVorhanden | ||
end | |||
function logObject(...) | |||
if logOn then | |||
mw.logObject(...) | |||
end | |||
end | end | ||
return p | return p | ||
Aktuelle Version vom 18. 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")
local logOn = true -- loggings an/aus
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)
if logOn then
mw.log("karte(frame, args)")
end
logObject(args, "args")
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 -- oder implizite GeoJson mit gleichem Seitennamen
geoobjects.geojson.fullpagename = "GeoJson:" .. geoobjects.geojson.pagename
geoobjects.geojson.url =
"{{canonicalurl:" .. geoobjects.geojson.fullpagename .. "}}" -- über diese kommt man schneller dazu, eine neue GeoJson-Karte anzulegen
geoobjects.geojson.exists = wik.pageExists(geoobjects.geojson.fullpagename)
geoobjects.geojson.missing =
(geoobjects.geojson.arg ~= nil and not geoobjects.geojson.exists)
-- 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 -- zerlegt locationlist und versucht geocode zu jeder location
local minimum_one_geocode_ok = false -- Flag, dass mindestens ein geocode erfolgreich war
-- locationlist in table splitten und mit location zusammenführen
local locationlist = {}
if args["locationlist"] ~= nil then
locationlist = str.splitAndStrip(args["locationlist"] or "", ";")
end
if args["location"] ~= nil then -- location hinzufügen
table.insert(locationlist, args["location"] .. "~" ..
(args["popuptitle"] or "") .. "~" .. (args["popuptext"] or "")) -- ein leeres ~ ~ wird später wieder bereinigt
end
-- alle locations durchiterieren und für jedes ein geoobject (später subobject) erstellen
for _, l in ipairs(locationlist) do
-- Aufteilung location ~ popuptitle ~ popuptext bzw. l[1] ~ l[2] ~ l[3]
l = str.split2(l, "~")
local location = str.nilStrip(l[1])
if location ~= nil then
-- location auswerten
local geoobject_entry = {["Geolokation"] = location,
["KartePopupTitle"] = str.nilStrip(l[2]),
["KartePopupText"] = str.nilStrip(l[3])}
-- Prüfung Koordinate (Zahl) oder textuelle Objektlokation
-- wenn textuelle Objektlokation und Ehemals, dann nicht auswerten,
-- weil diese in OSM nicht mehr vorhanden sind
if string.match(location, "%d") == nil and -- textuellen location (Keine Koordinaten-Zahl)?
com.isTrue(args["Ehemals"]) then
kategorien["Hat textuelle Objektlokation, ist aber ehemaliges Objekt"] = true
else
local geocode = frame:callParserFunction("#geocode", location)
if geocode ~= "Geocoding failed" then -- erfolgreiches geocode
geoobject_entry["Geokoordinate"] = geocode -- Koordinate übernehmen
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 .. "]]" .. -- liefert nil, wenn nix gefunden
"[[SubObjektTyp::Geo]]" ..
"[[Geolokation::" .. location .. "]]" ..
"|?Geokoordinate|limit=1") or {{}} -- deswegen {{}}
smw_geokoordinate = smw_geokoordinate[1]["Geokoordinate"] -- 1. Ergebnis (limit=1)
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 -- SMW-DB-Koordinate übernehmen (beibehalten)
geoobject_entry["Quellangaben"] = "SMW-DB"
minimum_one_geocode_ok = true
else -- geocode und SMW-DB-Abfrage nicht erfolgreich
kategorien["Hat Geo-Kodierungsfehler und Geokoordinate nicht in SMW-DB vorhanden"] = true
geoobject_entry["Quellangaben"] = "geocode error"
end
end -- if geocode ~= "Geocoding failed" then
end -- if textuellen location (Keine Koordinaten-Zahl)?
table.insert(geoobjects, geoobject_entry)
end -- if location ~= nil then
end -- for _, l in ipairs(locationlist) do
-- 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 geokoordinate = frame:callParserFunction( -- lat/lon-Angabe in Default-Format konvertieren und prüfen
"#coordinates", args["lat"] .. "," .. args["lon"])
if string.find(geokoordinate, "error") == nil then -- Fehlermeldung enthält kein "error"
local geoobject_entry = {
["Geokoordinate"] = geokoordinate,
["Quellangaben"] = "lat/lon",
["KartePopupTitle"] = str.nilStrip(args["popuptitle"]),
["KartePopupText"] = str.nilStrip(args["popuptext"])}
table.insert(geoobjects, geoobject_entry)
else
kategorien["Hat fehlerhafte Koordinate"] = true
end
end
logObject(geoobjects, "geoobjects")
-- Attribute setzen
if not com.isTrue(args["noattr"]) then -- kann per noattr deaktiviert werden
-- Geokoordinate setzen (zusätzlich zu den subobjects für div. Karten-Queries)
for _, o in ipairs(geoobjects) do
setAttr(attrlist, "Geokoordinate", o["Geokoordinate"])
end
-- GeoJson
if geoobjects.geojson.exists then
setAttr(attrlist, "GeoJson", geoobjects.geojson.fullpagename)
end
-- zoom
setAttr(attrlist, "Zoomlevel", args["zoom"])
-- jetzt "normale" Attribute setzen
logObject(attrlist, "attrlist")
mw.smw.set(attrlist)
-- geoobjects als subobjects setzen
for _, o in ipairs(geoobjects) do
local id = "Geo " ..
smw.subobjectIdCleaner(o["Geolokation"] or o["Geokoordinate"])
local attrlist = { ["SubObjektTyp"] = "Geo",
["Geolokation"] = o["Geolokation"],
["Geokoordinate"] = o["Geokoordinate"],
["Quellangaben"] = o["Quellangaben"]}
logObject(id, "id (subobject)")
logObject(attrlist, "attrlist (subobject)")
mw.smw.subobject(attrlist, id)
end
end
-- Karte anzeigen
if not com.isTrue(args["nomap"]) then -- keine Karte anzeigen oder nur geoobjects und SMW-DB?
-- Anwendung: Faktenbox, aber mit eigener Karten-Darstellung z.B. Straße
-- Karten-Argumente (display_map) erstellen
local map_args = { "", ["zoom"] = args["zoom"], -- gemeinsame settings und erstmal leere locationlist
["width"] = args["width"], ["height"] = args["height"], -- map_args[1] = ""
["enablefullscreen"] = "yes", ["resizable"] = "yes"}
-- geojson-Argument
if geoobjects.geojson.exists then
map_args["geojson"] = geoobjects.geojson.pagename
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 -- Anwendung: Es soll GeoJson-Karte aber ohne die location/lat/lon-Nadeln angezeigt werden
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"]
-- PopUp-Text und -Titel
if o["KartePopupTitle"] ~= nil then
map_args[1] = map_args[1] .. "~" .. o["KartePopupTitle"]
if o["KartePopupText"] ~= nil then -- keine Text ohne Titel
map_args[1] = map_args[1] .. "~" .. o["KartePopupText"]
end
end
end
end
end
-- Karte (display_map)
logObject(map_args, "map_args")
if map_args[1] ~= "" or map_args["geojson"] ~= nil then -- wenn locationlist oder geojson vorhanden
t = t .. frame:callParserFunction("#display_map", map_args)
if geoobjects.geojson.missing then
t = t .. "<small>Karte [" .. geoobjects.geojson.url .. " " ..
geoobjects.geojson.arg .. "] nicht gefunden. </small>"
end
-- Fehlermeldung bei geocode-Fehler
if kategorien["Hat Geo-Kodierungsfehler"] then
t = t .. "<small>Geo-Kodierungsfehler: Objekt(e) nicht gefunden. </small>"
end
elseif kategorien["Hat Geo-Kodierungsfehler"] then
t = t .. "Geo-Kodierungsfehler: Objekt(e) nicht gefunden."
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["Hat keine Positionsangabe"] = true
end
-- Box um Karte
if com.isTrue(args["box"]) then
local headline = args["headline"] -- Box-Überschrift
if headline == nil and geoobjects.geojson.exists then
headline = geoobjects.geojson.pagename
end
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
-- Check "Hat geojson und location/lat/lon"
if geoobjects.geojson.exists and #geoobjects > 0 then
kategorien["Hat geojson und location/lat/lon"] = true
end
-- Kategorien nun setzen
logObject(kategorien, "kategorien")
if wik.namespace() == "" then
for k, _ in pairs(kategorien) do
t = t .. "[[Kategorie:" .. k .. "]]"
end
end
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
function logObject(...)
if logOn then
mw.logObject(...)
end
end
return p