Altes Köln

Widget:Leaflet: Unterschied zwischen den Versionen

Aus Altes Köln
Wechseln zu:Navigation, Suche
Keine Bearbeitungszusammenfassung
Markierung: Zurückgesetzt
Keine Bearbeitungszusammenfassung
 
(26 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
<div id="map" style="width:100%; height:600px;"></div>
<div id="map" style="width: 100%; height: 600px;"></div>


<!-- Leaflet CSS -->
<!-- SMW Datenabfrage -->
<script id="smw-data" type="application/json">
{{#ask:
[[Kategorie:Schule]]
|?Position=coords
|?Schultyp=type
|?Name=name
|format=json
|plain=yes
}}
</script>
 
<!-- Leaflet Ressourcen -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css"/>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css"/>
<!-- Leaflet JS -->
<script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"></script>


<!-- MarkerCluster CSS + JS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.5.3/dist/MarkerCluster.css"/>
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.5.3/dist/MarkerCluster.css"/>
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.5.3/dist/MarkerCluster.Default.css"/>
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.5.3/dist/MarkerCluster.Default.css"/>
Zeile 13: Zeile 22:


<script>
<script>
(function() {
    // Daten aus SMW holen
    var raw = document.getElementById('smw-data').textContent.trim();
    if (!raw) return;
    var json = JSON.parse(raw);
    var data = [];
    // JSON in vernünftige Objekte überführen
    if (json.results) {
        for (var key in json.results) {
            if (!json.results.hasOwnProperty(key)) continue;
            var rec = json.results[key];
            var po  = rec.printouts || {};


// Layer-Gruppen
            var coords = po.coords && po.coords[0] ? po.coords[0] : null;
var layerGrund = L.markerClusterGroup();
            var typ    = po.type && po.type[0] ? po.type[0] : 'Unbekannt';
var layerGym = L.markerClusterGroup();
            var name  = po.name && po.name[0] ? po.name[0] : rec.fulltext;
var layerGes = L.markerClusterGroup();
var layerBeruf = L.markerClusterGroup();
var layerFoerder = L.markerClusterGroup();


// Karte erzeugen
            data.push({
var map = L.map('map').setView([50.94, 6.96], 11);
                name: name,
                type: typ,
                coords: coords
            });
        }
    }


L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    // Leaflet Karte erzeugen
     maxZoom: 18,
     var map = L.map('map').setView([50.94, 6.96], 11);
    attribution: '© OpenStreetMap contributors'
}).addTo(map);


// === SMW ASK Platzhalter (MediaWiki füllt das automatisch) ===
    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
{{#ask:
        maxZoom: 18,
[[Kategorie:Schule]]
        attribution: '© OpenStreetMap contributors'
|?Koordinaten
    }).addTo(map);
|?Schultyp
 
|?Has page=link
    // Cluster nach Schultyp
|format=array
    var clusters = {
|name=schoolData
        Grundschule: L.markerClusterGroup(),
}}
        Gymnasium: L.markerClusterGroup(),
        Gesamtschule: L.markerClusterGroup(),
        Berufskolleg: L.markerClusterGroup(),
        Förderschule: L.markerClusterGroup(),
        Unbekannt: L.markerClusterGroup()
    };
 
    var bounds = [];


// Marker setzen
    // Marker erzeugen
schoolData.forEach(function(school){
    data.forEach(function(s) {
    if(!school.Koordinaten) return;
        if (!s.coords) return;
        var parts = s.coords.split(',');
        if (parts.length !== 2) return;


    var coords = school.Koordinaten.split(',');
        var lat = parseFloat(parts[0]);
    var lat = parseFloat(coords[0]);
        var lon = parseFloat(parts[1]);
    var lon = parseFloat(coords[1]);
        if (isNaN(lat) || isNaN(lon)) return;


    var marker = L.marker([lat, lon])
        var marker = L.marker([lat, lon])
        .bindPopup('<strong>' + school.link + '</strong><br>' + school.Schultyp);
            .bindPopup('<strong>' + s.name + '</strong><br>' + s.type);


    switch(school.Schultyp){
         var layer = clusters[s.type] || clusters.Unbekannt;
         case "Grundschule":      layerGrund.addLayer(marker); break;
         layer.addLayer(marker);
        case "Gymnasium":        layerGym.addLayer(marker); break;
         case "Gesamtschule":    layerGes.addLayer(marker); break;
        case "Berufskolleg":    layerBeruf.addLayer(marker); break;
        case "Förderschule":    layerFoerder.addLayer(marker); break;
        default:                layerGrund.addLayer(marker);
    }
});


// Default Layer anzeigen
        bounds.push([lat, lon]);
layerGrund.addTo(map);
    });
