3.17 Map

The following example report is a map that shows the results for the 2008 United States presidential election. The states are colored based on the winning candidate. This map also shows a bubble for each state. The bubble size is based on the number of electoral votes for each state.

Map example

Figure 25: Map example

The data source that is used in this report is "ElectionMap". Two datasets, "Spatial" and "Analytics", are defined in the report. The map report item contains one MapPolygonLayer that shows the map of the states.

The MapSpatialDataSet element within the layer describes how the spatial data is retrieved from the "Spatial" dataset. The MapSpatialDataSet.DataSetName element specifies the name of the dataset to be bound to. The MapSpatialDataSet.SpatialField element specifies the name of the field to use as the source for the spatial data. The MapFieldNames element specifies the name of the non-spatial fields to associate with the spatial elements. (Typically, these fields are used to join the spatial elements to the analytical dataset.)

The MapDataRegion element named "Map1_PolygonLayer1_DataRegion" specifies the source for analytical data. In this case, the source is the "Analytics" dataset. The MapMember element specifies how the rows in the dataset are grouped. In this case, the data is grouped by state by the group expression =Fields!State.Value.

After the spatial data and the analytical data are defined, the MapBindingFieldPairs element specifies how these data are joined together. Each MapBindingFieldPair element specifies a FieldName from the spatial data and a BindingExpression from the analytical data. If all the pairs match, the spatial element is bound to the analytical data.

Next is the role of the rules by which to visualize the analytical data. The polygon layer contains a MapPolygonRules element that has a MapColorRangeRule. This rule specifies the range of color to use to colorize the shapes, and a DataValue element to choose which field to visualize (in this case, =Fields!Winner.Value).

