1
votes

When you use the wheel of the mouse on the map, it's to zoom more or less like we see on Bing Maps or Google Maps. I saw that the factor of zooming is 1.2 everytime you scroll. I've been asked to change it because it was zooming too far or too close. So is it even possible?

I tried by using the MouseWheel event and manage the zoom myself by disabling it with "e.Handled = true;". It worked in a way, but I lose the animation that comes with it and also the zoom is pointing the current center of the map instead of the the cursor of the mouse.

Any help would be appreciated even if it's to say that it's not possible.

Thanks

1
Did you check if the SetView method is animating? - Clemens

1 Answers

3
votes

This is what the current implementation is doing:

In OnMouseWheel it calls the following method:

this.ZoomAboutViewportPoint(((double) e.Delta) / 100.0, e.GetPosition(this));

It's implementation is:

private void ZoomAboutViewportPoint(double zoomLevelIncrement, Point zoomTargetInViewport)
{
    base.ZoomAndRotateOrigin = new Point?(zoomTargetInViewport);
    base.ViewBeingSetByUserInput = true;
    base.SetView((double) (base.TargetZoomLevel + zoomLevelIncrement), base.TargetHeading);
    base.ViewBeingSetByUserInput = false;
}

Obviously you cant set base.ViewBeingSetByUserInput and base.ZoomAndRotateOrigin directly as they are internal.

You can however just use SetView accordingly with the viewport coordinates, but will still loose the nice animation part.

Alternatively you can set the aforementioned values via reflection, but that is a brittle hack and prone to break if the control changes.

--- UPDATE

As described above: If you hook up to the MouseWheel Event here is the code to make it work via the reflection call of the private method:

void BingMap_MouseWheel(object sender, MouseWheelEventArgs e)
  {
     e.Handled = true;

     System.Reflection.MethodInfo dynMethod = this.BingMap.GetType().GetMethod("ZoomAboutViewportPoint", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
     dynMethod.Invoke(this.BingMap, new object[] { (((double)e.Delta) / 400d), e.GetPosition(this.BingMap) });


  }

This brings it down to a quarter of the speed and makes it usable with the least amount of code. But again this is a hack!