ThinkGeo.com    |     Documentation    |     Premium Support

Plot/print WorldMapKitWmsDesktopOverlay into PdfGeoCanvas

When using WorldMapKitWmsDesktopOverlay in windows Form app as background overlay, how to draw or print view with other feature layer into pdf. Googlemap or openstreetmap has “layer” object vs “overlay” to add into sample code below for plotting purpose. However, WorldMapKitWmsDesktopOverlay does not expose corresponding layer object for drawing purpose.

I tried using WorldMapKitWmsDesktopOverlay.draw(pdfGeoCanvas). This only plot tile pieces instead of seamless background in viewing extent.

        PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();   

        // This allows you to control the area in which you want the   
        // map to draw in.  Leaving this commented out uses the whole page   
        //pdfGeoCanvas.DrawingArea = new Rectangle(200, 50, 400, 400);   
        Collection<SIMPLECANDIDATE> labelsInLayers = new Collection<SIMPLECANDIDATE>();   
        foreach (Layer layer in ((LayerOverlay)winformsMap1.Overlays[0]).Layers)   
        {   
            pdfGeoCanvas.BeginDrawing(page, winformsMap1.CurrentExtent, GeographyUnit.DecimalDegree);   
            layer.Open();   
            layer.Draw(pdfGeoCanvas, labelsInLayers);   
            layer.Close();   
            pdfGeoCanvas.EndDrawing();   
        }

Hi Sunshine,

Have you tried to use WorldMapKitLayer instead of WorldMapKitWmsDesktopOverlay in your code? I think it should be the corresponding layer.

Regards,

Don

@Don, thank you for the reply. WorldMapKitLayer fits the purpose. However, the output was off on zoom levels. My custom layer (pink dots) should all fall inside US boarder, but they are outside. The map control window displays correct overlay. Should I set zoom level of the map to WorldMapKitLayer zoom level? What’s the object for World Map Kit zoom level?

MapSuite PDF Map.pdf (222.8 KB)

Hi Sunshine,

What’s your detail dll version? And are you print it like the code as below?

            PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();

        // This allows you to control the area in which you want the
        // map to draw in.  Leaving this commented out uses the whole page
        //pdfGeoCanvas.DrawingArea = new Rectangle(200, 50, 400, 400);
        Collection<SimpleCandidate> labelsInLayers = new Collection<SimpleCandidate>();
        foreach (Layer layer in ((LayerOverlay)winformsMap1.Overlays[0]).Layers)
        {
            pdfGeoCanvas.BeginDrawing(page, winformsMap1.CurrentExtent, GeographyUnit.DecimalDegree);
            layer.Open();
            layer.Draw(pdfGeoCanvas, labelsInLayers);
            layer.Close();
            pdfGeoCanvas.EndDrawing();
        }

Regards,

Don

Version 9.0.0.0, Runtime v4.0.30319 for desktop edition and PdfExtension
C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite Desktop\Daily Full Production 9.0.0.361\Managed Assemblies - Strong Named\Spatial Extensions\Pdf Extension\PdfExtension.dll

My code is similar to yours. However, since I have more than one Map Overlay, I added an outer loop to print all overlays.

    Dim pdfGeoCanvas As New PdfGeoCanvas()

    ' This allows you to control the area in which you want the 
    ' map to draw in. Leaving this commented out uses the whole page 
    Dim labelsInLayers As New Collection(Of SimpleCandidate)()

    For each overLay As Overlay In Map.Overlays
        For Each layer As Layer In CType(overLay, LayerOverlay).Layers
            pdfGeoCanvas.BeginDrawing(page, Map.CurrentExtent, GeographyUnit.DecimalDegree)
            layer.Open()            
            layer.Draw(pdfGeoCanvas, labelsInLayers)            
            layer.Close()
            pdfGeoCanvas.EndDrawing()
        Next
    Next

Thank you.

Sunshine

Hi Sunshine,

Thanks for further information, we have recreated this issue and our developers are still work on it. I checked the source code and found there’s workaround for it. Please remove the default TileCache before exporting to PDF by the following code and have a try again.

 worldMapKitLayer.TileCache = null;

Thanks,
Peter

@Peter, your workaround did the trick, the pdf is all right after I added this vb line before create New PdfGeoCanvas()
ThinkGeoOnlineWorldLayer.TileCache = Nothing

One note: I wonder why I did not experience the same issue when using OpenStreetMapLayer as background.
Thank you.
Sunshine

Hi Sunshine,

It turns out a bug which has been fixed in version (Development branch)9.0.464.0, please get it when it’s available and have a try again.

Thanks,
Peter

1 Like

@Peter, I upgraded desktop reference to 9.0.464.0 and tried pdf print, problem fixed! Thank you very much.

You’re welcome.

Thanks,
Peter