New in 2012 v1, the C1ReportDesigner application has support for mapping. By adding visual maps to your reports you can do things like:
- Show sales totals per country or state
- Visualize which geographic areas have the most activity or revenue
- Draw lines connecting different cities to show routes or responsibilities
With the banded report model, you can easily render maps on multiple pages of the report (in each group or record), or just show a single map at the beginning or end of the report. The custom Map field is implemented using the C1.WPF.Maps assembly, and you can generate reports for any client (ie view the reports in Silverlight, ASP.NET, WPF, WinForms, etc).
Walk-through Using Maps in C1ReportDesigner
Now let’s walk through creating a simple report that shows customers by country using this new map field. First, let’s create the base report. Open up the C1ReportDesigner application and create a new report using the wizard. For this example I will use the classic Northwind database. Step 1: Create a new connection the Nwind.mdb file (you can find a copy under ComponentOne Samples/Common), and select the Customers table for the report. Step 2: Select some fields for the Detail section of the report, and some for the Group. This report will be grouped by Country, although it is not necessary for the map. Step 3: Select the outline layout for the new report. Step 4: Select the style for the new report, such as Aspect. Step 5: Name the report "Customers Report" and click finish. The report is now ready to add mapping. Add a Map field to the Header section of the report. You can customize various features of the map control such as tile and data layers, legends, styles, expressions, and zoom level. For this sample I want to see the whole world, but not those white spaces. Select the Map field and set these properties:
- AutoCenter: False
- AutoZoom: False
- CenterLatitude: 15
- ShowScale: False
- ZoomLevel: 0.5
Next, open the Layers collection and add a PointsLayer. This layer will be used to display a marker for every customer. Set these properties in the LayerBase Collection Editor:
- RecordSource: “SELECT * FROM CUSTOMERS”
- Caption: Customers
- MapLocation: City;Country
Setting the Location
The key to plotting markers on a map is knowing the longitude and latitude data. Points and lines layers provide two different ways to specify the spatial locations for the data:
- If you have the Latitude/Longitude data in your record source, then you simply map the Latitude and Longitude properties on the layer to these fields.
- In most cases you will not have the Lat/Long data. The special MapLocation property can be used to set an expression that can be used to retrieve the corresponding spatial location using an external online service using Goolge Maps. A typical MapLocation could look like this: “Address;City;PostalCode;Country” However you can use less information depending on what is available such as just “City;Country”
Whatever fields you specify in Latitude, Longitude or MapLocation must be part of the RecordSource query. Click OK and preview the report. Note that using MapLocation may be very time consuming due to Internet access. Hence by default the retrieved spatial data is stored in a local disk file. The path to that file is specified by the GeoCachePath property. By default the file's name is "geocache.xml", and it is stored in the same directory as the report definition. Disabling geocaching is not recommended.
The points layers collection supports clustering. When several point markers are located close to one another they may be "clustered" together into a single marker. Simply specify the cluster distance and the cluster styles in the layer collection editor.
- ClusterDistance: 10
- ClusterDistribution: Logarithmic
- ClusterStyles: add 1 with SizeExpr: 6
Adding a Legend
This sample just has one layer, but it’s quite possible to have many layers. Each layer may represent a different entity such as Suppliers, Employees, etc. You can add a Legend to the map by simply adding one to the Legends collection. By setting the legend’s Automatic property to True it will generate from the layers collection. Note: the text color of the legend items is determined by the text color specified for each layer. Add another PointsLayer with the RecordSource set to "SELECT * FROM SUPPLIERS" and set it up exactly like Customers but with a different style. Now we can show multiple layers and a legend.
For optimal disk space of your exported reports, you can lower the TargetDpi value. The map is rendered as an image in the final document. The TargetDpi controls the resolution of the image so the higher the resolution the larger the image file. The default value is 200. A good, bare minimum dpi is 72 if you are concerned about file size.
Adding maps can be an interesting way to view geographic data. The Map field also has support for drawing lines between two spatial locations, as well as loading KML files as the source. Below is a collection of sample reports that use more of the features than the sample described above. Download Sample Download Studio for WinForms