Hi,
We found a nice sample for restricting zoom extent for the here restricting zoom extent which we would like to have in our iOS solution for xamarin, however there is no event args cancel possibility on the iOS api,
We also tried setting the restricted zoom extent using the following code which give me an impression that it would work but didn’t.
MapView.MapTools.ZoomMapTool.GlobeExtent = initialExtent;
This is our adopted code based on the restricting zoom extent in WPF edition also does not work:
private void MapViewOnCurrentExtentChanging(object sender, CurrentExtentChangingMapViewEventArgs e)
{
if (restrictedExtentForZoomOut == null)
{
return;
}
// While changing zoom level. Does not allow zooming out beyond the restricted extent by using the geometric
// function IsWithin. The new extent has to be within the restricted extent or the zoomin out will be canceled.
if (e.PreviousExtent.GetBoundingBox().Width != e.CurrentExent.GetBoundingBox().Width)
{
if (e.CurrentExent.IsWithin(restrictedExtentForZoomOut) == false)
{
e.CurrentExent = e.PreviousExtent;
}
}
else
{
// While panning. It checks for the difference in area of the overlap (GetIntersection) of the current extent and the
// new extent with the restricted extent for panning. That way, we can be outside the restricted extent for panning after
// zooming out and still pan to get more within the restricted extent for panning.
RectangleShape currentIntersection = restrictedExtentForZoomOut.GetIntersection(e.PreviousExtent);
RectangleShape newIntersection = restrictedExtentForZoomOut.GetIntersection(e.CurrentExent);
//Gets the area. Meter is an arbitrary unit.
double currentArea = currentIntersection.GetArea(GeographyUnit.Meter, AreaUnit.SquareMeters);
double newArea = newIntersection.GetArea(GeographyUnit.Meter, AreaUnit.SquareMeters);
if (newArea < currentArea)
{
e.CurrentExent = e.PreviousExtent;
}
}
}