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);
 }
});
nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Dec 30, 2013 at 16:28
3
  • I found the solution. Need to convert the projection of the layer to map's projection first. Commented 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 Commented 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 } Commented May 24, 2016 at 22:39

2 Answers 2

1

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

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

answered Oct 3, 2017 at 10:22
0

If this is your full code, try adding

map.refresh();

answered Dec 30, 2013 at 21:51
2
  • 1
    map.refresh is not a function Commented 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. Commented Dec 31, 2013 at 16:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.