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

Center Property Not Correctly Set

5 Answers 106 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.
Trinh
Top achievements
Rank 1
Trinh asked on 01 Mar 2012, 03:26 AM
I'm trying to traverse through each item on the map randomly when the application is in idle. I did this by setting up a custom attach property and I would bind my storyboard animation to it. Inside the attach property, I would set the center/zoomlevel everytime the property value changes.

Example of setting the center value of the map.

private static void OnMapCenterPositionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var mapCtrl = (RadMap)d;
            var p = (Point)(e.NewValue);
            Debug.WriteLine("Old Value: " + mapCtrl.Center.Latitude + ", " + mapCtrl.Center.Longitude);
            var newLocation = new Location(p.X, p.Y);
            mapCtrl.Center = newLocation;
            Debug.WriteLine("New Value: " + p.X + ", " + p.Y);
            Debug.WriteLine("Changed Value: " + mapCtrl.Center.Latitude + ", " + mapCtrl.Center.Longitude);
        }

Storyboard
<Storyboard x:Name="TraverseStoryboard" Completed="TraverseStoryboardCompleted">
            <DoubleAnimationUsingKeyFrames x:Name="ZoomAnimation" AutoReverse="True"
                        Storyboard.TargetName="ProductMaps">
                <EasingDoubleKeyFrame KeyTime="0:0:0" Value="3.0">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <SineEase EasingMode="EaseOut" />
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="0:0:5" Value="17.0">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <SineEase EasingMode="EaseOut" />
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="0:0:10" Value="17"/>
            </DoubleAnimationUsingKeyFrames>
            <PointAnimationUsingKeyFrames x:Name="CenterPointAnimation"
                        Storyboard.TargetName="ProductMaps"  >
                <EasingPointKeyFrame x:Name="CenterPointKeyFrame"  KeyTime="0:0:2">
                    <EasingPointKeyFrame.EasingFunction>
                        <SineEase EasingMode="EaseOut" />
                    </EasingPointKeyFrame.EasingFunction>
                </EasingPointKeyFrame>
            </PointAnimationUsingKeyFrames>
        </Storyboard>


Snippet of the output:
Old Value: 47.1004638671875, -121.004898071289
New Value: 47.4084663391113, -121.796180725098
Changed Value: 47.4084663391113, -121.796180725098  -RIGHT
Old Value: 47.4084663391113, -121.796180725098
New Value: 47.5841407775879, -122.247497558594
Changed Value: 47.5841407775879, -122.247497558594 -RIGHT
Old Value: 47.5841407775879, -122.247497558594
New Value: 47.6220588684082, -122.344917297363
Changed Value: 47.6220588684082, -122.344917297363 -RIGHT
Old Value: 47.6220588684082, -60.4470691680906
New Value: 47.2447166442871, -110.667938232422
Changed Value: 47.2447166442871, -23.9447751045224 -WRONG
Old Value: 47.2447166442871, -23.9447751045224
New Value: 46.643497467041, -92.0630416870117
Changed Value: 51.8482260475886, -17.861059427261 - WRONG

I did not touch or pan the map while the map was animating.

I assumed that it could be a timing issue, especially when it is constantly setting the center property on every animation value change, so I tried and set the Map center value directly and see what's the value is after the CenterChanged event fired, but just as expected, the center value is off, usually the longitude that is wrong.

For the purpose of what I'm trying to do, this causes the map to zoom in randomly for example in the middle of the ocean instead of the item I have on the map.

Any help would be appreciated.

Thank You,

5 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 05 Mar 2012, 02:21 PM
Hi Trinh,

It is very complicated and it is hard to reproduce the problem without your solution, but using just the code snippet you sent.
Could you, please, provide us with your solution or with a small sample solution which reproduces it?

All the best,
Andrey Murzov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Trinh
Top achievements
Rank 1
answered on 05 Mar 2012, 09:26 PM
Hi Andrey,

I just put together a simple Silverlight application that demonstrates this problem. How do you want me to get this to you? The attachment feature below only support images.

Thanks,
-Trinh
0
Andrey
Telerik team
answered on 08 Mar 2012, 12:37 PM
Hi Trinh,

It is not allowed to attach any archives in our forums due to our policies. However you may use a third -party website and attach your runnable archived solution there.  

Greetings,
Andrey Murzov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Trinh
Top achievements
Rank 1
answered on 08 Mar 2012, 08:39 PM
Here is the sample solution.

---link removed---

I also noticed that the memory usage slowly increases as the map continues to animate over a long period of time. I get 250mb increase after 30+ minutes of running. I'm not sure if whether the Map control is leaking or my code.

-Trinh
0
Andrey
Telerik team
answered on 13 Mar 2012, 11:18 AM
Hi Trinh,

You use the RadMap.GeoBounds property in your application. In this case the RadMap corrects the Center property when you set the Center or ZoomLevel properties to keep the map inside the specified region.
For example if you try to set the Center to your pushpin which is located at right on map, then after the following code the Center property will be different than specified:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Telerik.Windows.Controls.Map;
using Telerik.Windows.Controls;
using System.Diagnostics;
 
namespace MapSample
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
 
            ProductMaps.GeoBounds =
                new LocationRect(new Location(ProductMaps.SpatialReference.MinLatitude, ProductMaps.SpatialReference.MinLongitude),
                    new Location(ProductMaps.SpatialReference.MaxLatitude, ProductMaps.SpatialReference.MaxLongitude));
 
            ProductMaps.ZoomChanged += new EventHandler(ProductMaps_ZoomChanged);
            ProductMaps.CenterChanged += new EventHandler(ProductMaps_CenterChanged);
 
            this.ProductMaps.ZoomLevel = 3;
            this.ProductMaps.Center = new Location(39.907337, 116.389187);
        }
 
        private void ProductMaps_CenterChanged(object sender, EventArgs e)
        {
            Debug.WriteLine("RadMap Center changed: " + (sender as RadMap).Center.ToString());
        }
 
        private void ProductMaps_ZoomChanged(object sender, EventArgs e)
        {
            Debug.WriteLine("RadMap Zoom changed: " + (sender as RadMap).ZoomLevel.ToString());
        }
 
    }
}


We checked the leaking. We got from 100 Mb up to 350 Mb of used memory, but this value is dynamically changed during animation. So, it seems the control works as expected.

One last note. Please, do not provide links to projects containing dev assemblies in public forums. You can ask the license holder to add you as a licensed developer, so you will be able to open a formal support ticket. I have removed the link from your message.

Best regards,
Andrey Murzov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Map
Asked by
Trinh
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Trinh
Top achievements
Rank 1
Share this question
or