How to obtain the extent of a layer programatically

625
2
Jump to solution
01-11-2012 02:51 PM
StephenLead
Regular Contributor III
Take an example of a Map Service in the REST API. This contains an Initial Extent and Full Extent:

Intial Extent:
XMin: -207.682974279982
YMin: -40.6075371681153
XMax: -37.1804225764967
YMax: 129.89501453537
Spatial Reference: 4269


When creating a new Tiled or Dynamic layer from this service, the Initial Extent and Full Extent are listed as null in FireBug. How can these values be obtained programmatically?

Feature Layer contains a fullExtent property but I can't see the equivalent for Dynamic or Tiled layers.

The goal is to zoom to the extent of the layer once it's been added.

Thanks,
Steve
0 Kudos
1 Solution

Accepted Solutions
JianHuang
Occasional Contributor III
Use if (layer.loaded) to make sure you can access those properties. Or, you may want to connect to the "onLoad" event.
Please see details at:
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/layer.htm#loaded

View solution in original post

0 Kudos
2 Replies
JianHuang
Occasional Contributor III
Use if (layer.loaded) to make sure you can access those properties. Or, you may want to connect to the "onLoad" event.
Please see details at:
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/layer.htm#loaded
0 Kudos
StephenLead
Regular Contributor III
Thanks, this works:
        
basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
map.addLayer(basemap);
dojo.connect(basemap, "onLoad", function() {
   alert(basemap.fullExtent.xmin);
});        

0 Kudos