title: Leaflet Remove Old/Error Tiles from Offline Map
body: <p>I have a Leaflet map that points to some offline tiles on a local machine. Initially, tiles that aren't found are shown as a grey image:</p>
  
  <p><a href="https://i.stack.imgur.com/djWeF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/djWeF.png" alt="enter image description here"></a></p>
  
  <p>If the user then zooms out, the corresponding tiles will be fetched for the current zoom level as usual. However, when the user zooms back in, the old "zoomed out" tiles persist, so you end up with a blurry image outside the bounds of the current tiles:</p>
  
  <p><a href="https://i.stack.imgur.com/F90Id.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F90Id.jpg" alt="enter image description here"></a></p>
  
  <p>Is there some way to delete these tiles or just not load tiles for which there is no data in the first place?</p>
  
  <p>Here's what I currently have:</p>
  
  <pre><code>L.tileLayer("offline_map/{z}/{x}/{y}.png",{
    maxZoom: 18,
    minZoom: 3,
  }).addTo(map);
  
  L.TileLayer.include({
      _tileOnError: function (done, tile, e) {
        map.removeLayer(tile);
      } 
  });
  </code></pre>