Select to view content in your preferred language

Printing in SL 2.0 comparsion

7282
59
10-04-2010 05:27 AM
LakshmananVenkatesan
Frequent Contributor
Dear All:

We have developed Print functionality in Web application using ESRI SL 1.2, ArcGIS 9.3.1. Client application willl send all visible layers, graphics (poly,line and point) as string , text symbols as string to server side and recreate a map document and construct geometry from string and generate a image and display in web page.

If we have say 100 lines as graphics, string which we generate is very big and unable to process( or send via http). Server side is done using GP Tool. Question is we have planned to move to ArcGIS 10 and SL 2.0.

What are all advantages in print functionality using ArcGIS 10 and SL 2.0  (MS SL 4.0) or rather how easy to print the map with graphics and other options ?

Please throw light on this
0 Kudos
59 Replies
ErikEngstrom
Frequent Contributor
Dominique,
I have successfully integrated your code into my application and think that it'll work for what we need it to do. Thank you so much for taking the time to develop it and to help us users out!

If you have time, there are a few behaviors that I'd like to address...

I have your print control inside a draggable-window control and this window is able to turn on/off. When the user first opens our map and pans around, adds/removes layers, adds graphics, etc. and then toggles the window on, the print shows all of the modifications and zooms to the extent the users is zoomed to. AWESOME!!!!

However, if the user modifies the map in any way (adds another layer, zooms to another portion of the map, or adds/removes more graphics) those changes are not reflected in the preview window and I'm not positive they are reflected in the printout.

This is what my XAML looks like:
  
<userControls:DraggableWindow IsOpen="True" x:Name="printWindow" Margin="0,20,20,0"
   VerticalAlignment="Top" HorizontalAlignment="Right" Width="Auto" Height="Auto" 
   Padding="0" HorizontalContentAlignment="Stretch" 
   VerticalContentAlignment="Stretch" Title="Print Map" Background="{StaticResource BaseColor}" Grid.Column="2">
   <i:Interaction.Triggers>
    <i:EventTrigger>
     <actions:ToggleWindowVisibilityAction/><!-- Hide at startup -->
    </i:EventTrigger>
   </i:Interaction.Triggers>  
   <ESRI_ArcGIS_Client_Samples_MapPrinting:PrintPreview x:Name="printPreviewMap" Grid.Column="1" HorizontalAlignment="Right" Margin="0,0,20,20" VerticalAlignment="Bottom">
    <ESRI_ArcGIS_Client_Samples_MapPrinting:MapPrinter x:Name="printMap" Map="{Binding ElementName=MyMap}"  MapUnits="Meters" d:LayoutOverrides="Width, Height" Style="{StaticResource MapPrinterStyle}" PrintExtent="{Binding Extent.Extent, ElementName=MyMap, Mode=TwoWay}" Title="{StaticResource Title}"/>
   </ESRI_ArcGIS_Client_Samples_MapPrinting:PrintPreview>
  </userControls:DraggableWindow> 


Is there anyway that I can sync up the preview window with layers turning on/off, graphics added/removed, etc.? I can live without the preview window zooming with the map control, but it's a bit of a showstopper if the user can't see in the preview their latest edits.

Thanks again for all your help!
0 Kudos
DominiqueBroux
Esri Frequent Contributor

if the user modifies the map in any way (adds another layer, zooms to another portion of the map, or adds/removes more graphics) those changes are not reflected in the preview window

The preview window was not designed to stay in sync with the main map. The idea was to get a snapshot of the main map when the preview opens. So after changing visibilities of a layer, the user has to close and reopen the preview window.

Nevertheless it makes sense to keep the 2 windows in sync, I will try to update the sample soon.
0 Kudos
ErikEngstrom
Frequent Contributor
The preview window was not designed to stay in sync with the main map. The idea was to get a snapshot of the main map when the preview opens. So after changing visibilities of a layer, the user has to close and reopen the preview window.

Nevertheless it makes sense to keep the 2 windows in sync, I will try to update the sample soon.

That would be fantastic!
For the time being, I'm working on getting the preview to reset when loading/unloading the control.
I have some code that removes the control on pageload. I stuck the control in its own grid (printgrid) on my mainpage.xaml so that it could be easily removed:
printGrid.Children.Remove(printPreviewMap);

Then, I have a button click event that toggles the control on/off:
  private void printMap_Click(object sender, RoutedEventArgs e)
  {
   int y = printGrid.Children.Count;
   if (y < 1)
   {
    printGrid.Children.Add(printPreviewMap);
   }
   else
   {
    printGrid.Children.Remove(printPreviewMap);
   }
  }


I was able to verify that the control is loading/unloading by inserting some code that fires on the load/unload events of the print control. This works for the extent on the preview window, however, the preview map is not honoring changes made to layers within the map control (MyMap). If layers or graphics are added/removed, they are not showing up in the preview map, even if the control is loaded/unloaded. Maybe I'm missing something...
0 Kudos
DominiqueBroux
Esri Frequent Contributor

