TextBlock in Informationlayer Polygon

3 posts, 0 answers
  1. Rieni De Rijke
    Rieni De Rijke avatar
    170 posts
    Member since:
    Mar 2010

    Posted 19 Dec 2011 Link to this post

    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. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 22 Dec 2011 Link to this post

    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Rieni De Rijke
    Rieni De Rijke avatar
    170 posts
    Member since:
    Mar 2010

    Posted 22 Dec 2011 Link to this post

    It works!
    Thank you very much!
Back to Top