Select to view content in your preferred language

Base map disappears when zooming in

928
3
10-02-2012 12:54 PM
SamirGambhir
Frequent Contributor
Hi,
Any action (using comboox list) to zoom to a selected sub-geography of the country makes the base map disappear from my application. Further, if I try to zoom in using the zoom slider, the ESRI street map disappears as well. Furthermore, if I select the entire country using the combobox (i.e. calling the full extent of the base map), all my map services are visible. I have looked up various posts here and checked the wkid issue as well, but haven't been able to resolve it. Please help.
Here is part of my JS code:

function getStateExt(State) {
var mapExtent;
if (State != "All India") {
   var myState = State.toUpperCase();
   mapExtent = new esri.geometry.Extent();
   var queryTask = new esri.tasks.QueryTask("http://nsmhpc7007:8399/arcgis/rest/services/wch3/MapServer/9");
   dojo.connect(queryTask, "onComplete", function(featureSet) {
    var features = featureSet.features;
    stateExtent = features[0].geometry.getExtent();
    mapExtent.xmin = stateExtent.xmin - 150000;
    mapExtent.ymin = stateExtent.ymin - 75000;
    mapExtent.xmax = stateExtent.xmax + 150000;
    mapExtent.ymax = stateExtent.ymax + 75000;
    map.setExtent(mapExtent);
   });
   var qState = new esri.tasks.Query();
   qState.where = "name = '" + myState + "'";
   qState.returnGeometry = true;
   qState.outFields = ["name"];
   queryTask.execute(qState);
  } else if (State == "All India") {
   mapExtent = new esri.geometry.Extent();
   mapExtent = iniExtentM; /*iniExtentM is set in the init() function as iniExtentM = new esri.geometry.Extent({
  "xmin" : 6906469.033685486,
  "ymin" : 507780.9570028302,
  "xmax" : 11085388.124604845,
  "ymax" : 4734224.864539183,
  "spatialReference" : {
   "wkid" : 102100
  }
});*/
map.setExtent(mapExtent);
  }
 
}

Thanks
Samir
0 Kudos
3 Replies
StephenLead
Honored Contributor
Hi Samir,

Further, if I try to zoom in using the zoom slider, the ESRI street map disappears as well.


It sounds like there are a few things going on here, so the best option is to strip your code back to the bare minimum. Once that's working, add an extra piece of functionality (eg the combo box) and see if that causes the error to occur. This will help you to debug precisely what is causing the problem.

So I would remove all functionality except the basemap, and verify that zooming in does not cause a problem. Now add the combo box, etc

Also, when posting code to the forums, use the CODE button (the # at the top right) to avoid losing your formatting.

Cheers,
Steve
0 Kudos
SamirGambhir
Frequent Contributor
Thanks Steve,
Let me try this approach.
Also, thanks for the tip for using the code button. I'll definitely use it next time.
Samir
0 Kudos
SamirGambhir
Frequent Contributor
Hi Steve,
I figured out the problem. I am trying to extract the extent of the geometry and trying to pass on this info to a common .setExtent method. I have the following code which is incorrect, but can you please suggest a way to do this? I would like to keep .setExtent outside my if-else loop. Thanks, Samir
function getStateExt(State) {
 var zoomExtent;
  if (State != "All India") {
   var myState = State.toUpperCase();
   var queryTask = new esri.tasks.QueryTask("http://nsmhpc7007:8399/arcgis/rest/services/wch3/MapServer/9");
   var qState = new esri.tasks.Query();
   qState.where = "name = '" + myState + "'";
   qState.returnGeometry = true;
   qState.outFields = ["name"];
   queryTask.execute(qState);
   dojo.connect(queryTask, "onComplete", function(featureSet) {
    var features = featureSet.features;
    stateExtent = features[0].geometry.getExtent();
    var zoomExtentXmin = stateExtent.xmin - 150000;
    var zoomExtentYmin = stateExtent.ymin - 75000;
    var zoomExtentXmax = stateExtent.xmax + 150000;
    var zoomExtentYmax = stateExtent.ymax + 75000;
    zoomExtent = new esri.geometry.Extent({"xmin":zoomExtentXmin, "ymin":zoomExtentYmin, "xmax":zoomExtentXmax, "ymax":zoomExtentYmax,"spatialReference":{"wkid":102100}});
   });
  } else if (State == "All India") {
   zoomExtent = iniExtentM.getExtent();
  }
  mapM.setExtent(zoomExtent);
 
}
0 Kudos