# Shape Reader

The **RadMap** allows you to read data from several data formats and wrap it in **MapShape** objects. The currently supported formats are:

* [KML Data](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/kml-data-import)

* [Shapefile Data](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shapefiles-support)

This topic will explain the following:

* [Reading Files](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-reder#reading-files)

* [Specifying a Tooltip](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-reder#specifying-a-tooltip)

* [Clearing the Layer](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-reder#clearing-the-layer)

* [Styling the Shapes](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-reder#styling-the-shapes)

## Reading Files

The **RadMap** control supports the visualization of **ESRI Shapefiles** and KML Data. It reads the data via the **MapShapeReader** class implemented in the **Information Layer**.

```XAML
<telerik:RadMap x:Name="radMap">
    <telerik:InformationLayer x:Name="informationLayer">
        <telerik:InformationLayer.Reader>
            <telerik:MapShapeReader />
        </telerik:InformationLayer.Reader>
    </telerik:InformationLayer>
</telerik:RadMap>
```

```C#
this.informationLayer.Reader = new MapShapeReader();
```

```VB.NET
	Me.informationLayer.Reader = New MapShapeReader()
```

To specify the type of the data the reader should read use the **SourceType** property of the **MapShapeReader** class. It can have the following values:

* **Auto** - automatically determines the type of the data.

* **KML** - specifies that the file to be read, contains KML Data.

* **Shapefile** - specifies that the file to be read contains Shapefile data.

To learn how to specify the files for each of the types read the respective topics:

* [KML Data Import](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/kml-data-import)

* [Shapefiles Support](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shapefiles-support)

## Specifying a Tooltip

The **MapShapeReader** object can use the data in the .dbf file and display it in a tooltip for the respective shape. In order to allow you to configure the tooltip's appearance and content, The **MapShapeReader** class exposes the following properties:

* [ToolTipFormat](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-reder#tooltipformat) - allows you to specify the format string for the tooltip. This is the simplest way to configure the tooltip, when having a one-line tooltip scenario.

* [ToolTipStyle](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-reder#tooltipstyle) - allows you to apply a Style that targets the ToolTip control.

* [ToolTipTemplate](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-reder#tooltiptemplate) - allows you to define a DataTemplate for the tooltip. This one is used when more complex, multiline and styled tooltip scenarios.

## ToolTipFormat

Using the **ToolTipFormat** property is the simplest way to create a single-line tooltip. The property is of type string and allow you to display both the value of a single property of the extended data and combination of the values of different extended data properties.

> tip To access the value of an extended data property use its name.

Here is an examples for different **ToolTipFormat** values.

## Single property value

```XAML
<telerik:RadMap x:Name="radMap1">
    <telerik:InformationLayer x:Name="informationLayer1">
        <telerik:InformationLayer.Reader>
            <telerik:MapShapeReader DataSource="/Silverlight.Help.RadMapSamples;component/Data/world.dbf"
	                                    Source="/Silverlight.Help.RadMapSamples;component/Data/world.shp"
	                                    ToolTipFormat="CNTRY_NAME" />
        </telerik:InformationLayer.Reader>
    </telerik:InformationLayer>
</telerik:RadMap>
```

```C#
this.informationLayer.Reader.ToolTipFormat = "CNTRY_NAME";
```

```VB.NET
	Me.informationLayer.Reader.ToolTipFormat = "CNTRY_NAME";
```

Here is a snapshot of the result:

![WPF RadMap Shape Reader Tooltip Format](https://www.telerik.com/products/wpf/documentation/assets/02b269867637823e7dad44dab8218f7e/radmap_shapefiles_01.png)

## Formatted property value

> Note that in this case the format string begins with "**{}**". This escapes the following **{PropertyName}** expressions. In code behind you mustn't add it to the actual format string.

```XAML
<telerik:RadMap x:Name="radMap2">
    <telerik:InformationLayer x:Name="informationLayer2">
        <telerik:InformationLayer.Reader>
            <telerik:MapShapeReader DataSource="/Silverlight.Help.RadMapSamples;component/Data/world.dbf"
	                                    Source="/Silverlight.Help.RadMapSamples;component/Data/world.shp"
	                                    ToolTipFormat="{}{SQKM|F2} sq.km." />
        </telerik:InformationLayer.Reader>
    </telerik:InformationLayer>
</telerik:RadMap>
```

```C#
this.informationLayer.Reader.ToolTipFormat = "{SQKM|F2} sq.km.";
```

```VB.NET
	Me.informationLayer.Reader.ToolTipFormat = "{SQKM|F2} sq.km.";
```

Here is a snapshot of the result:

![WPF RadMap Shape Reader Tooltip Format Custom](https://www.telerik.com/products/wpf/documentation/assets/1a39783f3768ed991282d588f0b3f763/radmap_shapefiles_02.png)

## Multiple formatted property values

> Note that in this case the format string begins with "**{}**". This escapes the following **{PropertyName}** expressions. In code behind you mustn't add it to the actual format string.

```XAML
<telerik:RadMap x:Name="radMap3">
    <telerik:InformationLayer x:Name="informationLayer3">
        <telerik:InformationLayer.Reader>
            <telerik:MapShapeReader DataSource="/Silverlight.Help.RadMapSamples;component/Data/world.dbf"
	                                    Source="/Silverlight.Help.RadMapSamples;component/Data/world.shp"
	                                    ToolTipFormat="{}{CNTRY_NAME} - {SQKM|F2} sq.km." />
        </telerik:InformationLayer.Reader>
    </telerik:InformationLayer>
</telerik:RadMap>
```

```C#
this.informationLayer.Reader.ToolTipFormat = "{CNTRY_NAME} - {SQKM|F2} sq.km.";
```

```VB.NET
	Me.informationLayer.Reader.ToolTipFormat = "{CNTRY_NAME} - {SQKM|F2} sq.km."
```

Here is a snapshot of the result:

![WPF RadMap Shape Reader Tooltip Format Multiple Values](https://www.telerik.com/products/wpf/documentation/assets/85d196bf0c91060ca4f9fb3b373b41e6/radmap_shapefiles_03.png)

## ToolTipStyle

The **ToolTipStyle** property allows you to specify a Style of the tooltip that gets displayed. The Style should target the ToolTip control. Here is an example.

> tip To learn how to modify the color of the shapes like on the snapshot below, you have to read the [Styling the Shapes](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shape-reder#styling-the-shapes) section.

```XAML
<telerik:RadMap x:Name="radMap4">
    <telerik:InformationLayer x:Name="informationLayer4">
        <telerik:InformationLayer.Reader>
            <telerik:MapShapeReader DataSource="/Silverlight.Help.RadMapSamples;component/Data/world.dbf"
	                                    Source="/Silverlight.Help.RadMapSamples;component/Data/world.shp"
	                                    ToolTipFormat="{}{CNTRY_NAME} - {SQKM|F2} sq.km.">
                <telerik:MapShapeReader.ToolTipStyle>
                    <Style TargetType="ToolTip">
                        <Setter Property="BorderBrush"
	                                Value="Orange" />
                        <Setter Property="Background"
	                                Value="Black" />
                        <Setter Property="Foreground"
	                                Value="White" />
                    </Style>
                </telerik:MapShapeReader.ToolTipStyle>
            </telerik:MapShapeReader>
        </telerik:InformationLayer.Reader>
    </telerik:InformationLayer>
</telerik:RadMap>
```

Here is a snapshot of the result:

![WPF RadMap Shape Reader Tooltip Style](https://www.telerik.com/products/wpf/documentation/assets/9dd1f2b5692d341d7942724be95a5324/radmap_shapefiles_04.png)

## ToolTipTemplate

The **ToolTipTemplate** property allows you to define a **DataTemplate** for the tooltip. This way you are able to create more complex layouts like multiline content or content containing different visual elements like **Borders**, **Images** etc.

In this case the **DataTemplate** takes as **DataContext** the entire Extended Data Set. To get a specific value you have to bind to it and use a converter to access the desired attribute. The **RadMap** provides such converter out of the box. It is represented by the **ExtendedDataConverter**. To use it just bind to the extended data set and pass the desired attribute name as parameter. Here is an example.

> The **ToolTipTemplate** property will take precedence over the **ToolTipFormat** one.

```XAML

<Grid>
    <Grid.Resources>
        <telerik:ExtendedDataConverter x:Key="ExtendedDataConverter" />
    </Grid.Resources>
    <telerik:RadMap x:Name="radMap5">
        <telerik:InformationLayer x:Name="informationLayer5">
            <telerik:InformationLayer.Reader>
                <telerik:MapShapeReader DataSource="/Silverlight.Help.RadMapSamples;component/Data/world.dbf"
	                                    Source="/Silverlight.Help.RadMapSamples;component/Data/world.shp">
                    <telerik:MapShapeReader.ToolTipTemplate>
                        <DataTemplate>
                            <StackPanel Margin="10,5">
                                <TextBlock FontWeight="Bold"
	                                        Text="{Binding Converter={StaticResource ExtendedDataConverter}, ConverterParameter='CNTRY_NAME'}" />
                                <TextBlock Text="{Binding Converter={StaticResource ExtendedDataConverter}, ConverterParameter='SQKM', StringFormat='Area: {0:#,#.0} sq.km.'}" />
                            </StackPanel>
                        </DataTemplate>
                    </telerik:MapShapeReader.ToolTipTemplate>
                </telerik:MapShapeReader>
            </telerik:InformationLayer.Reader>
        </telerik:InformationLayer>
    </telerik:RadMap>
</Grid>
```

Here is a snapshot of the result:

![WPF RadMap Shape Reader Tooltip Template](https://www.telerik.com/products/wpf/documentation/assets/56657eeec8974062b5e0dd86e0292686/radmap_shapefiles_05.png)

## Clearing the Layer

When adding the read shapes to the layer, the **MapShapeReader** is able to clear it first. This means that all previously added shapes will get removed and the new ones will be added. This behavior is controled by the **ClearLayer** property of the **MapShapeLayer**. It's default value is **True**. This means that the described behavior will be active by default. To disable it set the property to **False**.

## Styling the Shapes

To modify the appearance of the shapes in terms of **Fill**, **Stroke** etc. you can either use the HighlightFill and Shape Fill properties of the **InformationLayer** or use the [Colorizer](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/colorizer) property of the **InformationLayer**.

## See Also

* [Shapefiles Support](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/shapefiles-support)
* [KML Data Import](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/kml-data-import)
* [Colorizer](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/information-layer/colorizer)
* [Map Legend](https://www.telerik.com/products/wpf/documentation/controls/radmap/features/map-legend)
