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

Custom colorizer

2 Answers 62 Views
Map
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 08 Aug 2011, 07:10 AM
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"?
Thanks.

2 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 08 Aug 2011, 12:14 PM
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?
0
Andrey
Telerik team
answered on 10 Aug 2011, 03:41 PM
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:RadMap.Provider>
        <telerik:EmptyProvider />
    </telerik:RadMap.Provider>
    <telerik:InformationLayer x:Name="informationLayer">
        <telerik:InformationLayer.Reader>
            <telerik:MapShapeReader DataSource="world.dbf" Source="world.shp"
                PreviewReadCompleted="MapShapeReader_PreviewReadCompleted"
                ToolTipFormat="CNTRY_NAME"/>
        </telerik:InformationLayer.Reader>
    </telerik:InformationLayer>
</telerik:RadMap>

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

Tags
Map
Asked by
Alexander
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or