1
votes

I am currently using a Microsoft.Phone.Map in my Windows 8 Phone App and want to be able stop interactions for changing the zoom level and moving (scrolling) around the map.

I've tried disabling interaction but the problem is I have a layer with Points of Interests that need to be tapped to expand information which doesn't work when I disable the map with IsEnabled = True;

The zoom level is set to this.BigMap.ZoomLevel = 16; to start with and then to try and stop this from changing with interaction I did this:

void BigMap_ZoomLevelChanged(object sender, MapZoomLevelChangedEventArgs e)
    {
        this.BigMap.ZoomLevel = 16;
    }

But it means that I get a rather jumpy effect - is there a better way to disable zoom?

And does anyone know how to stop the map moving - I want just the section that fits on the screen to stay put and not let the user move it around.

1
WAG: IsHitTestVisible="false" should turn off hit testing on the map, which would turn off all user interaction with it.user1228
If I do IsHitTestVisible="false" on my hold event which is when I need the map to lock how do I then get it to recognize that the finger is no longer on screen. I need some sort of event handler that can then set the `IsHitTestVisible=true" so that interaction is normal In fact it would be better if you could never scroll / zoom and the map only recognise Hold and Tap events.hemit
lay another control over it that is transparent. Have that control be the target of interaction, and do what needs to be done (no idea what) to the underlying map control.user1228
Good, Mr. Will, IsHitTestVisible .... to lock /unlock the map, its good.Zia Ur Rahman

1 Answers

0
votes

You can find the map-element's grid, and stop it's zoom and moving manipulations like this:

xaml:

<Grid x:Name="LayoutRoot">
    <maps:Map ZoomLevel="10"
              x:Name="MyMap"
              Loaded="Map_Loaded"
              Tap="MyMap_Tap"/>
</Grid>

cs:

    private void Map_Loaded(object sender, RoutedEventArgs e)
    {
        Grid grid = FindChildOfType<Grid>(MyMap);
        grid.ManipulationCompleted += Map_ManipulationCompleted;
        grid.ManipulationDelta += Map_ManipulationDelta;
    }

    private void Map_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        // disable zoom
        if (e.DeltaManipulation.Scale.X != 0.0 ||
            e.DeltaManipulation.Scale.Y != 0.0)
            e.Handled = true;

        //disable moving
        if (e.DeltaManipulation.Translation.X != 0.0 ||
            e.DeltaManipulation.Translation.Y != 0.0)
            e.Handled = true;
    }

    private void Map_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
    {
        // disable zoom
        if (e.FinalVelocities.ExpansionVelocity.X != 0.0 ||
            e.FinalVelocities.ExpansionVelocity.Y != 0.0)
            e.Handled = true;

        //disable moving
        if (e.FinalVelocities.LinearVelocity.X != 0.0 ||
            e.FinalVelocities.LinearVelocity.Y != 0.0)
        {
            e.Handled = true;
        }
    }

    public static T FindChildOfType<T>(DependencyObject root) where T : class
    {
        var queue = new Queue<DependencyObject>();
        queue.Enqueue(root);

        while (queue.Count > 0)
        {
            DependencyObject current = queue.Dequeue();
            for (int i = VisualTreeHelper.GetChildrenCount(current) - 1; 0 <= i; i--)
            {
                var child = VisualTreeHelper.GetChild(current, i);
                var typedChild = child as T;
                if (typedChild != null)
                {
                    return typedChild;
                }
                queue.Enqueue(child);
            }
        }
        return null;
    }

    private void MyMap_Tap(object sender, GestureEventArgs e)
    {
        //This is still working
    }

Because you disable only zoom and moving manipulations, taps and holds are working normally.

Hopefully this helps!

edit: Note that when you call FindChildOfType(MyMap), the map element should be visible.