private void DrawPath(MapPath path, bool close = false) { if (path.Points.Count < 2) { return; } Color c = _pathColors[path]; MapVectorD lastView = _map.LatLonToViewPoint(path.Points[0]); for (int i = 1; i < path.Points.Count; i++) { var currentView = _map.LatLonToViewPoint(path.Points[i]); if (_map.ViewBounds.Contains(currentView) || _map.ViewBounds.Contains(lastView)) { _sBatch.DrawLine(lastView.ToVector2(), currentView.ToVector2(), c, (float)path.LineWidth); } lastView = currentView; } if (close) { var firstView = _map.LatLonToViewPoint(path.Points[0]); if (_map.ViewBounds.Contains(firstView) || _map.ViewBounds.Contains(lastView)) { _sBatch.DrawLine(lastView.ToVector2(), firstView.ToVector2(), c, (float)path.LineWidth); } } }
protected IconMarkerBase(string textureName) { _textureName = textureName; TextureIdentifier = $"resx-icons-{textureName}"; using (var bmp = (Bitmap)Icons.ResourceManager.GetObject(textureName)) { Size = new MapSize(bmp.Width, bmp.Height); } Offset = new MapVectorD(Size.Width / 2.0, Size.Height); }
/// <summary> /// Converts a point within the view of the map (offset from top left of the viewbounds) to the MapCoordinate of that point. /// </summary> /// <param name="viewPoint">The point in the view coordinate system</param> /// <returns>The corresponding point in the map coordinate system.</returns> public MapVector ViewPointToMapPoint(MapVectorD viewPoint) { MapVectorD middleMapPoint = new MapVectorD(LatLonToMapPoint(Position)); MapVectorD viewMiddlePoint = new MapVectorD() { X = ViewBounds.X + ViewBounds.Width / 2.0, Y = ViewBounds.Y + ViewBounds.Height / 2.0 }; MapVectorD viewOffset = viewPoint - viewMiddlePoint; return(new MapVector(middleMapPoint + (viewOffset / CoordinateScale))); }
/// <summary> /// Zoom the map around the given view coordinate within the displayed map. /// </summary> /// <param name="zoom">The new zoom level</param> /// <param name="mousePos">The point within the view coordinate system to zoom the map around</param> private void SetZoomMouse(int zoom, MapVector mousePos) { MapVectorD mouse = new MapVectorD(mousePos); MapVectorD middle = new MapVectorD() { X = _map.ViewBounds.Width / 2.0, Y = _map.ViewBounds.Height / 2.0 }; MapVectorD offset = middle - mouse; // Vector from mouse position to middle position // 1. move the map to the position the mouse is at _map.Position = _map.ViewPointToLatLon(mouse); // 2. zoom the map _map.Zoom = zoom; // 3. move the map back about the same amount we move it in (1.) _map.Position = _map.ViewPointToLatLon(middle + offset); // Plus here because the offset is mouse -> middle }
public MapVectorD MapPointToViewPoint(MapVectorD mapPoint) { var topLeftMap = new MapVectorD(ViewPointToMapPoint(ViewBounds.Location)); return((mapPoint - topLeftMap) * CoordinateScale); }
public MapPointLatLon ViewPointToLatLon(MapVectorD viewPoint) => MapPointToLatLon(ViewPointToMapPoint(viewPoint));
public static Vector2 ToVector2(this MapVectorD vect) { return(new Vector2((float)vect.X, (float)vect.Y)); }