ThinkGeo.com    |     Documentation    |     Premium Support

Print Custom Overlays to PDF

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)

Hi M_Saeed_Chamman,

Thanks for your information, we hadn’t found the reason of that, our developer will look into it, any update I will let you know.

Regards,

Ethan

Hi M_Saeed_Chamman,

It should caused by our update for GoogleMapsLayer, because we remove the multiply tile mode from it, and Google update the tile size based on different user level.

Please try this package when it can be downloaded: https://www.nuget.org/packages/ThinkGeo.MapSuite.Layers.GoogleMaps/11.0.0-beta011

Any issue please feel free to let us know.

Regards,

Ethan

Hi,

I have tried the latest beta version available for download and i have attached the result. It is still have difference in boundaries but better than before. Please consider it.MapSuitePDFMap_636788318768200002.pdf (2.1 MB)

Hi M_Saeed_Chamman,

Thanks for your update. But in our test sample it cover well. So I think maybe some other points we missed.

Could you please upload a simple sample with your test data? We have your code but I think a project which can reproduce it maybe contains the missing points.

Regards,

Ethan