From 847e66e4ab7e74c6ed4aeac4e51f93fa0c902f85 Mon Sep 17 00:00:00 2001
From: Armand Bahi <armand.bahi@veremes.com>
Date: Thu, 8 Nov 2018 09:56:12 +0100
Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20performances?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../javascript/app/vmap/map/mapcompare.js     | 106 ++++++++++++------
 1 file changed, 71 insertions(+), 35 deletions(-)

diff --git a/src/module_vmap/module/javascript/app/vmap/map/mapcompare.js b/src/module_vmap/module/javascript/app/vmap/map/mapcompare.js
index 37bbe8ae..4fdf3a75 100644
--- a/src/module_vmap/module/javascript/app/vmap/map/mapcompare.js
+++ b/src/module_vmap/module/javascript/app/vmap/map/mapcompare.js
@@ -446,6 +446,26 @@ nsVmap.MapCompare.prototype.mapCompareController = function ($scope, $window, $e
      */
     this.duration = 1000;
 
+    /**
+     * Timestamp of the last map center sync
+     */
+    this.lastMapSyncCenter_ = 0;
+
+    /**
+     * Timestamp of the last map compare center sync
+     */
+    this.lastCompareMapSyncCenter_ = 0;
+
+    /**
+     * Timestamp of the last map scale sync
+     */
+    this.lastMapSyncScale_ = 0;
+
+    /**
+     * Timestamp of the last map compare scale sync
+     */
+    this.lastCompareMapSyncScale_ = 0;
+
     /**
      * @type {ol.Map}
      * @private
@@ -547,24 +567,30 @@ nsVmap.MapCompare.prototype.mapCompareController.prototype.startAnimation = func
     this.animationDelay.start();
 };
 
-
 /**
  * Update the map size with animation
  * @returns {undefined}
  */
 nsVmap.MapCompare.prototype.mapCompareController.prototype.synchronizeMap = function () {
     oVmap.log('nsVmap.MapCompare.prototype.mapCompareController.prototype.synchronizeMap');
+
     var this_ = this;
-    // blocage infinite loop
+
+    // Synchro Échelle
     oVmap.getMap().getOLMap().getTargetElement().addEventListener('mouseenter', function(){
-        oVmap.getMap().getOLMap().getView().on("change:resolution", this_.updateCompareScaleMap, this_);
-        this_.map.getView().un("change:resolution", this_.updateScaleMap, this_);
+        oVmap.getMap().getOLMap().on("moveend", this_.updateCompareScaleMap, this_);
+        this_.map.un("moveend", this_.updateScaleMap, this_);
     });
     this_.map.getTargetElement().addEventListener('mouseenter', function(){
-      oVmap.getMap().getOLMap().getView().un("change:resolution", this_.updateCompareScaleMap, this_);
-      this_.map.getView().on("change:resolution", this_.updateScaleMap, this_);
+      oVmap.getMap().getOLMap().un("moveend", this_.updateCompareScaleMap, this_);
+      this_.map.on("moveend", this_.updateScaleMap, this_);
     });
-    // position du curseur sur l'autre carte
+
+    // Synchro centre
+    oVmap.getMap().getOLMap().on("pointerdrag", this_.updateCenterCompareMap, this_);
+    this_.map.on("pointerdrag", this_.updateCenterMap, this_);
+
+    // Synchro curseur sur l'autre carte
     oVmap.getMap().getOLMap().on('pointermove', function(e){
       var coord = e.coordinate;
       //si le composant existe sur l'autre composant on le supprime
@@ -623,50 +649,58 @@ nsVmap.MapCompare.prototype.mapCompareController.prototype.synchronizeMap = func
 
       this_.targetOverlay_.setPosition(convertCoord);
     });
-    // synchro de la carte avec la carte de comparaison
-    oVmap.getMap().getOLMap().on("pointerdrag", this_.updateCenterCompareMap, this_);
-    // synchro de la carte de comapraison avec la carte de base
-    this_.map.on("pointerdrag", this_.updateCenterMap, this_);
 };
+
 /**
  * Update the map extent with animation
  * @returns {undefined}
  */
-nsVmap.MapCompare.prototype.mapCompareController.prototype.updateCompareScaleMap = function(e){
-  var this_ = this
-  this_.updateCenterCompareMap();
-  oVmap.getMapCompare().setScale(oVmap.getMap().getScale());
+nsVmap.MapCompare.prototype.mapCompareController.prototype.updateCompareScaleMap = function(e) { console.log('updateCompareScaleMap');
+    var this_ = this
+    this_.updateCenterCompareMap();
+    oVmap.getMapCompare().setScale(oVmap.getMap().getScale());
+
+    this.lastCompareMapSyncScale_ = Date.now();
 }
+
 /**
  * Update the map extent with animation
  * @returns {undefined}
  */
-nsVmap.MapCompare.prototype.mapCompareController.prototype.updateScaleMap = function(e){
-  var this_ = this
-  this_.updateCenterMap();
-  oVmap.getMap().setScale(oVmap.getMapCompare().getScale())
+nsVmap.MapCompare.prototype.mapCompareController.prototype.updateScaleMap = function(e) { console.log('updateScaleMap');
+    var this_ = this
+    this_.updateCenterMap();
+    oVmap.getMap().setScale(oVmap.getMapCompare().getScale());
+
+    this.lastMapSyncScale_ = Date.now();
 }
+
 /**
- * Update the map extent with animation
- * @returns {undefined}
- */
-nsVmap.MapCompare.prototype.mapCompareController.prototype.updateCenterMap = function(e){
-  var this_ = this
-  // Récupère l'étendue de la carte principale
-  var oldCenter = this_.map.getView().getCenter();
+* Update the map extent with animation
+* @returns {undefined}
+*/
+nsVmap.MapCompare.prototype.mapCompareController.prototype.updateCenterMap = function(e) {
+
+    var this_ = this
+    // Récupère l'étendue de la carte principale
+    var oldCenter = this_.map.getView().getCenter();
 
-  // Récupère l'ancienne et la nouvelle projection
-  var newProjection = oVmap.getMap().getOLMap().getView().getProjection().getCode();
-  var oldProjection = this_.map.getView().getProjection().getCode();
+    // Récupère l'ancienne et la nouvelle projection
+    var newProjection = oVmap.getMap().getOLMap().getView().getProjection().getCode();
+    var oldProjection = this_.map.getView().getProjection().getCode();
 
-  var newCenter = ol.proj.transform(oldCenter, oldProjection, newProjection);
-  oVmap.getMap().getOLMap().getView().setCenter(newCenter);
+    var newCenter = ol.proj.transform(oldCenter, oldProjection, newProjection);
+    oVmap.getMap().getOLMap().getView().setCenter(newCenter);
+
+    this.lastMapSyncCenter_ = Date.now();
 }
+
 /**
- * Update the map extent with animation
- * @returns {undefined}
- */
-nsVmap.MapCompare.prototype.mapCompareController.prototype.updateCenterCompareMap = function(e){
+* Update the map extent with animation
+* @returns {undefined}
+*/
+nsVmap.MapCompare.prototype.mapCompareController.prototype.updateCenterCompareMap = function(e) {
+
     var this_ = this;
     // Récupère l'étendue de la carte principale
     var oldCenter = oVmap.getMap().getOLMap().getView().getCenter();
@@ -677,6 +711,8 @@ nsVmap.MapCompare.prototype.mapCompareController.prototype.updateCenterCompareMa
 
     var newCenter = ol.proj.transform(oldCenter, oldProjection, newProjection);
     this_['map'].getView().setCenter(newCenter);
+
+    this.lastCompareMapSyncCenter_ = Date.now();
 }
 
 /**
-- 
GitLab