1

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);
   }
});
  • I found the solution. Need to convert the projection of the layer to map's projection first. – Alex Dec 31 '13 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 – James Milner Sep 1 '15 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 '16 at 22:39
1

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

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

0

If this is your full code, try adding

map.refresh();

  • 1
    map.refresh is not a function – Alex Dec 31 '13 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 '13 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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