Widget showing weather radar image

Former Member
Former Member
I'd like to write a simple widget that uses the Communications API makeImageRequest() to access a radar image of Switzerland (in my case, other countries may follow).

Did anybody get makeImageRequest() to execute properly and without errors? Would anybody mind posting an example here, and advise where to call it?

class SwissRadarView extends Ui.View {

var bitmap = null;

// .... deleted stuff here

//! Restore the state of the app and prepare the view to be shown
function onShow() {
var url = "meteo.search.ch/.../meteomap_outline.png";
Comm.makeImageRequest(url, {}, method(:onReceive));
}

//! Update the view
function onUpdate(dc) {
// Call the parent onUpdate function to redraw the layout

View.onUpdate(dc);
if (bitmap != null) {
bitmap.draw(dc);
}

}


function onReceive(responseCode, data) {
Sys.println(responseCode);
if (data != null) {
bitmap = data;
Ui.requestUpdate();
}
}
  • Please post your code snippets inside tags. It maintains whitespace, which makes your code much easier to read.
  • Former Member
    Former Member
    Please post your code snippets inside tags. It maintains whitespace, which makes your code much easier to read.


    Done. Any further comments?
  • I don't really have anything to add. I have no experience with makeImageRequest() at this point. I'm not sure if the functionality is available on any devices, how well it works, or best practices.

    I can say that I would probably avoid putting the call to makeImageRequest() in onShow() since something as simple as showing a menu can cause the system to initiate another download. Assuming you're going to have a menu, I'd add some checks to avoid requesting data if the current image is relatively recent.

    I'd probably go a little crazy after that. I'd think about some sort of logic to prevent more than one simultaneous request, and I'd do something to ensure that I don't get new data unless the current image is sufficiently old. If there were a way to cache a bitmap locally, I'd probably throw that in (nobody likes waiting for a page load).

    I think the bigger question is to ask what do you want your widget to do. How do you plan to make it responsive when most of the data you are displaying is pulled down from the internet via a very slow data link?
  • Former Member
    Former Member
    Hi, I am also trying makeImageRequest. I have switched the image from PNG to BITMAP. But I am having problem assigning the bitmap data on the callback method.
    The responseCode shows: Bitmap 256 x 37888 but the data is null.

    Not sure how can I create the bitmap objection or assign/store the bitmap data anywhere so that it can be drawn.

    Can anyone who managed to get this done advise? Or is sdk1.1.1 still not ready for this method?
  • Former Member
    Former Member
    Hey guys,

    Sorry this went so long without a response. the makeImageRequest API is not functional in SDK 1.1.1. We are still working on completing development for this API, and plan to enable it in a future SDK release.
  • Former Member
    Former Member
    Hey guys,

    Sorry this went so long without a response. the makeImageRequest API is not functional in SDK 1.1.1. We are still working on completing development for this API, and plan to enable it in a future SDK release.


    Hi Brian, I presume it's not yet updated for the SDK 1.1.2?
  • Former Member
    Former Member
    It is not. I don't expect this to be updated in a 1.1.x SDK.
  • makeImageRequest() is still in the programmers guide

    There's still documentation showing makeImageRequest() in the 1.1.3 programmers guide on page 61. I wish it hadn't taken me three days to find this thread.