Altes Köln

Schulkarte-Test: Unterschied zwischen den Versionen

Aus Altes Köln
Wechseln zu:Navigation, Suche
Keine Bearbeitungszusammenfassung
(Der Seiteninhalt wurde durch einen anderen Text ersetzt: „<pre> {{#ask: Kategorie:Schule |?Schule |?Schultyp |?Position |format=table }} </pre>“)
Markierung: Ersetzt
Zeile 1: Zeile 1:
JSON-Test:
<pre>
<script id="smw-data" type="application/json">
[
{{#ask:
{{#ask:
  [[Kategorie:Schule]]
  [[Kategorie:Schule]]
Zeile 7: Zeile 5:
  |?Schultyp
  |?Schultyp
  |?Position
  |?Position
  |format=list
  |format=table
|template=SchulJSON
|sep=,
|headers=hide
|link=none
|plain=yes
}}
}}
]
</pre>
</script>
 
 
 
<!-- JSON-Daten für Leaflet -->
<script id="smw-data" type="application/json">
[
{{#ask:
[[Kategorie:Schule]]
|?Schule
|?Schultyp
|?Position
|format=list
|template=SchulJSON
|sep=,
|headers=hide
|link=none
|plain=yes
}}
]
</script>
 
<!-- Leaflet-Karte -->
<div id="map" style="width:100%; height:600px;"></div>
 
<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>
<script src="https://unpkg.com/leaflet.markercluster@1.5.3/dist/leaflet.markercluster.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>
(function(){
    var raw = document.getElementById('smw-data').textContent.trim();
    if (!raw) { console.error('Keine Daten gefunden'); return; }
 
    var schoolData;
    try {
        schoolData = JSON.parse(raw);
    } catch(e) {
        console.error('JSON Parse Fehler:', e);
        return;
    }
 
    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);
 
    var clusters = {
        "Gymnasium": L.markerClusterGroup(),
        "Volksschule": L.markerClusterGroup(),
        "Förderschule": L.markerClusterGroup(),
        "Gesamtschule": L.markerClusterGroup()
    };
 
    var icons = {
        "Gymnasium": "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-blue.png",
        "Volksschule": "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-green.png",
        "Förderschule": "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-red.png",
        "Gesamtschule": "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-orange.png"
    };
 
    var bounds = [];
 
    schoolData.forEach(function(s){
        if (!s.coords) return;
        var parts = s.coords.split(',');
        if (parts.length !== 2) return;
        var lat = parseFloat(parts[0]), lon = parseFloat(parts[1]);
        if (isNaN(lat) || isNaN(lon)) return;
 
        var iconUrl = icons[s.type] || icons["Gymnasium"];
        var markerIcon = new L.Icon({
            iconUrl: iconUrl,
            shadowUrl: 'https://unpkg.com/leaflet@1.9.3/dist/images/marker-shadow.png',
            iconSize: [25,41],
            iconAnchor: [12,41],
            popupAnchor: [1,-34],
            shadowSize: [41,41]
        });
 
        var marker = L.marker([lat, lon], {icon: markerIcon})
            .bindPopup('<strong>' + s.name + '</strong><br>' + s.type);
 
        var layer = clusters[s.type] || clusters["Gymnasium"];
        layer.addLayer(marker);
 
        bounds.push([lat, lon]);
    });
 
    for (var key in clusters) {
        clusters[key].addTo(map);
    }
 
    L.control.layers(null, {
        "Gymnasien": clusters["Gymnasium"],
        "Volksschulen": clusters["Volksschule"],
        "Förderschulen": clusters["Förderschule"],
        "Gesamtschulen": clusters["Gesamtschule"]
    }, {collapsed:false}).addTo(map);
 
    if (bounds.length) map.fitBounds(bounds);
 
})();
</script>

Version vom 10. Dezember 2025, 15:34 Uhr

{{#ask:
 [[Kategorie:Schule]]
 |?Schule
 |?Schultyp
 |?Position
 |format=table
}}
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.