Parameters
- mapMember
- MapMember object defining data source for the report.
| Exception | Description |
|---|---|
| ArcGIS.Core.CalledOnWrongThreadException | This method or property must be called within the lambda passed to QueuedTask.Run. |
| System.ArgumentNullException | mapMember |
| System.ArgumentException | MapMember is not a valid report data source. |
{
//Note: Run within QueuedTask.Run()
// get the first map in the project
MapProjectItem item = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(n => n.Name == "Cities");
if (item == null)
return;
Map map = item.GetMap();
if (map == null)
return;
Layer cityLayer = map.FindLayers("U.S. Cities")[0];
if (cityLayer == null)
return;
// load template information
var templatePath = System.IO.Path.Combine($@"{Project.Current.HomeFolderPath}\TemplateSimpleReportWithTokens.rptt");
ReportCustomTemplateDefinition templateDef = ReportTemplateManager.GetCustomTemplateDefinition(templatePath);
if (templateDef == null || templateDef.ReportTemplateDataSourceItems?.Count() < 1)
return;
// get template info of first data source (parent) and set its data source
ReportCustomTemplateDataSourceInfo parentDataSourceInfo = templateDef.ReportTemplateDataSourceItems.ElementAt(0);
parentDataSourceInfo.SetReportDataSource(cityLayer);
TemplateTokenFieldInfoValues templateTokenFieldInfoValues = parentDataSourceInfo.TokenInfoValues;
parentDataSourceInfo.DefinitionQuery = "STATE_NAME = 'Massachusetts'";
templateTokenFieldInfoValues["[text-field-value-0]"] = "CITY_NAME";
templateTokenFieldInfoValues["[text-field-name-0]"] = "City";
templateTokenFieldInfoValues["[numeric-field-value-0]"] = "POP1990";
templateTokenFieldInfoValues["[numeric-field-name-0]"] = "Population";
if (templateDef.CanCreateReport())
{
// create the report
report = ReportFactory.Instance.CreateReport("RelateSiblingsFromCode", templateDef);
}
//UI thread
if (report != null)
{
//open report
await FrameworkApplication.Panes.CreateReportPaneAsync(report);
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)