Tag Archives: Printing

Version 2.6 of the ArcGIS API for JavaScript released today

Version 2.6 of the ArcGIS API for JavaScript is now available! Highlights include:

Improved map display using HTML5 and CSS3

When supported by the browser, the API now uses CSS3 transforms to provide a smoother zooming and panning experience.

Support for the latest version of maps from ArcGIS Online

ArcGIS Online web maps with layers created from remotely hosted comma-separated values (CSV) files are supported. This includes fusion tables and CSV files hosted on the open web.

Enhancements to the Basemap Gallery widget

The Basemap Gallery now supports working with a group of maps within ArcGIS Online. To use a group, specify the basemapsGroup constructor parameter when creating a Basemap Gallery widget.

Support for new features in ArcGIS Server 10.1 beta 2

New features now supported by the ArcGIS API for JavaScript but that require a 10.1 service:

Additional API Enhancements and Bug Fixes

Please refer to the What’s New in Version 2.6 topic in the documentation for additional information about version 2.6 of the ArcGIS API for JavaScript.

Contributed by Derek Swingley of the ArcGIS API for JavaScript development team

Posted in Services | Tagged , , , , | 1 Comment

An introduction to arcpy.mapping for ArcGIS Server developers

Python is very popular among ArcGIS Desktop developers because it helps automate workflows for map production, management of documents, GIS analysis, and so on. ArcGIS Server developers generally use Python to create geoprocessing services. In this post we will introduce a new Python module arcpy.mapping that is included in ArcGIS 10.

The purpose of arcpy.mapping is to aid with the manipulation of map documents (.mxd) and layer files (.lyr) . For ArcGIS Server, the most obvious use of arcpy.mapping is to support high quality print functionality through a web service. For example, you can use arcpy.mapping to programmatically open a map document, zoom to an area of interest, set the map scale, change the title of the page layout, and create a PDF document that people can download through a browser and then send to the printer.

While you could do all of this with ArcObjects within a server object extension, you may want to consider scripting with Python because the code is comparatively simple. Also, with Python scripting you can take advantage of all the goodies of the geoprocessing service framework, including a REST endpoint that works with all the ArcGIS Web APIs, asynchronous execution, error reporting, and so forth.

If you are not familiar with geoprocessing services, have a look at this overview of geoprocessing with ArcGIS Server. Once you understand how geoprocessing services work, the Python code is the easy part. In this five minute video we go over the examples and patterns for using arcpy.mapping with ArcGIS Server.

Some arcpy.mapping examples

We’ve put together three arcpy.mapping examples to get you started:

  • Simple Map Export–This is a very simple app, probably the best to warm-up. It shows you the basics of using the ExportToPDF operation. Try it with your own data, and look at the source code of both the web app and Python script to get started. The source code is available here.
  • Map Export Plus–This takes the previous example further: it shows you how to manipulate the visibility of layers within a map document, plus introduces a creative way to handle graphics. The source code is also included as part of the ArcGIS.com item.
  • Strip Map–In this example, arcpy.mapping is used in combination with Data Driven Pages to create multiple maps along a user-defined polyline. This is also known as a strip map, which is useful to map linear infrastructures like a pipeline. The maps are added to a multi-page PDF map document. In each page we include an overview of the area, a detailed map of a portion of your line, and a terrain profile. The source code is available here.

In all examples above, the arcpy.mapping code follows a simple pattern: Your web mapping application displays data from web services. Some of these are dynamic, others are cached… Your Python script is set so it has access to map documents .(mxd files) on your server. These map documents point to the same data that your web mapping app is using. When the geoprocessing service is invoked, the Python script loads the map document, changes some of its properties such as the extent of the map, text elements in the layout or even the visibility of layers, and then calls ExportToPDF to generate a pdf file that can be downloaded by the client.

Tips for arcpy.mapping

