Is there some place that I can change them? If they are from a style, could you please share the style template? I don't have the blend...Thank you
You have to retemplate the MapPrinterDialog. The default style is provided with the sources in MapPrinterDialog.Theme.xaml
Should I add this file via Add-Add existing item in my application?
<UserControl.Resources> <controls:LogConverter x;Key="logConverter" /> <Style x:Key="myMapPrinterDialogStyle" TargetType="controls:MapPrinterDialog"> .......... <controls:MapPrinterDialog Style="{StaticResource myMapPrinterDialogStyle}" ... ...
In my application, I actually use a button (not a toggle button) to show the print dialog. Is there a way to get a zoomed map in the print dialog?
I use the 'layerids' to limit the layers displayed in the legend. But I didn't find the similar thing in the legend in the printer style.
private void PrintBtn_Click(object sender, RoutedEventArgs e) { if (MapPrinterDialog.Visibility == System.Windows.Visibility.Collapsed) { MapPrinterDialog.Visibility = System.Windows.Visibility.Visible; mapPrinterWithDialog.IsActive = true; } else { MapPrinterDialog.Visibility = System.Windows.Visibility.Collapsed; mapPrinterWithDialog.IsActive = false; } }
<!--set the print dialog--> <controls:MapPrinterDialog x:Name="MapPrinterDialog" Background="White" Width="350" Height="400" Style="{StaticResource MyMapPrinterDialogStyle}" Visibility="Collapsed" > <controls:MapPrinter x:Name="mapPrinterWithDialog" Map="{Binding ElementName=MyMap}" Style="{StaticResource WithLegend}" Title="DIRT" PageChanged="mapPrinter_PageChanged" IsScaleFixed="True" Scale="2000000" /> <!--IsActive="{Binding ElementName=PrintBtn }"--> </controls:MapPrinterDialog> <controls:MapPrinterIndicator MapPrinter="{Binding ElementName=mapPrinter}" />
IsScaleFixed="True" Scale="2000000"
<!-- Legend --> <Border Background="{TemplateBinding Background}"> <StackPanel> <TextBlock Text="Legend" FontWeight="Bold" HorizontalAlignment="Center"/> <esri:Legend x:Name="PrintLegend" Map="{Binding ElementName=PrintMap}" LayerIDs="Visible Layers,,,"> <esri:Legend.Style> <Style TargetType="esri:Legend"> <Setter Property="LayerItemsMode" Value="Flat" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="esri:Legend"> <ItemsControl ItemsSource="{TemplateBinding LayerItemsSource}"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Vertical"> <!--Layer Item--> <TextBlock Text="{Binding Label}" FontWeight="SemiBold"/> <!--Legend Items--> <ItemsControl ItemsSource="{Binding LegendItems}" > <ItemsControl.ItemTemplate> <DataTemplate > <ContentPresenter Content="{Binding}" ContentTemplate="{Binding Template}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ControlTemplate> </Setter.Value> </Setter> </Style> </esri:Legend.Style> </esri:Legend> </StackPanel> </Border>
But with the fixed scale, when I click the button to unfold the MapPrinterDialog, the print extent doesn't change.
This legend is located in the style 'WithLegend'. Then how should I call this legend in the code behind??
Legend printLegend; //this event used in print legend style to get access to the element in the style private void PrintLegend_Loaded(object sender, RoutedEventArgs e) { printLegend = sender as Legend; printLegend.LayerIDs.SetValue("MySelectionGraphicsLayer", legendIDcount); }
<!-- Map--> <Border BorderBrush="Black" BorderThickness="1"> <esri:Map x:Name="PrintMap" IsLogoVisible="False" controls:CloneMap.Map="{TemplateBinding Map}" controls:SurrogateBinder.OverviewMapPrinter="{Binding RelativeSource={RelativeSource TemplatedParent}}"> <controls:PrintOverviewLayer> <controls:PrintOverviewLayer.ExtentFillSymbol> <esri:SimpleFillSymbol BorderBrush="Red" BorderThickness="3" Fill="Transparent" /> </controls:PrintOverviewLayer.ExtentFillSymbol> </controls:PrintOverviewLayer> </esri:Map> </Border>
I see there is a big number in the red rectangle on the print dialog and it is the page number. I went through the map part in the template, but didn't find where I can modify to disable this big number....
<controls:PrintOverviewLayer TextSymbol="{x:Null}"> <controls:PrintOverviewLayer.ExtentFillSymbol> <esri:SimpleFillSymbol BorderBrush="Red" BorderThickness="3" Fill="Transparent" /> </controls:PrintOverviewLayer.ExtentFillSymbol> </controls:PrintOverviewLayer>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="2" Grid.ColumnSpan="2" Text="{Binding Scale, RelativeSource={RelativeSource TemplatedParent}, StringFormat='1 : {0:F0} '}" />
Text="{Binding Scale, RelativeSource={RelativeSource TemplatedParent}, StringFormat='1 : {0:F0} '}"
controls:MapPrinterDialog x:Name="MapPrinterDialog" Background="White" Width="350" Height="400" Style="{StaticResource MyMapPrinterDialogStyle}" Visibility="Collapsed" > <controls:MapPrinter x:Name="mapPrinterWithDialog" Map="{Binding ElementName=MyMap}" Style="{StaticResource WithLegend}" Title="WIRT" Loaded="mapPrinterWithDialog_Loaded"/> <!--IsScaleFixed="True" Scale="2000000"--> <!--IsActive="{Binding ElementName=PrintBtn }"--> </controls:MapPrinterDialog> <controls:MapPrinterIndicator MapPrinter="{Binding ElementName=mapPrinter}" />
private void mapPrinterWithDialog_Loaded(object sender, RoutedEventArgs e) { MapPrinter mapPrinterWithDialog = sender as MapPrinter; double mapHeight = MyMap.ActualHeight; double mapWidth = MyMap.ActualWidth; Envelope printExtent = mapPrinterWithDialog.PrintExtent; var mapSize = new Size(mapPrinterWithDialog.RotateMap ? mapHeight : mapWidth, mapPrinterWithDialog.RotateMap ? mapWidth : mapHeight); var mapUnit = mapPrinterWithDialog.MapUnits; bool isWebMercator = (mapPrinterWithDialog.Map != null && mapPrinterWithDialog.Map.SpatialReference != null && (mapPrinterWithDialog.Map.SpatialReference.WKID == 102100 || mapPrinterWithDialog.Map.SpatialReference.WKID == 102113 || mapPrinterWithDialog.Map.SpatialReference.WKID == 3857)); double ratioScaleResolution = RatioScaleResolution(mapUnit, printExtent.GetCenter().Y, isWebMercator); double scale = mapPrinterWithDialog.Scale; double printResolution; printResolution = Math.Max(printExtent.Width / mapSize.Width, printExtent.Height / mapSize.Height); scale = ratioScaleResolution * printResolution; if (scale != mapPrinterWithDialog.Scale) mapPrinterWithDialog.Scale = scale; } private static double RatioScaleResolution(MapUnit mapUnit, double yCenter, bool isWebMercator) { double ratio; int dpi = 96; double toRadians = 0.017453292519943295769236907684886; double earthRadius = 6378137; //Earth radius in meters (defaults to WGS84 / GRS80) double degreeDist = earthRadius * toRadians;// distance of 1 degree at equator in meters if (isWebMercator) { // Transform yCenter from web mercator to decimal degree yCenter = Math.Min(Math.Max(yCenter, -20037508.3427892), 20037508.3427892); var point = new MapPoint(0, yCenter); yCenter = point.WebMercatorToGeographic().Y; ratio = Math.Cos(yCenter * toRadians) * dpi * 39.37; // 39.37 = MapUnit.Meters/MapUnit.Inches } else if (mapUnit == MapUnit.DecimalDegrees || mapUnit == MapUnit.Undefined) { if (Math.Abs(yCenter) > 90) ratio = 0.0; else ratio = Math.Cos(yCenter * toRadians) * degreeDist * dpi * 39.37; } else { ratio = (double)dpi * (int)mapUnit / (int)MapUnit.Inches; } return ratio; }
Actually I don't have 'PreparePages' function...so the scale doesn't get any value and it doesn't work I guess.
But the user seems to want to omit this scale stuff. So shifted my attention to implement other functions.
So can I have another button similar to this one to open a standard windows SaveFile dialog?
You can use the standard SaveFileDialog provided by Silverlight. Note that for security reason, the SaveFileDialog can only be shown in response to an user initiated event (a button should be OK then).
<controls:MapPrinter x:Name="mapPrinter" Map="{Binding ElementName=MyMap}" Locale="fr" Title="Tour de France 2010" IsScaleFixed="True" Scale="2000000"/>
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.