[GIS] How to zoom to layer using ArcGIS Javascript API

arcgis-javascript-apiarcgis-server

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)
   {
    return;
   }
   else
   {
    var lyrExt=layer.fullExtent;
    var gsvc=  esriConfig.defaults.geometryService;
    var outSR = new esri.SpatialReference({ wkid: 102100 });
    gsvc.project([lyrExt], outSR, function(newExt) {
    map.setExtent(newExt[0],true);
   }
});

Best Answer

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

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