function zoomToFeature(e) {

                // reset counters;
                contained_fires_counter = 0;
                active_fires_counter = 0;
                protest_counter = 0;
                // zoom to map
                myMap.fitBounds(e.target.getBounds());
                // update html state name
                state = e.target.feature.properties.name;
                map_component.attr("state_name", state);

                // call state functions

                stateUnemployment(state, datetoPass);
                single_state_fxn(state, datetoPass);
                optionChanged(state, datetoPass);

                // getting state polygon coordinates using state dictionary
                var state_index = state_dict[state];
                var polygon_coords = statesData.features[state_index].geometry.coordinates;
                var final_coords = [];
                // switching lat and long for final coords
                for (i = 0; i < polygon_coords[0].length; i++) {
                    var update_coord = [polygon_coords[0][i][1], polygon_coords[0][i][0]];
                    final_coords.push(update_coord);
                }

                var state_check = L.polygon(final_coords);

                // find markers within clicked state 
                // contained fires
                for (var i = 0; i < contained_fires.length; i++) {
                    // special requirements for Alaska (multipolygon)
                    if (state_index == 1) {
                        if (contained_fires[i]._latlng.lat > 52) {
                            contained_fires_counter = contained_fires_counter + 1;
                        }
                    }
                    // special requirements for Hawaii (multipolygon)
                    if (state_index == 11) {
                        if ((contained_fires._latlng.lng < -126) && (contained_fires._latlng.lat < 50)) {
                            contained_fires_counter = contained_fires_counter + 1;
                        }
                    }
                    // special requirements for Michigan (multipolygon)
                    if (state_index == 22) {
                        if ((contained_fires[i]._latlng.lng > -87) && (contained_fires[i]._latlng.lat > 41.8) && (contained_fires[i]._latlng.lng < -82.5)) {
                            contained_fires_counter = contained_fires_counter + 1;
                        }
                    }
                    // all other states check
                    else {
                        var marker_inside_polygon = state_check.contains(contained_fires[i].getLatLng());

                        if (marker_inside_polygon) {
                            contained_fires_counter = contained_fires_counter + 1;
                        }
                    }
                }

                // active fires
                for (var i = 0; i < total_active_fires.length; i++) {
                    if (state_index == 1) {
                        if (total_active_fires[i]._latlng.lat > 52) {
                            active_fires_counter = active_fires_counter + 1;
                        }
                    }
                    if (state_index == 11) {
                        if ((total_active_fires._latlng.lng < -126) && (total_active_fires._latlng.lat < 50)) {
                            active_fires_counter = active_fires_counter + 1;
                        }
                    }

                    if (state_index == 22) {
                        if ((total_active_fires[i]._latlng.lng > -87) && (total_active_fires[i]._latlng.lat > 41.8) && (total_active_fires[i]._latlng.lng < -82.5)) {
                            active_fires_counter = active_fires_counter + 1;
                        }
                    }

                    else {
                        var marker_inside_polygon1 = state_check.contains(total_active_fires[i].getLatLng());
                        if (marker_inside_polygon1) {
                            active_fires_counter = active_fires_counter + 1;
                        }
                    }
                }

                // protest data
                for (var i = 0; i < protest_icons.length; i++) {
                    if (state_index == 1) {
                        if (protest_icons[i]._latlng.lat > 52) {
                            protest_counter = protest_counter + 1;
                        }
                    }
                    if (state_index == 11) {
                        if ((protest_icons._latlng.lng < -126) && (protest_icons._latlng.lat < 50)) {
                            protest_counter = protest_counter + 1;
                        }
                    }

                    if (state_index == 22) {
                        if ((protest_icons[i]._latlng.lng > -87) && (protest_icons[i]._latlng.lat > 41.8) && (protest_icons[i]._latlng.lng < -82.5)) {
                            protest_counter = protest_counter + 1;
                        }
                    }

                    else {
                        var marker_inside_polygon2 = state_check.contains(protest_icons[i].getLatLng());
                        if (marker_inside_polygon2) {
                            protest_counter = protest_counter + 1;
                        }
                    }
                }

                // update the state information on html when state is clicked
                d3.select(".contained_fires").text(contained_fires_counter);
                d3.select(".active_fires").text(active_fires_counter);
                d3.select(".protests").text(protest_counter);
                d3.select(".state").text(state);
            }
