Is there an event that is fired when the map is done rendering?

841 views Asked by At

I am looking for an event that is fired on zoomend AND/OR moveend.
Basically I have a popup that needs to happen after either of these events, and that popup depends on queryRenderedFeatures, which can only be queried if they are in the map view.

I am currently using a setTimeout function if there is not zoomend, but this is not ideal.
Yes, I can attach functions after both of these, but this get messy.
I see there is a map.on('data') event, but is there a map.on('data.load') or something similar, like on map.on('style.load')?

What I am wanting is something that is fired after there is no longer any map.on('data') events firing. Maybe this can be done in Javascript with setInterval or something.

Thanks

1

There are 1 answers

3
justswim On

You can bind your query function to map.on('move', function() {}) which will fire continuously as the map is being zoomed or dragged.

In my application, I use map.on('move', function() {}) to get the center lat/lng of the map. So my code roughly looks like this:

setCenter () {
  const center = map.getCenter()
  // render the center coords
}

// later in my code
map.on('move', this.setCenter)

// and when I'm done
map.off('move', this.setCenter)