*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>