0

I want to load tiled map in a mapbox of SharpMap. I have GeoServer and send WMS request to that but I receive only single tile map. how can I receive multi-tile map? here is my code:

    Dim wmsUrl As String = "http://192.168.21.202:8080/geoserver/threem/gwc/service/wms?tiled=true&version=1.1.0"
    Dim layWms As New SharpMap.Layers.WmsLayer("threem_zoom", wmsUrl)
    layWms.AddLayer("threem_zoom")
    layWms.SetImageFormat("image/png")
    layWms.TimeOut = 5000
    layWms.SRID = 4326
    layWms.Version = "1.1.0"
    MapBox1.Map.Layers.Add(layWms)
    MapBox1.PanOnClick = True
    MapBox1.Map.ZoomToExtents()
    MapBox1.Refresh()
Ehsan Zand
  • 350
  • 1
  • 15

3 Answers3

1

This is possible using SharpMap's TileLayerAsync. See an sample of TileLayerAsync here. You need to specify a suitable tile source.

With GeoServer's tile=true it looks you still publish it as an ordinary WMS but taking into account label placing. In this case you need to something like this here

Perhaps better is to use GeoServer to publish it as a proper tile layer using TMS, WMTS or WMS-C. In that case you need to access it through BruTile's HttpTileSource.

pauldendulk
  • 1,378
  • 12
  • 23
  • See also this answer on gis stackexchange: http://gis.stackexchange.com/questions/183904/is-there-a-way-to-use-wms-like-a-tiled-map-service-in-sharpmap – pauldendulk Nov 14 '16 at 06:07
  • Thank you @pauldendulk. you are exactly right. I did that with TileLayerAsync and WmscTileSource.CreateFromWmscCapabilties. I will post my code for others. And good point about GeoServer's tile=true. – Ehsan Zand Nov 22 '16 at 09:33
0

From the documentation it looks as if on simple WMS layers are supported - so you would need to handle construction of the tile bounds yourself and make multiple WMS requests to get a tiled image back.

The WMS Layer support is currently pretty basic. You will have to decipher the server capabilities yourself, and specify the nessesary layers and other properties in the resource property.

Ian Turton
  • 10,018
  • 1
  • 28
  • 47
0

I solved this problem with this code:

Try
        form1.Mapbox1.Map.Layers.Clear()
        Dim Map As Map = New Map()
        Dim xmlDoc As New XmlDocument()
        If My.Settings.Cache Then
            xmlDoc.Load("http://" & My.Settings.ServerIP & ":" & My.Settings.ServerPort & "/" & My.Settings.ServerName & "/gwc/service/wms?SERVICE=WMS&VERSION=" & My.Settings.WMSVer & "&REQUEST=getcapabilities&TRANSPARENT=TRUE&TILED=true")
        Else
            xmlDoc.Load("http://" & My.Settings.ServerIP & ":" & My.Settings.ServerPort & "/" & My.Settings.ServerName & "/wms?SERVICE=WMS&VERSION=" & My.Settings.WMSVer & "&REQUEST=getcapabilities&TRANSPARENT=TRUE&TILED=true")
        End If
        Dim xDoc = Program.ConvertToXDocument(xmlDoc)
        Dim source As List(Of ITileSource)
        source = WmscTileSource.CreateFromWmscCapabilties((xDoc))
        Dim tileSource = source.FirstOrDefault(Function(x) x.Schema.Name = My.Settings.WorkSapce & ":" & My.Settings.LayerName)
        Dim tileLayer = New TileAsyncLayer(tileSource, My.Settings.WorkSapce & ":" & My.Settings.LayerName) With {.SRID = My.Settings.SRIDNum}
        tileLayer.OnlyRedrawWhenComplete = True
        form1.Mapbox1.Map.Layers.Add(tileLayer)
        form1.Mapbox1.PanOnClick = True
        Dim env = New Envelope(44.0509701, 25.0652748, 63.3556599, 39.796795)
        form1.Mapbox1.Map.ZoomToBox(env)
        form1.Mapbox1.Map.ZoomToExtents()
        form1.Mapbox1.Map.Center = New Coordinate(53.682362, 32.420654)
        form1.Mapbox1.Refresh()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
Ehsan Zand
  • 350
  • 1
  • 15