I am very new to GEE. After the app is published, I access it through the link and get a flat map centered in the USA without any of the options programmed in the script.
It’s basically a study on 12 points of the NDVI time series from 2020 to 2024. The idea is for the app user to be able to interact with the points and be able to obtain a plot with the time series of the point they click on.
The script does that when I run it, but after publishing, the app offers nothing.
// Cargar el polígono del área de interés y visualizarlo
var campo = ee.FeatureCollection('projects/numeric-dialect-419011/assets/padron_3962_claudia').geometry();
Map.centerObject(campo, 12);
Map.addLayer(campo, {color: 'gray'}, 'Área de interés');
// Definir el rango de fechas y cargar las imágenes de Sentinel-2
var startDate = '2020-01-01';
var endDate = '2024-01-01';
var dataset = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
.filterBounds(campo)
.filterDate(startDate, endDate)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.map(function(image) {
return image.clip(campo);
});
// Calcular y visualizar NDVI
var ndvi = dataset.map(function(image) {
return image.addBands(image.normalizedDifference(['B8', 'B4']).rename('NDVI'));
});
var ndviVis = {min: 0, max: 1, palette: ['blue', 'white', 'green']};
Map.addLayer(ndvi.median().select('NDVI'), ndviVis, 'NDVI'); // Asegurarse de seleccionar solo la banda 'NDVI'
// Visualizar imagen de color verdadero
var trueColorVis = {bands: ['B4', 'B2', 'B3'], max: 4000};
Map.addLayer(dataset.median(), trueColorVis, 'Color Verdadero');
var points = ee.FeatureCollection([
ee.Feature(ee.Geometry.Point([-57.23236811941059,-33.078842641353845]), {name: 'Punto 1'}),
ee.Feature(ee.Geometry.Point([-57.22627414052875,-33.08409259193794]), {name: 'Punto 2'}),
ee.Feature(ee.Geometry.Point([-57.22936404531391,-33.088623119281436]), {name: 'Punto 3'}),
ee.Feature(ee.Geometry.Point([-57.25528491323383,-33.09121188724903]), {name: 'Punto 4'}),
ee.Feature(ee.Geometry.Point([-57.2466160136977,-33.08279811268316]), {name: 'Punto 5'}),
ee.Feature(ee.Geometry.Point([-57.25219500844867,-33.08632192821269]), {name: 'Punto 6'}),
ee.Feature(ee.Geometry.Point([-57.242152817896915,-33.08905458590245]), {name: 'Punto 7'}),
ee.Feature(ee.Geometry.Point([-57.254684098414494,-33.080281015145815]), {name: 'Punto 8'}),
ee.Feature(ee.Geometry.Point([-57.254684098414494,-33.075965823207895]), {name: 'Punto 9'}),
ee.Feature(ee.Geometry.Point([-57.26172221486957,-33.07510275941848]), {name: 'Punto 10'}),
ee.Feature(ee.Geometry.Point([-57.236659653834415,-33.08215086591086]), {name: 'Punto 10'}),
ee.Feature(ee.Geometry.Point([-57.22309840505512,-33.082618322390864]), {name: 'Punto 10'})
]);
var pointStyle = {color: 'red', fillColor: '00000000'};
Map.addLayer(points, pointStyle, 'Puntos de Interés');
// Crear un panel para mostrar gráficos e instrucciones
var panel = ui.Panel({style: {width: '400px', position: 'bottom-left'}});
var introLabel = ui.Label('Haga clic en un punto para ver la serie temporal de NDVI.');
panel.add(introLabel);
ui.root.add(panel);
// Función para mostrar gráficos en el panel al hacer clic en un punto
function showNDVIGraphs(point) {
var pointData = ndvi.filterBounds(point.geometry());
var chart = ui.Chart.image.seriesByRegion(pointData, point, ee.Reducer.mean(), 'NDVI', 10)
.setChartType('LineChart')
.setOptions({
title: 'NDVI Time Series for ' + point.get('name').getInfo(),
vAxis: {title: 'NDVI'},
hAxis: {title: 'Date'},
lineWidth: 1,
colors: ['00FF00']
});
panel.clear();
panel.add(introLabel); // Mantener las instrucciones visibles
panel.add(chart);
}
// Agregar un click listener para detectar cuando se hace clic cerca de un punto
Map.onClick(function(coords) {
var clickPoint = ee.Geometry.Point([coords.lon, coords.lat]);
var buffer = clickPoint.buffer(500); // Ajustar según sea necesario
points.filterBounds(buffer).evaluate(function(result) {
if (result.features.length > 0) {
var feature = ee.Feature(result.features[0]);
showNDVIGraphs(feature);
} else {
panel.clear();
panel.add(introLabel);
panel.add(ui.Label('No se detectaron puntos cercanos.'));
}
});
});
Link: https://code.earthengine.google.com/90675ffa834bbc28a09e740ee0b70177