This is a migrated thread and some comments may be shown as answers.

TextBlock in Informationlayer Polygon

2 Answers 99 Views
Map
This is a migrated thread and some comments may be shown as answers.
Rieni De Rijke
Top achievements
Rank 1
Rieni De Rijke asked on 19 Dec 2011, 11:58 AM
In our Radmap we have an InformationLayer and a SpatialDataReader.
We display regions as polygons.
How can we use a TextBlock or a label to show the RegionName in the polygon.
We tried making a DataTemplate but it would not work...

<telerik:InformationLayer x:Name="MyLayer">
                    
   <telerik:InformationLayer.Reader>
        <telerik:SqlGeospatialDataReader x:Name="MyReader"  Source="{Binding}" 
                                         GeospatialPropertyName="RegionGeometry" ToolTipFormat="RegionName">
        </telerik:SqlGeospatialDataReader>
   </telerik:InformationLayer.Reader>
					
   <telerik:InformationLayer.ShapeFill>
					    <telerik:MapShapeFill Fill="#50CCFF66" Stroke="Orange" StrokeThickness="3" />
    </telerik:InformationLayer.ShapeFill>
				
</telerik:InformationLayer>

2 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 22 Dec 2011, 11:13 AM
Hello Rieni De Rijke,

You can use the CaptionLocation and the CaptionTemplate properties of MapShape to set the region name. It could be done using the InformationLayer.PreviewReadCompleted event. The sample code is below.
<Window x:Class="ShapeCaption.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <telerik:ExtendedDataConverter x:Key="ExtendedDataConverter" />
        <DataTemplate x:Key="CaptionTemplate">
            <Grid Background="Yellow" telerik:MapLayer.HotSpot="0.5, 0.5">
                <TextBlock Foreground="Blue" Text="{Binding Path=Data, Converter={StaticResource ExtendedDataConverter}, ConverterParameter=STATE_NAME}"/>
            </Grid>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <telerik:RadMap x:Name="RadMap1">
            <telerik:RadMap.Provider>
                <telerik:EmptyProvider />
            </telerik:RadMap.Provider>
            <telerik:InformationLayer x:Name="MyLayer">
                <telerik:InformationLayer.Reader>
                    <telerik:SqlGeospatialDataReader x:Name="MyReader" Source="{Binding}" GeospatialPropertyName="RegionGeometry" ToolTipFormat="RegionName" PreviewReadCompleted="PreviewReadCompleted">
                    </telerik:SqlGeospatialDataReader>
                </telerik:InformationLayer.Reader>
            </telerik:InformationLayer>
        </telerik:RadMap>
    </Grid>
</Window>

using System.Windows;
using Telerik.Windows.Controls.Map;
 
namespace ShapeCaption
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void PreviewReadCompleted(object sender, Telerik.Windows.Controls.Map.PreviewReadShapesCompletedEventArgs eventArgs)
        {
            if (eventArgs.Error == null)
            {
                DataTemplate template = this.Resources["CaptionTemplate"] as DataTemplate;
                foreach (MapShape shape in eventArgs.Items)
                {
                    Location location = shape.GeographicalBounds.Center;
 
                    shape.CaptionLocation = location;
                    shape.CaptionTemplate = template;
                }
            }
        }
    }
}

All the best,
Andrey Murzov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Rieni De Rijke
Top achievements
Rank 1
answered on 22 Dec 2011, 03:59 PM
It works!
Thank you very much!
Tags
Map
Asked by
Rieni De Rijke
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Rieni De Rijke
Top achievements
Rank 1
Share this question
or