MapControl distinguishes between a user or software center change

In WinRt / WP 8.1 MapControl, how can I distinguish when a user changes the center of the screen by scrolling or changing programs?

In WinRt / WP 8.1 MapControl there is a CenterChanged event ( http://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.maps.mapcontrol.centerchanged.aspx ), but this does not provide any information about what caused the center change.

Is there any other way to find out if the user has changed the center of the map?


/ * To give another context, my specific scenario is as follows:
Given the application that displays the map, I want to track the user's gps position.

  • If the gps position is found, I want to put a point on the map and center the map on that point.
  • If a change in gps position is detected, I want to center the map on this point.
  • If the user changes the position of the map by touching / scrolling, I no longer want to center the map when changing the gps position.

I could hack this by comparing the position and center of gps, but its gps position latLng is a different type and precision like Map.Center latLng. I would prefer a simpler, less hacker solution. * /

+4
source share
1 answer

I solved this by setting bool ignoreNextViewportChangesin truebefore calling the pending ones TrySetViewAsyncand resetting it to falseafter performing the asynchronous action.

, ignoreNextViewportChanges - .

, :

bool ignoreNextViewportChanges;

public void HandleMapCenterChanged() {
    Map.CenterChanged += (sender, args) => {
        if(ignoreNextViewportChanges)
            return;
        //if you came here, the user has changed the location
        //store this information somewhere and skip SetCenter next time
    }
}

public async void SetCenter(BasicGeoposition center) {
    ignoreNextViewportChanges = true;
    await Map.TrySetViewAsync(new Geopoint(Center));
    ignoreNextViewportChanges = false;
}

, SetCenter ( SetCenter , SetCenter), :

int viewportChangesInProgressCounter;

public void HandleMapCenterChanged() {
    Map.CenterChanged += (sender, args) => {
        if(viewportChangesInProgressCounter > 0)
            return;
        //if you came here, the user has changed the location
        //store this information somewhere and skip SetCenter next time
    }
}

public async void SetCenter(BasicGeoposition center) {
    viewportChangesInProgressCounter++;
    await Map.TrySetViewAsync(new Geopoint(Center));
    viewportChangesInProgressCounter--;
}
0

All Articles