Skip to content

Commit 4dfe729

Browse files
committed
Use key to avoid data going out of date issues, with the first feature in the GeoJSON' intensity used as the key.
1 parent 6727688 commit 4dfe729

File tree

3 files changed

+3
-65
lines changed

3 files changed

+3
-65
lines changed

frontend/src/component/Mapper/ClimateMap.tsx

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -457,66 +457,6 @@ const ClimateMap = ({ onMount = () => true }) => {
457457
[],
458458
);
459459

460-
// Calculate average temperature for a region based on points within it
461-
const calculateRegionTemperature = useCallback(
462-
(
463-
regionFeature: GeoJSON.Feature,
464-
temperatureData: TemperatureDataPoint[],
465-
) => {
466-
const regionName =
467-
regionFeature.properties?.name ||
468-
regionFeature.properties?.name_en ||
469-
regionFeature.properties?.admin ||
470-
"Unknown";
471-
472-
const pointsInRegion = temperatureData.filter((point) => {
473-
// Use turf.js for accurate point-in-polygon checking
474-
const isInside = isPointInRegion(
475-
point.lat,
476-
point.lng,
477-
regionFeature.geometry,
478-
);
479-
return isInside;
480-
});
481-
482-
console.log(
483-
`Region ${regionName}: found ${pointsInRegion.length} points within region`,
484-
);
485-
486-
// Debug: For first few regions, test with some sample points
487-
if (temperatureData.length > 0) {
488-
const samplePoint = temperatureData[0];
489-
const testResult = isPointInRegion(
490-
samplePoint.lat,
491-
samplePoint.lng,
492-
regionFeature.geometry,
493-
);
494-
console.log(
495-
`Region ${regionName}: testing sample point (${samplePoint.lat}, ${samplePoint.lng}) - inside: ${testResult}`,
496-
);
497-
}
498-
499-
if (pointsInRegion.length === 0) {
500-
// Fallback: find nearest point
501-
const nearestPoint = findNearestPoint(regionFeature, temperatureData);
502-
console.log(
503-
`Region ${regionName}: using nearest point fallback, temp: ${nearestPoint ? nearestPoint.temperature : "null"}`,
504-
);
505-
return nearestPoint ? nearestPoint.temperature : null;
506-
}
507-
508-
// Calculate average temperature
509-
const avgTemp =
510-
pointsInRegion.reduce((sum, point) => sum + point.temperature, 0) /
511-
pointsInRegion.length;
512-
console.log(
513-
`Region ${regionName}: calculated average temp: ${avgTemp} from ${pointsInRegion.length} points`,
514-
);
515-
return avgTemp;
516-
},
517-
[],
518-
);
519-
520460
// Calculate temperature and coordinate info for a region
521461
const calculateRegionTemperatureWithCoords = useCallback(
522462
(

frontend/src/component/Mapper/InterfaceInputs/ModelSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface YamlData {
2626

2727
const parseYamlText = (yamlText: string): YamlData => {
2828
const lines = yamlText.split("\n");
29-
const result: Record<string, any> = {};
29+
const result: Record<string, string | string[]> = {};
3030
let currentKey = "";
3131
let isInArray = false;
3232
let arrayItems: string[] = [];

frontend/src/component/Mapper/utilities/GridToNutsConverter.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ export class GridToNutsConverter {
9090
return index;
9191
}
9292

93-
private getPolygonBounds(
94-
polygon: turf.Feature<turf.Polygon | turf.MultiPolygon>,
95-
): {
93+
private getPolygonBounds(polygon: GeoJSONFeature<Polygon | MultiPolygon>): {
9694
minLat: number;
9795
maxLat: number;
9896
minLng: number;
@@ -209,7 +207,7 @@ export class GridToNutsConverter {
209207

210208
private createPolygonFromFeature(
211209
feature: GeoJSONFeature,
212-
): turf.Feature<turf.Polygon | turf.MultiPolygon> | null {
210+
): GeoJSONFeature<Polygon | MultiPolygon> | null {
213211
try {
214212
if (feature.geometry?.type === "Polygon") {
215213
return turf.polygon((feature.geometry as Polygon).coordinates);

0 commit comments

Comments
 (0)