AnsweredAssumed Answered

map.setExtent(extent,true) not working on webmaps.

Question asked by Reda20 on Oct 28, 2014
Latest reply on Oct 28, 2014 by rscheitlin

Hi everyone,


I have the following issue :

I don't get to set the extent of my webmap.

Please find below the code used.

I tried many ways: using graphics, feature layers, document element,.

The code does a spatial selection based on a dropdownlist value:



Please kindly advice where could be the error.


var mapid = "bd44b693be444c3a9a4a620661e7ce66";

var map = new esri.Map("mapDiv");


   var mapDeferred = esri.arcgis.utils.createMap(mapid, "mapDiv").then(function(response)


     map =;  


     //Define a feature layer

     var ZonesQueryFeatureLayer = new esri.layers.FeatureLayer("", {

         id: 'ZonesQueryFeatureLayer',

         mode: esri.layers.FeatureLayer.MODE_SELECTION,

         outFields: ["*"]



  //connect event to onchange of a zone selection from the dropdownlist(Ref. ResultQID)

  dojo.connect(dojo.byId('#ResultQID'), "onchange", function(evt) {

             console.log("option changed to: " +;



             var selectQuery = new esri.tasks.Query();

             selectQuery.where = "Zone_Name LIKE '"+ +"'";

             selectQuery.outFields = ["*"];

             ZonesQueryFeatureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {

             //after highlighting feature (or not), zoom to feature to show detailed map

                  if (features !== undefined && features.length !== 0) {

                 //should be only one result returned, so using first array value [0]

                  ZonesQueryFeatureLayer.getMap().setExtent(features[0].geometry.getExtent(), true);

                  // I also tried:

                  //map.setExtent(features[0].geometry.getExtent(), true);

                   //mapDeferred.setExtent(features[0].geometry.getExtent(), true);

                   //document.getElementById("mapDiv").setExtent(features[0].geometry.getExtent(), true);


                  else {

                 alert("zone not found/Please select a proper Zone.")