Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions src/MapComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,41 @@ class HeatMap extends Component {
}

componentDidMount() {
fetch("https://fastapi-service-34404463322.us-central1.run.app/geojson")
.then((response) => response.json())
.then((data) => {
const jitteredFeatures = this.jitterOverlappingPoints(data.features);
const jitteredData = {
type: "FeatureCollection",
features: jitteredFeatures,
};
this.setState({ geoJsonData: jitteredData });
})
.catch((error) => console.error("Error loading GeoJSON from API:", error));
this.fetchGeoJsonData(); // 🔁 initial load

this.updateInterval = setInterval(() => {
this.fetchGeoJsonData();
}, 30000);
}

componentWillUnmount() {
clearInterval(this.updateInterval); // 🚫 clean up interval when unmounted
}

fetchGeoJsonData = () => {
fetch("https://fastapi-service-34404463322.us-central1.run.app/geojson")
.then((response) => response.json())
.then((data) => {
const jitteredFeatures = this.jitterOverlappingPoints(data.features);
const jitteredData = {
type: "FeatureCollection",
features: jitteredFeatures,
};
this.setState({ geoJsonData: jitteredData });


if (this.state.selectedNews) {
const stillExists = jitteredData.features.find(
(f) => f.properties.link === this.state.selectedNews.properties.link
);
if (!stillExists) {
this.setState({ selectedNews: null, showPopup: false });
}
}
})
.catch((error) => console.error("Error loading GeoJSON from API:", error));
};

jitterOverlappingPoints = (features) => {
const jittered = [];
const seenCoords = new Set();
Expand Down