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:
IfTypeOfovlIsWmsOverlayThenDimwmsovl =DirectCast(ovl, WmsOverlay)Dimwmslyr =NewWmsRasterLayer()wmslyr.Name = wmsovl.Namewmslyr.Uri = wmsovl.ServerUris(0)
Trywmslyr.IsVisible =True
DimshowLayers()AsString=Nothing
'traverse key/value pairs in URL, transfer to WmsLayer parametersIfwmslyr.Uri.AbsoluteUri.Split("?").Count > 1ThenDimxp = wmslyr.Uri.AbsoluteUri.Split("?").Last.Split("&")ForEachx2InxpDimx = x2.Split("=")Ifx.Count = 2ThenSelectCasex(0).ToUpperCase“USERNAME”’CaseElsewmslyr.Parameters.Add(x(0), x(1))EndSelectEndIfNextEndIf
'traverse key/value pairs in parameters, transfer to WmsLayer parametersForEachxInwmsovl.ParametersSelectCasex.Key.ToUpperCase“SRS”'Debug?CaseElsewmslyr.Parameters.Add(x.Key, x.Value)Ifx.Key.ToUpper =“LAYERS”ThenshowLayers = x.Value.Split(",")EndIfEndSelectNext
wmslyr.Open()'fetch capabilities (needs login !)
'set getmap parameters
wmslyr.ActiveLayerNames.Clear()'just in caseForEachlyrnamInwmslyr.GetServerLayerNames()IfshowLayers.Contains(lyrnam)Thenwmslyr.ActiveLayerNames.Add(lyrnam)EndIfNext
Ifwmslyr.ActiveLayerNames.Count = 0ThenThrowNewException(“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
Trywmslyr.Draw(myGdiPlusGeoCanvas, LabelsInLayer)CatchexAsException'DebugEndTry
wmslyr.Close()
CatchexAsException'Debug.WriteLine("FAILURE :-( – Cannot draw WMS layer: " + wmslyr.Name + ": " + ex.Message)EndTryEndIf
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