To display the bubble for the number of electoral votes, a MapPolygonLayer.MapCenterPointRules element is defined in the layer together with the MapSizeRule element. The MapSizeRule element controls the size of the bubbles based on the expression =Sum(Fields!ID_EV.Value).

 <?xml version="1.0" encoding="utf-8"?>
 <Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"
 xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
   <DataSources>
     <DataSource Name="ElectionMap">
       <ConnectionProperties>
         <DataProvider>SQL</DataProvider>
         <ConnectString>Data Source=.\map7;Initial Catalog=Election</ConnectString>
         <IntegratedSecurity>true</IntegratedSecurity>
       </ConnectionProperties>
       <rd:DataSourceID>b1cba34d-af07-4e11-9d13-8df5f2fd0325</rd:DataSourceID>
       <rd:SecurityType>Windows</rd:SecurityType>
     </DataSource>
   </DataSources>
   <DataSets>
     <DataSet Name="Analytics">
       <Fields>
         <Field Name="State">
           <DataField>State</DataField>
           <rd:TypeName>System.String</rd:TypeName>
         </Field>
         <Field Name="ID_EV">
           <DataField>#EV</DataField>
           <rd:TypeName>System.Double</rd:TypeName>
         </Field>
         <Field Name="Date">
           <DataField>Date</DataField>
           <rd:TypeName>System.DateTime</rd:TypeName>
         </Field>
         <Field Name="BO">
           <DataField>BO</DataField>
           <rd:TypeName>System.Double</rd:TypeName>
         </Field>
         <Field Name="JM">
           <DataField>JM</DataField>
           <rd:TypeName>System.Double</rd:TypeName>
         </Field>
         <Field Name="Balance">
           <DataField>Balance</DataField>
           <rd:TypeName>System.Int32</rd:TypeName>
         </Field>
         <Field Name="Winner">
           <DataField>Winner</DataField>
           <rd:TypeName>System.String</rd:TypeName>
         </Field>
       </Fields>
       <Query>
         <DataSourceName>ElectionMap</DataSourceName>
         <CommandText>SELECT
   Election.[State]
   ,Election.#EV
   ,Election.[Date]
   ,Election.BO
   ,Election.JM
   ,Election.Balance
   ,Election.Winner
 FROM
   Election</CommandText>
         <rd:RQDDesignerState>
           <QueryDefinition 
 xmlns="http://schemas.microsoft.com/ReportingServices/QueryDefinition/Relational">
             <SelectedColumns>
               <ColumnExpression ColumnOwner="Election" ColumnName="State" />
               <ColumnExpression ColumnOwner="Election" ColumnName="#EV" />
               <ColumnExpression ColumnOwner="Election" ColumnName="Date" />
               <ColumnExpression ColumnOwner="Election" ColumnName="BO" />
               <ColumnExpression ColumnOwner="Election" ColumnName="JM" />
               <ColumnExpression ColumnOwner="Election" ColumnName="Balance" />
               <ColumnExpression ColumnOwner="Election" ColumnName="Winner" />
             </SelectedColumns>
           </QueryDefinition>
         </rd:RQDDesignerState>
       </Query>
     </DataSet>
     <DataSet Name="Spatial">
       <Fields>
         <Field Name="Name">
           <DataField>Name</DataField>
           <rd:TypeName>System.String</rd:TypeName>
         </Field>
         <Field Name="SpatialData">
           <DataField>SpatialData</DataField>
           <rd:TypeName>Microsoft.SqlServer.Types.SqlGeometry, 
 Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, 
 PublicKeyToken=89845dcd8080cc91</rd:TypeName>
         </Field>
       </Fields>
       <Query>
         <DataSourceName>ElectionMap</DataSourceName>
         <CommandText>SELECT
   USA.Name
   ,USA.SpatialData
 FROM
   USA</CommandText>
         <rd:RQDDesignerState>
           <QueryDefinition 
 xmlns="http://schemas.microsoft.com/ReportingServices/QueryDefinition/Relational">
             <SelectedColumns>
               <ColumnExpression ColumnOwner="USA" ColumnName="Name" />
               <ColumnExpression ColumnOwner="USA" ColumnName="SpatialData" />
             </SelectedColumns>
           </QueryDefinition>
         </rd:RQDDesignerState>
       </Query>
     </DataSet>
   </DataSets>
   <ReportSections>
     <ReportSection>
       <Body>
         <ReportItems>
           <Map Name="Map1">
             <MapViewport>
               <MapCoordinateSystem>Geographic</MapCoordinateSystem>
               <MapProjection>Mercator</MapProjection>
               <ProjectionCenterX>0</ProjectionCenterX>
               <ProjectionCenterY>0</ProjectionCenterY>
               <MapLimits>
                 <MinimumX>NaN</MinimumX>
                 <MinimumY>NaN</MinimumY>
                 <MaximumX>NaN</MaximumX>
                 <MaximumY>NaN</MaximumY>
               </MapLimits>
               <SimplificationResolution>0.01</SimplificationResolution>
               <MapCustomView>
                 <CenterX>55.0153007507324</CenterX>
                 <CenterY>50.9827842712402</CenterY>
                 <Zoom>112.46826171875</Zoom>
               </MapCustomView>
               <MapMeridians>
                 <Style>
                   <Border>
                     <Color>#c08080ff</Color>
                     <Style>None</Style>
                   </Border>
                   <Color>#c08080ff</Color>
                 </Style>
                 <Hidden>true</Hidden>
                 <Interval>NaN</Interval>
                 <ShowLabels>true</ShowLabels>
               </MapMeridians>
               <MapParallels>
                 <Style>
                   <Border>
                     <Color>#c08080ff</Color>
                     <Style>None</Style>
                   </Border>
                   <Color>#c08080ff</Color>
                 </Style>
                 <Hidden>true</Hidden>
                 <Interval>NaN</Interval>
                 <ShowLabels>true</ShowLabels>
               </MapParallels>
               <GridUnderContent>false</GridUnderContent>
               <Style>
                 <Border>
                   <Color>Gray</Color>
                   <Style>Solid</Style>
                 </Border>
                 <BackgroundColor>White</BackgroundColor>
                 <BackgroundGradientType>DiagonalLeft</BackgroundGradientType>
                 <BackgroundGradientEndColor>
                   LightGrey
                 </BackgroundGradientEndColor>
                 <ShadowOffset>1pt</ShadowOffset>
               </Style>
               <LeftMargin>4pt</LeftMargin>
               <RightMargin>4pt</RightMargin>
               <TopMargin>4pt</TopMargin>
               <BottomMargin>4pt</BottomMargin>
             </MapViewport>
             <MapDataRegions>
               <MapDataRegion Name="Map1_PolygonLayer1_DataRegion">
                 <DataSetName>Analytics</DataSetName>
                 <MapMember>
                   <Group Name="Map1_PolygonLayer1_Group">
                     <GroupExpressions>
                       <GroupExpression>=Fields!State.Value</GroupExpression>
                     </GroupExpressions>
                   </Group>
                 </MapMember>
               </MapDataRegion>
             </MapDataRegions>
             <MapLayers>
               <MapPolygonLayer Name="PolygonLayer1">
                 <MapPolygonTemplate>
                   <CenterPointOffsetX>0</CenterPointOffsetX>
                   <CenterPointOffsetY>0</CenterPointOffsetY>
                   <Style>
                     <Border>
                       <Color>White</Color>
                       <Style>Solid</Style>
                     </Border>
                     <BackgroundColor>White</BackgroundColor>
                     <BackgroundGradientType>None</BackgroundGradientType>
                     <BackgroundGradientEndColor>
                       LightGrey
                     </BackgroundGradientEndColor>
                     <FontSize>8pt</FontSize>
                     <FontWeight>Bold</FontWeight>
                     <Color>White</Color>
                   </Style>
                   <Hidden>false</Hidden>
                   <OffsetX>0</OffsetX>
                   <OffsetY>0</OffsetY>
                   <Label>#NAME</Label>
                   <ToolTip />
                   <DataElementLabel />
                 </MapPolygonTemplate>
                 <MapPolygonRules>
                   <MapColorRangeRule>
                     <StartColor>#c3ff0000</StartColor>
                     <EndColor>#c30000ff</EndColor>
                     <ShowInColorScale>true</ShowInColorScale>
                     <DataValue>=Fields!Winner.Value</DataValue>
                     <StartValue />
                     <EndValue />
                     <LegendName>Legend1</LegendName>
                     <LegendText>#FROMVALUE{N0} - #TOVALUE{N0}</LegendText>
                   </MapColorRangeRule>
                 </MapPolygonRules>
                 <MapMarkerTemplate>
                   <MapMarker>
                     <MapMarkerStyle>Circle</MapMarkerStyle>
                   </MapMarker>
                   <Style>
                     <Border>
                       <Color>Gray</Color>
                       <Style>Solid</Style>
                     </Border>
                     <BackgroundColor>White</BackgroundColor>
                     <BackgroundGradientType>
                       DiagonalLeft
                     </BackgroundGradientType>
                     <BackgroundGradientEndColor>
                       #00ffffff
                     </BackgroundGradientEndColor>
                   </Style>
                   <Hidden>false</Hidden>
                   <OffsetX>0</OffsetX>
                   <OffsetY>0</OffsetY>
                   <Label />
                   <ToolTip />
                   <DataElementLabel />
                 </MapMarkerTemplate>
                 <MapCenterPointRules>
                   <MapSizeRule>
                     <StartSize>10pt</StartSize>
                     <EndSize>60pt</EndSize>
                     <DataValue>=Sum(Fields!ID_EV.Value)</DataValue>
                     <StartValue />
                     <EndValue />
                     <LegendName>Legend2</LegendName>
                     <LegendText>
                       #FROMVALUE - #TOVALUE
                     </LegendText>
                   </MapSizeRule>
                 </MapCenterPointRules>
                 <MapDataRegionName>
 Map1_PolygonLayer1_DataRegion
                 </MapDataRegionName>
                 <MapBindingFieldPairs>
                   <MapBindingFieldPair>
                     <FieldName>Name</FieldName>
                     <BindingExpression>=Fields!State.Value</BindingExpression>
                   </MapBindingFieldPair>
                 </MapBindingFieldPairs>
                 <MapFieldDefinitions>
                   <MapFieldDefinition>
                     <Name>Name</Name>
                     <DataType>String</DataType>
                   </MapFieldDefinition>
                 </MapFieldDefinitions>
                 <MapSpatialDataSet>
                   <DataSetName>Spatial</DataSetName>
                   <SpatialField>SpatialData</SpatialField>
                   <MapFieldNames>
                     <MapFieldName>Name</MapFieldName>
                   </MapFieldNames>
                 </MapSpatialDataSet>
               </MapPolygonLayer>
             </MapLayers>
             <MapLegends>
               <MapLegend Name="Legend1">
                 <MapLegendTitle>
                   <Style>
                     <BackgroundColor>#00ffffff</BackgroundColor>
                   </Style>
                   <Caption>Candidates</Caption>
                 </MapLegendTitle>
                 <AutoFitTextDisabled>false</AutoFitTextDisabled>
                 <InterlacedRows>false</InterlacedRows>
                 <EquallySpacedItems>false</EquallySpacedItems>
                 <Position>RightTop</Position>
                 <DockOutsideViewport>false</DockOutsideViewport>
                 <Hidden>false</Hidden>
                 <ToolTip />
                 <Style>
                   <Border>
                     <Color>Gray</Color>
                     <Style>Solid</Style>
                   </Border>
                   <BackgroundColor>White</BackgroundColor>
                   <BackgroundGradientType>
                     DiagonalLeft
                   </BackgroundGradientType>
                   <BackgroundGradientEndColor>
                     LightGrey
                   </BackgroundGradientEndColor>
                   <ShadowOffset>1pt</ShadowOffset>
                 </Style>
                 <LeftMargin>4pt</LeftMargin>
                 <RightMargin>4pt</RightMargin>
                 <TopMargin>4pt</TopMargin>
                 <BottomMargin>4pt</BottomMargin>
               </MapLegend>
               <MapLegend Name="Legend2">
                 <MapLegendTitle>
                   <Style>
                     <BackgroundColor>#00ffffff</BackgroundColor>
                   </Style>
                   <Caption>Electoral Votes</Caption>
                 </MapLegendTitle>
                 <AutoFitTextDisabled>false</AutoFitTextDisabled>
                 <InterlacedRows>false</InterlacedRows>
                 <EquallySpacedItems>false</EquallySpacedItems>
                 <Position>RightBottom</Position>
                 <DockOutsideViewport>false</DockOutsideViewport>
                 <Hidden>false</Hidden>
                 <ToolTip />
                 <Style>
                   <Border>
                     <Color>Gray</Color>
                     <Style>Solid</Style>
                   </Border>
                   <BackgroundColor>White</BackgroundColor>
                   <BackgroundGradientType>DiagonalLeft</BackgroundGradientType>
                   <BackgroundGradientEndColor>
                     LightGrey
                   </BackgroundGradientEndColor>
                   <ShadowOffset>1pt</ShadowOffset>
                 </Style>
                 <LeftMargin>4pt</LeftMargin>
                 <RightMargin>4pt</RightMargin>
                 <TopMargin>4pt</TopMargin>
                 <BottomMargin>4pt</BottomMargin>
               </MapLegend>
             </MapLegends>
             <MapDistanceScale>
               <Position>RightBottom</Position>
               <DockOutsideViewport>false</DockOutsideViewport>
               <Hidden>true</Hidden>
               <ToolTip />
               <Style>
                 <Border>
                   <Color>Gray</Color>
                   <Style>Solid</Style>
                 </Border>
                 <BackgroundColor>White</BackgroundColor>
                 <BackgroundGradientType>DiagonalLeft</BackgroundGradientType>
                 <BackgroundGradientEndColor>
                   LightGrey
                 </BackgroundGradientEndColor>
                 <ShadowOffset>1pt</ShadowOffset>
               </Style>
               <MapSize>
                 <Width>80</Width>
                 <Height>40</Height>
                 <Unit>Point</Unit>
               </MapSize>
               <LeftMargin>4pt</LeftMargin>
               <RightMargin>4pt</RightMargin>
               <TopMargin>4pt</TopMargin>
               <BottomMargin>4pt</BottomMargin>
             </MapDistanceScale>
             <MapColorScale>
               <MapColorScaleTitle>
                 <Style />
                 <Caption />
               </MapColorScaleTitle>
               <LabelFormat>#,##0.##</LabelFormat>
               <HideEndLabels>false</HideEndLabels>
               <NoDataText>No data</NoDataText>
               <Position>LeftBottom</Position>
               <DockOutsideViewport>false</DockOutsideViewport>
               <Hidden>true</Hidden>
               <ToolTip />
               <Style>
                 <Border>
                   <Color>Gray</Color>
                   <Style>Solid</Style>
                 </Border>
                 <BackgroundColor>White</BackgroundColor>
                 <BackgroundGradientType>DiagonalLeft</BackgroundGradientType>
                 <BackgroundGradientEndColor>
                   LightGrey
                 </BackgroundGradientEndColor>
                 <ShadowOffset>1pt</ShadowOffset>
               </Style>
               <LeftMargin>4pt</LeftMargin>
               <RightMargin>4pt</RightMargin>
               <TopMargin>4pt</TopMargin>
               <BottomMargin>4pt</BottomMargin>
             </MapColorScale>
             <MapBorderSkin>
               <Style>
                 <Border />
                 <BackgroundColor>Gray</BackgroundColor>
                 <BackgroundGradientType>None</BackgroundGradientType>
                 <BackgroundGradientEndColor>
                   White
                 </BackgroundGradientEndColor>
                 <Color>White</Color>
               </Style>
             </MapBorderSkin>
             <MaximumSpatialElementCount>0</MaximumSpatialElementCount>
             <MaximumTotalPointCount>0</MaximumTotalPointCount>
             <Top>0.57223in</Top>
             <Height>6.09737in</Height>
             <Width>9.89583in</Width>
             <Style>
               <Border>
                 <Color>Gray</Color>
                 <Style>None</Style>
               </Border>
               <BackgroundColor>White</BackgroundColor>
             </Style>
           </Map>
           <Textbox Name="ReportTitle">
             <CanGrow>true</CanGrow>
             <KeepTogether>true</KeepTogether>
             <Paragraphs>
               <Paragraph>
                 <TextRuns>
                   <TextRun>
                     <Value>2008 United States Presidential Election</Value>
                     <Style>
                       <FontStyle>Normal</FontStyle>
                       <FontFamily>Verdana</FontFamily>
                       <FontSize>16pt</FontSize>
                       <FontWeight>Normal</FontWeight>
                       <TextDecoration>None</TextDecoration>
                     </Style>
                   </TextRun>
                 </TextRuns>
                 <Style />
               </Paragraph>
             </Paragraphs>
             <rd:WatermarkTextbox>Title</rd:WatermarkTextbox>
             <rd:DefaultName>ReportTitle</rd:DefaultName>
             <Top>0.13056in</Top>
             <Left>2.48958in</Left>
             <Height>0.4in</Height>
             <Width>6.66667in</Width>
             <ZIndex>1</ZIndex>
             <Style>
               <Border>
                 <Style>None</Style>
               </Border>
               <PaddingLeft>2pt</PaddingLeft>
               <PaddingRight>2pt</PaddingRight>
               <PaddingTop>2pt</PaddingTop>
               <PaddingBottom>2pt</PaddingBottom>
             </Style>
           </Textbox>
         </ReportItems>
         <Height>6.76681in</Height>
         <Style>
           <Border>
             <Style>None</Style>
           </Border>
         </Style>
       </Body>
       <Width>10.36333in</Width>
       <Page>
         <PageFooter>
           <Height>0.25208in</Height>
           <PrintOnFirstPage>true</PrintOnFirstPage>
           <PrintOnLastPage>true</PrintOnLastPage>
           <Style>
             <Border>
               <Style>None</Style>
             </Border>
           </Style>
         </PageFooter>
         <LeftMargin>1in</LeftMargin>
         <RightMargin>1in</RightMargin>
         <TopMargin>1in</TopMargin>
         <BottomMargin>1in</BottomMargin>
         <Style />
       </Page>
     </ReportSection>
   </ReportSections>
   <rd:ReportID>bd235c9b-b91c-480f-8759-edc46cbf8e32</rd:ReportID>
   <rd:ReportUnitType>Inch</rd:ReportUnitType>
 </Report>