/// <summary> /// Converts from map coordinates to screen. /// </summary> /// <param name="mapPoint">Point to conversion (in map coordinates).</param> /// <param name="extent">Map extent.</param> /// <param name="width">Image width.</param> /// <param name="height">Image height.</param> /// <returns>Converted point in screen coordinates.</returns> private SysWindows.Point _ConvertPoint(AppGeometry.Point mapPoint, EnvelopeN extent, double width, double height) { Debug.Assert(null != mapPoint); Debug.Assert(null != extent); Debug.Assert(0 < width); Debug.Assert(0 < height); AppGeometry.Point projectedPointFrom = WebMercatorUtil.ProjectPointToWebMercator(mapPoint, _mapInfo.SpatialReference.WKID); double x = width * (projectedPointFrom.X - extent.XMin) / (extent.XMax - extent.XMin); double y = height - height * (projectedPointFrom.Y - extent.YMin) / (extent.YMax - extent.YMin); SysWindows.Point pointTo = new SysWindows.Point(x, y); return(pointTo); }
/// <summary> /// Gets map extent for route. /// </summary> /// <param name="route">Route to getting points.</param> /// <param name="sortedRouteStops">Sorted stops from route.</param> /// <returns>Map extent for route (all points on map).</returns> private EnvelopeN _GetExtent(Route route, IList <Stop> sortedRouteStops) { Debug.Assert(null != route); Debug.Assert(null != sortedRouteStops); int spatialRefId = _mapInfo.SpatialReference.WKID; int startIndex = _GetStartIndex(route, sortedRouteStops); int processCount = _GetProcessStopCount(route, sortedRouteStops); var points = new List <AppGeometry.Point>(); bool isStartFound = false; for (int stopIndex = startIndex; stopIndex < processCount; ++stopIndex) { Stop stop = sortedRouteStops[stopIndex]; // NOTE: path to first stop not showing if (isStartFound && (null != stop.Path) && !stop.Path.IsEmpty) { for (int index = 0; index < stop.Path.Groups.Length; ++index) { AppGeometry.Point[] pointsArray = stop.Path.GetGroupPoints(index); foreach (AppGeometry.Point point in pointsArray) { AppGeometry.Point pt = WebMercatorUtil.ProjectPointToWebMercator(point, spatialRefId); points.Add(pt); } } } if (stop.MapLocation.HasValue) { AppGeometry.Point location = stop.MapLocation.Value; AppGeometry.Point loc = WebMercatorUtil.ProjectPointToWebMercator(location, spatialRefId); points.Add(loc); if (!isStartFound) { isStartFound = true; } } } var rect = new AppGeometry.Envelope(); rect.SetEmpty(); foreach (AppGeometry.Point point in points) { rect.Union(point); } // increase extent double heightInc = ROUTE_EXTENT_INDENT * rect.Height; if (heightInc == 0) { heightInc = ROUTE_EXTENT_INDENT; } double widthInc = ROUTE_EXTENT_INDENT * rect.Width; if (widthInc == 0) { widthInc = ROUTE_EXTENT_INDENT; } rect.left -= widthInc; rect.right += widthInc; rect.top += heightInc; rect.bottom -= heightInc; var extent = new EnvelopeN(); extent.XMax = rect.right; extent.XMin = rect.left; extent.YMax = rect.top; extent.YMin = rect.bottom; return(extent); }