title: leaflet remove previous polyline
body: <p>I have a function that will recreate polyline on click event. it works but the refresh layer still got the previous polyline. only when I zoom the map the previous polyline is gone.</p>
  
  <p>My code.</p>
  
  <pre><code>function buildHotline(response) {
      //clearMap();
      //clear_polyline();
      document.getElementById('mapid').innerHTML = "&lt;div id='map' style='width: 100%; height: 100%;'&gt;&lt;/div&gt;";
      //document.getElementById('map').innerHTML = "&lt;div id='mapid' style='width: 100%; height: 100%;'&gt;&lt;/div&gt;";
      var tiles = L.tileLayer('http://{s}.tile.openstreetmap.se/hydda/full/{z}/{x}/{y}.png', {
      attribution: 'Tiles courtesy of &lt;a href="http://openstreetmap.se/" target="_blank"&gt;OpenStreetMap Sweden&lt;/a&gt; &amp;mdash; Map data &amp;copy; &lt;a href="http://www.openstreetmap.org/copyright"&gt;OpenStreetMap&lt;/a&gt;'});
  
  
      var map = new L.map('map', {
          layers: [tiles],
          scrollWheelZoom: true,
          dragging: true,
          tap: false
      });
  
  
      var hotlineLayer = L.hotline(response, {
          min: 0,
          max: 120,
          palette: {
              0.0: '#3ebcef',
              0.5: '#78b3d3',
              1.0: '#000203'
          },
          weight: 5,
          outlineColor: '#000203',
          outlineWidth: 1
      });
  
  
  
      //clear first
      clear_polyline();
  
      bounds = hotlineLayer.getBounds();
      map.fitBounds(bounds);
  
  
  
      hotlineLayer.addTo(map);
  
  
      function clear_polyline() {
          try {
              // statements
              setTimeout(function(){ map.invalidateSize()}, 400);
              //alert("erase line");
              map.removeLayer( hotlineLayer );
  
          } catch(e) {
              // statements
              console.log(e);
          }
  
      }
  
  }
  </code></pre>
  
  <p>where do I have to put the <code>clear_polyline</code> to clear it first before the new polyline is created. Thanks</p>