How to colorize objects by non digital values

2 posts, 0 answers
  1. Nikolai
    Nikolai avatar
    13 posts
    Member since:
    Oct 2010

    Posted 08 Aug 2012 Link to this post

    Здравствуйте.
    У меня имеется 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?
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 10 Aug 2012 Link to this post

    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.

  3. DevCraft banner
Back to Top