通过 brutile/sharpmap 向地理服务器发送 wms 请求以加载平铺地图 (tiled=true)

sending wms request to geoserver via brutile/sharpmap to load tiled map (tiled=true)

我想在 SharpMap 的 mapbox 中加载分块地图。我有 GeoServer 并向其发送 WMS 请求,但我只收到单个图块地图。 我怎样才能收到多图块地图? 这是我的代码:

    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()

documentation 看来好像支持简单的 WMS 层 - 因此您需要自己处理图块边界的构造并发出多个 WMS 请求以获取图块图像。

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.

这可以使用 SharpMap 的 TileLayerAsync。请参阅 TileLayerAsync here 的示例。您需要指定合适的图块来源。

使用 GeoServer 的 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

也许更好的方法是使用 GeoServer 使用 TMS、WMTS 或 WMS-C 将其发布为适当的图块层。在这种情况下,您需要通过 BruTile 的 HttpTileSource 访问它。

我用这段代码解决了这个问题:

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