From 0fa2551f5712392114eaee380e0b92022d380fed Mon Sep 17 00:00:00 2001
From: Jussi Surma-Aho <L4929@student.jamk.fi>
Date: Fri, 28 Jun 2019 08:23:35 +0300
Subject: [PATCH] Can get ids from all edited and deleted elements. Should be
 able to easily send data to back-end now. Waiting for back-end to be ready

---
 src/components/DrawTools.js | 21 ++++++++++++++++-----
 src/components/UserMap.js   |  2 +-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/components/DrawTools.js b/src/components/DrawTools.js
index a0ae6a9..cad46eb 100644
--- a/src/components/DrawTools.js
+++ b/src/components/DrawTools.js
@@ -36,14 +36,23 @@ class DrawTools extends Component {
     // this.props.sendGeoJSON(e.poly);
   };
 
-  _onEditStart = () => {
+  _onEditDeleteStart = () => {
     this.setState({ editModeActive: true });
   };
 
-  _onEditStop = () => {
+  _onEditDeleteStop = () => {
     this.setState({ editModeActive: false });
   };
 
+  _onDeleted = e => {
+    console.log(e.layers._layers);
+    /* to be added once back-end functionality is available
+    for(layer in e.layers._layers) {
+      this.sendGeoJSON(layer.options.id);
+    }
+    */
+  };
+
   shouldComponentUpdate() {
     // disable re-rendering when edit mode is active
     return !this.state.editModeActive;
@@ -92,12 +101,14 @@ class DrawTools extends Component {
         <EditControl
           position="topright"
           onCreated={this._onCreated}
-          onDrawStop={this._onDrawStop}
-          onEditStart={this._onEditStart}
-          onEditStop={this._onEditStop}
+          onEditStart={this._onEditDeleteStart}
+          onEditStop={this._onEditDeleteStop}
           onEditMove={this._onEditMove}
           onEditResize={this._onEditResize}
           onEditVertex={this._onEditVertex}
+          onDeleted={this._onDeleted}
+          onDeleteStart={this._onEditDeleteStart}
+          onDeleteStop={this._onEditDeleteStop}
           draw={{
             circle: {
               repeatMode: true, // allows using the tool again after finishing the previous shape
diff --git a/src/components/UserMap.js b/src/components/UserMap.js
index 33a82de..b79dfc2 100644
--- a/src/components/UserMap.js
+++ b/src/components/UserMap.js
@@ -133,7 +133,7 @@ class UserMap extends Component {
         <ZoomControl position="topright" />
         <DrawTools
           position={this.props.position}
-          addToGeojsonLayer={this.addToGeojsonLayer}
+          sendGeoJSON={this.sendGeoJSON}
           geoJSONLayer={this.state.geoJSONLayer}
         />
         {this.state.ownLat !== null && (
-- 
GitLab