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: 

Map integration in a Roku scenegraph Project

Hi Developer's,
I need some advice and help in Roku scenegraph Project
i need to implement map in my roku app dynamically
is it possible or not ?
i want to show flight departure and arrival position using app according to the airport using map in roku
can any buddy give me you valuable feedback.

Thanks  in Advance 
0 Kudos
3 REPLIES 3
RokuNB
Roku Guru

Re: Map integration in a Roku scenegraph Project

Perhaps using https://sdkdocs.roku.com/display/sdkdoc/Poster ?
multiple ones - one image for the map and others on top of it for say moving airplane and such
0 Kudos
timkolesa
Visitor

Re: Map integration in a Roku scenegraph Project

*note different map servers will require specific parameters passed to them in the http: url
*m.lonDPP# and m.latDPP# are degrees per pixel dependent on the zoom level

main.brs


sub Main()
    showMapScreen()
end sub
sub showMapScreen()
  m.mapScreen=CreateObject("roSGScreen")
  m.port=CreateObject("roMessagePort")
  m.mapScreen.setMessagePort(m.port)
  m.mapScene=m.mapScreen.CreateScene("MapScene")
  m.mapScreen.show()
  while(true)
    msg=wait(0, m.port)
    msgType=type(msg)
    if msgType="roSGScreenEvent"
      if msg.isScreenClosed() then return
    end if
  end while
end sub

mapreader.xml

<?xml version = "1.0" encoding = "utf-8" ?>

<component name = "MapReader" extends = "Task" >

  <interface>
    <field id = "mapURL" type = "uri" />
    <field id = "mapContent" type = "uri" />
  </interface>

  <script type = "text/brightscript" >

    <![CDATA[

    sub init()
      m.top.functionName = "getMap"
    end sub

    sub getMap()
      m.ImgFetcher = CreateObject("roUrlTransfer")
      m.ImgFetcher.SetCertificatesFile("common:/certs/ca-bundle.crt")
      m.ImgFetcher.AddHeader("X-Roku-Reserved-Dev-Id", "")
      m.ImgFetcher.InitClientCertificates()
      m.ImgFetcher.SetUrl(m.top.mapURL)
      m.ImgFetcher.GetToFile("tmp:/dlfile.png")
      m.top.mapContent=m.top.mapURL
      return
    end sub

    ]]>

  </script>

</component>

nationalmap.xml

<?xml version = "1.0" encoding = "utf-8" ?>

<component name="MapScene" extends="Scene">

  <script type="text/brightscript" >

    <![CDATA[

    sub init()

      m.top.backgroundURI = "pkg:/images/bg_hd.jpg"

      m.lonDPP#=.05381945
      m.latDPP#=.04012346
      m.lonCntr#=-95
      m.latCntr#=37
      m.xCntr=640
      m.yCntr=360

      rndPart=stri(rnd(9999999))
      m.mapFileName="map"+right(rndPart,len(rndPart)-1)+".png"

      m.readMapTask = createObject("roSGNode", "MapReader")
      m.readMapTask.observeField("mapContent", "mapShow")
      loadMap()

      m.top.setFocus(true)

    end sub

    sub loadMap()

      labelObject=m.top.findnode("loadingLabel")
      labelObject.text="Loading map ..."


      m.mapURL = "https://basemap.nationalmap.gov/arcgis/services/USGSTopo/MapServer/WMSServer?service=WMS&request=GetMap&version=1.3.0&format=image/png&layers=0&width=1152&height=648&crs=CRS:84&styles=default&"
      lLon#=m.lonCntr#-(m.xCntr*m.lonDPP#)
      rLon#=m.lonCntr#+(m.xCntr*m.lonDPP#)
      tLat#=m.latCntr#-(m.yCntr*m.latDPP#)
      bLat#=m.latCntr#+(m.yCntr*m.latDPP#)
      m.imgURL=m.mapURL+"bbox="+dtstr(lLon#)+","+dtstr(tLat#)+","+dtstr(rLon#)+","+dtstr(bLat#)+"&"
      m.readMapTask.mapURL = m.imgURL
      m.readMapTask.control = "RUN"

    end sub

    sub mapShow()
      m.readMapTask.control = "INIT"
      DeleteFile("tmp:/"+m.mapFileName)
      rndPart=stri(rnd(9999999))
      m.mapFileName="map"+right(rndPart,len(rndPart)-1)+".png"
      MoveFile("tmp:/dlfile.png","tmp:/"+m.mapFileName)
      labelObject=m.top.findnode("loadingLabel")
      labelObject.text=""
      mapObject=m.top.findnode("mapArea")
      mapObject.uri="tmp:/"+m.mapFileName
    end sub

    function dtstr(num#)
        neg=0
        if num#<0
            neg=1
        end if
        absnum#=abs(num#)
        intnum=int(val(str(absnum#)))
        strint=str(intnum)
        rem#=absnum#-intnum
        strrem=str(rem#)
        strdec=right(strrem,len(strrem)-3)
        retval=""
        if neg=1
           retval=retval+"-"
        end if
        retval=retval+right(strint,len(strint)-1)+"."+strdec
        if instr(1,retval,"e")>0
          retval=left(retval,len(retval)-4)
        end if
        return retval
    end function

    ]]>

  </script>

  <children >

    <Poster
      id="mapArea"
      width="1152"
      height="648"
      translation="[64,36]"
      uri=""
    />

    <Label
      id="loadingLabel"
      width = "400"
      height = "30"
      font = "font:LargeBoldSystemFont"
      text = ""
      horizAlign = "left"
      vertAlign = "top"
      translation = "[80,80]"
      color="0x000000FF"
    />

    <Label
      id="creditsLabel"
      width = "1000"
      height = "20"
      font = "font:MediumSystemFont"
      text = "Topo images courtesy of the U.S. Geological Survey."
      horizAlign = "left"
      vertAlign = "top"
      translation = "[80,650]"
      color="0x000000FF"
    />

  </children>

</component>
0 Kudos

Re: Map integration in a Roku scenegraph Project

Thanks for your Valuable feedback Timkolesa  
0 Kudos