You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!--10. Define color scheme and add it to a general styling function. Place under the creation of the geojson variable-->
84
+
85
+
<script>// <- Don't add
86
+
//Define classification scheme and colors
87
+
functiongetColor(d){
88
+
returnd>=10 ? '#006837' :
89
+
d>=7 ? '#31a354' :
90
+
d>=4 ? '#78c679' :
91
+
d>=1 ? '#c2e699' :
92
+
'#ffffcc';
93
+
}
94
+
95
+
//Style the polygons
96
+
functionstyle(feature){
97
+
return{
98
+
fillColor: getColor(feature.properties.p_hung),
99
+
weight: 1,
100
+
opacity: 1,
101
+
color: '#000',
102
+
fillOpacity: 0.5
103
+
};
104
+
}
105
+
</script><!-- <- Don't add-->
106
+
107
+
108
+
<!--11. Add styling to our geojson layer. This goes in the commented out section of geojson=L.geoJSON...addTo(map); Your updated call for the external geojson should look like this:-->
style: style//<- This is the new line in your geojson variable
115
+
//feature interaction call will go here
116
+
}).addTo(map);
117
+
</script><!-- <- Don't add-->
118
+
119
+
120
+
<!--12. Add mouse interaction. This will highlight the feature your mouse is in and zoom to the feature you click. This goes underneath the style function-->
121
+
<script>// <- Don't add
122
+
//Changes style property for feature when your mouse touches it
123
+
functionhighlightFeature(e){
124
+
varlayer=e.target;
125
+
126
+
layer.setStyle({
127
+
weight: 3,
128
+
color: '#fff',
129
+
fillOpacity: 0.5
130
+
});
131
+
132
+
if(!L.Browser.ie&&!L.Browser.opera){
133
+
layer.bringToFront();
134
+
}
135
+
136
+
// we'll add something here eventually
137
+
}
138
+
139
+
// Resets the style of the highlighted feature after your mouse leaves
140
+
functionresetHighlight(e){
141
+
geojson.resetStyle(e.target);
142
+
// we'll add something here eventually.
143
+
}
144
+
145
+
// Zooms to the feature you click
146
+
functionzoomToFeature(e){
147
+
map.fitBounds(e.target.getBounds());
148
+
}
149
+
150
+
// This pulls the previous 3 functions together. It says "For each particular interaction (mouseover, mouseout, and click, with a feature (a census tract) in a layer (our Lucas Co. census tract geojson), carry out these functions (highlightFeature, resetHighlight, and zoomToFeature)
151
+
functiononEachFeature(feature,layer){
152
+
layer.on({
153
+
mouseover: highlightFeature,
154
+
mouseout: resetHighlight,
155
+
click: zoomToFeature
156
+
});
157
+
}
158
+
</script><!-- <- Don't add-->
159
+
160
+
161
+
<!--13. Associate interaction of onEachFeature function to our geojson. Add one line to our call for the external geojson to complete defining the interaction-->
onEachFeature: onEachFeature//<- This is the new line in your geojson variable
167
+
}).addTo(map);
168
+
</script><!-- <- Don't add-->
169
+
170
+
171
+
<!--14. Create function for generating custom info window with information about a selected tract. Put this right under where we created var geojson-->
172
+
173
+
<script>// <- Don't add
174
+
// Function for the tooltip box
175
+
varinfo=L.control();
176
+
177
+
info.onAdd=function(map){
178
+
this._div=L.DomUtil.create('div','info');// create a div with a class "info"
179
+
this.update();
180
+
returnthis._div;
181
+
};
182
+
183
+
// method that we will use to update the control based on feature properties passed
184
+
info.update=function(props){
185
+
this._div.innerHTML='<h4>% of Population Claiming Hungarian Ancestry</h4>'+(props ?
186
+
'<b>'+props.t_hung+'</b> people claiming Hungarian ancestry.<br />That is '+'<b>'+props.p_hung+'%</b>'+' of the population of Lucas Co. <b>Census Tract '+props.NAME+'</b>.'
187
+
: 'Hover over a state');
188
+
};
189
+
</script><!-- <- Don't add-->
190
+
191
+
192
+
<!--15. We need to associate info with geojson so the we can display a feature's data on on mousein and reset on mouse out. We need to update the highlightFeature and resetHighlight function-->
193
+
194
+
<script>// <- Don't add
195
+
functionhighlightFeature(e){
196
+
varlayer=e.target;
197
+
198
+
layer.setStyle({
199
+
weight: 3,
200
+
color: '#fff',
201
+
fillOpacity: 0.5
202
+
});
203
+
204
+
if(!L.Browser.ie&&!L.Browser.opera){
205
+
layer.bringToFront();// <- Add this
206
+
}
207
+
208
+
info.update(layer.feature.properties);
209
+
}
210
+
211
+
functionresetHighlight(e){
212
+
geojson.resetStyle(e.target);
213
+
info.update();// <- Add this
214
+
}
215
+
</script><!-- <- Don't add-->
216
+
217
+
<!--16. Create styling for the info box. Add this between the <style> tags in the head beneath your css for html, body, and #map-->
0 commit comments