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– Alex2013年12月31日 20:42:04 +00:00Commented 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. SpatialReferenceJames Milner– James Milner2015年09月01日 00:23:45 +00:00Commented 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– alexGIS2016年05月24日 22:39:28 +00:00Commented 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
map.refresh();
-
1map.refresh is not a functionAlex– Alex2013年12月31日 14:34:28 +00:00Commented 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– Alex2013年12月31日 16:01:37 +00:00Commented Dec 31, 2013 at 16:01
Explore related questions
See similar questions with these tags.