Hi,
I am new on thinkgeo. I am trying to zoom the map based on image resolution. I am using the following code for getting minimum & maximum zoom scale & current extent.
public static double GetMinZoomScale(RectangleShape currentExtent, float mapActualWidth, GeographyUnit mapUnit, float dpi) {
try {
if (mapActualWidth > 0) {
double minScale = ExtentHelper.GetScale(currentExtent, mapActualWidth, mapUnit, dpi);
return minScale;
}
else {
throw new Exception("Invalid map width");
}
}
catch (Exception) {
throw;
}
}
public static double GetMaxZoomScale(RectangleShape currentExtent, float mapActualWidth, GeographyUnit mapUnit)
{
try {
if (mapActualWidth > 0) {
double maxScale = ExtentHelper.GetScale(currentExtent, mapActualWidth, mapUnit);
return maxScale;
}
else {
throw new Exception("Invalid map width");
}
}
catch (Exception) {
throw;
}
}
public static RectangleShape GetFitExtent(RectangleShape sourceExtent, double mapScreenWidth, double mapScreenHeight) {
try {
double resolution = Math.Min(sourceExtent.Width / mapScreenWidth, sourceExtent.Height / mapScreenHeight) * .5;
PointShape center = sourceExtent.GetCenterPoint();
double mapHalfWorldWidth = resolution * mapScreenWidth * .5;
double mapHalfWorldHeight = resolution * mapScreenHeight * .5;
double left = center.X - mapHalfWorldWidth;
double right = center.X + mapHalfWorldWidth;
double top = center.Y + mapHalfWorldHeight;
double bottom = center.Y - mapHalfWorldHeight;
RectangleShape currentExtend = new RectangleShape(left, top, right, bottom);
return currentExtend;
}
catch (Exception) {
throw;
}
}
map.MapUnit = GeographyUnit.DecimalDegree;
map.MinimumScale = GetMinZoomScale(map.FullExtend, (float)mapWidth, GeographyUnit.DecimalDegree, 20);
map.RestrictExtent = map.FullExtend;
RectangleShape mapExtend = MapExtendUtility.GetFitExtent(map.FullExtend, mapWidth, mapHeight);
map.MaximumScale = ZoomLevelUtility.GetMaxZoomScale(mapExtend, (float)mapWidth, GeographyUnit.DecimalDegree);
map.CurrentExtent = mapExtend;
The prb is when I try to click the middle of the navigation tool, the application crashes.
Am I missing something?
Thanks,
Nadia