我尝试在地图中添加图例,因此我使用此代码:
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;
}