var query = 'PREFIX geo: <http://www.opengis.net/ont/geosparql#>\
PREFIX foaf: <http://xmlns.com/foaf/0.1/>\
PREFIX ref: <http://course.geoinfo2016.org/G1/vocabulary/ref#>\
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\
SELECT DISTINCT\
?name ?total ?yes ?no ?wkt \
WHERE {\
GRAPH <http://course.geoinfo2016.org/G1>{\
?district rdf:type ref:District;\
foaf:name ?name;\
ref:hasTotalVoters ?total;\
ref:hasYesVotes ?yes;\
ref:hasNoVotes ?no;\
geo:hasGeometry ?geo.\
?geo geo:hasSerialization ?wkt.\
}}';

var url = 'http://giv-lodumdata.uni-muenster.de:8282/parliament/sparql'

$(document).ready(function() {
    $.ajax({
        url: url,
        data: {
            'query': query,
            'format': 'json'
        },
        dataType: 'json',
        success: function(data) {
            L.geoJson(sparql2GeoJSON(data)).addTo(map);
        }
    })
});

function sparql2GeoJSON(input) {
    var output = [];
    for (i in input.results.bindings) {
        var entry = input.results.bindings[i];
        var new_entry = {
            type: "Feature",
            geometry: {},
            properties: {}
        };
        new_entry.geometry = $.geo.WKT.parse(entry.wkt.value);
        new_entry.properties.name = entry.name.value;
        new_entry.properties.totalVoters = entry.name.totalVoters;
        new_entry.properties.yes = entry.name.yes;
        new_entry.properties.no = entry.name.no;
        output.push(new_entry);
    }
    return output;
}

@@ -830,16 +830,71 @@
 ON(data)
+, %7Bstyle : reservesStyle, onEachFeature: onEachFeature%7D
 ).addTo(
@@ -1524,8 +1524,395 @@
 tput;%0A%7D%0A
+    %0Afunction reservesStyle(feature) %7B%0A   return %7B%0A       fillColor: 'green',%0A       weight: 0,%0A       opacity: 1,%0A       color: 'white',%0A       fillOpacity: 0.7%0A   %7D;  %0A%7D%0A%0Afunction onEachFeature(feature, layer)%7B%0A    if (feature.properties && feature.properties.name) %7B%0A        var popupContent = %22This is: %22 + feature.properties.name;%0A        layer.bindPopup(popupContent);%0A    %7D%09%09%0A%7D%0A%0A%0A

add popup