Select to view content in your preferred language

Good news:  How to set the Work-around to set min and max scales for MyMap

1117
0
02-03-2014 07:57 AM
YurongTan
Regular Contributor
Here is a work-sround to set the max and min scales for application main map MyMap.  It uses the  MyMap_ExtentChanged(object sender, ExtentEventArgs e) event.  This is to prevent the user from zoomming in/out outside the preset min & max map scales.  ESRI can trweak it to make it better or simply to add a property for the application main map.

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