Zoom to extent of Dynamic Layer (that has a def expression)

4378
8
11-30-2010 07:28 AM
PaulForbess
New Contributor III
I don't see any methods that zoom to the extent of a Dynamic layer. Am I missing it somewhere?

What I'm doing is filtering a arcgisdynamicmapservice layer by adding a definition expression, and then would like the map to zoom to the extent of the definition expression. I know in ArcMap, when you right click a layer and choose 'zoom to layer', it honors the definition expression, so I would assume that ArcGIS Server would also do this. But, doesn't seem to be any way in the Javascript API to zoom to the extent of a Dynamic Layer anyway?

The layers I'm using are way too large - so I can't convert them to graphics and then zoom because of performance (potentially i need to zoom to the extent of 100,000 points).
0 Kudos
8 Replies
PaulForbess
New Contributor III
Here's some things I found:


ArcGISDynamicMapServiceLayer is a subclass of DynamicMapServiceLayer, and DynamicMapServiceLayer DOES have FULLEXTENT and INITIALEXTENT properties.

var lyrFullExtent = lyr.fullExtent
var lyrInitExtent = lyr.initialExtent

They both return an EXTENT object, so then you can use lyrFullExtent.minx, lyrFullExtent.maxx, etc. . . .

But, unfortunately, the returned values do not seem to honor the definition query that was set on the layer.

These values match the values on the /rest/services page for the layer.

The fullExtent looks like the actual outer extent of the whole layer itself.

The initialExtent makes no sense, it does not even match the extent of the MSD's dataframe. Not sure how this gets set for the service. Can anyone shed light on where/how the initialExtent gets set for a service?
0 Kudos
timgogl
New Contributor II
if you have defined extents, just use:
map.setExtent(myextent);


http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jsapi_start.htm
0 Kudos
MarkHoover
Occasional Contributor II
That doesn't really solve his problem, though.  If he had a global layer and put a definition expression on it that said something like "COUNTRY = 'Germany'", then that fixed extent zoom isn't very helpful anymore.
0 Kudos
PaulForbess
New Contributor III
Yes, it's beginning to look like I will have to perform an identical definition query back on the server/database in SQL (maybe use st_geometry), get the coordinates from the database and send them back through to the javascript to set the new extent. Yuck.

I'm just not seeing any other way. I can't use the 'out-of-the-box' querytask functionality, there is no way the Javascript API is going to perform reasonably with thousands of graphic features streaming back to the client in order to get the new extent.
0 Kudos
KirstenLawrence
New Contributor III

I see this post is pretty old, I'm looking for a way to to the same thing. Did you ever find a reasonable answer?

0 Kudos
PaulForbess
New Contributor III

Yes,  run the definition query in sql (we use Java JDBC) and use st_geometry functions to get the min and max for the returned features. Then set the map extent to those values.

0 Kudos
KirstenLawrence
New Contributor III

Thanks for the reply. I’m a novice with javascript, I’m not sure how I would retrieve these values in javascript? Do you have some sample code you wouldn’t mind sharing?

0 Kudos
LeoDonahue
Occasional Contributor III
nevermind, read the api and no def query allowed on what I was going to suggest.
0 Kudos