Select to view content in your preferred language

Is there any print example that can be referenced for SL 4?

10822
71
07-14-2010 01:18 PM
weiliang
Deactivated User
I try to incorporate the print feature into our website (with SL 4, and ESRI API 2.0). I used the following code, but it direct me to the print dialog box only. How can I make a print template (e.g., http://citizengis.chesterfield.gov/) to print the current map extent with some controls (e.g, scale bar) into a pdf. Is there any easy way to do so or I must create a WCF service?


PrintDocument doc = new PrintDocument();
doc.PrintPage += (s, e) =>
{
   e.PageVisual = MyMap
   e.HasMorePages = false;
};
doc.Print("Map");

Many thanks,

Wei
0 Kudos
71 Replies
YingLin
Emerging Contributor
I have tried the sample. Looks like "http://www.esri.com/schemas/ArcGIS/9.3" is not recognized. Is this link still good for reference? I replaced the reference with ArcGIS Client, the program built successfully. but when i tried to run the application, the app stops at

ArcGIS_SOAP_Silverlight.GetMapNameResponse _result = ((ArcGIS_SOAP_Silverlight.GetMapNameResponse)(base.EndInvoke("GetMapName", _args, result)));

and i got this error
System.ServiceModel.CommunicationException was unhandled by user code
  Message=The remote server returned an error: NotFound.
  StackTrace:
       at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
       at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
       at ArcGIS_SOAP_Silverlight.MapServerPortClient.MapServerPortClientChannel.EndGetMapName(IAsyncResult result)
       at ArcGIS_SOAP_Silverlight.MapServerPortClient.ArcGIS_SOAP_Silverlight.MapServerPort.EndGetMapName(IAsyncResult result)
       at ArcGIS_SOAP_Silverlight.MapServerPortClient.EndGetMapName(IAsyncResult result)
       at ArcGIS_SOAP_Silverlight.MapServerPortClient.OnEndGetMapName(IAsyncResult result)
       at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
  InnerException: System.Net.WebException
       Message=The remote server returned an error: NotFound.
       StackTrace:
            at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
            at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
            at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
       InnerException: System.Net.WebException
            Message=The remote server returned an error: NotFound.
            StackTrace:
                 at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
                 at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
                 at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
            InnerException:

Wonder if the soap url is correct or not? thanks
Ying
0 Kudos
YingLin
Emerging Contributor
I just add the reference into my project and copied the code and folders. The error is gone.

Thanks.

I still need to work on the layout of the print out. It is not properly scaled down and stretched on a letter size paper. Thanks again for sharing the code.
0 Kudos
JaehyungYu
New Contributor
Hi. Lisa,

Thank you so much for sharing your code.
It looks really good!.
But my project is using "Feature layer". 
If user click the feature layer on map, the print preview needs to show all highlighted map features as well.

It seems your code doesn't support feature layer...

Could you please help how I can handle this?

Thank you in advance.
0 Kudos
LisaChesley
Emerging Contributor
Good afternoon!

I don't have any experience with feature layers, but I'm going to look into that and I'll try to post something once I've sussed out what they are, exactly, and how they differ from dynamic and graphic layers.

Thanks for your patience!

Lisa
0 Kudos
YingLin
Emerging Contributor
The code works great!
However, I have a problem when printing the map with a graphic layer. In my application, I have a identify tool. When user click on the property, it gets highlighted and info is displayed. When creating the print map, the map has the highlighted graphic too which is what i wanted. Once the print map window is dismissed either from closing or printing, the graphic on the main map disappears. And, if user use the identify tool again, the app stops at the line where I add the graphic to the graphicsLayer on the main map. See attached document.

The app is ok if there is no graphics added to the print map. Looks like when the childwindow for print map got dismissed, it somehow destroy the graphiclayer in the main map or something.
0 Kudos
LisaChesley
Emerging Contributor
Good morning!

I'm noticing that error myself.  Have you upgraded to ArcGIS 10, or are you still using 9.whatever (we recently upgraded to 10)?  I will be making a post about that myself, hopefully there are some answers to be found.  Until I have answers, I have disable the printing of graphics in my applications as well.

Thanks for bringing that up!

Lisa
0 Kudos
KevinSesock
Emerging Contributor
Lisa, if you could share your code, kasesock@owrb.ok.gov
0 Kudos
YingLin
Emerging Contributor
Good morning!

I'm noticing that error myself.  Have you upgraded to ArcGIS 10, or are you still using 9.whatever (we recently upgraded to 10)?  I will be making a post about that myself, hopefully there are some answers to be found.  Until I have answers, I have disable the printing of graphics in my applications as well.

Thanks for bringing that up!

Lisa


Thanks Lisa
I am using ArcGIS 9.3.1 sp1.
0 Kudos
LisaChesley
Emerging Contributor
Good afternoon!

@Kevin - the project is in the mail

@Ying - we're using ArcGIS 10 and experiencing the same problem.  I have created a new thread and posted a sample project in hopes that someone can help us out!

http://forums.arcgis.com/threads/11754-Trouble-printing-graphics-layer-with-Silverlight-4

Thanks!

Lisa
0 Kudos
LisaChesley
Emerging Contributor
Hi. Lisa,

Thank you so much for sharing your code.
It looks really good!.
But my project is using "Feature layer". 
If user click the feature layer on map, the print preview needs to show all highlighted map features as well.

It seems your code doesn't support feature layer...

Could you please help how I can handle this?

Thank you in advance.


Good afternoon!

I've taken a look at the feature layers, and they look like just a cross between a dynamic layer and graphics layer.  I still don't have any available to use myself, so this is purely conjecture, but you should be able to accomodate them with the following steps:

1. In the MapPrintViewViewModel, add a new class (like DynamicMapLayerInformation) in the Custom Objects region.  Call it something memorable, like FeatureLayerInformation, or something.  Make sure it has as properties a string called url, and an ObservableCollection of type Graphic, called graphics, or something along that line.  Depending on how you set up your feature layer, additional properties might be necessary.  Don't forget to add this as a property to the view model, with VisibleLayers, which is a collection of DynamicLayerInformation, as your model.

2. In MainPage.xaml.cs, in the btnPrint_Click handler, in the foreach statement that is looping through the layers, add a new try/catch block under the graphics layer one, as follows:

try
{
     FeatureLayer featureLayer = dLayer as FeatureLayer;
     viewModel.<Name of your new property here>.Add(new <Name of your new object here>(<instantiate class here with properties from feature layer on map>));
}
catch {}

For the above, use the dynamic layer section as your model.

3. Back in the MapPrintViewViewModel.cs, in the CreateMap function, add a new case statement after the MapGraphics that is like the Dynamic layer one, but with your new feature layer object instead.  Instead of using CreateDynamicLayer(), create a new function called CreateFeatureLayer(), and give it a return type of FeatureLayer, and in it, create a new Feature Layer, assign the Feature Layer properties as in CreateDynamicLayer, plus a GraphicCollection like in CreateGraphicsLayer().

That should do it (I hope).

Failing that, if you just want the graphics that the feature layer creates, with the hassle of creating the layer again, I think you could just duplicate the code for the GraphicsLayer, and creat a new GraphicsLayer with a Graphics property equal to the Graphics property from the Feature Layer.

Please let me know if that works, or if it even made any sense. 🙂

Thanks!

Lisa
0 Kudos