Modul:Karte: Unterschied zwischen den Versionen
(#set: GeoJson verschoben von Vorlage:Karte hierher) |
(+ nowarn) |
||
| (41 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
p = {} | local p = {} | ||
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 = false -- loggings an/aus | |||
p.karten_args = { -- Liste mit den Karten-Argumenten | |||
["lat"] = true, ["lon"] = true, | |||
["location"] = true, ["locationlist"] = true, | |||
["geojson"] = true, ["GeoJsonKarte"] = true, | |||
["zoom"] = true} | |||
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 | 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 | |||
local | |||
end | end | ||
function p.karte(frame, args) | function p.karte(frame, args) | ||
mw.log("karte(frame, args)") | if logOn then | ||
mw.log("karte(frame, args)") | |||
end | |||
logObject(args, "args") | |||
local t = "" | local t = "" | ||
local kategorien = {} | |||
local attrlist = {} | |||
local geoobjects = {} | local geoobjects = {} | ||
local pagename = args["pagename"] or wik.pagename() -- nur zum Debuggen pagename vorgebbar | local pagename = args["pagename"] or wik.pagename() -- nur zum Debuggen pagename vorgebbar | ||
local nowarn = com.isTrue(args["nowarn"]) | |||
-- defaults setzen | -- 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) | |||
-- geocode location and locationlist | -- 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 | 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 | |||
local geokodierungsfehler = false | |||
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 | ||
if not nowarn then | |||
mw.smw.set{["Wartungsmeldung"] = | |||
"Geo-Kodierungsfehler - Objekt-Lokation bei ehemaligen Objekt funktioniert nicht"} | |||
end | |||
else | else | ||
local geocode = frame:callParserFunction("#geocode", location) | |||
local geocode = geocode | if geocode ~= "Geocoding failed" then -- erfolgreiches geocode | ||
if geocode ~= "Geocoding failed" then | geoobject_entry["Geokoordinate"] = geocode -- Koordinate übernehmen | ||
geoobject_entry["Geokoordinate"] = geocode | |||
geoobject_entry["Quellangaben"] = "location" | geoobject_entry["Quellangaben"] = "location" | ||
minimum_one_geocode_ok = true | minimum_one_geocode_ok = true | ||
else | else | ||
-- geocode nicht erfolgreich => SMW-DB nehmen | -- geocode nicht erfolgreich => SMW-DB-Eintrag nehmen | ||
geokodierungsfehler = true | |||
local smw_geokoordinate = mw.smw.ask( | if not nowarn then | ||
"[[-Has subobject::" .. pagename .. "]]" .. | mw.smw.set{["Wartungsmeldung"] = | ||
"Geo-Kodierungsfehler - Objekt-Lokation nicht gefunden"} | |||
end | |||
local smw_geokoordinate = mw.smw.ask( -- SMW-Abfrage | |||
"[[-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? | ||
if not nowarn then | |||
geoobject_entry["Geokoordinate"] = smw_geokoordinate | mw.smw.set{["Wartungsmeldung"] = | ||
"Geo-Kodierungsfehler, aber Geokoordinate in SMW-DB noch vorhanden"} | |||
end | |||
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 -- geocode und SMW-DB-Abfrage nicht erfolgreich | |||
if not nowarn then | |||
mw.smw.set{["Wartungsmeldung"] = | |||
"Geo-Kodierungsfehler und Geo-Koordinate nicht in SMW-DB vorhanden"} | |||
end | |||
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 | |||
local | local geokoordinate = frame:callParserFunction( -- lat/lon-Angabe in Default-Format konvertieren und prüfen | ||
"#coordinates", args["lat"] .. "," .. args["lon"]) | |||
if | if string.find(geokoordinate, "error") == nil then -- Fehlermeldung enthält kein "error" | ||
geoobject_entry["Geokoordinate"] = | local geoobject_entry = { | ||
["Geokoordinate"] = geokoordinate, | |||
["Quellangaben"] = "lat/lon", | |||
["KartePopupTitle"] = str.nilStrip(args["popuptitle"]), | |||
["KartePopupText"] = str.nilStrip(args["popuptext"])} | |||
table.insert(geoobjects, geoobject_entry) | |||
elseif not nowarn then | |||
mw.smw.set{["Wartungsmeldung"]="Geo-Fehler - fehlerhafte Koordinate"} | |||
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 | ||
smw.addAttrToList(attrlist, "Geokoordinate", o["Geokoordinate"]) | |||
end | |||
-- jetzt "normale" Attribute setzen | |||
logObject(attrlist, "attrlist") | |||
mw.smw.set(attrlist) | |||
-- geoobjects als subobjects setzen | |||
for _, o in ipairs(geoobjects) do | for _, o in ipairs(geoobjects) do | ||
o["SubObjektTyp"] = "Geo" | o.subid = "Geo " .. | ||
smw.subobjectIdCleaner(o["Geolokation"] or o["Geokoordinate"]) | |||
mw.smw.subobject(o | local attrlist = { ["SubObjektTyp"] = "Geo", | ||
["Geolokation"] = o["Geolokation"], | |||
["Geokoordinate"] = o["Geokoordinate"], | |||
["Zoomlevel"] = args["zoom"], | |||
["Quellangaben"] = o["Quellangaben"]} | |||
if geoobjects.geojson.exists then | |||
attrlist["GeoJson"] = geoobjects.geojson.fullpagename | |||
end | |||
logObject(o.subid, "o.subid") | |||
logObject(attrlist, "attrlist (subobject)") | |||
mw.smw.subobject(attrlist, o.subid) | |||
end | end | ||
end | |||
-- | -- Karte anzeigen | ||
if | 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 | end | ||
-- | -- Karte (display_map) | ||
t = t .. " | 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 geokodierungsfehler then | |||
t = t .. "<small>Geo-Kodierungsfehler: Objekt(e) nicht gefunden. </small>" | |||
end | |||
elseif geokodierungsfehler 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]]" | |||
if not nowarn then | |||
mw.smw.set{["Wartungsmeldung"] = | |||
"Geo-Kodierungsfehler - Positionsangabe fehlt"} | |||
end | |||
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 | |||
end | |||
-- Kategorien setzen | -- Kategorien setzen | ||
kategorien["Hat Karte"] = true | kategorien["Hat Karte"] = true | ||
-- Check "Hat Geolokation, aber keine Geokoordinate" | -- Check "Hat Geolokation, aber keine Geokoordinate" | ||
for _, o in ipairs(geoobjects) do | |||
if o["Geolokation"] ~= nil and o["Geokoordinate"] == nil and not nowarn then | |||
mw.smw.set{["Wartungsmeldung"]="Geo-Kodierungsfehler - fehlende Geo-Koordinate trotz Objekt-Lokation"} | |||
-- | 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 | |||
-- Kategorien nun setzen | |||
logObject(kategorien, "kategorien") | |||
if | if wik.namespace() == "" then | ||
kategorien["Hat | for k, _ in pairs(kategorien) do | ||
end | t = t .. "[[Kategorie:" .. k .. "]]" | ||
-- nun setzen | end | ||
for k, _ in pairs(kategorien) do | |||
end | end | ||
logObject(t, "t") | |||
t = frame:preprocess(t) | t = frame:preprocess(t) | ||
return t | return t, geoobjects | ||
end | end | ||
function | 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 | end | ||
function | function logObject(...) | ||
if | if logOn then | ||
mw.logObject(...) | |||
end | end | ||
end | end | ||
return p | return p | ||
Aktuelle Version vom 17. Januar 2026, 09:17 Uhr
Modul:Karte
Zusätzliche Parameter karte()
| Parameter | Beschreibung | Typ | Status | |
|---|---|---|---|---|
| Keine Attribute setzen. | noattr |
| Wahrheitswert | optional |
| Keine Karte rendern. | nomap |
| Wahrheitswert | optional |
| Keine Wartungsmeldungen ausgeben. | nowarn |
| Wahrheitswert | optional |
| Karte befindet sich in Seite mit Formular | form | keine Beschreibung
| Wahrheitswert | optional |
| Ehemals | Ehemals | keine Beschreibung
| Wahrheitswert | optional |
| location/locationlist/lat/lon Nadeln ausblenden, wenn GeoJson vorhanden | hide_loc_latlon | keine Beschreibung
| Wahrheitswert | optional |
geoobjects-Daten-table
geoobjects[]Einzel-Objekte (table)geoobjects[]["Geolokation"]geoobjects[]["Geokoordinate"]geoobjects[]["Quellangaben"]= Quelle von Geokoordinategeoobjects[]["KartePopupTitle"]geoobjects[]["KartePopupText"]
geoobjects.geojsonGeoJson-Datengeoobjects.geojson.arg= übergebenes GeoJson-Argumentgeoobjects.geojson.pagename= GeoJson-Seitenname ohne "GeoJson:"geoobjects.geojson.fullpagename= GeoJson-Seitenname mit "GeoJson:"geoobjects.geojson.url= GeoJson-URL (über diese kommt man schneller dazu, eine neue GeoJson-Karte anzulegen)geoobjects.geojson.exists= GeoJson-Karte existiertgeoobjects.geojson.missing= GeoJson-Karte explizit angegeben, aber existiert nicht
Vorlage:Karte
Diese Vorlage zeigt eine Karte wahlweise in einer oder ohne Box an.
| Parameter | Beschreibung | Typ | Status | |
|---|---|---|---|---|
| Breitengrad | lat |
| Zahlenwert | optional |
| Längengrad | lon |
| Zahlenwert | optional |
| Objekt-Lokation | location |
| Einzeiliger Text | optional |
| Objekt-Lokations-Liste | locationlist | Siehe Beispiele unten
| Einzeiliger Text | optional |
| GeoJson-Karte | geojson | Kartenname ohne 'GeoJson:' | Seitenname | optional |
| Zoom-Faktor | zoom | keine Beschreibung
| Zahlenwert | optional |
| Popup-Titel | popuptitle | Wird angezeigt, wenn Maus über location-Pin. Darf auch Links enthalten. Bei einer grafischen GeoJson-Karte wird der Popup-Titel im grafischen Editor für jedes Element (Pin, Linie, Fläche) einzeln eingetragen und dieser Parameter wird ignoriert. Nicht bei Objekt-Lokations-Liste (locationlist). | Einzeiliger Text | optional |
| Popup-Text | popuptext | Wird angezeigt, wenn Maus über location-Pin. Darf auch Links enthalten. Bei einer grafischen GeoJson-Karte wird der Popup-Titel im grafischen Editor für jedes Element (Pin, Linie, Fläche) einzeln eingetragen und dieser Parameter wird ignoriert. Nicht bei Objekt-Lokations-Liste (locationlist). | Mehrzeiliger Text | optional |
| Box-Anzeige: Karte in einer Box oder ohne. | box | Entweder 'ja' oder 'nein'
| Wahrheitswert | optional |
| Box-Überschrift | headline | Wenn eingebunden in einer Box. Darf auch Links enthalten.
| Einzeiliger Text | optional |
| Kartenbreite | width | Entweder in Prozent oder in Pixel angegeben (wenn NICHT eingebunden in einer Box)
| Zahlenwert | optional |
| Kartenhöhe | height | Entweder in Prozent oder in Pixel angegeben (wenn NICHT eingebunden in einer Box)
| Zahlenwert | optional |
Einbindung
Möglichkeiten/Parameter zur Einbindung:
- Bei Angabe einer Koordinate (
lat/lon-Wertepaar):
{{ Karte | lat=... | lon=... | zoom=... | headline=... | popuptitle=... | popuptext=... | box=... | width=... | height=... }}
- Bei Angabe von Objekt-Lokation (
location):
{{ Karte | location=... | zoom=... | headline=... | popuptitle=... | popuptext=... | box=... | width=... | height=... }}
- Bei Angabe von Liste mit Objekt-Lokationen (
locationlist):
{{ Karte | locationlist=... | zoom=... | headline=... | box=... | width=... | height=... }}
- Bei Angabe von grafischer GeoJson-Karte2) (
geojson):
{{ Karte | geojson=... | zoom=... | headline=... | box=... | width=... | height=... }}
- Bei Angabe von grafischer GeoJson-Karte und Koordinate2),3):
{{ Karte | geojson=... | lat=... | lon=... | zoom=... | headline=... | box=... | width=... | height=... }}
- Bei Angabe von grafischer GeoJson-Karte und Objekt-Lokation2),3):
{{ Karte | geojson=... | location=... | zoom=... | headline=... | box=... | width=... | height=... }}
- Grafische GeoJson-Karte mit gleichem Seitennamen1),2):
{{ Karte | zoom=... | headline=... | box=... | width=... | height=... }}
- Anmerkungen
1) Wenn weder lat/lon noch location noch locationlist noch geojson angegeben sind, dann wird implizit die GesJson-Karte mit gleichem Seitennamen wie die eigentliche Seite angenommen. Beispiel: GeoJson:Pegnitz ist die zu Pegnitz gehörende Karte.
2) Wenn die GesJson-Karte (noch) nicht existiert, erscheint eine entsprechende Meldung mit der Klick-Möglichkeit, diese neu anzulegen.
3) Wenn geojson und zusätzlich location bzw. lat/lon übergeben werden, dann wird die GeoJson-Karte angezeigt, aber location bzw. lat/lon als Geokoordinate (Semantic) gesetzt. Zweck ist, dass man der Karte eine (Mitten-)Position mitgeben kann, damit sie z. B. per Semantisches Browsen gefunden werden kann.
Beispiele
{{Karte|lat=49.4805779|lon=10.9978422|zoom=17}}
{{Karte|location=Uhrenhäusla, Fürth, Bayern, Deutschland|zoom=17}}
{{Karte|location=Uhrenhäusla, Fürth, Bayern, Deutschland|headline=Hier steht das Uhrenhäusla|zoom=17}}
{{Karte|location=Uhrenhäusla, Fürth, Bayern, Deutschland|headline=Hier steht das Uhrenhäusla|popuptitle=Uhrenhäusla|popuptext=Siehe Uhrenhäusla|zoom=17}}
{{Karte|locationlist=Uhrenhäusla, Fürth, Bayern, Deutschland|zoom=17}}
{{Karte|locationlist=Uhrenhäusla, Fürth, Bayern, Deutschland; Rathaus Rathaus, Fürth, Bayern, Deutschland|zoom=15}}
{{Karte|locationlist=Uhrenhäusla, Fürth, Bayern, Deutschland ~ Uhrenhäusla ~ Hier steht das Uhrenhäusla; Rathaus Rathaus, Fürth, Bayern, Deutschland ~ Rathaus ~ Hier steht das Rathaus|zoom=15}}
{{Karte|geojson=Südstadt|headline=Südstadt|zoom=13}}
{{Karte|lat=49.4805779|lon=10.9978422|geojson=BlaBla|zoom=17}}
{{Karte|location=Uhrenhäusla, Fürth, Bayern, Deutschland|geojson=BlaBla|zoom=17}}
Breiten-/Längengrad (lat/lon) fehlt, Objekt-Lokation (location) fehlt oder fehlende Karte
GeoJson:Karte
Hier klicken zum Anlegen der Karte
GeoJson:Karte.
Siehe auch Hilfe:Karten
{{Karte|zoom=14}}
Breiten-/Längengrad (lat/lon) fehlt, Objekt-Lokation (location) fehlt oder fehlende Karte
GeoJson:BlaBla
Hier klicken zum Anlegen der Karte
GeoJson:BlaBla.
Siehe auch Hilfe:Karten
{{Karte|geojson=BlaBla}}
{{Karte|lat=49.4805779|lon=10.9978422|box=nein}}
{{Karte|lat=49.4805779|lon=10.9978422|box=nein|width=100%|height=500}}
Siehe auch
Unterseiten
Siehe auch
local 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 = false -- loggings an/aus
p.karten_args = { -- Liste mit den Karten-Argumenten
["lat"] = true, ["lon"] = true,
["location"] = true, ["locationlist"] = true,
["geojson"] = true, ["GeoJsonKarte"] = true,
["zoom"] = true}
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
local nowarn = com.isTrue(args["nowarn"])
-- 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
local geokodierungsfehler = false
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
if not nowarn then
mw.smw.set{["Wartungsmeldung"] =
"Geo-Kodierungsfehler - Objekt-Lokation bei ehemaligen Objekt funktioniert nicht"}
end
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
geokodierungsfehler = true
if not nowarn then
mw.smw.set{["Wartungsmeldung"] =
"Geo-Kodierungsfehler - Objekt-Lokation nicht gefunden"}
end
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?
if not nowarn then
mw.smw.set{["Wartungsmeldung"] =
"Geo-Kodierungsfehler, aber Geokoordinate in SMW-DB noch vorhanden"}
end
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
if not nowarn then
mw.smw.set{["Wartungsmeldung"] =
"Geo-Kodierungsfehler und Geo-Koordinate nicht in SMW-DB vorhanden"}
end
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)
elseif not nowarn then
mw.smw.set{["Wartungsmeldung"]="Geo-Fehler - fehlerhafte Koordinate"}
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
smw.addAttrToList(attrlist, "Geokoordinate", o["Geokoordinate"])
end
-- jetzt "normale" Attribute setzen
logObject(attrlist, "attrlist")
mw.smw.set(attrlist)
-- geoobjects als subobjects setzen
for _, o in ipairs(geoobjects) do
o.subid = "Geo " ..
smw.subobjectIdCleaner(o["Geolokation"] or o["Geokoordinate"])
local attrlist = { ["SubObjektTyp"] = "Geo",
["Geolokation"] = o["Geolokation"],
["Geokoordinate"] = o["Geokoordinate"],
["Zoomlevel"] = args["zoom"],
["Quellangaben"] = o["Quellangaben"]}
if geoobjects.geojson.exists then
attrlist["GeoJson"] = geoobjects.geojson.fullpagename
end
logObject(o.subid, "o.subid")
logObject(attrlist, "attrlist (subobject)")
mw.smw.subobject(attrlist, o.subid)
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 geokodierungsfehler then
t = t .. "<small>Geo-Kodierungsfehler: Objekt(e) nicht gefunden. </small>"
end
elseif geokodierungsfehler 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]]"
if not nowarn then
mw.smw.set{["Wartungsmeldung"] =
"Geo-Kodierungsfehler - Positionsangabe fehlt"}
end
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 and not nowarn then
mw.smw.set{["Wartungsmeldung"]="Geo-Kodierungsfehler - fehlende Geo-Koordinate trotz Objekt-Lokation"}
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 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