Android Question GoogleMapsExtras How to connect to WMS?

gvoulg

Member
Licensed User
Longtime User
Does anybody have success initializing a CustomTileProvider with a WMS server?
Thanks in advance for any code snippet
George
 

M6SOFT

Member
Licensed User
Longtime User
You need to build correct WMS url:
B4X:
http://WMSServer.com?VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=xxx&SRS=EPSG:4326&BBOX=yyy&WIDTH=256&HEIGHT=256&TRANSPARENT=True&FORMAT=image/png8&styles=
Key part is determine layers (xxx) (by hardcode in adress or let the user make choice) and BBOX (yyy).
BBOX is calculated based on TileX, TileY and Zoom (lon&","&lat1&","&lon1&","&lat):
B4X:
    Dim n As Double
    Dim nn As Double
    Dim lat As Double
    Dim lon As Double
    Dim lat1 As Double
    Dim lon1 As Double
 
    n = Power(2, Zoom)
    nn=cPI * (1 - 2 * TileY / n)
    lat=180/cPI*(ATan((Power(cE,nn)-Power(cE, (-nn)))/2))
    nn=cPI * (1 - 2 * (TileY+1) / n)
    lat1=180/cPI*(ATan((Power(cE,nn)-Power(cE, (-nn)))/2))
    lon=TileX / n * 360.0 - 180.0
    lon1=(TileX+1) / n * 360.0 - 180.0
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
I think GoogleMapsExtras would need to be updated to pass the WMS tile URL.

@gvoulg
Can you post an example tile request URL?
Omit the domain if you want to but let me see the various parameters you need to pass to the tile server.

Martin.
 
Upvote 0

gvoulg

Member
Licensed User
Longtime User
Thanks
I will give it a try and see if i can do it successfully in my program

ps.
Start testing and 2 questions
1.The code that M6SOFT wrote goes in the GetTileUrl sub?
2.How we initialize the CustomUrlTileProvider
CustomUrlTileProvider2.Initialize("",256,256) or something else in event name
 
Last edited:
Upvote 0

gvoulg

Member
Licensed User
Longtime User
Thanks M6SOFT
I can construct now the url and it is the write one because when I paste one of them (from the logs) in mozilla I can see the right tile on PC screen.
But I cannot see the tiles on Tablet.
Anyway I know I am close now:).
Maybe something with other parameters of TileOverlayOptions?
 
Upvote 0

gvoulg

Member
Licensed User
Longtime User
I think GoogleMapsExtras would need to be updated to pass the WMS tile URL.

@gvoulg
Can you post an example tile request URL?
Omit the domain if you want to but let me see the various parameters you need to pass to the tile server.

Martin.
Hi Martin
That's what I am trying.
B4X:
 Dim CustomUrlTileProvider2 As CustomUrlTileProvider
'after that inside Mapfragment_ready
     Dim TileOverlayOptions2 As TileOverlayOptions 
     CustomUrlTileProvider2.Initialize("WMS",256,256)
     
     TileOverlayOptions2.Initialize
     TileOverlayOptions2.SetTileProvider(CustomUrlTileProvider2)
     TileOverlay2=GoogleMapsExtras1.AddTileOverlay(GoogleMap1, TileOverlayOptions2)
''and the sub that M6SOFT wrote is something like this
 
Sub WMS_GetTileURL(TileX As Int, TileY As Int, Zoom As Int) As String
  Dim baseURL,format1,layers,styles,srs  As String
  Dim url As String
  Dim n As Double
  Dim nn1 As Double
  Dim lat As Double
  Dim lon As Double
  Dim lat1 As Double
  Dim lon1 As Double
  Dim bound As String
  n = Power(2, Zoom)
  nn1=cPI * (1 - 2 * TileY / n)
  lat=180/cPI*(ATan((Power(cE,nn1)-Power(cE, (-nn1)))/2))
  nn1=cPI * (1 - 2 * (TileY+1) / n)
  lat1=180/cPI*(ATan((Power(cE,nn1)-Power(cE, (-nn1)))/2))
  lon=TileX / n * 360.0 - 180.0
  lon1=(TileX+1) / n * 360.0 - 180.0
 bound=lon & "," & lat1 & "," & lon1 & "," & lat
 baseURL = "http://gis.ktimanet.gr/wms/wmsopen/wmsserver.aspx?"
 format1 = "image/png" '; //Type of image returned
 layers = "THE BASEMAP OF KTIMATOLOGIO" '; //WMS layers To display
 styles = ""'; //styles To use For the layers
 srs = "EPSG:4326"'; //Projection To display.
 url = baseURL & "version=1.1.1&SERVICE=WMS&request=GetMap&Layers=" & layers & "&Styles=" & styles & "&SRS=" & srs & "&BBOX=" & bound & "&width=256&height=256&format=" & format1 & "&transparent=true"
 Log (url)
Return url
End Sub
the wms_gettileurl function is called and the url that is created is proper but I dont see any tiles on screen.
 
Upvote 0

M6SOFT

Member
Licensed User
Longtime User
Maybe ZIndex?
Try to add:
TileOverlayOptions2.SetZIndex(2) after TileOverlayOptions2.SetTileProvider
and maybe:
TileOverlayOptions2.SetVisible(true)
 
Upvote 0

gvoulg

Member
Licensed User
Longtime User
Are you encoding those spaces in the URL?
As I wrote in previous message if I use the url in Mozilla I can upload and see the tile.
I take the string from the logs and its acceptable.
If you want to try with this wms server (its the greek cadastral wms server with orthofotos of Greece) you have to zoom somewhere in Greece
(try lat:38.06414 , lon:23.691754)


Maybe ZIndex?
Try to add:
TileOverlayOptions2.SetZIndex(2) after TileOverlayOptions2.SetTileProvider
and maybe:
TileOverlayOptions2.SetVisible(true)
I have these statements in my code .
I load a mapsforge layer too.You think this could be the problem?
Works OK using tiles from mbtiles format (with mapsforge on another layer) .

ps
I run in release mode because we cannot see tiles in dedug
 
Upvote 0
Top