Pregunta

I am reading a file of moving objects an put them in a dictionary (validMovingObjects). I represent each object as a pushpin on the map (baseMap). When an object changes its location (latitude or longitude), I update the validMovingObjects by (delete old instance and insert new one). Then I add all the objects in validMovingObjects to a map layer (objectsLayer) and yet to the baseMap. I do this with each single reading from the file by calling the refereshMap method below.

The problem:

The pushpins do not move. Only the last locations of the moving objects appear on the map as static pushpins.

Any help will be appreciated. Thanks

public void refereshMap(MapLayer objectsLayer, Microsoft.Maps.MapControl.WPF.Map baseMap)
{
    System.Threading.Thread.Sleep(500);

    baseMap.Children.Clear();

    objectsLayer.Children.Clear();

    PositionOrigin objectPositionOrigin = PositionOrigin.Center;

    Location objectLocation;

    foreach (KeyValuePair<int, MovingObject> pair in validMovingObjects) 
    {        
        objectLocation = new Location(pair.Value.objectLatitude,pair.Value.objectLongitude);

        objectsLayer.AddChild(pair.Value.objectPin, objectLocation, objectPositionOrigin);
    }

    baseMap.Children.Add(objectsLayer);
}
¿Fue útil?

Solución

You are certainly blocking the UI thread by repeatedly calling your refreshMap method in a loop.

Consider updating the pushpin positions in a Tick event handler of a DispatcherTimer.

Note also that it is not necessary to constantly remove and add pushpins to your objectLayer. Once a pushpin has been added to a MapLayer, you may just change its MapLayer.Position attached property.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top