Я пытаюсь добавить легенду к моей карте, поэтому я использую этот код:
function getColour(d) {
switch (d) {
case 'IPMSAN': return '#00FF00';
case 'PARK': return '#000000';
;
}
};
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
let faultstatus = ['IPMSAN', 'PARK'];
// loop through the status values and generate a label with a coloured square for each value
for (var i = 0; i < faultstatus.length; i++) {
div.innerHTML +=
'<i class="circle" style="background:' + getColour(faultstatus[i]) + '"></i> ' + (faultstatus[i] ? faultstatus[i] + '<br>' : '+');
}
return div;
};
legend.addTo(map);
Как вы можете видеть, я установил цвет следующим образом, но на моей карте я не вижу только цвет "faultstatus". Любая помощь или руководство о том, как я могу его показать?
и это CSS:
.legend {
text-align: left;
line-height: 30px;
color: #555;
}
.legend i {
width: 20px;
height: 30px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
.legend .circle {
border-radius: 50%;
width: 10px;
height: 10px;
margin-top: 8px;
}