Select to view content in your preferred language

Zoom To Layer

1983
8
11-08-2011 05:59 AM
BrianGustafson
Occasional Contributor
I am adding a layer programatically and I am trying to zoom to that layer.  However the service that I am adding is in a different spatial reference than my map.  Is there still a way to zoom to that layer when it is added to the map?
0 Kudos
8 Replies
BrianGustafson
Occasional Contributor
Will the ZoomToLayerAction do this?  How does that work if I want to implement this in the code behind.
0 Kudos
SanajyJadhav
Deactivated User
Even if spatial reference of the later service is different, it would be re projected on the fly to the spatial reference of the map.So,there should not be any issue.
0 Kudos
BrianGustafson
Occasional Contributor
The data draws correctly because it does reproject on the fly.  The issue is using that layers geometry to zoom to it when it is loaded into the map.
0 Kudos
SanajyJadhav
Deactivated User
Just for the clarification.

You want to zoom to the extent of the service that is being added later on, right? If yes, are you using Layer::FullExtent property?
0 Kudos
BrianGustafson
Occasional Contributor
Correct, but that service is in a different projection than the map so it throws an error.  Is there away around that?
0 Kudos
SanajyJadhav
Deactivated User
One thing could be tried out.

1. Create new envelope.
2. Use xMin,xMax,yMin and yMax of the LaterService::FullExtent to set the coordinates of this envelope.
3. Use spatial referene of the map to set Envelope::SpatialReference
4. Set extent.

Let me know if this helps.
0 Kudos
JenniferNery
Esri Regular Contributor
What type of layer are you trying to add programmatically? Did you call map.ZoomTo(layer.FullExtent)?
0 Kudos
BrianGustafson
Occasional Contributor
It is a DynamicMapServiceLayer map service layer that is a different spatial reference than the map.  I am trying to zoom to the layer in the map inside of the initialized event of the loaded layer.
0 Kudos