It took two days of reading and researching about what could possibly cause a problem, but I just don't understand.
I have two API's: one from NASA with position of sattelite, and another for a map layer from GIS software. I try to update the map coordinates by fetching current coordinates of sattelite position in space. This will fire every 1 second and it will update the position of the map from the coordinates of the sattelite. However, the state just doesn't update.
Here is the code:
let url = 'http://api.open-notify.org/iss-now.json';
class Basemap extends React.Component {
constructor(props) {
super(props);
this.state = {
center: [31, 13]
};
}
componentDidMount() {
this.getCenter();
this.interval = setInterval(this.getCenter, 2000);
}
getCenter() {
fetch(url)
.then(d => d.json())
.then(d => (d) => {
this.setState({
center: [d.iss_position.latitude, + ', ' +
d.iss_position.longitude]
});
});
}
render() {
return (
<Map style={{ width: '100vw', height: '100vh' }}
mapProperties={{ basemap: 'satellite' }}
viewProperties= { this.state } />
);
}
}
export default Basemap;
I succesfully retrieve the updated coords of the sattelite every second by refiring the fetch function, however the state of the map doesn't change.
What am I possibly missing?!