// function to zoom into a state when the user clicks the state
function to zoom into a state when the user clicks the state
function to zoom into a state when the user clicks the state
function zoomToFeature(e) {
                contained_fires_counter = 0;
                active_fires_counter = 0;
                protest_counter = 0;
                myMap.fitBounds(e.target.getBounds());
                state = e.target.feature.properties.name;
                map_component.attr("state_name", state);
                stateUnemployment(state, datetoPass);
                single_state_fxn(state, datetoPass);
                optionChanged(state, datetoPass);
                var state_index = state_dict[state];
                var polygon_coords = statesData.features[state_index].geometry.coordinates;
                var final_coords = [];
                for (i = 0; i < polygon_coords[0].length; i++) {
                    var update_coord = [polygon_coords[0][i][1], polygon_coords[0][i][0]];
                    final_coords.push(update_coord);
                }
                var state_check = L.polygon(final_coords);
                for (var i = 0; i < contained_fires.length; i++) {
                    if (state_index == 1) {
                        if (contained_fires[i]._latlng.lat > 52) {
                            contained_fires_counter = contained_fires_counter + 1;
                        }
                    }
                    if (state_index == 11) {
                        if ((contained_fires._latlng.lng < -126) && (contained_fires._latlng.lat < 50)) {
                            contained_fires_counter = contained_fires_counter + 1;
                        }
                    }
                    if (state_index == 22) {
                        if ((contained_fires[i]._latlng.lng > -87) && (contained_fires[i]._latlng.lat > 41.8) && (contained_fires[i]._latlng.lng < -82.5)) {
                            contained_fires_counter = contained_fires_counter + 1;
                        }
                    }
                    else {
                        var marker_inside_polygon = state_check.contains(contained_fires[i].getLatLng());
                        if (marker_inside_polygon) {
                            contained_fires_counter = contained_fires_counter + 1;
                        }
                    }
                }
                for (var i = 0; i < total_active_fires.length; i++) {
                    if (state_index == 1) {
                        if (total_active_fires[i]._latlng.lat > 52) {
                            active_fires_counter = active_fires_counter + 1;
                        }
                    }
                    if (state_index == 11) {
                        if ((total_active_fires._latlng.lng < -126) && (total_active_fires._latlng.lat < 50)) {
                            active_fires_counter = active_fires_counter + 1;
                        }
                    }
                    if (state_index == 22) {
                        if ((total_active_fires[i]._latlng.lng > -87) && (total_active_fires[i]._latlng.lat > 41.8) && (total_active_fires[i]._latlng.lng < -82.5)) {
                            active_fires_counter = active_fires_counter + 1;
                        }
                    }
                    else {
                        var marker_inside_polygon1 = state_check.contains(total_active_fires[i].getLatLng());
                        if (marker_inside_polygon1) {
                            active_fires_counter = active_fires_counter + 1;
                        }
                    }
                }
                for (var i = 0; i < protest_icons.length; i++) {
                    if (state_index == 1) {
                        if (protest_icons[i]._latlng.lat > 52) {
                            protest_counter = protest_counter + 1;
                        }
                    }
                    if (state_index == 11) {
                        if ((protest_icons._latlng.lng < -126) && (protest_icons._latlng.lat < 50)) {
                            protest_counter = protest_counter + 1;
                        }
                    }
                    if (state_index == 22) {
                        if ((protest_icons[i]._latlng.lng > -87) && (protest_icons[i]._latlng.lat > 41.8) && (protest_icons[i]._latlng.lng < -82.5)) {
                            protest_counter = protest_counter + 1;
                        }
                    }
                    else {
                        var marker_inside_polygon2 = state_check.contains(protest_icons[i].getLatLng());
                        if (marker_inside_polygon2) {
                            protest_counter = protest_counter + 1;
                        }
                    }
                }
                d3.select(".contained_fires").text(contained_fires_counter);
                d3.select(".active_fires").text(active_fires_counter);
                d3.select(".protests").text(protest_counter);
                d3.select(".state").text(state);
            }
