ThinkGeo.com    |     Blog    |     Wiki    |     Support

Print Custom Overlays to PDF

Jakub, 



We made a sample for the strench issue. Please have a look at it. 



Thanks,

Howard



1092-GoogleMapLayerTest.zip (9.05 KB)

I am trying to use this sample but i am getting the following error:screencast.com/t/DiFyjEMl7Ry


I have Upgraded the application to Version VS2010 and MapSuite5



GoogleMapLayerExport.zip (259 KB)

Hello Gregory, 
  
 Thanks for your sample and stacktrace image, I find that your GoogleApiKey length is not right for a Base64String, it should be not zero or a multiple of 4. 
  
 Could you please check your key? 
  
 Regards, 
  
 Gary

I am using my Google Map API Key ??? What key must i use ??

Hello Gregory, 



When you create the GoogleMapsLayer, you need to set a privatekey, that is your Google Maps APIs key, like the code below, API Key is "ABQIAAAA1KPQi4YfHGdBrxrD7xfk3BShg55qzDjUncDQtZWMkgWc-6jGwhTE2_EhbB-MTW6vtSxa--SpoABjPA" 


GoogleMapsLayer googleLayer = new GoogleMapsLayer("c:\\cache\\", "GoogleMapLayer1", "ABQIAAAA1KPQi4YfHGdBrxrD7xfk3BShg55qzDjUncDQtZWMkgWc-6jGwhTE2_EhbB-MTW6vtSxa--SpoABjPA");



But this key is not working now, as for the Google Maps APIs key, I suggest that you refer to the web page below which has clarified how to register the key and make it valid for that domain, its subdomains, all URLs on hosts in those domains. 


code.google.com/apis/maps/faq.html#keysystem




Regards, 



Gary 



Sorry I do not get to this sooner 
 I am getting error 
 "An item with the same key has already been added." 
 on         Map1.CustomOverlays.Add(googleMapsOverlay) 
 statement in Sub Page_Load after the "Print to PDF button" is clicked/ Sub Button1_Click fires 
  
 Why? The error is not there when the page loads first time. 


Hello Jakub, 
  
 This problems seem like you have run this code more than once. 
  
 Map1.CustomOverlays.Add(googleMapsOverlay)  
  
 Because the googleMapsOverlay have the same name, so it will throw exception. 
  
 Regards, 
  
 Gary 


Hi, 

I have seldom tried to print custom Overlays to PDF. But when it comes to PDF converting process, I have another question, I wonder have you ever tried to convert pdf to other image files before? As for myself, I am testing the related PDF to PNG converting , PDF to BMP converting , and PDF to JPG converting programs these days. Do you have experience about it? Any suggestion will be appreciated. Thanks in advance.    







Best regards, 

Pan

Hi Pan, 
  
 Thanks for your question, but I am sorry we don’t have experience to convert from PDF to any other format before. 
  
 If you want to implement that, I think you should want to find some 3rd part utility for it. 
  
 Regards, 
  
 Don

Hi,
I am trying to upgrade the mapsuite 9 to mapsuite 10 because of some licensing issue and that is done, but now the pdfsharp print is not looking good. can you please help me out.

I have attached the pdf file just for the reference.Mapsuite 10 Afghanistan shape file is wrong.pdf (2.8 MB)Mapsuite 9 Afghanistan at the right postion.pdf (2.4 MB)

Hi M_Saeed_Chamman,

We find the vector layer and raster layer aren’t matched from your attached PDF files. We guess you don’t set the DPI for PDF canvas which causes your issue. The default DPI of PrintDocument is 100. The default DPI of PdfGeoCanvas is 96, so you should change its DPI to 100.

Here attached is a demo, please refer it to print map.
MapPrinterDemo_WebForms.zip (82.7 KB)

If your issue still exists, please give us a sample with data to recreate your issue?

Thanks,
Rex

Thanks, i will try it out.

Hi M_Saeed_Chamman,

Any question please let us know.

Regards,

Ethan

I have tried that sample code and that is working OK, but in my case i’m drawing the layer on a specific area of the page and that is the problematic code i think. Please find it below

int FooterHeight = 80;
int headerHeight = 70;
int margin = 5;
headerHeight = headerHeight + 2 + margin;
int MapHeight = Convert.ToInt32(page.Height - (headerHeight + FooterHeight));
pdfGeoCanvas.DrawingArea = new Rectangle(0, headerHeight, (int)page.Width, MapHeight);

            Collection<SimpleCandidate> labelsInLayers = new Collection<SimpleCandidate>();
            RectangleShape rect = new RectangleShape(double.Parse(args["left"].ToString()), double.Parse(args["top"].ToString()), double.Parse(args["right"].ToString()), double.Parse(args["bottom"].ToString()));
            RectangleShape shape = ExtentHelper.GetDrawingExtent(rect, (float)page.Width, MapHeight);
            foreach (LayerOverlay layeroverlay in lstlayeroverlay)
            {
                foreach (Layer layer in layeroverlay.Layers)
                {
                    layer.Open();
                    pdfGeoCanvas.BeginDrawing(page, shape, map.MapUnit);
                    layer.Draw(pdfGeoCanvas, labelsInLayers);
                    layer.Close();
                    pdfGeoCanvas.EndDrawing();
                }
            }

The extent is coming from the front end of the mvc app using Map1.getExtent(); and that is working perfectly well. when i remove the canvas DrawingArea function the map is working pretty much ok but not with it. I don’t know what part i’m missing. One thing the same code is working on older version.

Hi M_Saeed_Chamman,

Do you means your sample code works in before version but not works in the sample of Rex. Could you please let me know which version it works so we can compare the result? And I want to make sure whether it’s blank white in your machine for the latest version.

And I think the problem should be the value of “shape”, I think you can check the value of it when debug and see whether it’s not correct for 3857 projection(Google Map Projection).

Regards,

Ethan

The older version of maps is 9 on which this codes works ok but on the latest version 10 its not working as expected and even on the sample code of Rex it has the same issue.

Projection is working ok when the map is displayed but not on print this is what i’m unable to understand.

Hi M_Saeed_Chamman,

Thanks to let me to know it, but it looks the sample code from Rex and the sample code you pasted don’t contains code related with Projection.

I tested the sample from Rex, and it print the same result just like it rendered on map.

So I think you should want to modify the sample from Rex and upload it here, if the sample can reproduce the problem our developer can research this problem based on it.

Regards,

Ethan

Hi,

The normal printing is working fine, but when i draw it on the specific part of the page like if i leave the header and footer space and draw it on the center of the page on specific area then both the layers have different results which are shown in my screenshots. The Method DrawingArea of the Canvas is something which works good on the previous version of mapsuite but not on the new one.

Hi M_Saeed_Chamman,

If it don’t works well in some special scenario, I think that’s maybe related with screen coordinate and world coordinate.

For solve that, you can draw the layer on an image first, then draw the image into PDF, which should looks better.

You mentioned the DrawingArea don’t work in latest version, could you please let us know which earlier version you used it? So we can compare that, and a screen shot which contains the different result with same code should be helpful.

Regards,

Ethan

Hi,

I have attached the sample of my code of Print and Display functions, Web page screenshots and Print pdf files of both versions. Please review it.
9-0.zip (2.6 MB)
10-3-0.zip (2.3 MB)