layerGym.addTo(map);


// Layer Control (Legende)
    // Markergruppen aktivieren
var overlays = {
    Object.values(clusters).forEach(function(group) {
    "Grundschulen": layerGrund,
        map.addLayer(group);
     "Gymnasien": layerGym,
     });
    "Gesamtschulen": layerGes,
    "Berufskollegs": layerBeruf,
    "Förderschulen": layerFoerder
};


L.control.layers(null, overlays, {collapsed:false}).addTo(map);
    // Layersteuerung
    L.control.layers(null, {
        "Grundschulen":  clusters.Grundschule,
        "Gymnasien":      clusters.Gymnasium,
        "Gesamtschulen":  clusters.Gesamtschule,
        "Berufskollegs":  clusters.Berufskolleg,
        "Förderschulen":  clusters.Förderschule,
        "Sonstige":      clusters.Unbekannt
    }, {collapsed:false}).addTo(map);


    // Karte auf Marker zoomen
    if (bounds.length) {
        map.fitBounds(bounds);
    }
})();
</script>
</script>

Aktuelle Version vom 10. Dezember 2025, 00:07 Uhr

<script id="smw-data" type="application/json"> JSON </script>

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

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

<script> (function() {

   // Daten aus SMW holen
   var raw = document.getElementById('smw-data').textContent.trim();
   if (!raw) return;
   var json = JSON.parse(raw);
   var data = [];
   // JSON in vernünftige Objekte überführen
   if (json.results) {
       for (var key in json.results) {
           if (!json.results.hasOwnProperty(key)) continue;
           var rec = json.results[key];
           var po  = rec.printouts || {};
           var coords = po.coords && po.coords[0] ? po.coords[0] : null;
           var typ    = po.type && po.type[0] ? po.type[0] : 'Unbekannt';
           var name   = po.name && po.name[0] ? po.name[0] : rec.fulltext;
           data.push({
               name: name,
               type: typ,
               coords: coords
           });
       }
   }
   // Leaflet Karte erzeugen
   var map = L.map('map').setView([50.94, 6.96], 11);
   L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
       maxZoom: 18,
       attribution: '© OpenStreetMap contributors'
   }).addTo(map);
   // Cluster nach Schultyp
   var clusters = {
       Grundschule: L.markerClusterGroup(),
       Gymnasium: L.markerClusterGroup(),
       Gesamtschule: L.markerClusterGroup(),
       Berufskolleg: L.markerClusterGroup(),
       Förderschule: L.markerClusterGroup(),
       Unbekannt: L.markerClusterGroup()
   };
   var bounds = [];
   // Marker erzeugen
   data.forEach(function(s) {
       if (!s.coords) return;
       var parts = s.coords.split(',');
       if (parts.length !== 2) return;
       var lat = parseFloat(parts[0]);
       var lon = parseFloat(parts[1]);
       if (isNaN(lat) || isNaN(lon)) return;
       var marker = L.marker([lat, lon])
           .bindPopup('' + s.name + '
' + s.type);
       var layer = clusters[s.type] || clusters.Unbekannt;
       layer.addLayer(marker);
       bounds.push([lat, lon]);
   });
   // Markergruppen aktivieren
   Object.values(clusters).forEach(function(group) {
       map.addLayer(group);
   });
   // Layersteuerung
   L.control.layers(null, {
       "Grundschulen":   clusters.Grundschule,
       "Gymnasien":      clusters.Gymnasium,
       "Gesamtschulen":  clusters.Gesamtschule,
       "Berufskollegs":  clusters.Berufskolleg,
       "Förderschulen":  clusters.Förderschule,
       "Sonstige":       clusters.Unbekannt
   }, {collapsed:false}).addTo(map);
   // Karte auf Marker zoomen
   if (bounds.length) {
       map.fitBounds(bounds);
   }

})(); </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.