Altes Köln

Widget:LeafletSMWMap: Unterschied zwischen den Versionen

Aus Altes Köln
Wechseln zu:Navigation, Suche
(testweise jsonUrl verändert)
Keine Bearbeitungszusammenfassung
Zeile 9: Zeile 9:


   // const jsonUrl  = '{{{json}}}';
   // const jsonUrl  = '{{{json}}}';
  const jsonUrl = '/api.php?action=ask&format=json&query=%5B%5BKategorie%3ASchule%5D%5D'; //nur testweise!
const ask = '[[Kategorie:Schule]] [[Position::+]]|?Position|?Schultyp|limit=50';//nur testweise
const jsonUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(ask);//nur testweise
 
 


   const posProp  = '{{{position}}}';
   const posProp  = '{{{position}}}';

Version vom 17. Dezember 2025, 19:43 Uhr

<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 () {

 // const jsonUrl   = '{{{json}}}';

const ask = ' Die folgende Koordinate wurde nicht erkannt: +.|?Position|?Schultyp|limit=50';//nur testweise const jsonUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(ask);//nur testweise


 const posProp   = '{{{position}}}';
 const typeProp  = '{{{type}}}';
 const iconSpec  = '{{{iconMap}}}';
 const defIcon   = '{{{defaultIcon}}}';
 // Icon-Mapping "Typ=Datei.png;Typ2=Datei2.png"
 const iconMap = {};
 iconSpec.split(';').forEach(pair => {
   const [k,v] = pair.split('=');
   if (k && v) {
     iconMap[k.trim()] =
       '/wiki/Spezial:Dateipfad/' + encodeURIComponent(v.trim());
   }
 });
 const defaultIcon =
   '/wiki/Spezial:Dateipfad/' + encodeURIComponent(defIcon);
 const data = await (await fetch(jsonUrl, { credentials:'same-origin' })).json();
 const map = L.map('smwmap');
 L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
   { maxZoom: 19, attribution: '© OpenStreetMap' }
 ).addTo(map);
 const bounds = [];
 const results = data.query?.results || {};
 for (const key in results) {
   const r   = results[key];
   const pos = r.printouts?.[posProp]?.[0];
   if (!pos || typeof pos.lat !== 'number') continue;
   const type = r.printouts?.[typeProp]?.[0] || ;
   const iconUrl = iconMap[type] || defaultIcon;
   const icon = L.icon({
     iconUrl, iconSize:[24,24], iconAnchor:[12,24]
   });
   L.marker([pos.lat, pos.lon], { icon })
     .addTo(map)
     .bindPopup(
       `<a href="${r.fullurl}">${r.fulltext}</a>
${type}` );
   bounds.push([pos.lat, pos.lon]);
 }
 bounds.length ? map.fitBounds(bounds,{padding:[20,20]})
               : 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.