Select to view content in your preferred language

Good news:  Work-around to set the max and min scales for application main map MyMap.

561
0
02-03-2014 08:05 AM
YurongTan
Regular Contributor
Here is a work-around to set the max and min scales for an application main Map (or MyMap).  It is based on the MyMap_ExtentChanged event and its purpose is to prevent the user from zooming beyond the preset scales. ESRI can tweak it to make it better or to simply add a property values for the main Map.  Thanks

private void MyMap_ExtentChanged(object sender, ExtentEventArgs e)
{
double myMapScale = MyMap.Scale;
double SmallestScaleFactor = 300000, LargestScaleFactor = 50000000;
if (myMapScale < SmallestScaleFactor || myMapScale > LargestScaleFactor)
{
  ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = MyMap.Extent;
  double MapxCenter = (displayExtent.XMax + displayExtent.XMin) / 2.0;
  double MapyCenter = (displayExtent.YMax + displayExtent.YMin) / 2.0;
  double view_x = (displayExtent.XMax - displayExtent.XMin) / (double)myMapScale;
  double view_y = (displayExtent.YMax - displayExtent.YMin) / (double)myMapScale;

  double newxmin, newxmax, newymin, newymax, NewScaleFactor = (double)myMapScale;
  if (myMapScale > LargestScaleFactor) NewScaleFactor = LargestScaleFactor;
  if (myMapScale < SmallestScaleFactor) NewScaleFactor = SmallestScaleFactor;
  newxmin = MapxCenter - ((view_x * NewScaleFactor) / 2.0);
  newxmax = MapxCenter + ((view_x * NewScaleFactor) / 2.0);
  newymin = MapyCenter - ((view_y * NewScaleFactor) / 2.0);
  newymax = MapyCenter + ((view_y * NewScaleFactor) / 2.0);
  ESRI.ArcGIS.Client.Geometry.Envelope LimittedDisplayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
    newxmin, newymin, newxmax, newymax);
  MyMap.ZoomTo(LimittedDisplayExtent);
}
}
0 Kudos
0 Replies