效果图
![](https://i-blog.csdnimg.cn/blog_migrate/037ae749ee7546cf5496e54c22ac8da0.png)
实现代码
var legend = ui.Panel({
style: {
position: 'bottom-left',
padding: '8px 15px'
}
});
var legendTitle = ui.Label({
value: 'NDVI',
style: {
fontWeight: 'bold',
fontSize: '18px',
margin: '0 0 9px 0',
padding: '0'
}
});
legend.add(legendTitle);
var makeRow = function(color, name) {
var colorBox = ui.Label({
style: {
backgroundColor: '#' + color,
padding: '8px',
margin: '0 0 4px 0'
}
});
var description = ui.Label({
value: name,
style: {margin: '0 0 4px 6px'}
});
return ui.Panel({
widgets: [colorBox, description],
layout: ui.Pan