Legend with marker icons |
var map = L.map('map', { center: [33.8, -84.4], zoom: 11, layers: [trainLayer, treeLayer] }); var overlayMaps = { "Train": trainLayer, "Tree": treeLayer }; L.control.layers(null, overlayMaps, { collapsed: false }).addTo(map);
Default legend |
var overlayMaps = { "<img src='http://mollietaylor.com/skills/js/leaflet/train.png' height=24>Train": trainLayer, "<img src='http://mollietaylor.com/skills/js/leaflet/arbol.png' height=24>Tree": treeLayer };
It's really that simple! I searched the documentation and the web, and I couldn't figure out how to do this, so I figured I'd just try adding the HTML. Turns out it looks great!
Full code available on CodePen. Map icons by Nicolas Mollet and Axel Rodriguez.