@@ -47,8 +47,30 @@ $(document).ready(function() {
4747
4848} ) ;
4949
50- // function defs below
51-
50+ // the active attribute doesn't change until after onclick is resolved so it's easier to manually track button state
51+ var button_onoff = {
52+ "charter" :1 ,
53+ "public" :1 ,
54+ "elementary" :1 ,
55+ "middle" :1 ,
56+ "high" :1 ,
57+ } ;
58+ $ ( '.btn-group' ) . on ( 'click' , 'button' , function ( e ) {
59+ var selected = $ ( this ) . attr ( 'value' ) ;
60+ // console.log(selected);
61+ if ( $ ( this ) . hasClass ( "active" ) ) {
62+ button_onoff [ selected ] = 0 ;
63+ $ ( this ) . removeClass ( "btn-primary" ) ;
64+ //$(this).addClass("btn-inverse");
65+ // console.log("deactivating "+selected);
66+ } else {
67+ $ ( this ) . removeClass ( "btn-inverse" ) ;
68+ $ ( this ) . addClass ( "btn-primary" ) ;
69+ button_onoff [ selected ] = 1 ;
70+ // console.log("activating "+selected);
71+ }
72+ displaySchools ( 'none' , $ ( this ) ) ;
73+ } ) ;
5274
5375var first_pass = 1 ;
5476var layer ;
@@ -64,23 +86,8 @@ function displaySchools(e,toggleswitch) {
6486 toggleswitch = 'none'
6587 layer = e . target ;
6688 }
67- // active switches don't toggle until after onclick has already passed
68- // there must be a better way to do the toggleswitch piece
69- var inactive_charter = $ ( 'button[name="schoolinfo"].active' )
70- . filter ( '[id="charter"]' ) . val ( ) == "charter" ? 0 : 1 ;
71- if ( toggleswitch == 'togglecharter' ) { inactive_charter = inactive_charter + 1 % 2 ; }
72- var inactive_public = $ ( 'button[name="schoolinfo"].active' )
73- . filter ( '[id="public"]' ) . val ( ) == "public" ? 0 : 1 ;
74- if ( toggleswitch == 'togglepublic' ) { inactive_public = inactive_public + 1 % 2 ; }
75- var inactive_elementary = $ ( 'button[name="schoolinfo"].active' )
76- . filter ( '[id="elementary"]' ) . val ( ) == "elementary" ? 0 : 1 ;
77- if ( toggleswitch == 'toggleelementary' ) { inactive_elementary == inactive_elementary + 1 % 2 ; }
78- var inactive_middle = $ ( 'button[name="schoolinfo"].active' )
79- . filter ( '[id="middle"]' ) . val ( ) == "middle" ? 0 : 1 ;
80- if ( toggleswitch == 'togglemiddle' ) { inactive_middle == inactive_middle + 1 % 2 ; }
81- var inactive_high = $ ( 'button[name="schoolinfo"].active' )
82- . filter ( '[id="high"]' ) . val ( ) == "high" ? 0 : 1 ;
83- if ( toggleswitch == 'togglehigh' ) { inactive_high == inactive_high + 1 % 2 ; }
89+ // console.log(" button checks: "+ button_onoff["charter"]+" "+button_onoff["public"]+
90+ // " "+button_onoff["elementary"] +" "+ button_onoff["middle"] +" "+ button_onoff["high"]);
8491
8592 // sometimes there will be no lines but a legend because of the filters so first pass is used.
8693 if ( first_pass != 1 ) {
@@ -101,11 +108,11 @@ function displaySchools(e,toggleswitch) {
101108 // if the button is off then make sure the school of that class is excluded
102109 // elementary/middle/high schools are all tagged by a specific grade ranges!
103110 if ( typeof schools [ i ] . lat === 'number'
104- && ! ( inactive_public == 1 && schools [ i ] . school_type == 'Regular school' )
105- && ! ( inactive_charter == 1 && schools [ i ] . charter == true )
106- && ! ( inactive_elementary == 1 && schools [ i ] . elementary_tag == true )
107- && ! ( inactive_middle == 1 && schools [ i ] . middle_tag == true )
108- && ! ( inactive_high == 1 && schools [ i ] . high_tag == true )
111+ && ! ( button_onoff [ "public" ] == 0 && schools [ i ] . school_type == 'Regular school' )
112+ && ! ( button_onoff [ "charter" ] == 0 && schools [ i ] . charter == true )
113+ && ! ( button_onoff [ "elementary" ] == 0 && schools [ i ] . elementary_tag == true )
114+ && ! ( button_onoff [ "middle" ] == 0 && schools [ i ] . middle_tag == true )
115+ && ! ( button_onoff [ "high" ] == 0 && schools [ i ] . high_tag == true )
109116 ) {
110117 //var marker = L.circleMarker([schools[i].lat, schools[i].lon], {radius: 5+((schools[i].count<10)?0:Math.sqrt(schools[i].count))});
111118 //marker.addTo(neighmap);
@@ -139,4 +146,3 @@ function onEachFeature(feature, layer) {
139146 } ) ;
140147}
141148
142-
0 commit comments