diff --git a/src/components/DrawTools.js b/src/components/DrawTools.js index f7b326a6aeaab50a051a167529a55f064c6fd711..352d1df005dc4976fa71da8c822eb9b3535f3038 100644 --- a/src/components/DrawTools.js +++ b/src/components/DrawTools.js @@ -22,7 +22,9 @@ class DrawTools extends Component { //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( + "UserMapille lähetettävä layeri: " + JSON.stringify(geoJSON, null, 4) + ); // printing GeoJSON data of the previous object create // console.log("newGeoJSONAll.length: " + newGeoJSONAll.length); this.props.addToGeojsonLayer(geoJSON); }; diff --git a/src/components/UserMap.js b/src/components/UserMap.js index d777a0726b55aa63f1d405b3d5682e40064480e9..a17894e0503e598a2b7de2ed4b0f815f88837f4d 100644 --- a/src/components/UserMap.js +++ b/src/components/UserMap.js @@ -36,18 +36,21 @@ class UserMap extends Component { this.fetchGeoJSON(); } // Sends the players drawings to the backend (and database) - sendGeoJSON() { + sendGeoJSON(layerToDatabase) { console.log( "Lähetettävät jutut: " + JSON.stringify(this.state.geoJSONLayer) ); - fetch("http://localhost:5000/mapmarkers/insertLocation", { + fetch("http://localhost:5000/mapmarkers/insert-location", { method: "PUT", headers: { Authorization: "Bearer " + sessionStorage.getItem("token"), Accept: "application/json", "Content-Type": "application/json" }, - body: JSON.stringify(this.state.geoJSONLayer) + body: JSON.stringify({ + type: "FeatureCollection", + features: layerToDatabase + }) }); } // Get the drawings from the backend and add them to the state, so they can be drawn @@ -67,11 +70,12 @@ class UserMap extends Component { data.map(item => { newFeatures.push(item.features); }); + console.log("Mapataan featureita: ", newFeatures); this.setState({ geoJSONLayer: { type: "FeatureCollection", - features: newFeatures + features: [...newFeatures] } }); console.log( @@ -130,15 +134,16 @@ class UserMap extends Component { // Function to be passed to DrawTools so it can add geojson data to this components state addToGeojsonLayer(layerToAdd) { - this.setState({ + this.setState(() => ({ geoJSONLayer: { - features: layerToAdd + type: "FeatureCollection", + features: [...this.state.geoJSONLayer.features, layerToAdd] } - }); + })); console.log( "Geojsonlayer state: " + JSON.stringify(this.state.geoJSONLayer) ); - this.sendGeoJSON(); + this.sendGeoJSON(layerToAdd); } render() {