diff --git a/src/components/DrawTools.js b/src/components/DrawTools.js index 87531290abbd352b64efc3836c0dfe0c9cceea06..f7b326a6aeaab50a051a167529a55f064c6fd711 100644 --- a/src/components/DrawTools.js +++ b/src/components/DrawTools.js @@ -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 makeGeoJSON = e => { let geoJSON = e.toGeoJSON(); - let newGeoJSONAll = this.state.geoJSONAll; - newGeoJSONAll.push(geoJSON); - this.setState({ geoJSONAll: newGeoJSONAll }); + //let newGeoJSONAll = this.state.geoJSONAll; + //newGeoJSONAll.push(geoJSON); + //this.setState({ geoJSONAll: newGeoJSONAll }); console.log(JSON.stringify(geoJSON, null, 4)); // printing GeoJSON data of the previous object create - console.log("newGeoJSONAll.length: " + newGeoJSONAll.length); - this.props.addToGeojsonLayer(this.state.geoJSONAll); + // console.log("newGeoJSONAll.length: " + newGeoJSONAll.length); + this.props.addToGeojsonLayer(geoJSON); }; render() { diff --git a/src/components/UserMap.js b/src/components/UserMap.js index 1340fe59dbd11605043ed0dd00c1037503afeb34..d777a0726b55aa63f1d405b3d5682e40064480e9 100644 --- a/src/components/UserMap.js +++ b/src/components/UserMap.js @@ -35,7 +35,7 @@ class UserMap extends Component { }); this.fetchGeoJSON(); } - // Sends the players marker to the backend + // Sends the players drawings to the backend (and database) sendGeoJSON() { console.log( "Lähetettävät jutut: " + JSON.stringify(this.state.geoJSONLayer) @@ -50,7 +50,7 @@ class UserMap extends Component { 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() { fetch("http://localhost:5000/mapmarkers/getall", { method: "GET", @@ -62,12 +62,10 @@ class UserMap extends Component { }) .then(res => res.json()) .then(data => { + console.log(data); let newFeatures = []; data.map(item => { - item.features[0].map(feature => { - newFeatures.push(feature); - }); - return newFeatures; + newFeatures.push(item.features); }); this.setState({ @@ -132,10 +130,11 @@ class UserMap extends Component { // Function to be passed to DrawTools so it can add geojson data to this components state addToGeojsonLayer(layerToAdd) { - let oldFeatures = []; - oldFeatures.push(layerToAdd); - const newFeatures = oldFeatures; - this.setState({ geoJSONLayer: { features: newFeatures } }); + this.setState({ + geoJSONLayer: { + features: layerToAdd + } + }); console.log( "Geojsonlayer state: " + JSON.stringify(this.state.geoJSONLayer) );