however, the preview map is not honoring changes made to layers within the map control (MyMap). If layers or graphics are added/removed, they are not showing up in the preview map, even if the control is loaded/unloaded. Maybe I'm missing something...


With the sample application, you can take of the layer visiibilities and of the current extent by closing and reopening the preview window.
The scenario is this one:
- launch the application
- close the preview window
- open the table of contents
- change some layer visibilities and/or opacity
- change the current extent
- open the print preview window
You will notice that the print is taking care of all your changes.

This is done by using the IsActive property of the MapPrinter. The map is cloned for printing when the IsActive property is set to true (and the cloned map is freed when IsActive is set to false).
So binding the IsActive property to the visibility of the preview window allows to take care of all changes when the preview window is opened and to free the resources when it's closed.

Merry Christmas:).
0 Kudos
ErikEngstrom
Frequent Contributor

This is done by using the IsActive property of the MapPrinter. The map is cloned for printing when the IsActive property is set to true (and the cloned map is freed when IsActive is set to false).
So binding the IsActive property to the visibility of the preview window allows to take care of all changes when the preview window is opened and to free the resources when it's closed.
Merry Christmas:).

That's what I needed!

I added statements for changing the IsActive property to my code. This is how it looks now:
  private void printMap_Click(object sender, RoutedEventArgs e)
  {
   int y = printGrid.Children.Count;
   if (y < 1)
   {
    printGrid.Children.Add(printPreviewMap); 
    printMap.IsActive = true;
   }
   else
   {
    printGrid.Children.Remove(printPreviewMap);
    printMap.IsActive = false;
   }
  }


Thanks for the help!
0 Kudos
PhilDegler
Emerging Contributor
I am using some of the map printer code from the map printing sample application that has been mentioned above.  I'm having a problem with a feature layer.  When the print preview window appears, my feature layer graphics appear on the preview map, but disappear from the main map.  When I close the preview window, the graphics will reappear on the main map when I pan or zoom.

Another issue I am running into involves clustering.  If I bring up the print preview window and zoom in, some of clusters will split apart into individual graphics as I would expect.  When I close the preview window (and pan to get the graphics to show up in the main window again), the clustering that appears is how it appeared in the preview map, even though the main map extent may be different (in other words the individual graphics will show up based on the preview extent).

I have been looking into map printing in silverlight for a while and have noticed other developers with some of these problems.  Is there any solution to this that anyone knows of?  It seems that even though the preview map is a clone of the main map, they are somehow still joined at the hip.

Phil
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I'm having a problem with a feature layer. When the print preview window appears, my feature layer graphics appear on the preview map, but disappear from the main map.

I tested the print sample with feature layers again and I didn't notice the issues you are talking about.
Note that in the sample, when cloning a map, the graphic layers are a specific case since we need to clone the graphics as well. It's why there is code like this one:
// For graphics layer, a clone of the graphic collection is done and is frozen
// No web requests will be done
private static Layer CloneLayer(Layer layer)
{
    Layer toLayer;
    if (layer is GraphicsLayer) // Include FeatureLayer and GeoRSS layers
    {
        var fromLayer = layer as GraphicsLayer;
        var printLayer = new GraphicsLayer();
............

Check that you are using the same kind of code and that your graphics are cloned. Once the graphics are cloned, the preview window should not impact the main window.


Another issue I am running into involves clustering. If I bring up the print preview window and zoom in, some of clusters will split apart into individual graphics as I would expect. When I close the preview window (and pan to get the graphics to show up in the main window again), the clustering that appears is how it appeared in the preview map, even though the main map extent may be different (in other words the individual graphics will show up based on the preview extent).


Likely this's tied to the previous issue, if the graphics are not cloned, you can end up with this kind of situation.
0 Kudos
PhilDegler
Emerging Contributor
Thankyou for your reply.

I followed your readme file when attempting to add this functionality to my application.  I'm using VS2010, so I built the MapPrintingControls dll, added it as a reference in my project and added the MapPrinterDialog control to a xaml page (with the MapPrinter object pointing to my main map).  I'm then showing and hiding the dialog based on a print button.

The funny thing is that when I noticed the issue with the graphics layer, I changed some code in the CloneLayer method of the CloneMap class just to see if I could get something different to happen with that layer.  My code changes had no effect (positive or negative) which makes me think that this method (clonelayer) is not being called in my scenario.  Is that possible based on my setup according to the readme file?

Phil
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Could you test with the MapPrinting sample application just by adding your feature layer to the map?
Is it working or are you experimenting the same issue?


My code changes had no effect (positive or negative) which makes me think that this method (clonelayer) is not being called in my scenario. Is that possible based on my setup according to the readme file?

Is the print dialog working well with other layer types?
At this time, I can't figure out how it could work without cloning the layers. Try to set a breakpoint to CloneLayer and execute in debug mode.
0 Kudos
PhilDegler
Emerging Contributor
Hi Dominique,

For some reason, I am not able to run the sample application locally.  When I build the application, I get a message "Invalid URI scheme 'file://' for map control.  Control must be hosted in a HTTP(s) website."

I get this message when trying to run the sample app with the esri services.

Phil
0 Kudos