Skip to content
Snippets Groups Projects
Commit 2772c3da authored by Taneli Riihimäki's avatar Taneli Riihimäki
Browse files

Got rid of the duplicates, still some known bugs (the map clears when drawing...

Got rid of the duplicates, still some known bugs (the map clears when drawing something new, and cant delete drawings from the database for example)
parent 59008528
No related branches found
No related tags found
1 merge request!21Development
...@@ -19,12 +19,12 @@ class DrawTools extends Component { ...@@ -19,12 +19,12 @@ class DrawTools extends Component {
// turn layer to GeoJSON data and add it to an array of all GeoJSON data of the current map // turn layer to GeoJSON data and add it to an array of all GeoJSON data of the current map
makeGeoJSON = e => { makeGeoJSON = e => {
let geoJSON = e.toGeoJSON(); let geoJSON = e.toGeoJSON();
let newGeoJSONAll = this.state.geoJSONAll; //let newGeoJSONAll = this.state.geoJSONAll;
newGeoJSONAll.push(geoJSON); //newGeoJSONAll.push(geoJSON);
this.setState({ geoJSONAll: newGeoJSONAll }); //this.setState({ geoJSONAll: newGeoJSONAll });
console.log(JSON.stringify(geoJSON, null, 4)); // printing GeoJSON data of the previous object create console.log(JSON.stringify(geoJSON, null, 4)); // printing GeoJSON data of the previous object create
console.log("newGeoJSONAll.length: " + newGeoJSONAll.length); // console.log("newGeoJSONAll.length: " + newGeoJSONAll.length);
this.props.addToGeojsonLayer(this.state.geoJSONAll); this.props.addToGeojsonLayer(geoJSON);
}; };
render() { render() {
......
...@@ -35,7 +35,7 @@ class UserMap extends Component { ...@@ -35,7 +35,7 @@ class UserMap extends Component {
}); });
this.fetchGeoJSON(); this.fetchGeoJSON();
} }
// Sends the players marker to the backend // Sends the players drawings to the backend (and database)
sendGeoJSON() { sendGeoJSON() {
console.log( console.log(
"Lähetettävät jutut: " + JSON.stringify(this.state.geoJSONLayer) "Lähetettävät jutut: " + JSON.stringify(this.state.geoJSONLayer)
...@@ -50,7 +50,7 @@ class UserMap extends Component { ...@@ -50,7 +50,7 @@ class UserMap extends Component {
body: JSON.stringify(this.state.geoJSONLayer) body: JSON.stringify(this.state.geoJSONLayer)
}); });
} }
// Mikä vitum readablestream :( // Get the drawings from the backend and add them to the state, so they can be drawn
fetchGeoJSON() { fetchGeoJSON() {
fetch("http://localhost:5000/mapmarkers/getall", { fetch("http://localhost:5000/mapmarkers/getall", {
method: "GET", method: "GET",
...@@ -62,12 +62,10 @@ class UserMap extends Component { ...@@ -62,12 +62,10 @@ class UserMap extends Component {
}) })
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
console.log(data);
let newFeatures = []; let newFeatures = [];
data.map(item => { data.map(item => {
item.features[0].map(feature => { newFeatures.push(item.features);
newFeatures.push(feature);
});
return newFeatures;
}); });
this.setState({ this.setState({
...@@ -132,10 +130,11 @@ class UserMap extends Component { ...@@ -132,10 +130,11 @@ class UserMap extends Component {
// Function to be passed to DrawTools so it can add geojson data to this components state // Function to be passed to DrawTools so it can add geojson data to this components state
addToGeojsonLayer(layerToAdd) { addToGeojsonLayer(layerToAdd) {
let oldFeatures = []; this.setState({
oldFeatures.push(layerToAdd); geoJSONLayer: {
const newFeatures = oldFeatures; features: layerToAdd
this.setState({ geoJSONLayer: { features: newFeatures } }); }
});
console.log( console.log(
"Geojsonlayer state: " + JSON.stringify(this.state.geoJSONLayer) "Geojsonlayer state: " + JSON.stringify(this.state.geoJSONLayer)
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment