Altes Köln

Widget:SchulkarteLeaflet

Aus Altes Köln
Version vom 17. Dezember 2025, 18:44 Uhr von Christopher (Diskussion | Beiträge)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu:Navigation, Suche

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" /> <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>

<script> (async function () {

 // SMW-API (bei Ihnen ohne /wiki/)
 const ask = ' Die folgende Koordinate wurde nicht erkannt: +.|?Position|?Schultyp|limit=5000';
 const jsonUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(ask);
 // Icons nach Schultyp

const filePath = (name) => '/wiki/Spezial:Dateipfad/' + encodeURIComponent(name); const iconForType = {

 "Gymnasium": filePath('MarkerRot.png'),
 "Volksschule": filePath('MarkerBlau.png')

}; const defaultIconUrl = filePath('MarkerBlau.png');


 // JSON laden
 const resp = await fetch(jsonUrl, { credentials: 'same-origin' });
 if (!resp.ok) throw new Error('SMW JSON nicht erreichbar: ' + resp.status);
 const data = await resp.json();
 // Leaflet Karte
 const map = L.map('schulkarte');
 L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
   maxZoom: 19,
   attribution: '© OpenStreetMap'
 }).addTo(map);
 const bounds = [];
 // Ergebnisse
 const results = (data && data.query && data.query.results) ? data.query.results : {};
 for (const key in results) {
   const r = results[key];
   const po = r.printouts || {};
   const pos = (po.Position && po.Position[0]) ? po.Position[0] : null;
   // defensiv: ungültige Position überspringen
   if (!pos || typeof pos.lat !== 'number' || typeof pos.lon !== 'number') continue;
   const typ = (po.Schultyp && po.Schultyp[0]) ? String(po.Schultyp[0]) : ;
   const iconUrl = iconForType[typ] || defaultIconUrl;
   const icon = L.icon({
     iconUrl,
     iconSize: [24, 24],
     iconAnchor: [12, 24]
   });
   const title = r.fulltext || key;
   const url = r.fullurl || ('/wiki/' + encodeURIComponent(title));
   L.marker([pos.lat, pos.lon], { icon })
     .addTo(map)
     .bindPopup(`<a href="${url}">${title}</a>
Schultyp: ${typ || '-'}`);
   bounds.push([pos.lat, pos.lon]);
 }
 // Zoom/Extent
 if (bounds.length) {
   map.fitBounds(bounds, { padding: [20, 20] });
 } else {
   map.setView([50.94, 6.96], 12);
 }

})(); </script>

Cookies helfen uns bei der Bereitstellung von Altes Köln. Durch die Nutzung von Altes Köln erklärst du dich damit einverstanden, dass wir Cookies speichern.