Hi,
For my old 5.5 projects I developed a code chunk to generate a PDF output of a map window. It works by traversing the visible map layers, and drawing them to a PDF canvas when relevant, and it worked without hickups (still does).
I’m now trying to employ the same code in 9.0, but have problems getting the wms layers to display in the pdf. They work fine in the map window.
Basically what I’m doing is trying to do is create a new WmsLayer, and transferring all parameters from the map’s WmsOverlay.
Are there any caveats wrt. WmsLayer I should know when comparing versions 5.5 and 9.0 ?
Cheers
Lars
Converting WmsOverlay to WmsLayer
I should add, that the PDF is generated fine, and the map is included. But the map just has no wms backdrop.
Hi,
Here’s a trimmed down version of the conversion taking place:
If
TypeOf
ovl
Is
WmsOverlay
Then
Dim
wmsovl =
DirectCast
(ovl, WmsOverlay)
Dim
wmslyr =
New
WmsRasterLayer()
wmslyr.Name = wmsovl.Name
wmslyr.Uri = wmsovl.ServerUris(0)
Try
wmslyr.IsVisible =
True
Dim
showLayers()
As
String
=
Nothing
'traverse key/value pairs in URL, transfer to WmsLayer parameters
If
wmslyr.Uri.AbsoluteUri.Split(
"?"
).Count > 1
Then
Dim
xp = wmslyr.Uri.AbsoluteUri.Split(
"?"
).Last.Split(
"&"
)
For
Each
x2
In
xp
Dim
x = x2.Split(
"="
)
If
x.Count = 2
Then
Select
Case
x(0).ToUpper
Case
“USERNAME”
’
Case
Else
wmslyr.Parameters.Add(x(0), x(1))
End
Select
End
If
Next
End
If
'traverse key/value pairs in parameters, transfer to WmsLayer parameters
For
Each
x
In
wmsovl.Parameters
Select
Case
x.Key.ToUpper
Case
“SRS”
'Debug?
Case
Else
wmslyr.Parameters.Add(x.Key, x.Value)
If
x.Key.ToUpper =
“LAYERS”
Then
showLayers = x.Value.Split(
","
)
End
If
End
Select
Next
wmslyr.Open()
'fetch capabilities (needs login !)
'set getmap parameters
wmslyr.ActiveLayerNames.Clear()
'just in case
For
Each
lyrnam
In
wmslyr.GetServerLayerNames()
If
showLayers.Contains(lyrnam)
Then
wmslyr.ActiveLayerNames.Add(lyrnam)
End
If
Next
If
wmslyr.ActiveLayerNames.Count = 0
Then
Throw
New
Exception(
“Internal error: NO layers !”
)
wmslyr.OutputFormat =
“IMAGE/JPEG”
wmslyr.Crs =
“EPSG:25832”
'wmsovl.GetBaseEpsgProjection.ToUpper
'draw WmsLayer onto pdf canvas
wmslyr.DrawingExceptionMode = DrawingExceptionMode.
Default
'debug
'wmslyr.DrawingExceptionMode = DrawingExceptionMode.DrawException
wmslyr.Exceptions =
“application/vnd.ogc.se_xml”
'wmslyr.Exceptions = “application/vnd.ogc.se_inimage” 'default
Try
wmslyr.Draw(myGdiPlusGeoCanvas, LabelsInLayer)
Catch
ex
As
Exception
'Debug
End
Try
wmslyr.Close()
Catch
ex
As
Exception
'Debug.WriteLine("FAILURE :-( – Cannot draw WMS layer: " + wmslyr.Name + ": " + ex.Message)
End
Try
End
If
Cheers
Lars
Hi Lars,
I guess there isn’t any problem with the code attached here, could you provide your whole demo for us debug? You can send it to forumsupport@thinkgeo.com.
Thanks,
Johnny
Hi Don,
Did you have a look at my project I sent ?
Cheers
Lars
Hi Lars,
I am sorry I just found you had sent us the email with project from forumsupport mailbox, but it looks the shared link had expired.
Could you please share us that again?
Regards,
Don
Hi Don,
I’ve sent the file again.
Cheers
Lars I.
Hi Lars,
Thanks for your update, but I get the error as below when I tried to login:
"Your login attempt was not successful. Please try again."
Please have a look at that, and I am reading your code related with your convert, any update I will let you know.
Regards,
Don