Provides access to the Center And Scale Map Area Interface.
When To Use
Use ICenterAndScale to apply a new geographic extent to a map by specifying a center point and map scale.
Members
Name | Description | |
---|---|---|
Center | The center of the map. | |
MapScale | The map scale. |
ICenterAndScale.Center Property
The center of the map.
Public Property Center As IPoint
public IPoint Center {get; set;}
ICenterAndScale.MapScale Property
The map scale.
Public Property MapScale As Double
public double MapScale {get; set;}
Classes that implement ICenterAndScale
Classes | Description |
---|---|
CenterAndScale | The Center And Scale coclass allows you to change the spatial extent of a map by specifying the center and scale. |
Remarks
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.
It is important to remember that CenterAndScale does not compute map extent. When used in ExportMapImage function, the returned object IMapImage can be used to get the updated map extent. To compute map extent based on a center point and a scale without calling the ArcGIS Server, a client side solution is required. Please see the code snippet below.
The following sample codes show (1) how to zoom to a specified scale using ICenterAndScale, (2) how to compute the map extent based on a scale and a center point, and (3) how to compute the map extent based on a scale and a center point when the esriDisplay library is not available (in case of WSDL). Last two code snippets may be modified to accept a point and a scale instead of a ICenterAndScale.
It assumes that you already have a valid MapServer, MapDescription and ImageDescription objects and that you are not working with a server context. However, if you are developing an ArcGIS for 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.
Example# 1: Zoom to a specified scale using CenterAndScale object
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;
//Exporting map to the specified scaleIMapImage pMapImage = pMapServer.ExportMapImage(mapDesc, pImageDescriptipn);
Example# 2: Compute Map Extent with a location and scale
Example# 3: Compute Map Extent with a location and scale in WSDL