Here are a few things we’ve learned in our work with arcpy.mapping.

  • Map automation, not quick print–arcpy.mapping is really about map automation. It is great if you need to generate high quality maps; that is, maps that print at the specific scale you want, with the look and feel that you can give your maps in ArcGIS Desktop, including all the goodies of ArcMap layouts like dynamic text elements, fancy legends, scale elements, index grids, and so forth. If you are really looking for a quick and dirty print tool, client-side printing might be a simpler option. Here are some quick print samples for Flex and Silverlight.
  • Caution with large maps–With arcpy.mapping, you can generate very large maps: 33 by 44 inch maps for example. But you need to keep in mind that the bigger the map, the more CPU-intensive the operation will be on your server. If you use imagery, it’s going to eat up a lot of memory too. It’s generally good to keep a low ratio of geoprocessing service instances to your available cores to avoid overutilization in concurrency scenarios. For example, do not start more than two instances of your geoprocessing service per available core. That way, concurrent requests will be queued and will not exhaust available resources on your server.
  • Use local data for large format maps–Large format maps only work really well when you are using data that is local to your Python script. So let’s say that you include data from ArcGIS Online base maps in your map. Well, these map tiles were cooked with 96 DPI, which is not going to look well on paper unless you print on a 11×17 inch piece of paper or smaller. If it happens that you want to use your own cached maps in your web apps, we recommend that you go ahead and point your web app to the cached service, but point your Python script to the original data sources that were used to generate that map cache. That way you get the speed of the web, and the best high quality for your PDF. In other words, your web app looks at map tiles, but your python script goes straight to the live data and generates the PDF out of that.
  • Managing graphics and visibility of layers–The biggest challenge with arcpy.mapping is to sync up the contents of your web mapping application with the map documents your Python script uses. It’s easy to sync up things like the extent of the map, its scale, and its layout text, but what about selected features, filters, graphics, and visibility of layers? In the examples above, we provided source code to you that shows how to do all of this. You will notice that handling graphics and visibility of layers requires quite a bit of logic in both your web application and Python script. We wanted to show a couple of creative ways to do this today, but you should be aware that we are working to beef up arcpy.mapping in our next version of ArcGIS to simplify some of these challenging aspects.

Contributed by Ismael Chivite, Mark Smith, and David Spriggs of Esri

Posted in Services | Tagged , , | 7 Comments

Take advantage of new Silverlight 4.0 features in the ArcGIS Silverlight API

Our recent 2.0 beta release of the ArcGIS Silverlight API was built on the Silverlight 4.0 platforn, taking advantage of several of its new capabilities. Below are a few of my favorite new features:

Namespace prefixes

In Silverlight 3.0 you had to use multiple namespace prefixes to access classes in XAML that were located in different namespaces. This meant you often ended up with something like this in the page header:

xmlns:esri="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client"
xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client"
xmlns:esriGeometry="clr-namespace:ESRI.ArcGIS.Client.Geometry;assembly=ESRI.ArcGIS.Client"
xmlns:esriToolkit="clr-namespace:ESRI.ArcGIS.Client.Toolkit;assembly=ESRI.ArcGIS.Client.Toolkit"

In Silverlight 4 we can now map multiple namespaces to the same xmlns prefix, and the 2.0 API takes full advantage of this both in Silverlight and WPF. This means that you don’t have to declare multiple prefixes for core, geometry, symbols, toolkit, etc… but can just use one for them all:

xmlns:esri="http://schemas.esri.com/arcgis/client/2009"

This is what it looks like in intellisense:


 
So even though the following four objects are all in different namespaces, the namespace prefix is the same:

<esri:Map />
<esri:Navigator />
<esri:MapPoint />
<esri:SimpleMarkerSymbol />


Graphic.Attributes Binding

Before Silverlight 4, support for binding to dictionaries was lacking compared to WPF, and you had to use a custom converter to access attributes on a graphic feature. In Silverlight 4.0, this is now much easier, and you will never have to use the DictionaryConverter again (round of applause please):

Silverlight 3 (assuming the DataContext is the Graphic.Attributes, for example inside a MapTip):

<Grid.Resources>
    <esriConverters:DictionaryConverter x:Key="MyDictionaryConverter" />
</Grid.Resources>


<TextBlock Text="{Binding Converter={StaticResource  
    MyDictionaryConverter},ConverterParameter=StateName}" />

Silverlight 4:

 <TextBlock Text="{Binding [StateName]}" />

Even more interesting is that you can now update your attributes inside a map tip by simply using Two-Way binding on a textbox:

<TextBox Text="{Binding [StateName], Mode=TwoWay}" />

From now on consider the DictionaryConverter to be obsolete. 

The attributes type has also been updated (implements IDictionary) so if you bind to the attributes and change any values, it will automatically trigger a rebind.


Printing

By far the #1 requested feature, not only for our API, but also for Silverlight in general. Silverlight 4 finally comes to the rescue and provides an API for printing. You simply give it a control to print:

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


Binding to DependencyObject

Prior to Silverlight 4, you were only allowed to set binding expressions on objects that inherit from FrameworkElement. This limitation has been relaxed so now you can bind to anything that inherits from DependencyObject (like in WPF). This means you can bind an attribute to a symbol and rotate it based on the attribute value. Example:

<esri:MarkerSymbol x:Key="MySymbol">
   <esri:MarkerSymbol.ControlTemplate>
     <ControlTemplate>
       <TextBlock Text="=>">
         <TextBlock.RenderTransform>
           <RotateTransform Angle="{Binding Attributes[Heading]}" />
         </TextBlock.RenderTransform>
       </TextBlock>
     </ControlTemplate>
   </esri:MarkerSymbol.ControlTemplate>
</esri:MarkerSymbol >


