I just figured out how to restrict only the zoom levels. I only need the centerpoint for the initial extent. Map | API Reference | ArcGIS API for JavaScript 3.18
map <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Map</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"map"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN> basemap<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"streets"</SPAN><SPAN class="punctuation token">,</SPAN> center<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">96.8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">38.5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> maxZoom<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">15</SPAN><SPAN class="punctuation token">,</SPAN> minZoom<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">4</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Lloyd,
OK now I see. So ignore all the LOD stuff mentioned then and lets get back to your minExtent var.
So you are using:
minExtent <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"map"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN> zoom<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">15</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
and as you mentioned earlier that you thought this was the issue, well it absolutely is. You can not get a valid extent with that code. You need to build a true extent class and set the minExtent to that.
So the issue of the extent re-centering at the initial value can be over come using the Extent classes centerAt method:
Extent | API Reference | ArcGIS API for JavaScript 3.18 | centerAt
map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setExtent</SPAN><SPAN class="punctuation token">(</SPAN>maxExtent<SPAN class="punctuation token">.</SPAN><SPAN class="token function">centerAt</SPAN><SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getCenter</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
What I'm saying is that my map is not tiled/cached. What I'm trying to do is just restrict the minimum and maximum zoom levels. Earlier in this thread someone said the API does not have this functionality. I tried using this method to revert to the initial extent if someone tries to zoom out too far, but I didn't take into account that this would also send them back to the default center point. If there are any features outside of that level (to the east or west), they can't be accessed.
Sorry your question is not making any sense to me:
How would I use a cached basemap if I'm hosting on an ArcGIS server? I can't upload basemaps as part of a map service.
Can you clarify what you are wanting to do?
Thanks Robert. I realized that I won't be able to use this method because it's returning to the default center in addition to the zoom. If there is a feature located outside of the default extent, I can't navigate to it.
A couple of things. Number 1 do not get in the habit of use the depreciated dojo.connect. What you should use is on
<SPAN style="color: #000000;">map</SPAN><SPAN style="color: #999999;">.on(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">"load"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN style="color: #000000;"> </SPAN><SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">function</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">{</SPAN>
and
<SPAN style="color: #000000;">map</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.on(</SPAN><SPAN style="border: 0px; color: #000000; font-weight: inherit;">"</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;">extent-change"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN style="color: #000000;"> </SPAN><SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">function</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN style="color: #000000;">extent</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">{</SPAN>
Next if you are using an tiled/cached basemap then you get set the LODs you want to use to limit the zoom in and zoom out like discussed about. If you are not using a tiled/cached basemap then use your method.
Reviving this old thread. I'm trying to set max and min zooms in my map. I want the initial (max) extent to be zoom level 3, and I don't want to be able to zoom in any further than level 15 or so (min extent). I found a snippet of JS that works for the first part, and I'm trying to adapt it to work for the second. I think my issue is how I'm trying to set the minimum extent. I only want a lat/lon center point for the maximum (initial) extent. Here is the code snippet. The first if statement works but the else if does not.
map <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Map</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"map"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN> basemap<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"streets"</SPAN><SPAN class="punctuation token">,</SPAN> center<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">105</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">45</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> zoom<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">3</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//set max extent to inital extent</SPAN> dojo<SPAN class="punctuation token">.</SPAN><SPAN class="token function">connect</SPAN><SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"onLoad"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> maxExtent <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">;</SPAN> minExtent <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"map"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN> zoom<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">15</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//check to see if map is within max extent when its extent changes. If not, roll back to the max</SPAN> <SPAN class="comment token">//extent that we set above</SPAN> dojo<SPAN class="punctuation token">.</SPAN><SPAN class="token function">connect</SPAN><SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"onExtentChange"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>extent<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>xmin <SPAN class="operator token"><</SPAN> maxExtent<SPAN class="punctuation token">.</SPAN>xmin<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">||</SPAN> <SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>ymin <SPAN class="operator token"><</SPAN> maxExtent<SPAN class="punctuation token">.</SPAN>ymin<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">||</SPAN> <SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>xmax <SPAN class="operator token">></SPAN> maxExtent<SPAN class="punctuation token">.</SPAN>xmax<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">||</SPAN> <SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>ymax <SPAN class="operator token">></SPAN> maxExtent<SPAN class="punctuation token">.</SPAN>ymax<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setExtent</SPAN><SPAN class="punctuation token">(</SPAN>maxExtent<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>xmin <SPAN class="operator token">></SPAN> minExtent<SPAN class="punctuation token">.</SPAN>xmin<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">||</SPAN> <SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>ymin <SPAN class="operator token">></SPAN> minExtent<SPAN class="punctuation token">.</SPAN>ymin<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">||</SPAN> <SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>xmax <SPAN class="operator token"><</SPAN> minExtent<SPAN class="punctuation token">.</SPAN>xmax<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">||</SPAN> <SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>ymax <SPAN class="operator token"><</SPAN> minExtent<SPAN class="punctuation token">.</SPAN>ymax<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setExtent</SPAN><SPAN class="punctuation token">(</SPAN>minExtent<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
var lods = [ { "level": 0, "resolution": 156543.03392800014, "scale": 5.91657527591555E8 }, { "level": 1, "resolution": 78271.51696399994, "scale": 2.95828763795777E8 } ]; map = new Map("map", { basemap: "streets", autoResize: true, logo: false, showAttribution: false, lods: lods });
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.