How do I display shapes on a map? I have a list of co-ordinates in WKT format that make up simple polygons. I want to fill each polygon with a colour and display it on a map for the report.
Do I use a choropleth, or a ShapeMapSeries, or something else?
I've tried following this documentation and doing it programmatically, but I get this unhelpful error:
An error has occurred while rendering the report: System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.Reporting.XamlRendering.DocumentWriting.PrimitiveWriter.WriteText(TextElement textElement)
at Telerik.Reporting.XamlRendering.DocumentWriting.PrimitiveElementWriter.Visit(TextElement textElement)
at Telerik.Reporting.Processing.Primitives.TextElement.Accept(PrimitiveElementVisitor visitor)
at Telerik.Reporting.XamlRendering.DocumentWriting.XamlGraphWriter.Write(PrimitiveElement primitiveElement)
at Telerik.Reporting.Processing.GraphWriter.<WriteGraphArea>b__4(PrimitiveElement a)
at Telerik.Reporting.EnumerableExtensions.ForEach[T](IEnumerable`1 source, Action`1 action)
at Telerik.Reporting.Processing.GraphWriter.WriteGraphArea(GraphArea graphArea)
at Telerik.Reporting.Processing.GraphWriter.Write(Graph g)
at Telerik.Reporting.XamlRendering.DocumentWriting.GraphWriter.WriteDataItemContent(LayoutElement element, ElementPageInfo pageInfo)
at Telerik.Reporting.XamlRendering.DocumentWriting.DataItemWriter.WriteContent(LayoutElement element, ElementPageInfo pageInfo)
at Telerik.Reporting.XamlRendering.XamlWriter.WriteStartElement(LayoutElement element, ElementPageInfo pageInfo)
at Telerik.Reporting.BaseRendering.PageHandler.Telerik.Reporting.Paging.IPageHandler.StartElement(LayoutElement element, ElementPageInfo info)
at Telerik.Reporting.Paging.PageStartElement.AddToPage(IPageHandler handler)
at Telerik.Reporting.Paging.PageElementLayer.AddToPage(IPageHandler handler)
at Telerik.Reporting.Paging.PageElementManager.AddToPage(IPageHandler handler)
at Telerik.Reporting.Paging.PageCompositionBase.AddElementsToPage()
at Telerik.Reporting.Paging.PageCompositionBase.SendPhysicalPages()
at Telerik.Reporting.Paging.PageCompositionBase.OutputPage()
at Telerik.Reporting.Paging.PageCompositionBase.CreatePages()
at Telerik.Reporting.Paging.PagerBase.Telerik.Reporting.Paging.IPager.CreatePages(IPageHandler handler, Report report)
at Telerik.Reporting.BaseRendering.RenderingExtensionBase.Render(Report report, Hashtable renderingContext, Hashtable deviceInfo, CreateStream createStreamCallback, EvaluateHeaderFooterExpressions evalHeaderFooterCallback)
Here is an example of the code I'm using:
ObservableCollection<PrettyShape> data = GetTestData();
var myReport =
new
Report();
var detail =
new
DetailSection { KeepTogether =
true
};
var testGroup =
new
MapGroup();
var detailPanel =
new
Panel
{
Docking = DockingStyle.Top,
Size =
new
SizeU(Unit.Pixel(600), Unit.Pixel(400)),
Items =
{
new
Map
{
Size =
new
SizeU(Unit.Pixel(600), Unit.Pixel(450)),
Location =
new
PointU(Unit.Pixel(0), Unit.Pixel(50)),
TileProvider =
new
GenericTileProvider { UrlTemplate =
"url of tile provider goes here - tested in WPF RadMap"
},
Projection =
new
MercatorProjection(),
DataSource = data,
Series =
{
new
ShapeMapSeries
{
ShapeMapGroup =
new
ShapeMapGroup(),
SeriesGroup = testGroup,
ColorData =
"=Fields.FillColour"
,
SourceType =
new
WellKnownTextSourceType { SpatialField =
"=Fields.BoundaryPoints"
}
}
},
SeriesGroups = { testGroup }
}
detail.Items.Add(detailPanel);
myReport.Items.Add(detail);
MyReportViewer.ReportSource =
new
InstanceReportSource { ReportDocument = myReport };
MyReportViewer.RefreshReport();
and here is the data object:
public
class
PrettyShape
{
public
string
BoundaryPoints {
get
;
set
; }
public
string
FillColour
{
get
{
//various logic
return
"LimeGreen"
;
}
}
}
ObservableCollection<PrettyShape> GetTestData()
{
var list = new List<PrettyShape>
{
new PrettyShape{ BoundaryPoints = "POLYGON ((-22.635025359284 118.120505304517, -22.635025359284 118.103713989258, -22.64653164056320 118.103713989258, -22.64653164056320 118.120505304517))" }
};
return new ObservableCollection<PrettyShape>(list);
}