Design Time editor in Visual Studio 2010

Visual Studio 2010 now supports previewing and editing your XAML in design view, similar to what you did in Expression Blend. Our design time support works the same way in Visual Studio as in Blend, so you can now use Visual Studio to do some quick design-time editing.   However, I do believe Blend is still an invaluable tool and has very powerful support for creating good looking layouts, animations, etcetera. 


Morten Nielsen
Senior Software Engineer
ArcGIS Server.NET, Silverlight/WPF, MapIt

Posted in Web | Tagged , , , | 21 Comments

Print Task templates with the 9.3.1 .NET Web ADF

The 9.3.1 ArcGIS Server Web ADF for .NET introduces an extensibility point to the Print Task that allows you to customize the look of your printouts using template files on the Web server.

A new property called LayoutTemplateFile is introduced to define the template file. This property can point to any file on disk but must be accessible via a web URL. The file may be part of the same application or can reside in a separate application (for example, the aspnet_client folder).

In Visual Studio, select the PrintTask control and you’ll see the new property. Clicking the Browse button allows you to browse to the custom template file.

Viewing the LayoutTemplateFile property for the PrintTask

How do you create a simple custom template?

An easy way to create a template is to modify the ADF’s default template.

  1. Within Visual Studio, right-click your project and choose “Add New Item…” from the menu. When the dialog appears, choose “HTML Page” and give it a suitable name. This will create an HTML document which you can use as the template.
  2. Open the default template file which is typically installed in the ADF runtime folder (Example: C:Inetpubwwwrootaspnet_clientESRIWebADFPrintTaskLayoutTemplatesdefault.htm). This file defines the default appearance and layout of the Print Task output window.
  3. Overwrite the markup of the new page with the contents from default.htm.
  4. Modify the markup and CSS to obtain the output you desire.

What can you do with these custom templates?

Using custom templates, you can:

  • Control the layout of elements and their styles

    In the template file, you can define the position and dimensions of the different elements on the page such as the map title, map image, and legend information. You can style the template page using inline CSS or an externally linked style sheet.

  • Inject dynamic content

    The template file is not restricted to static HTML files but can reference resources which generate dynamic content (such as .aspx files or .ashx files). For example, the current time stamp could be included in the print output using a dynamic page.

  • Control the display of results

    You can control the styling of task results through CSS and you may also choose to render the result entirely, forgoing the default generated table view. If you want to get more advanced, you might add an image generated using the Google Chart API or a report section rendered using a browser plugin like Silverlight.

  • Use JavaScript hooks

    In addition to providing extensibility with respect to layout and rendering, the Print Task also exposes JavaScript events which can be used to completely control and customize the output. This is achieved by having “callback functions” defined in the template file which are invoked at specific stages of the output rendering.

Further reading

The SDK sample Common Print Task demonstrates the above capabilities where a chart is drawn dynamically using the Google Chart API

Contributed by Nikhil Shampur of the ArcGIS Server .NET software development team.

Posted in Services | Tagged , , , | 1 Comment

ArcGIS JavaScript API printing through PDF

PrinterA common question we received at this year’s ESRI User Conference is how to print maps from the ArcGIS JavaScript API. One way to get a printable map is to export to PDF. ESRI’s Rahul Ravikumar recently uploaded a sample to the Code Gallery that captures an ArcGIS JavaScript API map in a PDF, which can then be printed. He calls this sample Map2PDF.

Map2PDF is a RESTful service that prints all types of layers, including cached (or tiled) map layers, dynamic map layers, and client-side graphics. The sample includes a script PrintMap.js, which helps in serializing ‘map state’ and sends it to the web service. This service uses an open source iText PDF rendering engine to create the PDF.

The Map2PDF sample uses Java Servlet technology and can be deployed any Servlet / J2EE container including Apache Tomcat 6, IBM Websphere, Oracle Weblogic etc. Deployment instructions are included with the Code Gallery download.

Download the Map2PDF sample from the Code Gallery

See an example

Posted in Services | Tagged , , | 2 Comments

What's new in the 9.3.1 .NET Web ADF

Here’s a brief look at what’s new in the ArcGIS Server .NET Web ADF at 9.3.1. This information comes from the What’s new in ArcGIS 9.3.1 PDF where you can read about new features in all areas of the product. If you have questions about any of the new features, please leave a comment to this post.

Customizing the look and feel of MapTips

The Web ADF JavaScript Library has been enhanced to provide greater control over customizing the look and feel of MapTips. New examples have been added to the MapTips sample that demonstrate how to leverage this new capability. In addition, a new MapTips custom control template is also available from the ArcGIS Server Resource Center .NET code gallery that enables drag-and-drop configuration of the new customization endpoints.

User control task

