Skip to content

Commit bc2f9f4

Browse files
committed
finish leaflet steps
1 parent b82fbf2 commit bc2f9f4

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

maps/steps/lucasCo_hungarian_leaflet-steps.html

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,50 @@
239239
info.addTo(map);
240240
</script> <!-- <- Don't add-->
241241

242-
<!--Legend and we're done!-->
242+
<!--18. Create legend using the colors in our style. The JS also creates a div and adds content to it. Put this in the <script> tags underneath where we created our info box-->
243+
244+
<script> // <- Don't add
245+
// Legend settings
246+
var legend = L.control({position: 'bottomright'});
247+
248+
legend.onAdd = function (map) {
249+
250+
var div = L.DomUtil.create('div', 'info legend'), //creates div and classes 'info' and 'legend'
251+
grades = [0, 1, 4, 7, 10], //class breaks
252+
labels = [];
253+
254+
// loop through our density intervals and generate a label with a colored square for each interval
255+
for (var i = 0; i < grades.length; i++) {
256+
div.innerHTML +=
257+
'<i style="background:' + getColor(grades[i]) + '"></i> ' +
258+
grades[i] + (grades[i + 1] ? '&ndash;' + (grades[i + 1]-0.1) + '<br>' : '+');
259+
}
260+
261+
return div;
262+
};
263+
</script> <!-- <- Don't add-->
264+
265+
266+
<!--19. Style the legend. Add this to the bottom of your <style> tag in the head-->
267+
268+
<style> /* <- Don't add */
269+
.legend {
270+
line-height: 18px;
271+
color: #555;
272+
}
273+
.legend i {
274+
width: 36px;
275+
height: 18px;
276+
float: left;
277+
margin-right: 8px;
278+
opacity: 0.5;
279+
}
280+
</style> <!-- <- Don't add -->
281+
282+
283+
<!--20. Add legend to map. Put this at the end of your <script> tag, but before the final });-->
284+
285+
<script> // <- Don't add
286+
// Add legend to map
287+
legend.addTo(map);
288+
</script> <!-- <- Don't add-->

0 commit comments

Comments
 (0)