0

So MinZoomLevel and MaxZoomLevel are get-only properties.

I can't inherit MapControl and override them, because MapControl is sealed.

I can use different MapTileSource and set there ZoomLevelRange and that works.

But the main question is, how to set MinZoomLevel and MaxZoomLevel on default MapControl that uses Bing maps? I can't set it on MapTileSourceof bing maps, because that field is null for bing maps.

Edit: Also with different MapTileSource when I set ZoomLevelRange, it doesn't help either. You can still scroll outside of it, but you don't get data. So that is just data constriction. Not scroll constriction.

Jacob
  • 627
  • 6
  • 15
  • From the docs for MinZoomLevel: _"The maximum and minimum values of ZoomLevel depend on the type of map view: 2D, 3D, or Streetside"_ – stuartd Aug 24 '16 at 14:47

1 Answers1

0

MinZoomLevel and MaxZoomLevel are read-only, you can't set them.

Can you try listening to the ZoomLevelChanged event and if the zoom level goes outside the range you want to limit it to, set it back within the desired range?

Something like:

MapControl mapControl = new MapControl();
mapControl.ZoomLevelChanged += MapControl_ZoomLevelChanged;

private void MapControl_ZoomLevelChanged(MapControl sender, object args)
{
     const int maxZoom = 7;
     const int minZoom = 5;

     if (mapControl.ZoomLevel > maxZoom)
     {
         mapControl.ZoomLevel = maxZoom;
     }
     else if(mapControl.ZoomLevel < minZoom)
     {
         mapControl.ZoomLevel = minZoom;
     }
}
S. Matthews
  • 355
  • 2
  • 9
  • Ah yes I know about that. Thank you. This works, but it is clumsy, because when you scroll with MouseWheel and hit below 5 or above 7 it weirly jumps. Also with different `MapTileSource` when I set `ZoomLevelRange`, it doesn't help either. You can still scroll outside of it, but you don't get data. So that is just data constriction. – Jacob Sep 01 '16 at 11:55