Nicholas Pappas
Nicholas Pappas

Reputation: 10624

Bing Maps WPF API - Limiting Zoom?

I am re-asking this as my previous question was mistakenly closed.

Is it possible to limit the zoom for the Bing Maps WPF control? My goal is to prevent the user from zooming too far out and seeing multiple "worlds" tiled side by side.

This is not a duplicate of the similar question relating to the AJAX API. The AJAX API and the WPF API are not the same, and function quite differently in many respects. Zoom appears to be one of them as attempting to implement the AJAX solution (before I asked the question) was unsuccessful.

Thanks!

Upvotes: 0

Views: 1669

Answers (3)

jobert
jobert

Reputation: 21

Well, this worked just fine for me without any graphical sideeffects...

    private void myMap_ViewChangeOnFrame(object sender, MapEventArgs e)
    {
        double z = myMap.ZoomLevel;

        //Maximum Zoom 19.5
        if (z > 19.5)
        {
            myMap.ZoomLevel = 19.5;
        }

        //Minimum Zoom 2.5
        if (z < 2.5)
        {
            myMap.ZoomLevel = 2.5;
        }
    }

Upvotes: 0

Eugene Balykov
Eugene Balykov

Reputation: 46

Something like that maybe?

    private void map_ViewChangeOnFrame(object sender, MapEventArgs e)
    {
        if (this.bingMap.ZoomLevel < ViewLogic.MinimumZoomLevel)
        {
            this.bingMap.SetView(this.previousFrameCenter, ViewLogic.MinimumZoomLevel);

            e.Handled = true; // Do we need it???
        }
        else
        {
            this.previousFrameCenter = this.bingMap.Center;
        }

        if (this.DoUpdate())
        {
            // Avoiding "jerking" effect and updating only for certain zoom/pan deltas
            this.UpdateModelViewPort();
        }
    }

Upvotes: 1

Eugene Balykov
Eugene Balykov

Reputation: 46

It seems that WPF control is not as powerfull as AJAX or SilverLight yet. So many things had to be done manually...

You can try brute force approach by handling Map.MouseWheel event and restricting zoom increase/decrease if threshold value was met

I'm trying to resctrict whole map view - and it's painfull to deal with that :)

Upvotes: 0

Related Questions