using System.Windows; using System.Windows.Controls; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; using System; namespace CSHowDoISamples { /// /// Interaction logic for DisplayASimpleMap.xaml /// public partial class DisplayASimpleMap : UserControl { public DisplayASimpleMap() { InitializeComponent(); } private void WpfMap_Loaded(object sender, RoutedEventArgs e) { Map1.MapUnit = GeographyUnit.DecimalDegree; Map1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9); WorldMapKitWmsWpfOverlay worldOverlay = new WorldMapKitWmsWpfOverlay(); Map1.Overlays.Add("WMK", worldOverlay); Map1.Refresh(); Map1.MinimumScale = GetMinZoomScale(Map1.MaxExtent, (float)Map1.ActualWidth, GeographyUnit.DecimalDegree, 20); Map1.RestrictExtent = Map1.MaxExtent; RectangleShape Map1Extend = GetFitExtent(Map1.MaxExtent, Map1.ActualWidth, Map1.ActualHeight); Map1.MaximumScale = GetMaxZoomScale(Map1Extend, (float)Map1.ActualHeight, GeographyUnit.DecimalDegree); Map1.CurrentExtent = Map1Extend; } 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; } } } }