OpenLayers: How to detect the map view is completely loaded? - openlayers-3

I'm implementing map exporting functionality using OpenLayers 3.
But there is one problem: one cannot determine whether the map view is completely loaded or a few tiles is missing yet.
It seems there is no such API or event. The close one is tileloadstart - tileloadend pair. But OpenLayers loads tiles asynchronously, and before the tile is actually loading the tileloadstart is not fired - that is, a tile that is queued in the tile queue does not fire the event before actually loading.
Hot can I detect the map view is completely loaded?

postrender event seems to do the trick, like this:
map.once('postrender', function(event) {
doyourmagic();
});
Works at least from OpenLayers 3.8.2. There is fine answer there about the subject.

I eventually implemented the export function successfully. Below is the rough explanation.
Register tileloadstart, tileloadend, tileloaderror event handlers on the ol.sources using ol.source.on(), and start managing the tile load count.
Register postcompose event handlers on the ol.Map using ol.Map.once().
call ol.Map.renderSync(). This triggers the tile loading, so from now if there is no tile loading, it will mean that all tile have been loaded.
On postcompose event handler, capture the map content from event.context using event.context.canvas.toDataURL(), and register postrender function using event.frameState.postRenderFunctions.push() (a bit hacky).
On the registered postrender function, check the tile load count (which can be managed by the tileload* event handlers). If the count is not zero, abandon the captured content. Else, the capture is done.
On tileloadend and tileloaderror, if the tile load count becomes zero, retry from the step 3 above.

Meanwhile, OpenLayers provides a much sought after rendercomplete event which may be handy.

Basically to make sure everything is rendered on your map you need to listen for loadend events for each layer you have on the map. For wms and wfs layers this is clear and I guess you know how to do it.
For the tile layers , check this example here

Related

How can I measure a reaction time?

I'm creating a web game using Ruby on rails. A text or an image appears and the player has to take it or not, and I neeed to measure his reaction time precisely (in milliseconds).
I can't start the timer in the controller method because of the delay between the server and the player.
Is there a way to start the timer when the page has finished loading ? Or is there an other way to do ? I haven't found any solutions..
You can do it in javascript land - save performance.now() in body onLoad or similar ($(function(){ ... }) if you're using jQuery),
For an image - take first measurement in its onload event, because image may be loaded and shown later than just text. Also take into account custom fonts loading that may also delay rendering.
Then on user reaction take second value, difference between these will be in milliseconds.

Detect UI changes

I have a function that continuously takes screenshots of an UI element to then draw it itself. The UI element can change, so I take a screenshot in very short intervals to not have the second drawing lag behind (please don't question this and just assume that redrawing it is the right way. The use case is a bit more complicated).
However, taking the screenshot and invalidating the previous drawing to redraw it is quite an expensive operation, and most often not needed as the UI element doesn't update that often. Is there a way to detect when a UI element changes in such a way that it needs redrawing, including when it happens to one of its subviews? One solution would be to copy the state and the states of all its descendents and then check that, but that doesn't seem like a good solution either. iOS must know internally when it needs to redraw/update the views, is there any way to hook into this? Note that I tagged this UIKit and Core-Animation, I suppose the way to go for this is Core-Animation, but I'm open for a solution that uses either of these.

Rikulo - touchEnd check if ended inside bounds

When "listening" to touchEnd event of a View, how can I determine weather the touch ended inside it's bounds?
in other words, the equivalent of the iOS touchUpInside.
Note-
I'm adding a touchEnd handler and not only on.click because iOS devices have this 300 ms intentional delay and I would like to eliminate it (please point out if there is a better solution to this).
Regarding the event handling, Rikulo UI doesn't handle specially but adding a thin layer on top of what Dart API provides. After all, a view is simply a DIV element with some special attributes.
Here is the list of events we wrapped: Rikulo events. If there is a miss, please let us know (by posting an issue to Github).
Regarding simulation of touchUpInside, this one might help.

created live tile looks corrupt

am creating custom live tiles by updating the text in a 173x173 XAML control, then using writablebitmap.Render to create a JPEG. Finally, create StandardTileData, set the two images, and put them on the correct tile. Works most of the time. Actually it always updates fine. But once in a while when a new tile is created, or deleted, the image is corrupted. The text is all mushed on the left side of the tile and there is no background color.
Any ideas what could be happening? It's not a background task as that is disabled. Something to do with the system scanning the newly created jpegs while I'm trying to set the tile data?
thanks.
found solution here
rendering usercontrol live tile windows phone
Obviously a system bug.
calling UpdateLayout before and after each measure and arrange call

WP 7.1 Live Tiles "Unpinned" listener

I'm playing with live tiles on Mango and it's all nice and all. User can delete secondary tiles and everything, but if the user "unpins" a secondary tile is there a way to know that tile is gone?
I want to persist data about an object when it's pinned. And I want to be able to delete that data when it's unpinned (from the start menu).
Is there something that's fired when a secondary tile tied to your app is unpinned?
There is no event that is fired when the secondary tile is unpinned. However, you can check for your application's active live tiles by querying the ShellTile.ActiveTiles collection. Not knowing your scenario you could run this check during the various application lifecycle events.
There is a decent screen cast on how to update tiles and use secondary tiles over on http://msdev.com as well as a How-To on MSDN. Both of these show examples of using the ShellTile.ActiveTiles API.

Resources