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

Dynamic Layer Example : "Must create DependencySource on same Thread as the DependencyObject."}

7 Answers 138 Views
Map
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 05 Feb 2016, 08:38 PM

Hi,

I take the Dynamic Layer example and i try to replace the points by the polylines.

internal List<PolylineData> GetFeatures(
            double upperLeftLat,
            double upperLeftLong,
            double lowerRightLat,
            double lowerRightLong,
            GeomType storeType)
        {
            try
            {
                PolylineData polyline1 = new PolylineData()
                {
                    ShapeFill = new MapShapeFill()
                    {
                        Stroke = new SolidColorBrush(Colors.Red),
                        StrokeThickness = 2
                    }
                };
 
                LocationCollection pt = new LocationCollection
                {
                    new Location(44.6957539183824, 23.3327663758679),
                    new Location(44.1429369264591, 24.7498095849434),
                    new Location(44.5131732087098, 27.4611884843576),
                    new Location(45.2073941930888, 27.9275176988258)
                };
 
                polyline1.Points = pt;
                _listPolylineDatas.Add(polyline1);
                return _listPolylineDatas;

 

But i have an exception : {"Must create DependencySource on same Thread as the DependencyObject."}

Do you have an solution for this issue ?

 

Thank you

7 Answers, 1 is accepted

Sort by
0
Julien
Top achievements
Rank 1
answered on 09 Feb 2016, 01:13 PM
The issue comes from this line : request.CompleteItemsRequest(list); Do you have a solution for the dynamic data ?
0
Martin Ivanov
Telerik team
answered on 09 Feb 2016, 01:42 PM
Hello Julien,

I wasn't able to reproduce the reported exception. However, keep in mind that the MapShapData object as PolylineData are designed to work asynchronously inside a VisualizationLayer. On the other hand the DynamicLayer works on a single thread which might causes the issue.

I recommend you to use MapShape along with the DynamicLayer or MapShapeData only with the VisualizationLayer. The VisualizationLayer is the new shapes rendering engine of the map which combines the old layers (VirtualizationLayer, DynamicLayer, InformationLayer). The new layer has improved performance and also few new features as reading shape files async and built-in selection. 

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Julien
Top achievements
Rank 1
answered on 09 Feb 2016, 01:44 PM

OK. Can you share an example ?

Thx

0
Martin Ivanov
Telerik team
answered on 09 Feb 2016, 01:49 PM
Hello,

You can take a look at the Items Virtualization and Map Shapes Virtualization help articles. The UI Virtualization demo also will be helpful.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Julien
Top achievements
Rank 1
answered on 09 Feb 2016, 02:19 PM

Thank you Martin for your information.

    

     
internal List<PolylineData> GetPolylineDatas(
    double upperLeftLat,
    double upperLeftLong,
    double lowerRightLat,
    double lowerRightLong,
    GeomType storeType)
{
        PolylineData polyline1 = new PolylineData()
        {
            ShapeFill = new MapShapeFill()
            {
                Stroke = new SolidColorBrush(Colors.Red),
                StrokeThickness = 2
            }
        };
 
        LocationCollection pt = new LocationCollection
        {
            new Location(44.6957539183824, 23.3327663758679),
            new Location(44.1429369264591, 24.7498095849434),
            new Location(44.5131732087098, 27.4611884843576),
            new Location(45.2073941930888, 27.9275176988258)
        };
 
        polyline1.Points = pt;
        _listPolylineDatas.Add(polyline1);
        return _listPolylineDatas;

After this function, i call SetPolylinesFeatures:

internal void SetPolylinesFeatures(List<PolylineData> list, MapItemsRequestEventArgs request)
        {
            request.CompleteItemsRequest(list);
        }

 

And i have this issue: Must create DependencySource on same Thread as the DependencyObject

 

0
Julien
Top achievements
Rank 1
answered on 10 Feb 2016, 01:09 PM

Do you have a solution ?

Thank you

0
Martin Ivanov
Telerik team
answered on 11 Feb 2016, 04:52 PM
Hello Julien,

It seems that the reported exception is thrown because the ShapeFill of the PolylineData object is set before the polyline is rendered in the visualization layer. The ShapeFill property accepts an object of type MapShapeFill which is a dependency object bound in the template of the map shape data elements. As the error states you cannot create a DependencyObject (the UIElement that represents the shape) on a different thread than the one on which is created the dependency source (the MapShapeFill object). On the other hand the layer works with the MapShapeData objects in different threads which causes the issue. 

To work this around you can avoid setting the MapShapeFill property of the MapShapeData elements and instead use the ShapeFill property of the VisualizationLayer. Also, you can take a look at the Graph Colorizer and Colorizer help articles.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Map
Asked by
Julien
Top achievements
Rank 1
Answers by
Julien
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or