Custom colorizer

3 posts, 0 answers
  1. Alexander
    Alexander avatar
    18 posts
    Member since:
    Jul 2010

    Posted 08 Aug 2011 Link to this post

    Is it possible to colorize the MapShape objects on the basis of some string condition?
    For example, how to fill shape with color depending on the name of shape: "if Country == 'United States' fill it with green"?
  2. Alex
    Alex avatar
    30 posts
    Member since:
    Aug 2010

    Posted 08 Aug 2011 Link to this post

    Please help!

    We need to paint the shapes based on some properties outside of the shapefile. The values, determining the colors, change frequently; so we can't place them into the shapefile. For example, I need to show the today's temperature in every country. How could we do it?
  3. DevCraft R3 2016 release webinar banner
  4. Andrey
    Andrey avatar
    1681 posts

    Posted 10 Aug 2011 Link to this post

    Hi Alexander,

    You can handle the PreviewReadCompleted event of the MapShapeReader to set color for map shape. Data from dbf-file will be available in the ExtendedData property of map shape. You can get it using the ExtendedData.GetValue method.
    The sample code is below.
    <telerik:RadMap x:Name="radMap">
            <telerik:EmptyProvider />
        <telerik:InformationLayer x:Name="informationLayer">
                <telerik:MapShapeReader DataSource="world.dbf" Source="world.shp"

    private void Reader_PreviewReadCompleted(object sender, PreviewReadShapesCompletedEventArgs eventArgs)
        if (eventArgs.Error == null)
            foreach (MapShape shape in eventArgs.Items)
                ExtendedData extendedData = shape.ExtendedData;
                if (extendedData != null)
                    string countryName = (string)shape.ExtendedData.GetValue("CNTRY_NAME");
                    if (countryName == "United States")
                        shape.Fill = new SolidColorBrush(Colors.Green);

    Kind regards,
    Andrey Murzov
    the Telerik team

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

Back to Top