Skip to content

Commit

Permalink
fix: rendering timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
turban committed Dec 4, 2023
1 parent 3ec9a34 commit 5d8ebdf
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,12 @@ export class MapGL extends Evented {

// Remove rendered class if rendering is happening
onRender = () => {
this._addClass(renderedClass)
this._removeClass(renderedClass)

if (this._renderTimeout) {
clearTimeout(this._renderTimeout)
this._renderTimeout = null
}
}

// Add rendered class if map is idle
Expand All @@ -276,7 +281,11 @@ export class MapGL extends Evented {
return
}

this._removeClass(renderedClass)
// Make sure the map stay rendered for at least 500ms
this._renderTimeout = setTimeout(() => {
this._addClass(renderedClass)
this._renderTimeout = null
}, 500)
}

// Set hover state for features
Expand Down Expand Up @@ -479,17 +488,17 @@ export class MapGL extends Evented {
_addClass(className) {
const { classList } = this.getContainer()

if (classList.contains(className)) {
classList.remove(className)
if (!classList.contains(className)) {
classList.add(className)
}
}

// Remove class from map container
_removeClass(className) {
const { classList } = this.getContainer()

if (!classList.contains(className)) {
classList.add(className)
if (classList.contains(className)) {
classList.remove(className)
}
}
}
Expand Down

0 comments on commit 5d8ebdf

Please sign in to comment.