{"id":1896,"date":"2014-08-27T09:01:58","date_gmt":"2014-08-27T09:01:58","guid":{"rendered":"http:\/\/galhano.com\/blog\/?p=1896"},"modified":"2014-08-27T09:02:27","modified_gmt":"2014-08-27T09:02:27","slug":"restrict-pan-and-zoom-in-arcgis-javascript-api","status":"publish","type":"post","link":"http:\/\/galhano.com\/blog\/?p=1896","title":{"rendered":"Restrict pan and zoom in ArcGIS Javascript API"},"content":{"rendered":"<p>[js]<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=utf-8&quot;&gt;<br \/>\n&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=7, IE=9, IE=10&quot;&gt;<br \/>\n&lt;meta name=&quot;viewport&quot; content=&quot;initial-scale=1, maximum-scale=1,user-scalable=no&quot;\/&gt;<br \/>\n&lt;title&gt;Simple Map&lt;\/title&gt;<br \/>\n&lt;link rel=&quot;stylesheet&quot; href=&quot;http:\/\/serverapi.arcgisonline.com\/jsapi\/arcgis\/3.5\/js\/dojo\/dijit\/themes\/claro\/claro.css&quot;&gt;<br \/>\n&lt;link rel=&quot;stylesheet&quot; href=&quot;http:\/\/serverapi.arcgisonline.com\/jsapi\/arcgis\/3.5\/js\/esri\/css\/esri.css&quot;&gt;<br \/>\n&lt;style&gt;<br \/>\nhtml, body, #map {<br \/>\nheight:100%;<br \/>\nwidth:100%;<br \/>\nmargin:0;<br \/>\npadding:0;<br \/>\n}<br \/>\nbody {<br \/>\nbackground-color:#FFF;<br \/>\noverflow:hidden;<br \/>\nfont-family:&quot;Trebuchet MS&quot;;<br \/>\n}<br \/>\n&lt;\/style&gt;<br \/>\n&lt;script src=&quot;http:\/\/serverapi.arcgisonline.com\/jsapi\/arcgis\/3.5\/&quot;&gt;&lt;\/script&gt;<br \/>\n&lt;script&gt;<br \/>\ndojo.require(&quot;esri.map&quot;);<br \/>\nvar map = null;<br \/>\nvar extent =\u00a0 null;<br \/>\nvar maxExtent = null;<\/p>\n<p>function init() {<br \/>\nmap = new esri.Map(&quot;map&quot;,{<br \/>\nbasemap:&quot;topo&quot;,<br \/>\ncenter:[-122.45,37.75], \/\/long, lat<br \/>\nzoom:13,<br \/>\nsliderStyle:&quot;small&quot;<br \/>\n});<br \/>\n\/\/set max extent to inital extent<br \/>\ndojo.connect(map, &quot;onLoad&quot;, function(){<br \/>\nmaxExtent = map.extent;<br \/>\n});<\/p>\n<p>\/\/check to see if map is within max extent when its extent changes.\u00a0 If not, roll back to the max<br \/>\n\/\/extent that we set above<br \/>\ndojo.connect(map, &quot;onExtentChange&quot;, function(extent){<br \/>\nif((map.extent.xmin &lt; maxExtent.xmin) ||<br \/>\n(map.extent.ymin &lt; maxExtent.ymin)\u00a0 ||<br \/>\n(map.extent.xmax &gt; maxExtent.xmax) ||<br \/>\n(map.extent.ymax &gt; maxExtent.ymax)<br \/>\n) {<br \/>\nmap.setExtent(maxExtent);<br \/>\nconsole.log(&quot;max extent reached, rolling back to previous extent&quot;);<br \/>\n}<\/p>\n<p>});<\/p>\n<p>}<\/p>\n<p>dojo.ready(init);<\/p>\n<p>&lt;\/script&gt;<br \/>\n&lt;\/head&gt;<\/p>\n<p>&lt;body class=&quot;claro&quot;&gt;<br \/>\n&lt;div id=&quot;map&quot;&gt;&lt;\/div&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>[\/js]<\/p>\n<p>http:\/\/jsfiddle.net\/gh\/gist\/library\/pure\/6050806\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[js] &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=utf-8&quot;&gt; &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=7, IE=9, IE=10&quot;&gt; &lt;meta name=&quot;viewport&quot; content=&quot;initial-scale=1, maximum-scale=1,user-scalable=no&quot;\/&gt; &lt;title&gt;Simple Map&lt;\/title&gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;http:\/\/serverapi.arcgisonline.com\/jsapi\/arcgis\/3.5\/js\/dojo\/dijit\/themes\/claro\/claro.css&quot;&gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;http:\/\/serverapi.arcgisonline.com\/jsapi\/arcgis\/3.5\/js\/esri\/css\/esri.css&quot;&gt; &lt;style&gt; html, body, #map { height:100%; width:100%; margin:0; padding:0; } body { background-color:#FFF; overflow:hidden; font-family:&quot;Trebuchet MS&quot;; } &lt;\/style&gt; &lt;script src=&quot;http:\/\/serverapi.arcgisonline.com\/jsapi\/arcgis\/3.5\/&quot;&gt;&lt;\/script&gt; &lt;script&gt; dojo.require(&quot;esri.map&quot;); var map = null; var extent =\u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"close","ping_status":"close","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[116,164],"tags":[],"class_list":["post-1896","post","type-post","status-publish","format-standard","hentry","category-arcgis","category-javascript","author-admin"],"_links":{"self":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1896"}],"version-history":[{"count":2,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1896\/revisions"}],"predecessor-version":[{"id":1898,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1896\/revisions\/1898"}],"wp:attachment":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1896"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}