Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
chandu
Visitor

Google Maps & Overlays in ROKU

Hi,

I am relatively new to ROKU platform and have an assignment to show google maps and some overlays over the maps. I will need some help in implementing this requirement and any help on this is much appreciated. Here is the requirement:
1. Open static google maps on basis of geo-coordinates of the place selected. This is going to be static map.
2. Get list of overlay images from a server (10 images to be displayed one after other). Each image is high resolution image 1280 * 720 px or more and size of the images ranges from 200 kb to 550 kb (totalling at around 5MB for 10 images).
3. I have implemented a solution after going through various posts on roku forum and referring to roku technical documentation but the implementation is badly hit by performance and freezes the screen or rotates images very slow; giving the end user bad experience of this feature. Here is the sample code:

function main()
m.mapCanvas = createObject("roImageCanvas")
mapPort = CreateObject("roMessagePort")
m.mapCanvas.SetMessagePort(mapPort)
m.mapCanvas.SetRequireAllImagesToDraw(false)
m.mapCanvas.PurgeCachedImages()
m.mapCanvas.AllowUpdates(false)
list = []
list.push({Color:"#b2cffb", CompositionMode:"Source"})
m.mapCanvas.setLayer(0, list)
m.mapCanvas.AllowUpdates(true)
m.mapCanvas.show()
while true
msg = wait(2500, mapPort)
if(type(msg) = "roImageCanvasEvent")
if(msg.isRemoteKeyPressed())
print "Remote Event called."
else if(msg.isScreenClosed())
print "Screen Closed Event called."
end if
else
showOverlay()
end if
end while
end function

Function showOverlay()
m.mapCanvas.AllowUpdates(false)
list = []
overlayURL = Different_Overlay_Url_Comes_Here_Every_Time

list.Push({
url: overlayURL
TargetRect:{x:0, y:0, w:1280, h:720}
})

m.mapCanvas.SetLayer(1, list)
m.mapCanvas.AllowUpdates(true)
End Function


Any help around this or sample code will be greatly appreciated. If I need to use some different control, please provide me sample code if you can.
0 Kudos
3 REPLIES 3
squirreltown
Roku Guru

Re: Google Maps & Overlays in ROKU

Your wait is set to 2500, thats some of your delay problem, make it shorter.
Sure seems like roScreen would be a better way to do this type of thing rather than using imagecanvas.

p.s. If you post code, put it in code brackets, it's easier to read.
Kinetics Screensavers
0 Kudos
chandu
Visitor

Re: Google Maps & Overlays in ROKU

Thank you for the response. I have used roScreen for doing this. Here is the code that I have worked on until now but I face an issue below:


Interface not a member of BrightScript Component (runtime error &hf3) in pkg:/so
urce/HTTPSample.brs(155)
155: m.region.SetWrap(true)

This error comes after I download 10 images and start animating them one after the other. It throws this error after 8 images are displayed. Can you help?



Library "v30/bslCore.brs"
Function main()

black=&hFF'RGBA
m.screen=CreateObject("roScreen")
m.compositor=CreateObject("roCompositor")
m.compositor.SetDrawTo(m.screen, black)
m.http = CreateObject("roUrlTransfer")
m.http.SetMessagePort(CreateObject("roMessagePort"))
getOverlays()
DownloadOverlays()

m.k = 0
m.mylocal= []
showOverlays()

End Function

Function DownloadOverlays()
'm.arr = CreateObject("roAssociativeArray")
m.myarray = []
i=0
'print "**********download url list**********"; m.overlays.response.tiles_overlays
for each uri in m.overlays.response.tiles_overlays
print "****download url**** "; uri.overlay_url
m.myarray[i]= uri.overlay_url
print "**Umesh Array** =" m.myarray[i]
i=i+1


end for


End Function


Function getOverlays()

port = CreateObject("roMessagePort")
m.http.SetMessagePort(port)
'url = "URL_TO_GET_OVERLAYS"

url = "http://data.weathernationtv.com/services/sonyvita/maps/tileoverlays?method_type=2&center_lat=39.7392&center_lng=-104.9847&width=1280&height=720&type_code=radar&zoomlevel=5"
'url = "http://54.241.13.70/services/roku/maps/tileoverlays?method_type=2&center_lat=" + Str(m.lat).trim() +"&center_lng=" + Str(m.lng).trim() +"&width="+(m.mapWidth).toStr()+"&height="+(m.mapHeight).toStr()+"&type_code="+m.selectedOverlay+"&zoomlevel=" + m.zoom.toStr()

