var roi = pie.FeatureCollection('RESDC/WORLD_COUNTRY_BOUNDARY')
.filter(pie.Filter.eq("fcname","中国"));
visroi = {
color: "ff0000ff", fillColor: "00000000", width: 1};
Map.addLayer(roi, visroi, "中国", false);
var chn = roi.getAt(0).geometry();
Map.centerObject(chn, 3);
var visParams = {
min: 0, max: 60,
palette:['000000','4c3300','664401','7f5501','996601','b27702',
'cc8802','e59902','ffad02','ffaf02','ffb102','ffb302','ffb502',
'ffb702','ffb902','ffbb02','ffbd02','ffc002','ffc202','ffc402',
'ffc602','ffc801','ffca01','ffcc01','ffce01','ffd001','ffd201',
'ffd501','ffd701','ffd901','ffdb01','ffdd01','ffdf01','ffe101',
'ffe300','ffe500','ffe700','ffea00','ffec00','ffee00','fff000',
'fff200','fff400','fff600','fff800','fffa00','fffc00','ffff00']};
function calcNT(night, chn){
var result = night.reduceRegion(pie.Reducer.mean(), chn, 1);
return result;
}
var xSeries = [];
var chnNT = [];
for(var i = 2013; i < 2021; i++){
var nightLight = pie.ImageCollection("VIIRS_VCMCFG/NIGHTTIME_LIGHTS")
.filterDate(i + "-01-01", i + "-12-31")
.map(function(image){
return image.select("avg_rad").divide(1000).rename("a_r");})
.mean();
print(String(i),nightLight);
Map.addLayer(nightLight, visParams, String(i), true);
var chnresult = calcNT(nightLight, chn);
xSeries.push(String(i));
chnNT.push(chnresult);
}
Map.playLayersAnimation(xSeries, 2, 100);
var data = {
title: "夜光指数",
colors: [ '#000000','#4c3300','#664401','#7f5501','#996601','#b27702',
'#cc8802','#e59902','#ffad02','#ffaf02','#ffb102','#ffb302','#ffb502',
'#ffb702','#ffb902','#ffbb02','#ffbd02','#ffc002','#ffc202','#ffc402',
'#ffc602','#ffc801','#ffca01','#ffcc01','#ffce01','#ffd001','#ffd201',
'#ffd501','#ffd701','#ffd901','#ffdb01','#ffdd01','#ffdf01','#ffe101',
'#ffe300','#ffe500','#ffe700','#ffea00','#ffec00','#ffee00','#fff000',
'#fff200','#fff400','#fff600','#fff800','#fffa00','#fffc00','#ffff00'],
step: 30
};
var style = {
top: "80%",
left: "40%",
height: "70px",
width: "350px"
};
var legend = ui.Legend(data. style);
Map.addUI(legend);