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.
Sara,
By using the GeometryService.project and ProjectParameters classes:
ProjectParameters | API Reference | ArcGIS API for JavaScript 3.20
https://developers.arcgis.com/javascript/3/jsapi/geometryservice-amd.html#project
Okay I will create a geometry Service and keep you in touch with what I've done,
thanks for your time
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
Thanks so much for the live Demo, How can I add a zoom level in that Code ?
How do you plan to use the zoom level?
I wanna zoom to that extent with a 10 level
After setting the map extent call:
map.setZoom(10);
Thank you Kristian for your time