perliedman / leaflet-control-geocoder

A simple geocoder form to locate places. Easily extended to multiple data providers.
http://www.liedman.net/leaflet-control-geocoder/
BSD 2-Clause "Simplified" License
560 stars 220 forks source link

Disappear polygon in map #337

Open vanithaak opened 1 year ago

vanithaak commented 1 year ago
var geocoder = L.Control.geocoder({
  defaultMarkGeocode: false
})
  .on('markgeocode', function(e) {
    var bbox = e.geocode.bbox;
    var poly = L.polygon([
      bbox.getSouthEast(),
      bbox.getNorthEast(),
      bbox.getNorthWest(),
      bbox.getSouthWest()
    ]).addTo(map);
    map.fitBounds(poly.getBounds());
  })
  .addTo(map);

I used this as mentioned in README file, but I'd like to make the polygon disappear after few seconds. I used setTImeout function here function(e) { and I get an error that it's not able to read e.geocode.bbox.

How can I achieve this?