public void Test_GetPointsFrame() { CoordsRect coordsRect = PlacesLoader.GetPointsFrame(null); Assert.AreEqual(0.0d, coordsRect.MinLon); Assert.AreEqual(0.0d, coordsRect.MinLat); Assert.AreEqual(0.0d, coordsRect.MaxLon); Assert.AreEqual(0.0d, coordsRect.MaxLat); ExtList <GeoPoint> mapPoints = new ExtList <GeoPoint>(); mapPoints.Add(new GeoPoint(11, 13, "pt1")); mapPoints.Add(new GeoPoint(22, 25, "pt1")); coordsRect = PlacesLoader.GetPointsFrame(mapPoints); Assert.AreEqual(13.0d, coordsRect.MinLon); Assert.AreEqual(11.0d, coordsRect.MinLat); Assert.AreEqual(25.0d, coordsRect.MaxLon); Assert.AreEqual(22.0d, coordsRect.MaxLat); mapPoints.Clear(); mapPoints.Add(new GeoPoint(21, 21, "pt1")); coordsRect = PlacesLoader.GetPointsFrame(mapPoints); Assert.AreEqual(1.0d, coordsRect.MinLon); Assert.AreEqual(1.0d, coordsRect.MinLat); Assert.AreEqual(41.0d, coordsRect.MaxLon); Assert.AreEqual(41.0d, coordsRect.MaxLat); }
public void ZoomToBounds() { CoordsRect rt = PlacesLoader.GetPointsFrame(fMapPoints); if (rt.MinLon == rt.MaxLon || rt.MinLat == rt.MaxLat) { return; } double centerLongtude = ((rt.MaxLon + rt.MinLon) / 2.0); double centerLatitude = ((rt.MaxLat + rt.MinLat) / 2.0); string script = "var point1 = new google.maps.LatLng({0}, {1});" + "var point2 = new google.maps.LatLng({2}, {3});" + "var bounds = new google.maps.LatLngBounds(point1, point2);" + "map.fitBounds(bounds);" + "map.setCenter(new google.maps.LatLng({4}, {5}));"; script = string.Format(script, new object[] { PlacesLoader.CoordToStr(rt.MinLat), PlacesLoader.CoordToStr(rt.MinLon), PlacesLoader.CoordToStr(rt.MaxLat), PlacesLoader.CoordToStr(rt.MaxLon), PlacesLoader.CoordToStr(centerLatitude), PlacesLoader.CoordToStr(centerLongtude) }); gm_ExecScript(script); }
/// <summary>Returns the location and extent in hexes, as a <see cref="CoordsRect"/>, of the current clipping region.</summary> /// <param name="this">The current {HexBoard}.</param> /// <param name="visibleClipBounds"></param> /// <param name="boardSizeHexes"></param> public static CoordsRect GetClipInHexes <THex>(this HexBoard <THex> @this, RectangleF visibleClipBounds, HexSize boardSizeHexes) where THex : IHex { var left = Math.Max((int)visibleClipBounds.Left / @this.GridSize.Width - 1, 0); var top = Math.Max((int)visibleClipBounds.Top / @this.GridSize.Height - 1, 0); var right = Math.Min((int)visibleClipBounds.Right / @this.GridSize.Width + 1, boardSizeHexes.Width); var bottom = Math.Min((int)visibleClipBounds.Bottom / @this.GridSize.Height + 1, boardSizeHexes.Height); return(CoordsRect.New(left, top, right - left, bottom - top)); }