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

How to colorize objects by non digital values

1 Answer 60 Views
Map
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nikolai
Top achievements
Rank 1
Nikolai asked on 08 Aug 2012, 06:08 AM
Здравствуйте.
У меня имеется shp-файл, содержащий полилинии. Необходимо раскрасить полилинии в зависимости от их кодов, которые прописаны в dbf-файле. Код линии не является числом. Можно ли выполнить раскраску без заложения функции отображающей значение поля в число?

Hello.
I have some shape file with polylines. I have to draw polylines by codes which are not numbers. Can I do this without coding field values by digits?

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 10 Aug 2012, 08:20 AM
Hi Nikolai,

Yes, you can colorize polylines using the dbf-field which is not numeric. You can use the PreviewReadCompleted event for this purpose. The sample code is below.
<telerik:RadMap x:Name="radMap" Center="40,-100" ZoomLevel="7">
    <telerik:RadMap.Provider>
        <telerik:OpenStreetMapProvider />
    </telerik:RadMap.Provider>
    <telerik:InformationLayer x:Name="informationLayer">
        <telerik:InformationLayer.Reader>
            <telerik:MapShapeReader Source="polylines" PreviewReadCompleted="OnPreviewReadCompleted" />
        </telerik:InformationLayer.Reader>
    </telerik:InformationLayer>
</telerik:RadMap>


private void OnPreviewReadCompleted(object sender, PreviewReadShapesCompletedEventArgs eventArgs)
{
    if (eventArgs.Error != null)
    {
        MessageBox.Show(eventArgs.Error.Message);
    }
    else
    {
        foreach (object item in eventArgs.Items)
        {
            var polyLine = item as MapPolyline;
            if (polyLine != null)
            {
                string code = (string)polyLine.ExtendedData.GetValue("CODE");
                this.SetPolylineColor(polyLine, code);
            }
        }
    }
}
 
private void SetPolylineColor(MapPolyline polyLine, string code)
{
    Color color = Colors.Blue;
    switch (code)
    {
        case "RED":
            color = Colors.Red;
            break;
 
        case "YELLOW":
            color = Colors.Yellow;
            break;
    }
 
    polyLine.Stroke = new SolidColorBrush(color);
    polyLine.StrokeThickness = 3;
}

All the best,
Andrey Murzov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

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