Map Idle Event
Using deck.gl with MapBox offers the ability to listen to an idle event
map.once('idle', function() {…})
I’m not aware, looking at the documentation of deck.gl, if and what event to listen for without the usage of MapBox. Using e.g. time out is error prone and obviously not the way to go. I tried to use a combination of onLoad onViewportStateChange and render but with no success.
Any idea on how to achieve the the result of MapBoxs function with pure deck.gl?
I needed this for a project recently. I ended up using a custom react hook that leverages createActivityDetector package. You may need to change the options to suit your needs.
import { useState, useEffect } from "react";
import createActivityDetector from "activity-detector";
export default function useIdle(options) {
const [isIdle, setIsIdle] = useState(false);
useEffect(() => {
const activityDetector = createActivityDetector(options);
activityDetector.on("idle", () => setIsIdle(true));
activityDetector.on("active", () => setIsIdle(false));
return () => activityDetector.stop();
}, []);
return isIdle;
}
Hej @mayteio thanks for the tipp, not exactly what I’m looking for though. This detects if a user is interacting with the page, I want to know when it is safe to assume that the map has rendered everything.
@cschlueter Just to clarify, do you want to know if the map has finished loading, or if deck.gl has rendered?
For the former, you have to listen to mapbox's own event. For the latter, you can use Deck's onAfterRender prop.
Hi @Pessimistress,
I think onAfterRender would be the one! I don’t use MapBox integration into Deck.gl at all, so the method above which I was referring to isn’t available to me, even though with MapBox it does exactly what I want.
Do you have any documentation hint for onAfterRender?
I did search the github repo: https://github.com/uber/deck.gl/search?q=onafterrender&unscoped_q=onafterrender
But to no avail, the function signature is unclear to me. The function itself seems to be indeed called like three times during my rendering example, so it’s going into the right direction.
Any pointer on how to configure the callback of onAfterRender? It seems to pass back the 2d rendering context, but that doesn’t help me figuring out if layers are finished rendering or not?
onAfterRender: () => {
testCase.onAfterRender({
deck,
layers: deck.layerManager.getLayers(),
done
});
}
This seems to be what I want, but I have no clue how to get it :)
The callback is only called after all layers are rendered. What do you need to access in your test case?
My mistake, it is actually sufficient for my use-case to "just know" that the layers have finished rendering. I just pass on the information and go from there. Thanks for you help.
Closing this issue, for future reference onAfterRender documentation can be found here: https://deck.gl/#/documentation/deckgl-api-reference/deck?section=onafterrender-function-optional-