function zoomToFeature ( e ) { contained_fires_counter = 0 ; active_fires_counter = 0 ; protest_counter = 0 ; myMap . fitBounds ( e . target . getBounds ( ) ) ; state = e . target . feature . properties . name ; map_component . attr ( "state_name" , state ) ; stateUnemployment ( state , datetoPass ) ; single_state_fxn ( state , datetoPass ) ; optionChanged ( state , datetoPass ) ; var state_index = state_dict [ state ] ; var polygon_coords = statesData . features [ state_index ] . geometry . coordinates ; var final_coords = [ ] ; for ( i = 0 ; i < polygon_coords [ 0 ] . length ; i ++ ) { var update_coord = [ polygon_coords [ 0 ] [ i ] [ 1 ] , polygon_coords [ 0 ] [ i ] [ 0 ] ] ; final_coords . push ( update_coord ) ; } var state_check = L . polygon ( final_coords ) ; for ( var i = 0 ; i < contained_fires . length ; i ++ ) { if ( state_index == 1 ) { if ( contained_fires [ i ] . _latlng . lat > 52 ) { contained_fires_counter = contained_fires_counter + 1 ; } } if ( state_index == 11 ) { if ( ( contained_fires . _latlng . lng < - 126 ) && ( contained_fires . _latlng . lat < 50 ) ) { contained_fires_counter = contained_fires_counter + 1 ; } } if ( state_index == 22 ) { if ( ( contained_fires [ i ] . _latlng . lng > - 87 ) && ( contained_fires [ i ] . _latlng . lat > 41.8 ) && ( contained_fires [ i ] . _latlng . lng < - 82.5 ) ) { contained_fires_counter = contained_fires_counter + 1 ; } } else { var marker_inside_polygon = state_check . contains ( contained_fires [ i ] . getLatLng ( ) ) ; if ( marker_inside_polygon ) { contained_fires_counter = contained_fires_counter + 1 ; } } } for ( var i = 0 ; i < total_active_fires . length ; i ++ ) { if ( state_index == 1 ) { if ( total_active_fires [ i ] . _latlng . lat > 52 ) { active_fires_counter = active_fires_counter + 1 ; } } if ( state_index == 11 ) { if ( ( total_active_fires . _latlng . lng < - 126 ) && ( total_active_fires . _latlng . lat < 50 ) ) { active_fires_counter = active_fires_counter + 1 ; } } if ( state_index == 22 ) { if ( ( total_active_fires [ i ] . _latlng . lng > - 87 ) && ( total_active_fires [ i ] . _latlng . lat > 41.8 ) && ( total_active_fires [ i ] . _latlng . lng < - 82.5 ) ) { active_fires_counter = active_fires_counter + 1 ; } } else { var marker_inside_polygon1 = state_check . contains ( total_active_fires [ i ] . getLatLng ( ) ) ; if ( marker_inside_polygon1 ) { active_fires_counter = active_fires_counter + 1 ; } } } for ( var i = 0 ; i < protest_icons . length ; i ++ ) { if ( state_index == 1 ) { if ( protest_icons [ i ] . _latlng . lat > 52 ) { protest_counter = protest_counter + 1 ; } } if ( state_index == 11 ) { if ( ( protest_icons . _latlng . lng < - 126 ) && ( protest_icons . _latlng . lat < 50 ) ) { protest_counter = protest_counter + 1 ; } } if ( state_index == 22 ) { if ( ( protest_icons [ i ] . _latlng . lng > - 87 ) && ( protest_icons [ i ] . _latlng . lat > 41.8 ) && ( protest_icons [ i ] . _latlng . lng < - 82.5 ) ) { protest_counter = protest_counter + 1 ; } } else { var marker_inside_polygon2 = state_check . contains ( protest_icons [ i ] . getLatLng ( ) ) ; if ( marker_inside_polygon2 ) { protest_counter = protest_counter + 1 ; } } } d3 . select ( ".contained_fires" ) . text ( contained_fires_counter ) ; d3 . select ( ".active_fires" ) . text ( active_fires_counter ) ; d3 . select ( ".protests" ) . text ( protest_counter ) ; d3 . select ( ".state" ) . text ( state ) ; }
function to zoom into a state when the user clicks the state
function to zoom into a state when the user clicks the state
// reset counters; // zoom to map // update html state name // call state functions // getting state polygon coordinates using state dictionary // switching lat and long for final coords // find markers within clicked state  // contained fires // special requirements for Alaska (multipolygon) // special requirements for Hawaii (multipolygon) // special requirements for Michigan (multipolygon) // all other states check // active fires // protest data // update the state information on html when state is clicked