Select to view content in your preferred language

Silverlight Printing

1035
2
12-08-2011 06:00 AM
JustinMunsters
Emerging Contributor
Good morning all,

I am using the silverlight printing sample from code gallery (http://www.arcgis.com/home/item.html...4358d0458f66e3).

The issue we are experiencing stems from a specific layer that seems to be generating a bug within the cloned map on the print dialog.  The offending layer is of annotations for parcel dimensions that, when present in the map layers, leaves the cloned map blank/grey.  When I comment out this layer in the XAML, everything works as expected.

The service will only display the layer when at an extent less than 1:2000, and while it is a cached layer, I am working with the layer on our ArcGIS Server, so I have it coded as a Dynamic Layer.  The bug occurs either way.

I have attempted to debug this within the print sample solution to no avail.  I have also been unable to find information posted already referencing this excellent discussion.

Here is some test code I am working with. The offending layer in the XAML is "layerDimensions".  If anyone has suggestions, they are greatly appreciated.

XAML
<UserControl x:Class="TestPrinting.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:controls="clr-namespace:ESRI.ArcGIS.Client.Samples.MapPrinting;assembly=MapPrintingControls">

    <Grid x:Name="LayoutRoot" Background="White">
        <esri:Map x:Name="MyMap" Background="White" Extent="12589861.5047889, 452193.576650939, 12776710.8368209, 634919.636547503" >
            <esri:ArcGISTiledMapServiceLayer ID="layerBase" Url="http://www.gis.co.ottawa.mi.us/GISWEB/rest/services/BaseLayerGrey/MapServer" />
            <esri:ArcGISTiledMapServiceLayer ID="layerParcels" Url="http://www.gis.co.ottawa.mi.us/GISWEB/rest/services/SL_Parcels/MapServer"/>
            <esri:ArcGISTiledMapServiceLayer ID="layerRoads" Url="http://www.gis.co.ottawa.mi.us/GISWEB/rest/services/SL_Roads1/MapServer" />
            <esri:ArcGISDynamicMapServiceLayer ID="layerDimensions" Url="http://www.gis.co.ottawa.mi.us/GISWEB/rest/services/SL_Dimensions/MapServer" />
        </esri:Map>

        <!--Print Dialog-->
        <controls:MapPrinterDialog x:Name="mapPrinterDialog" Visibility="Collapsed"
                         HorizontalAlignment="Center" VerticalAlignment="Top" Margin="10" Height="400" Width="320">
            <controls:MapPrinter x:Name="mapPrinter" Map="{Binding ElementName=MyMap}" Title="Test"
                        IsScaleFixed="True" Scale="500000"/>
        </controls:MapPrinterDialog>

        <!--Optional Busy indicator for the map printer-->
        <controls:MapPrinterIndicator MapPrinter="{Binding ElementName=mapPrinter}" />
        
        <ToggleButton x:Name="btnPrint" Click="btnPrint_Click" Content="Print Me" Width="150" Height="30" IsChecked="False" ></ToggleButton>
        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom">
            <esri:MapProgressBar Map="{Binding ElementName=MyMap}"
                       HorizontalAlignment="Center" VerticalAlignment="Center"
                       Width="150" Height="15" Margin="5"/>
        </StackPanel>

    </Grid>
</UserControl>



Code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace TestPrinting
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }


        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            if (btnPrint.IsChecked.Value)
            {
                mapPrinterDialog.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                mapPrinterDialog.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
    }
}
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
Your issue is not coming from the map printer, you should run into the same problem after removing the map printer from your application (i.e just by trying to display this layer in the main window).

The problem is that your layer has only 2 levels of tiles at scale 1:1000 and 1:2000.

When we try to display this layer at small scale (e.g. 1:500000), we have to process tons of tiles and this never ends.

With an ArcGISDynamicMapServiceLayer, the query sent to the server ends with a time-out.
With an ArcGISTiledMapServiceLayer, SL tries to load tons of tiles (240000 with the test I did) and this never ends.


The solution at the client side is to define a maximum resolution for this layer:

 
<esri:ArcGISTiledMapServiceLayer ID="layerDimensions" Url="http://www.gis.co.ottawa.mi.us/GISWEB/rest/services/SL_Dimensions/MapServer" MaximumResolution="3"/>


The client will no more try to display this layer at small scale (i.e large scale denominator, i.e large resolution:p)
Note : '3' looks a good value for a scale about 1:2000 and a map in feet, but you may have to adapt it for your need.

Just 2 tips for the mapprinter:
1) set the mapunits of the mapprinter else the print at scale will not work because the mapprinter can't initialize automatically this kind of (exotic for me:)) units
<
controls:MapPrinter x:Name="mapPrinter" Map="{Binding ElementName=MyMap}" Title="Test" MapUnits="Feet" .....

Note : the sample should use the new scale support available with 2.3 but it's not done for now.

2) You can tweak your code of the button 'print me' in order to use the current map extent as print extent (by using IsActive property).
 
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
if (btnPrint.IsChecked.Value)
{
mapPrinterDialog.Visibility = System.Windows.Visibility.Visible;
mapPrinter.IsActive = true;
}
else
{
mapPrinterDialog.Visibility = System.Windows.Visibility.Collapsed;
mapPrinter.IsActive = false;
}
}


With these changes you should be able to print your annotations at scale 1:1000 or 1:2000. See screenshot

0 Kudos
JustinMunsters
Emerging Contributor
Wonderful!  Thank you for such a fantastic and thorough response, Dominique.
0 Kudos