# Prevent Unfolding Map from panning off screen

**URL:** https://discourse.processing.org/t/prevent-unfolding-map-from-panning-off-screen/18328
**Category:** Libraries
**Created:** [March 2, 2020, 10:54pm UTC](https://discourse.processing.org/t/prevent-unfolding-map-from-panning-off-screen/18328 "2020-03-02T22:54:13Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![wcneill](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@wcneill](https://discourse.processing.org/u/wcneill)
#### Post date: [March 2, 2020, 10:54pm UTC](https://discourse.processing.org/t/prevent-unfolding-map-from-panning-off-screen/18328/1 "2020-03-02T22:54:13Z")

</div>

When I using unfolding maps, there is no limit on how far you can pan. When you pan too far, however, this happens:

 ![Untitled](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f2fd314dafc2960ea0019bb3fae33f1788df5390.png)

I have tried restricting panning via the method `setPanningRestriction(center, maxdistance)`, however this does not work well. For one, the docs say that maxdistance is kilometers, and that panning is restricted radially by maxdistance.

1.) Unfolding thinks that the earth is only 3000 kilometers in circumfereance.  
2.) The restriction INCREASES as you zoom into the map. By the time you are zoomed to city level, you cannot pan at all.

Any simple solutions appreciated.

---

<div class="post-metadata">

### Author: ![matheplica](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matheplica/32/21035_2.png) [@matheplica](https://discourse.processing.org/u/matheplica)
#### Post date: [March 4, 2020, 2:46pm UTC](https://discourse.processing.org/t/prevent-unfolding-map-from-panning-off-screen/18328/2 "2020-03-04T14:46:48Z")

</div>

Did you try [contrain()](https://processing.org/reference/constrain_.html) with variable argument ?

---

<div class="post-metadata">

### Author: ![wcneill](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@wcneill](https://discourse.processing.org/u/wcneill)
#### Post date: [March 5, 2020, 3:39pm UTC](https://discourse.processing.org/t/prevent-unfolding-map-from-panning-off-screen/18328/3 "2020-03-05T15:39:03Z")

</div>

Hi There!

What variable do you suggest I constrain? mouseX and mouseY don’t seem like good candidates.

Wes

---

<div class="post-metadata">

### Author: ![matheplica](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matheplica/32/21035_2.png) [@matheplica](https://discourse.processing.org/u/matheplica)
#### Post date: [March 5, 2020, 5:43pm UTC](https://discourse.processing.org/t/prevent-unfolding-map-from-panning-off-screen/18328/4 "2020-03-05T17:43:47Z")

</div>

I never use this library. What’s function allows you to zoom ?

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [March 5, 2020, 6:12pm UTC](https://discourse.processing.org/t/prevent-unfolding-map-from-panning-off-screen/18328/5 "2020-03-05T18:12:10Z")

</div>

Please share your working code reproducing the problem.

Panning restriction documented here: [http://unfoldingmaps.org/tutorials/interactions-simple](http://unfoldingmaps.org/tutorials/interactions-simple)  
If it does not work as advertised, file an issue with the library owner

Kf

---

<div class="post-metadata">

### Author: ![wcneill](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@wcneill](https://discourse.processing.org/u/wcneill)
#### Post date: [March 5, 2020, 6:17pm UTC](https://discourse.processing.org/t/prevent-unfolding-map-from-panning-off-screen/18328/6 "2020-03-05T18:17:29Z")

</div>

Well, zoom is not the issue. Panning is the issue… but that does give me an idea. Let me try something and get back to you. Thanks!

---

<div class="post-metadata">

### Author: ![wcneill](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@wcneill](https://discourse.processing.org/u/wcneill)
#### Post date: [March 5, 2020, 6:24pm UTC](https://discourse.processing.org/t/prevent-unfolding-map-from-panning-off-screen/18328/7 "2020-03-05T18:24:12Z")

</div>

I have already done that. If you have a work-around please feel free to contribute to the thread.

I will post my code later when I have time to trim it down to something reasonably readable on this forum.
