# Restricting zoom extent on map suite iOS for xamarin forms

**URL:** <https://community.thinkgeo.com/t/restricting-zoom-extent-on-map-suite-ios-for-xamarin-forms/8371>\
**Category:** iOS\
**Created:** [January 19, 2017, 12:32pm UTC](https://community.thinkgeo.com/t/restricting-zoom-extent-on-map-suite-ios-for-xamarin-forms/8371 "2017-01-19T12:32:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Syed\_Moshiur](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/779978/32.png) [@Syed\_Moshiur](https://community.thinkgeo.com/u/Syed_Moshiur)\
**Post date:** [January 19, 2017, 12:32pm UTC](https://community.thinkgeo.com/t/restricting-zoom-extent-on-map-suite-ios-for-xamarin-forms/8371/1 "2017-01-19T12:32:42Z")

</div>

Hi,  
We found a nice sample for restricting zoom extent for the here [restricting zoom extent](http://wiki.thinkgeo.com/wiki/source_code_desktopeditionsample_restrictingextent_cs_101103.zip) 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;
                }
            }
        }

```

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [January 20, 2017, 5:19am UTC](https://community.thinkgeo.com/t/restricting-zoom-extent-on-map-suite-ios-for-xamarin-forms/8371/2 "2017-01-20T05:19:07Z")

</div>

Hi Syed,

I tested the code as below in WpfEdition and make that works, wish it’s helpful.

void Map1\_CurrentExtentChanging(object sender, CurrentExtentChangingWpfMapEventArgs 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.CurrentExtent.GetBoundingBox().Width != e.NewExtent.GetBoundingBox().Width)
        {
            if (e.NewExtent.IsWithin(restrictedExtentForZoomOut) == false)
            {
                e.Cancel = true;                    
            }
        }
        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.CurrentExtent);
            RectangleShape newIntersection = restrictedExtentForZoomOut.GetIntersection(e.NewExtent);
            //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.Cancel = true;
            }
        }
    }

```

Regards,

Don

---

<div class="post-metadata">

**Author:** ![Syed\_Moshiur](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/779978/32.png) [@Syed\_Moshiur](https://community.thinkgeo.com/u/Syed_Moshiur)\
**Post date:** [January 20, 2017, 7:45am UTC](https://community.thinkgeo.com/t/restricting-zoom-extent-on-map-suite-ios-for-xamarin-forms/8371/3 "2017-01-20T07:45:41Z")

</div>

Dear Don,  
Thank you for your reply. But I think you missed the requirement, it works for WPF. But we want to have this in MapSuite for iOS Xamarin forms. And the iOS API(xamarin) does not have this event cancel property. Hence we adopted the code a little(as I have written in previous entry).

Please help!

Regards,  
Murshed

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [January 22, 2017, 1:25am UTC](https://community.thinkgeo.com/t/restricting-zoom-extent-on-map-suite-ios-for-xamarin-forms/8371/4 "2017-01-22T01:25:39Z")

</div>

Hi Murshed,

It looks I misunderstand your requirement. I thought you cannot run this sample both under WPF edition and IOS edition, so I just help you solved the WPF part.

IOS guys are very busy and may cannot help us reply the question on IOS now. I am not sure whether it works, but I think you can try to set the original extent to Map.CurrentExtent instead of cancel.

Regards,

Don
