Select to view content in your preferred language

How would you debounce the response of a timeslider?

508
2
Jump to solution
01-11-2024 02:01 PM
Josh-R
by
New Contributor III

Currently, when you move the timeslider reactiveutils.watch()  picks up every individual movement (e.g. it would register every year between 1850 and 1900) along the timeslider. Its potentially too many responses, if you want to do something like setting a definition expression using the slider value. I only want to get the ending time extent once the I've released the mouse button. Thanks!

0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

You could listen to the pointer-up event on the timeSlider div to achieve what you are trying to do. Here is a codepen showing how it is done. https://codepen.io/U_B_U/pen/abMJdaL?editors=1000

The following is the how you can do it. 

 

document.getElementById("timeSlider").addEventListener("pointerup",(event) => {
  console.log("here is your time extent", timeSlider.timeExtent);
});

 

 

You could also debounce when watching timeExtent using  the debounce function technique mentioned in this article: JavaScript Debounce Function (davidwalsh.name)

 

Hope this helps,

-Undral

View solution in original post

2 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

You could listen to the pointer-up event on the timeSlider div to achieve what you are trying to do. Here is a codepen showing how it is done. https://codepen.io/U_B_U/pen/abMJdaL?editors=1000

The following is the how you can do it. 

 

document.getElementById("timeSlider").addEventListener("pointerup",(event) => {
  console.log("here is your time extent", timeSlider.timeExtent);
});

 

 

You could also debounce when watching timeExtent using  the debounce function technique mentioned in this article: JavaScript Debounce Function (davidwalsh.name)

 

Hope this helps,

-Undral

Josh-R
by
New Contributor III

I ended up going with the "pointerup" method. Exactly what I was looking for. Thank you!!

0 Kudos