A new User Control task has been added to the available Web controls in the Web ADF. This new task is based on the User Control task sample available in the software developer kit (SDK). In addition, you can configure custom User Control tasks in ArcGIS Server Manager and include them in Web mapping applications.

Print task templates

In ArcGIS 9.3.1, a new property called LayoutTemplateFile is available that allows you to define the contents of your printed maps. This file, located at your Web site’s default root directory/aspnet_client/ESRI/WebADF/PrintTaskLayoutTemplates/default.htm, is customizable.

The Print task will generate a map layout based on your template. By default, at 9.3.1, this new map template includes the map title, map, and legend information. Task results and copyright text can also be included in the printed map.

Posted in Services | Tagged , , , , | 1 Comment

Print Task Sample

In this post, Bryan Baker comments on a new sample you can use to add a Print task to your Web ADF applications: 

A sample print task for the Web ADF for the Microsoft .NET Framework is now available at the ESRI Developer Network website. This sample allows users to do simple printing of a map and task results. ESRI plans to include printing in the upcoming 9.3 version, but this sample should get you started with printing from the Web ADF. The sample works in the Web ADFs for both ArcGIS Server and ArcIMS.

The sample task prints all resources and services in the Map control, including graphics layers and scalebar. It merges the resources into a single image that the browser displays in a new window. If the user has generated task results, such as with a query or identify, the user may also choose to print those results as a table below the map. The sample also allows entering a custom title. It does not currently support printing other items in the website, such as the table of contents or overview map.

In the website, the Map may be zoomed to any location, and other map properties may be set, such as turning layers on/off or displaying highlights from task results. If other tasks, such as a QueryAttributes task, have been added, the print task displays a list of results from those tasks to print. From the Print task dialog, the user may set a print title and task results to print (if any have been generated in the website). Clicking Print in the dialog pops up a new browser window with the title, map and task results (if any). The user may then print the page with their usual printing methods, to any available printer.

Some additional highlights:

  • The user may choose print size, resolution and scale. Resolution (e.g., 300 dpi) is accomplished via standard HTML in the browser.
  • The administrator can configure properties of the task, such as the default print page title, the maximum print size, whether to allow printing task results, and whether to print the scale bar on the map.

Installing the sample Print Task

You can install and use the sample task as-is, or customize it for your own use. To install the task you need to:

  1. Make sure the Web ADF is already installed, with Service Pack 1 or higher applied.
  2. Unzip the downloaded file.
  3. Register the task with the .NET global assembly cache.
  4. (Optional) Add the task to the Visual Studio toolbox.
  5. (Optional) Add the task to Manager.

Details for these steps are in the instructions at the EDN website, and also in the Readme.doc file accompanying the sample. The sample includes the source code for the task, which can be customized. (Note: If you downloaded the EDN sample before the date of this post, you should revisit the EDN site for updated instructions for adding the task to Manager.)

The instructions on EDN include the path to the ArcGIS Server Manager. To add the task to the ArcIMS Web Manager, follow the same instructions, except add the appropriate entry into the Tasks.xml file for the ArcIMS Web Manager, which by default is in C:InetpubwwwrootArcIMSManagerApplicationsApp_Data.

If you install a service pack for the Web ADF, you will need to reinstall the task into Manager. Uninstalling the task must be done manually; see the readme document for details.

Adding the sample Print Task to a Website

After you install the task, you can add it to a Web ADF web page, using either Manager or Visual Studio. In Manager, you should see the Print task in the list of available tasks when you create or edit a website. Add it to the list of tasks in the website, then configure it (you must click Configure for any task, even if you just keep the default settings). The configuration settings allows you to set properties such as the maximum allowed size and resolution and default title for the print page. When you save the website, the print task should appear in the menu of tasks in the website.

The Print task appears in the left menu of the Web mapping application

From Visual Studio, add the Print task like other tasks, usually into a TaskManager. Set the Print task's results container to a TaskResults control on the page, using the "smart tag" in the upper right of the task. You can set other properties in the Properties window of Visual Studio. You can set the task's Visible property to false if desired, and make sure a Menu or TreeView control is buddied to the TaskManager so the user sees a list of tasks to open.

The task currently requires that the web page include a Map control. If no Map control is present, an error will occur. The code could be customized to allow for a page with only tasks, such as a query task, with no map. Also, please note that the task will not work with ArcGIS Online services (currently in beta), since those services currently deliver maps only as cached tiles (this task requests new map images for printing).

This task does not use the layout of any ArcGIS Server service in the website. If you want to print using an MXD-based layout, you might want to check out Ismael Chivite's sample posted at ArcScripts that prints layouts.

We'd welcome your comments on this sample. The download page for the sample includes a user comments section. We'll also post periodic updates to the sample based on feedback.

You can try out the task yourself by printing a map from this example web application.

Posted in Services | Tagged , , , , | 12 Comments