moagrius / TileView

TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.
MIT License
1.46k stars 337 forks source link

TileManager.requestRender() throttling #117

Closed andreasschiestl closed 10 years ago

andreasschiestl commented 10 years ago

I tried to render the tile view while scrolling and zooming as described in the issue https://github.com/moagrius/TileView/issues/115

But the rendering doesn't start until the scrolling/zooming (and therefore the requests to render) stops for at least 250ms, because TileManager.requestRender() deletes all queued requests and create a new 250ms delayed request.

// throttle requests
if ( handler.hasMessages( RENDER_FLAG ) ) {
    handler.removeMessages( RENDER_FLAG );
}
// give it enough buffer that (generally) successive calls will be captured
handler.sendEmptyMessageDelayed( RENDER_FLAG, RENDER_BUFFER );

I changed the code, so that a new request is only created if there is no other request in the queue:

if( !handler.hasMessages( RENDER_FLAG ) ) {
    handler.sendEmptyMessageDelayed( RENDER_FLAG, RENDER_BUFFER );
}
moagrius commented 10 years ago

Sounds reasonable. I'll try to run live and review any possible unintended effects this weekend, but it looks like this might make a good update. It's a small amount of code to change so I don't mind doing it myself, but if you want to be listed as a contributor, feel free to fork, make the change, and issue a pull request.

Thanks for posting.

andreasschiestl commented 10 years ago

Thank you for the merge and thank you for the great widget!