16.318
Bearbeitungen
(fix #coordinates) |
(div. Optimierungen, fixes, Kleinkram, Kommentare) |
||
| Zeile 7: | Zeile 7: | ||
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) | ||
| Zeile 19: | 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 37: | 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 54: | 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 | 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 86: | 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"]) | "#coordinates", args["lat"] .. "," .. args["lon"]) | ||
geoobject_entry["Geokoordinate"] = | 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 | 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 132: | 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"]) | |||
local attrlist = { ["SubObjektTyp"] = "Geo", | |||
["Geolokation"] = o["Geolokation"], | |||
mw.smw.subobject( | ["Geokoordinate"] = o["Geokoordinate"], | ||
["Quellangaben"] = o["Quellangaben"]} | |||
logObject(id, "id (subobject)") | |||
logObject(attrlist, "attrlist (subobject)") | |||
mw.smw.subobject(attrlist, id) | |||
end | end | ||
end | end | ||
if not com.isTrue(args["nomap"]) then -- keine Karte anzeigen? | -- 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 | -- Karten-Argumente (display_map) erstellen | ||
local map_args = { "", ["zoom"] = args["zoom"], -- gemeinsame settings | local map_args = { "", ["zoom"] = args["zoom"], -- gemeinsame settings und erstmal leere locationlist | ||
["width"] = args["width"], ["height"] = args["height"], | ["width"] = args["width"], ["height"] = args["height"], -- map_args[1] = "" | ||
["enablefullscreen"] = "yes", ["resizable"] = "yes"} | ["enablefullscreen"] = "yes", ["resizable"] = "yes"} | ||
-- geojson-Argument | -- geojson-Argument | ||
if geoobjects.geojson.exists then | if geoobjects.geojson.exists then | ||
map_args["geojson"] = geoobjects.geojson.pagename | map_args["geojson"] = geoobjects.geojson.pagename | ||
end | end | ||
-- location/lat/lon-Argumente | -- location/lat/lon-Argumente | ||
if not (geoobjects.geojson.exists and -- Pin-Anzeige deaktivieren, wenn GeoJson vorhanden und hide_loc_latlon=Ja | 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 | com.isTrue(args["hide_loc_latlon"])) then -- SMW-DB wird trotzdem geschrieben | ||
for _, o in ipairs(geoobjects) do | 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 o["Geokoordinate"] ~= nil then | ||
if map_args[1] ~= "" then | if map_args[1] ~= "" then | ||
| Zeile 168: | Zeile 183: | ||
end | end | ||
map_args[1] = map_args[1] .. o["Geokoordinate"] | map_args[1] = map_args[1] .. o["Geokoordinate"] | ||
-- PopUp-Text und -Titel | |||
if o["KartePopupTitle"] ~= nil then | if o["KartePopupTitle"] ~= nil then | ||
map_args[1] = map_args[1] .. "~" .. o["KartePopupTitle"] | map_args[1] = map_args[1] .. "~" .. o["KartePopupTitle"] | ||
if o["KartePopupText"] ~= nil then | if o["KartePopupText"] ~= nil then -- keine Text ohne Titel | ||
map_args[1] = map_args[1] .. "~" .. o["KartePopupText"] | map_args[1] = map_args[1] .. "~" .. o["KartePopupText"] | ||
end | end | ||
| Zeile 177: | Zeile 193: | ||
end | end | ||
end | end | ||
-- Karte (display_map) | -- Karte (display_map) | ||
if map_args[1] ~= "" or map_args["geojson"] ~= nil then | 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) | t = t .. frame:callParserFunction("#display_map", map_args) | ||
if geoobjects.geojson. | if geoobjects.geojson.missing then | ||
t = t .. "<small>Karte [" .. geoobjects.geojson.url .. " " .. | t = t .. "<small>Karte [" .. geoobjects.geojson.url .. " " .. | ||
geoobjects.geojson.arg .. "] nicht gefunden</small>" | geoobjects.geojson.arg .. "] nicht gefunden. </small>" | ||
end | 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 | else | ||
if com.isTrue(args["form"]) then | if com.isTrue(args["form"]) then | ||
| Zeile 200: | Zeile 222: | ||
geoobjects.geojson.fullpagename .. | geoobjects.geojson.fullpagename .. | ||
"].<br>Siehe auch [[Hilfe:Karten]]" | "].<br>Siehe auch [[Hilfe:Karten]]" | ||
kategorien[" | kategorien["Hat keine Positionsangabe"] = true | ||
end | end | ||
-- Box um Karte | -- Box um Karte | ||
if com.isTrue(args["box"]) then | if com.isTrue(args["box"]) then | ||
local headline = args["headline"] | 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} | t = box.box{headline = headline, content = t, textalign = center} | ||
end | end | ||
| Zeile 218: | 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 248: | 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 | ||