I tried to get the function "Zoom to Layer" done using the following code snippet. But it does not change anything. The layer is a feature service layer, and I can see the full extent object of the layer which is not null. Any idea?

tree.on("dblClick", function (item, node, event) {
  var layerId=item.id[0];
  var layer = map.getLayer(layerId);

   if (!layer)
    var lyrExt=layer.fullExtent;
    var gsvc=  esriConfig.defaults.geometryService;
    var outSR = new esri.SpatialReference({ wkid: 102100 });
    gsvc.project([lyrExt], outSR, function(newExt) {
  • I found the solution. Need to convert the projection of the layer to map's projection first.
    – Alex
    Dec 31, 2013 at 20:42
  • If you're using a newer version of the API you can also drop all the esri. prefixes i.e. SpatialReference vs esri.SpatialReference. You can use the class names you define in the require block argument names i.e. SpatialReference Sep 1, 2015 at 0:23
  • I don't know if your code snippet is just partially copied, but as it appears now, you are missing a closing ) and }
    – alexGIS
    May 24, 2016 at 22:39

2 Answers 2


From @Alex's comment indicating he found the solution :

You "need to convert the projection of the layer to map's projection first."


If this is your full code, try adding


  • 1
    map.refresh is not a function
    – Alex
    Dec 31, 2013 at 14:34
  • I found where the problem is. The spatial reference's wkid of map is 102100 while the wkid of layer full extent object is 2248. Not sure how to fix this.
    – Alex
    Dec 31, 2013 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.