This project has moved. For the latest updates, please go here.

Map center after moving / panning

Oct 2, 2016 at 8:00 PM
Hi. I'd like to recenter after panning the map.
When i set the Center of the map with a new value, nothing happens (after panning), normally it works great. I tried the same with TargetCenter, the map also didn't get centered.

Has anyone an idea, how to solve this?
Thanks :)

Clemens, great work with this MapControl!
Oct 4, 2016 at 11:03 PM
Xaml:
<map:Map TargetCenter="{Binding OsmCenter}" TileLayer="{Binding SelectionTileLayer}"> ... </map>
ViewModel:
public void ReCenterMap()
{
      OsmCenter = null;
} 

public void CalculatePosition(Geopoint point)
{
        var location = new Location(point.Position.Latitude,
        LocationServiceHelper.Instance.Geoposition.Coordinate.Point.Position.Longitude            
        OsmCenter = location;
}
CalculatePosition gets updated everytime, when Position changes. .... ReCenterMap getting called through a button. My idea: When i set the location of the center null, and it gets a new value, the center of the map may jump to the new position. ...
Coordinator
Oct 5, 2016 at 8:14 AM
Edited Oct 5, 2016 at 8:15 AM
Both OsmCenter = null and OsmCenter = location should always work (provided that the OsmCenter property fires a PropertyChanged event). In case of OsmCenter = null the TargetCenter property is set to latitude zero and longitude zero.

No idea what it actually means when you say "when i set the location of the center null, and it gets a new value, the center of the map may jump to the new position".
Oct 5, 2016 at 10:01 AM
Edited Oct 5, 2016 at 10:03 AM
My Intention was: When i press the recenter button, the map center should be at the current position, instead of the ''moved'' position. So like you said, the OsmCenter should be set with null (or 0,0). But when i set the OsmCenter in CalculatePosition, the map should be at that position.

I tried OsmCenter = new Location(0,0), but the map won't go to after new set center.

When i don't move the map, the map gets recenter, but after moving, it won't center anymore.
Coordinator
Oct 5, 2016 at 10:07 AM
No idea why it shouldn't work. Does the OsmCenter property fire a PropertyChanged event?
Oct 5, 2016 at 10:09 AM
Edited Oct 5, 2016 at 10:11 AM
Yes, ... also after moving ...
private Location _osmCenter;
public Location OsmCenter
        {
            get { return _osmCenter; }
            set
            {
                _osmCenter = value;
                NotifyPropertyChanged();
            }
        }


public new event PropertyChangedEventHandler PropertyChanged;

        protected virtual async void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
        {
            await Dispatcher.DispatchAsync(() =>
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }, 0, CoreDispatcherPriority.High);
        }
Coordinator
Oct 5, 2016 at 11:16 AM
Which platform is that? Also, public new event PropertyChangedEventHandler PropertyChanged; looks dubious. Why new?
Oct 5, 2016 at 11:20 AM
Edited Oct 5, 2016 at 11:23 AM
UWP.
I use the Template10 Framework, but wanted to use my own PropertyChangedEventHandler, so the new .. The PropertyChanged works great, i have many other values, which getting updated through that handler, without problems ...
Coordinator
Oct 5, 2016 at 11:45 AM
Edited Oct 5, 2016 at 11:45 AM
Since the TargetCenter property is also set internally by the MapBase class, you'll have to make the Binding two-way (which is the default in the WPF version):
<map:Map TargetCenter="{Binding OsmCenter, Mode=TwoWay}" .../>
Marked as answer by Blorzorth on 10/5/2016 at 3:48 AM