Hi guys,
I want to get the extent of a featureLayer and Zoom to it, How I can Implement that in my code ?
Solved! Go to Solution.
Since layer.fullExtent isn't totally reliable, I suggest doing the following:
featureLayer.on("load", function(){
var query = new Query();
query.where = "1=1";
query.outSpatialReference = new SpatialReference(3857);
featureLayer.queryExtent(query, zoomToExtent);
});
function zoomToExtent(response){
var extent = response.extent;
map.setExtent(extent, true);
}
That way you don't have to bring in GeometryService and reproject geometries. Set the outSpatialReference to match the map and the resulting extent should be good. Here's a live demo of this as well: JS Bin - Collaborative JavaScript Debugging
Sara,
Something like this:
map.setExtent(layer17.fullExtent, true);
It gives me an error, Uncaught TypeError: Cannot read property 'fullExtent' of undefined
Then you featurelayer is not loaded yet, or you are just not getting the featurelayer based on the code you are using. Have you checked to see if layer17 is a valid FL?
It does not throw an error if I write :
but It does nothing, I want it to zoom to that extent with a 11 level !
Yes that line may not through an error but have you checked the value of layer17?
console.log(layer17);
in the console "
it gives:
Map: Geometry (wkid: PROJCS["zone1",GEOGCS["GCS_Merchich_Degree",DATUM["D_Merchich",SPHEROID["Clarke_1880_IGN",6378249.2,293.4660212936265]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",300000.0],PARAMETER["Central_Meridian",-5.4],PARAMETER["Standard_Parallel_1",34.866],PARAMETER["Standard_Parallel_2",31.725],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",33.3],UNIT["Meter",1.0]]) cannot be converted to spatial reference of the map (wkid: 102100)
So that means that the layers WKID is different from the maps WKID of 102100 and you will have to project the layers full extent to 102100.
so how can I do that ?
I found these lines:
var customExtentAndSR = new esri.geometry.Extent(-20037506,-9823074,20037506,10214431,new esri.SpatialReference({"wkid":54052})); //create map with new custom spatial reference and extent. The map will be in the Goode Homolosine Land projection var map = new esri.Map("map", { extent: customExtentAndSR });
How can use them for the extent of the layers ?