From eb1594e989b3cec268d48f54cc0eb204a7238721 Mon Sep 17 00:00:00 2001
From: Armand Bahi <armand.bahi@veremes.com>
Date: Tue, 6 Nov 2018 09:45:26 +0100
Subject: [PATCH] Synchronisation

---
 .../javascript/app/vmap/tools/select/select.js  | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/module_vmap/module/javascript/app/vmap/tools/select/select.js b/src/module_vmap/module/javascript/app/vmap/tools/select/select.js
index 50708b52..9c89bc22 100755
--- a/src/module_vmap/module/javascript/app/vmap/tools/select/select.js
+++ b/src/module_vmap/module/javascript/app/vmap/tools/select/select.js
@@ -540,14 +540,25 @@ nsVmap.nsToolsManager.Select.prototype.selectController = function ($scope, $tim
         var aFeatures = evt.features.getArray();
 
         // Évite les superpositions avec les autres couches si besoin
+        var j = 0;
         for (var i = 0; i < aFeatures.length; i++) {
             this_.avoidSuperpositions(aFeatures[i]).then(function(){
+                j++;
+                if (!j < aFeatures.length) {
+                    setTimeout(function () {
+                        this_.putFeaturesOnTheElement(this_.oOverlayFeatures_.getArray());
+                    });
+                }
             });
         }
 
+        // Cas où avoidSuperpositions n'ait pas effectué de callback
         setTimeout(function () {
-            this_.putFeaturesOnTheElement(this_.oOverlayFeatures_.getArray());
-        });
+            if (j === 0) {
+                console.error('avoidSuperpositions never sents callback');
+                this_.putFeaturesOnTheElement(this_.oOverlayFeatures_.getArray());
+            }
+        }, 3000);
     });
 
     /**
@@ -2215,6 +2226,8 @@ nsVmap.nsToolsManager.Select.prototype.selectController.prototype.avoidSuperposi
         this.setDiffGeom_(aSuperpositionBos, olFeature).then(function(olFeature){
             deferred.resolve(olFeature);
         });
+    } else {
+        deferred.resolve(olFeature);
     }
 
     return deferred.promise;
-- 
GitLab