Hi Anaish,You may use esri.geometry.Polygon.getExtent() method to get the extent of a polygon. Here is its documentation:http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/polygon.htm#getExtent
Hi swingley, thanks for the reply. I can't use static json files because the geometries in my web application are dynamic (i.e they can be added in an adhoc manner).
@hzhu that still brings all the geometries across the wire, which is what OP is trying to avoid.
@hzhu As you request more features (using either esri.request or a queryTask), the response size will grow. If the server only returned the extent of the features that satisfy a request, then the response size will be consistent if you ask for 10 or 1000 features. To my knowledge, there's not an out of the box way to get just a bounding box for features that satisfy a request w/o sending all of the geometries to the client.How is the return value of esri.request different than a queryTask? The JavaScript syntax for working with them differs but both fetch plain text from the server (you can verify this via firebug or chrome's dev tools) that is then turned into JavaScript objects on the client.
True, we're not likely to find a solution to OP's question/problem in this thread. But I'd like to continue this discussion as I think we still need to clarify for anyone else who comes across this thread. A featureSet, in the context of the JavaScript API and as delivered to the client, is a JSON object.Let's look at this from another angle. How about we talk about this in terms of the REST API? If you want features from a layer in a map service, how do you get them? You use the query endpoint. If you use the endpoint via the JavaScript API's QueryTask (recommended) or through esri.request, you are getting back JSON (as long as you specify f=json when using esri.request).
Are you sure response is a string? What does the rest of your esri.request() code look like?In practice, especially when talking to ArcGIS Server endpoints, I don't think there are many (any?) times you'd want text over json. Why mess around with wrapping a response in parens and calling eval() when the server can return jsonp?
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.