google.maps.event.addDomListener(window, 'load', initialize);

function initialize() {

    var bounds = new google.maps.LatLngBounds();
    var mapOptions = {
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        disableDefaultUI: true,
        panControl: true,
        zoomControl: true
    }
    var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    var categoryMap = {};

    // Get buildings from the API
    $.getJSON('/api/v1/buildings', function(data) {onGetJSON(data, bounds, map, categoryMap)});
}

function onGetJSON(buildingList, bounds, map, categoryMap) {
    //Place buildings on the map
    buildingList.forEach(function (building) {
        var latLong = new google.maps.LatLng(building.lat, building.lng);
        bounds.extend(latLong);
        var marker = new google.maps.Marker({
            position: latLong,
            map: map,
            title: building.title
        });

        // set marker color base on the complaints number
        var complaintNum = building.categories.length;
        if (complaintNum >= 4) {
            marker.setIcon('http://i.imgur.com/6s7buda.png');
        } else if (complaintNum >= 2) {
            marker.setIcon('http://i.imgur.com/PYNWdZn.png');
        } else {
            marker.setIcon('http://i.imgur.com/vErCcnm.png');
        }

        google.maps.event.addListener(marker, 'click', function () {
            window.location = "/building/" + building.id;
        });
        building.categories.forEach(function(category) {
            if(categoryMap[category]) {
                categoryMap[category].push(marker);
            } else {
                categoryMap[category] = [marker];
            }
        });
    });
    // Create the container for checkboxes
    var categoryContainer = $('<div/>', {
        id: 'categoryContainer',
        label: "Selectors",
        'class': 'item gradient rounded shadow'
    }).appendTo('#map-canvas');

    //Create category filter for each category
    Object.keys(categoryMap).forEach(function(category) {
        var label = $('<label/>', {
            'class' : "category"
        });

        var checkbox = $('<input/>', {
            'class': "categoryCheckbox",
            type: "checkbox",
            value: category,
            checked: true
        });

        // Hide/show the appropriate markers
        checkbox.change(function() {
            var markers = categoryMap[category];
            console.log(markers);
            markers.forEach(function(marker) {
                marker.setMap(checkbox.is(":checked") ? map : null);
            });
        });

        label.append(checkbox, category);
        label.appendTo(categoryContainer);
    });

    map.fitBounds(bounds);
    map.panToBounds(bounds);
}

@@ -404,16 +404,48 @@
 ap = %7B%7D;
+%0A    var checkedCategories = %7B%7D;
 %0A%0A    //
@@ -563,16 +563,35 @@
 egoryMap
+, checkedCategories
 )%7D);%0A%7D%0A%0A
@@ -647,16 +647,35 @@
 egoryMap
+, checkedCategories
 ) %7B%0A    
@@ -992,32 +992,64 @@
 itle%0A        %7D);
+%0A        marker.categories = %5B%5D;
 %0A%0A        // set
@@ -1622,32 +1622,78 @@
 ion(category) %7B%0A
+            marker.categories.push(category);%0A
             if(c
@@ -1849,24 +1849,72 @@
           %7D%0A
+            checkedCategories%5Bcategory%5D = true;%0A
         %7D);%0A
@@ -2660,146 +2660,668 @@
     
-console.log(markers);%0A            markers.forEach(function(marker) %7B%0A                marker.setMap(checkbox.is(%22:checked%22) ? map : null);%0A
+if(checkbox.is(%22:checked%22)) %7B%0A                markers.forEach(function(marker) %7B%0A                    marker.setMap(map);%0A                %7D);%0A                checkedCategories%5Bcategory%5D = true;%0A            %7D else %7B%0A                checkedCategories%5Bcategory%5D = false;%0A                markers.forEach(function(marker) %7B%0A                    var hide = true;%0A                    marker.categories.forEach(function(c) %7B%0A                        if(checkedCategories%5Bc%5D) %7B%0A                            hide = false;%0A                        %7D%0A                    %7D);%0A                    if(hide) %7B%0A                        marker.setMap(null);%0A                    %7D%0A    
     
@@ -3324,32 +3324,46 @@
             %7D);%0A
+            %7D%0A
         %7D);%0A%0A   

Fix marker hide/show logic