print "url=> "; url
m.http.SetUrl(url)
if (m.http.AsyncGetToString())
'**Begin a GET request to a string asynchronously. When the GET completes, an roUrlEvent will be sent to the message port associated with the object

While (true)
msg = wait(0, port)
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
print"**code**"; code

if (code = 200)
m.overlays = parseJSON(msg.GetString())
print "***OVERLAY**"; formatJSON(m.overlays)
exit while
else
print "Error Code: "; code
exit while
end if
end if
end while
end if
End Function
Function showOverlays()


print"store in tmp**************"
for each url in m.myarray
m.http.SetUrl(url)
print url m.k
m.k = m.k+1

index = "tmp:/VeryBigPng"+(m.k).tostr()+".png"
m.mylocal[m.k-1]= index
m.http.AsyncGetToFile(index)
wait(0, m.http.GetPort())
if m.k = 10
m.k =0
Animate()
end If

end for
'm.http.SetUrl(m.myarray[m.k])
'm.k = m.k+1
'index = "tmp:/VeryBigPng"+(m.k).tostr()+".png"
'm.mylocal[m.k-1]= index
'm.http.AsyncGetToFile(index)
'wait(0, m.http.GetPort())
'if m.k = 9
'm.k =0
'Animate()
'end If

'm.bigbm=CreateObject("roBitmap",index)
'm.region=CreateObject("roRegion", m.bigbm, 0, 0, 1280, 1280)
'm.region.SetWrap(true)

'view_sprite=m.compositor.NewSprite(0, 0, m.region)
'm.compositor.draw()

'm.screen.SwapBuffers()
m.msgport = CreateObject("roMessagePort")
m.screen.SetMessagePort(m.msgport)

codes = bslUniversalControlEventCodes()
'm.n = 1
While True

msg=wait(0, m.msgport) ' wait for a button
print "Msg: "; type(msg); " event: "; msg.GetInt()
If type(msg)="roUniversalControlEvent" Then
If msg.GetInt()=codes.BUTTON_UP_PRESSED Then

'm.http.SetUrl(m.myarray[m.k])
'm.k = m.k + 1
showOverlays()

Else If msg.GetInt()=codes.BUTTON_DOWN_PRESSED Then
Zip(m.screen, view_sprite, m.compositor, 0,+4) ' down
Else If msg.GetInt()=codes.BUTTON_RIGHT_PRESSED Then
Zip(m.screen, view_sprite, m.compositor, +4,0) ' right
Else If msg.GetInt()=codes.BUTTON_LEFT_PRESSED Then
Zip(m.screen, view_sprite, m.compositor, -4, 0) ' left
Else If msg.GetInt() = codes.BUTTON_BACK_PRESSED ' back button
Exit While
End If

else
print "image changed"
if(m.index = m.overlays.response.tiles_overlays.count()-1)
m.index = 0
else
m.index = m.index+1
end if

End If

'End If
End While
End Function


Function Animate()
for j=0 to 10 step 1
sleep(2000)
print"under animate***********"
print "url in animate" m.mylocal[j]
m.bigbm=CreateObject("roBitmap",m.mylocal[j])
m.region=CreateObject("roRegion", m.bigbm, 0, 0, 1280, 1280)
m.region.SetWrap(false)

view_sprite=m.compositor.NewSprite(0, 0, m.region)
m.compositor.draw()

m.screen.SwapBuffers()
m.msgport = CreateObject("roMessagePort")
m.screen.SetMessagePort(m.msgport)
end For



End Function

0 Kudos
squirreltown
Roku Guru

Re: Google Maps & Overlays in ROKU

I'm guessing but the error could be saying there isn't a bitmap to wrap because you've run out of memory.
In the code you posted, you never call any bitmaps invalid, and you are creating full-screen bitmaps which run about 3.8mb each, and will fill up the available space(that amount varies from box to box) quickly.
telnet into your box at port 8080. Then run this command : r2d2_bitmaps
It will return a list of all bitmaps currently in the box and also your max available memory.
When using a lot of big images, you probably need to download them to tmp: and then create and invalidate your bitmaps as you go along.
Kinetics Screensavers
0 Kudos