From a6cc19316a191651701d0d9c173ae1849060be57 Mon Sep 17 00:00:00 2001
From: BrittainJackson7 <brittainjackson7@gmail.com>
Date: Fri, 29 Sep 2023 13:47:04 -0700
Subject: [PATCH] remove symbols on dataset switch Fixes #20

---
 src/js/AstroMap.js |  2 +-
 src/leaflet.sld.js | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/js/AstroMap.js b/src/js/AstroMap.js
index b51779c40..7c24d792f 100644
--- a/src/js/AstroMap.js
+++ b/src/js/AstroMap.js
@@ -229,7 +229,6 @@ export default L.Map.AstroMap = L.Map.extend({
           this.SLDStyler.symbolize_with_icons(this._geoLayers[i], this);
         } else {
           this._geoLayers[i].removeFrom(this);
-          this.SLDStyler.remove_symbols();
         }
       }
     }
@@ -240,6 +239,7 @@ export default L.Map.AstroMap = L.Map.extend({
       if(this._geoLayers[i] && this._geoLayers[i].options.id === collectionId){
         let wrappedFeatures = this.cloneWestEast(myFeatures);
         this._geoLayers[i].addData(wrappedFeatures);
+
         this.SLDStyler.symbolize_with_icons(this._geoLayers[i], this);
       }
     }
diff --git a/src/leaflet.sld.js b/src/leaflet.sld.js
index 41388107d..cebc99c08 100644
--- a/src/leaflet.sld.js
+++ b/src/leaflet.sld.js
@@ -125,6 +125,7 @@ L.SLDStyler = L.Class.extend({
       }
    },
    initialize: function(sldStringOrXml, options) {
+      this.symbols = [];
       L.Util.setOptions(this, options);
       if (sldStringOrXml !== undefined) {
          this.featureTypeStylesNameMap = {};
@@ -522,15 +523,14 @@ L.SLDStyler = L.Class.extend({
       svgElement.innerHTML = symbol;
       svgElementBounds = [ [ point.y - 0.05, point.x + 0.05 ], [ point.y , point.x ] ];
       
-      L.svgOverlay(svgElement, svgElementBounds).addTo(map);
+      const addedSymbol = L.svgOverlay(svgElement, svgElementBounds).addTo(map);
+      this.symbols.push(addedSymbol);
    },
-   remove_symbols: function(){
-      let element = null
-      // for (var i in svg_ids)
-      // {
-      //    element = document.getElementById(i);
-      //    element.remove();
-      // }
+   remove_symbols: function(map){
+      for (var i = 0; i < this.symbols.length; i++) {
+         this.symbols[i].removeFrom(map);
+      }
+      this.symbols = [];
    }
 });
 
-- 
GitLab