case "放大":
MyDrawObject.IsEnabled = true;
_toolMode = "zoomin";
break;
case "缩小":
MyDrawObject.IsEnabled = true;
_toolMode = "zoomout";
break;
void MyDrawObject_DrawComplete(object sender, DrawEventArgs e)
{
if (_toolMode == "zoomin")
{
MyMap.ZoomTo(e.Geometry as ESRI.ArcGIS.Client.Geometry.Envelope);
}
else if (_toolMode == "zoomout")
{
Envelope currentExtent = MyMap.Extent;
Envelope zoomBoxExtent = e.Geometry as Envelope;
MapPoint zoomBoxCenter = zoomBoxExtent.GetCenter();
double whRatioCurrent = currentExtent.Width / currentExtent.Height;
double whRatioZoomBox = zoomBoxExtent.Width / zoomBoxExtent.Height;
Envelope newEnv = null;
if (whRatioZoomBox > whRatioCurrent)
// use width
{
double mapWidthPixels = MyMap.Width;
double multiplier = currentExtent.Width / zoomBoxExtent.Width;
double newWidthMapUnits = currentExtent.Width * multiplier;
newEnv = new Envelope(new MapPoint(zoomBoxCenter.X - (newWidthMapUnits / 2), zoomBoxCenter.Y),
new MapPoint(zoomBoxCenter.X + (newWidthMapUnits / 2), zoomBoxCenter.Y));
}
else
// use height
{
double mapHeightPixels = MyMap.Height;
double multiplier = currentExtent.Height / zoomBoxExtent.Height;
double newHeightMapUnits = currentExtent.Height * multiplier;
newEnv = new Envelope(new MapPoint(zoomBoxCenter.X, zoomBoxCenter.Y - (newHeightMapUnits / 2)),
new MapPoint(zoomBoxCenter.X, zoomBoxCenter.Y + (newHeightMapUnits / 2)));
}
if (newEnv != null)
MyMap.ZoomTo(newEnv);
}
}
MyDrawObject = new Draw(MyMap)
{
FillSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.FillSymbol,
DrawMode = DrawMode.Rectangle
};
MyDrawObject.DrawComplete += new EventHandler<DrawEventArgs>(MyDrawObject_DrawComplete);