ClemensFischer / XAML-Map-Control

XAML Map Control Library
Microsoft Public License
203 stars 59 forks source link

Trying to follow an object on the map #108

Closed o4oren closed 1 year ago

o4oren commented 1 year ago

I am not sure what is the right way to do this. I have an airplane which I represent via a canvas/path item on the map, and it updates it's location continuously. It moves fine on the map. But I want the map to follow the object. I tried several approaches, it seems that the map is only rendering a small rectangle around the original center location of the map when I do this: ` private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {

        var loc1 = new MapControl.Location(((FlightDataViewModel)this.DataContext).Position[0], ((FlightDataViewModel)this.DataContext).Position[1]);

        xMap.Center = loc1;
    }`

If I remove setting the Center, the map renders okay.

If I zoom out it looks like this:

1

The small rendered rect is at 0,0 (which is my original center in the xaml).

If I just comment out xMap.Center it renders fine, but of course, doesn't stay centered on the object:

2
ClemensFischer commented 1 year ago

You are probably setting the Center property too often, i.e. with a time interval that is shorter than the update delay of the MapTileLayer.

Either set the Center at a lower rate or set the MapTileLayer's UpdateWhileViewportChanging property to true.


From: Oren Geva @.> Sent: Sunday, May 7, 2023 8:12:51 AM To: ClemensFischer/XAML-Map-Control @.> Cc: Subscribed @.***> Subject: [ClemensFischer/XAML-Map-Control] Trying to follow an object on the map (Issue #108)

I am not sure what is the right way to do this. I have an airplane which I represent via a canvas/path item on the map, and it updates it's location continuously. It moves fine on the map. But I want the map to follow the object. I tried several approaches, it seems that the map is only rendering a small rectangle around the original center location of the map when I do this: ` private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {

    var loc1 = new MapControl.Location(((FlightDataViewModel)this.DataContext).Position[0], ((FlightDataViewModel)this.DataContext).Position[1]);
    xMap.Center = loc1;
}`

If I remove setting the Center, the map renders okay.

— Reply to this email directly, view it on GitHubhttps://github.com/ClemensFischer/XAML-Map-Control/issues/108, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADZIRPN72U2SYWVFEJXMGE3XE44OHANCNFSM6AAAAAAXYUNSXI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

o4oren commented 1 year ago

Thanks! Both approaches are working, of course setting UpdateWhileViewportChanging creates a smoother experience. Which one would you recommend? Is there a danger of app performance using UpdateWhileViewportChanging ? I am getting a constant stream of data from the source flight simulator software. I haven't noticed a problem with this so far.

ClemensFischer commented 1 year ago

It's up to you. However, I don't think it would make much sense to update the position more often than perhaps five times per second.

o4oren commented 1 year ago

What can I say, it's VERY smooth when I don't limit it. I get 60hz updates from the underlying code. And these are aircraft, they move fast, so with 0.2 seconds and if you zoom close enough you see jumps. I'll play with it. What's the downside of UpdateWhileViewportChanging="true" though?

BTW, it's a great project and I appreciate your work here!