Maximum extent

4774
5
07-12-2012 10:24 AM
EricPfirman
New Contributor III
I have 2 layers.
The bottom layer is the "World_Street_Map" tiled map service.
The top layer is a dynamic layer covers a portion of New York State.
I set the initial extent to the extent of the dynamic layer.

If I zoom all the way out with the ZoomSlider or with "navToolbar.zoomToFullExtent()" it zooms to the entire world. How can I constrain the map so the maximum extent is equal to the extent of the dynamic layer?

  var extentMap;
  extentMap = new esri.geometry.Extent({xmin:-8478000, ymin:5014590, xmax:-8099500, ymax:5245000, spatialReference:{wkid:102100}});
        map = new esri.Map("mapDiv", { extent: extentMap, nav:true});
0 Kudos
5 Replies
SiqiLi
by Esri Contributor
Esri Contributor
You need to define an array of LODs (Levels of Detail) to specify the zoom levels. Each LOD corresponds to a map at a given scale or resolution. Then, apply the array of LODs in the map constructor as an option. For example:

 function init() {
      var lods = [
 {"level" : 13, "resolution" : 19.1092570712683, "scale" : 72223.819286},
 {"level" : 14, "resolution" : 9.55462853563415, "scale" : 36111.909643},
 {"level" : 15, "resolution" : 4.77731426794937, "scale" : 18055.954822},
 {"level" : 16, "resolution" : 2.38865713397468, "scale" : 9027.977411},
 {"level" : 17, "resolution" : 1.19432856685505, "scale" : 4513.988705},
 {"level" : 18, "resolution" : 0.597164283559817, "scale" : 2256.994353},
 {"level" : 19, "resolution" : 0.298582141647617, "scale" : 1128.497176}
 ];
        var initExtent = new esri.geometry.Extent({"xmin":-1.3074977201954123E7,"ymin":4015620.159117397,"xmax":-1.3073987658308368E7,"ymax":4016419.790346289,"spatialReference":{"wkid":102100}});
        map = new esri.Map("map",{extent:initExtent, lods:lods});
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
        map.addLayer(basemap); 
        var dynamicLyr = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/PoolPermits/MapServer");  
        map.addLayer(dynamicLyr);

        dojo.connect(map, 'onLoad', function(theMap) {
        dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
        });
      }


FYI: You can look into the REST endpoint of the World_Street_Map service and pick the LODs you need. If you decide to use another tiled map service, make sure you look into that service's REST endpoint and pick up the correct LODs.
0 Kudos
StephenLead
Regular Contributor III
Note that this only restricts you to the same zoom level as the maximum extent of the layer - you'll still be able to pan to another location.

If that's a problem (ie, you want to prevent the user from navigating away from the study area) you could write a function which examines the map extent after panning or zooming (see the onExtentChange event) and nudges it back to the desired extent.

Steve
0 Kudos
LaurensZwakhals
New Contributor
Note that this only restricts you to the same zoom level as the maximum extent of the layer - you'll still be able to pan to another location.

If that's a problem (ie, you want to prevent the user from navigating away from the study area) you could write a function which examines the map extent after panning or zooming (see the onExtentChange event) and nudges it back to the desired extent.

Steve


Indeed, I'd like to prevent the user from navigating away from the study area. I'm not really a crack in writing functions using JavaScript. How should such a function look like?
0 Kudos
StephenLead
Regular Contributor III
To get started, I'd suggest you install Firefox and Firebug and spend some time playing around with the developer tools. Learn how to put a breakpoint into code and inspect what's happening.

Then add a listener for the onExtentChange event so you can see what happens when your map's extent changes.

Inside this function, put some logic which ensures that the user hasn't moved outside your study area - if they have, move the map back again.
0 Kudos
HaroldBostic
Occasional Contributor II
Hello, they have the solution to your question here

http://forums.arcgis.com/threads/27971-Constrain-Map-Extent?highlight=constrain
0 Kudos