Provides access to the Center And Scale Map Area Interface.
Use ICenterAndScale to apply a new geographic extent to a map by specifying a center point and map scale.
| CoClasses and Classes | Description |
|---|---|
| CenterAndScale | The Center And Scale coclass allows you to change the spatial extent of a map by specifying the center and scale. |
One way to change the map extent is using the object CenterAndScale. Create a new CenterAndScale object and set the geographic extent of the map by setting a center point and a map scale. If the spatial reference of the MapServer object has changed, remember to adjust the spatial reference of the center point to match the new spatial reference.
The following sample code shows how to zoom to a specified scale using ICenterAndScale. It assumes that you already have a valid MapDescription object and that you are not working with a server context. However, if you are developing an ArcGIS Server application using a server context, you should not use New to create local ArcObjects, but you should always create objects within the server by calling CreateObject on IServerContext.
IMapDescription mapDesc;
IEnvelope extent = mapDesc.MapArea.Extent;
double lXMin, lXMax, lYMin, lYMax;
lXMin = extent.XMin;
lXMax = extent.XMax;
lYMin = extent.YMin;
lYMax = extent.YMax;
// Calculate center point of current map extent
IPoint centerPoint = new PointClass();
centerPoint.SpatialReference = mapDesc.SpatialReference;
centerPoint.X = lXMin + (lXMax - lXMin) / 2;
centerPoint.Y = lYMin + (lYMax - lYMin) / 2;
// Assign center point and map scale to new CenterAndScale object
ICenterAndScale centerAndScale = new CenterAndScaleClass();
centerAndScale.Center = centerPoint;
centerAndScale.MapScale = 2000000;
// Assign new CenterAndScale object to MapDescription
mapDesc.MapArea = (IMapArea)centerAndScale;
The following sample code shows how to zoom to a specified scale using ICenterAndScale. It assumes that you already have a valid MapDescription object and that you are not working with a server context. However, if you are developing an ArcGIS Server application using a server context, you should not use New to create local ArcObjects, but you should always create objects within the server by calling CreateObject on IServerContext.
Dim pMapDesc as IMapDescription
'Get coordinates of current map extent
Dim pExtent As IEnvelope
Dim lXMin As Double, lXMax As Double, lYMin As Double, lYMax As Double
Set pExtent = pMapDesc.MapArea.Extent
lXMin = pExtent.XMin
lXMax = pExtent.XMax
lYMin = pExtent.YMin
lYMax = pExtent.YMax
'Calculate center point of current map extent
Dim pCenterPoint As IPoint
Set pCenterPoint = New Point
Set pCenterPoint.SpatialReference = pMapDesc.SpatialReference
pCenterPoint.x = lXMin + (lXMax - lXMin) / 2
pCenterPoint.y = lYMin + (lYMax - lYMin) / 2
'Assign center point and map scale to new CenterAndScale object
Dim pCenterScale As ICenterAndScale
Set pCenterScale = New CenterAndScale
pCenterScale.Center = pCenterPoint
pCenterScale.MapScale = 2000000
'Assign new CenterAndScale object to MapDescription
pMapDesc.MapArea = pCenterScale