From b90131de20929d57436ed78ef33331bac4c87e21 Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Thu, 26 Oct 2023 15:19:32 +0200
Subject: [PATCH] Gridmap: Simplify popup hiding before (re)creating

---
 spatial/static/spatial/js/slidingMap.js | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/spatial/static/spatial/js/slidingMap.js b/spatial/static/spatial/js/slidingMap.js
index 83b0f481..58186d06 100644
--- a/spatial/static/spatial/js/slidingMap.js
+++ b/spatial/static/spatial/js/slidingMap.js
@@ -187,6 +187,9 @@ function switchParameter(selectedParameter)
 
 async function displayQueryResult(evt)
 {
+    let popupElement = popup.getElement();
+    $(popupElement).popover('destroy');
+    
     let coordinate = proj4(map.getView().getProjection().getCode(), 'EPSG:25833', evt.coordinate)
     let currentWMSLayer = WMSLayersDateBucket[currentTimestamp][currentParameter];
     let currentLayer = getCurrentVisibleOLLayer();
@@ -205,8 +208,6 @@ async function displayQueryResult(evt)
     // User clicked outside of layer extent
     if(responseXML.trim().length == 0)
     {
-        let popupElement = popup.getElement();
-        $(popupElement).popover('destroy');
         return;
     }
 
@@ -218,8 +219,6 @@ async function displayQueryResult(evt)
         let warningStatus = xmlDOM.getElementsByTagName("warningStatus").length == 1 ? xmlDOM.getElementsByTagName("warningStatus")[0].getAttribute("value") : null;
         if(warningStatus == -1)
         {
-            let popupElement = popup.getElement();
-            $(popupElement).popover('destroy');
             return;
         }
         let parameters = {};
@@ -247,8 +246,6 @@ async function displayQueryResult(evt)
 
         // Render results
         // TODO: Handle click outside layer
-        let popupElement = popup.getElement();
-        $(popupElement).popover('destroy');
         popup.setPosition(evt.coordinate);
         $(popupElement).popover({
             'placement': 'top',
-- 
GitLab