/// <summary>
        /// Zoom to candidate depends on locator type.
        /// </summary>
        /// <param name="mapCtrl">Map control.</param>
        /// <param name="addressCandidate">Candidate to zoom.</param>
        /// <param name="locatorType">Type of locator, which return this candidate.</param>
        private static void _ZoomToCandidate(MapControl mapCtrl, AddressCandidate addressCandidate, LocatorType locatorType)
        {
            Debug.Assert(mapCtrl != null);
            Debug.Assert(addressCandidate != null);

            double extentInc = 0;

            // Get extent size.
            switch (locatorType)
            {
            case LocatorType.CityState:
            {
                extentInc = ZOOM_ON_CITY_STATE_CANDIDATE;
                break;
            }

            case LocatorType.Zip:
            {
                extentInc = ZOOM_ON_ZIP_CANDIDATE;
                break;
            }

            case LocatorType.Street:
            {
                extentInc = ZOOM_ON_STREET_CANDIDATE;
                break;
            }

            default:
            {
                Debug.Assert(false);
                break;
            }
            }

            // Make extent rectangle.
            ESRI.ArcLogistics.Geometry.Envelope rect = new ESRI.ArcLogistics.Geometry.Envelope();
            rect.SetEmpty();
            rect.Union(addressCandidate.GeoLocation);

            rect.left   -= extentInc;
            rect.right  += extentInc;
            rect.top    += extentInc;
            rect.bottom -= extentInc;

            ESRI.ArcGIS.Client.Geometry.Envelope extent = GeometryHelper.CreateExtent(rect,
                                                                                      mapCtrl.Map.SpatialReferenceID);
            mapCtrl.ZoomTo(extent);
        }
        /// <summary>
        /// Get extent for point collection.
        /// </summary>
        /// <param name="points">Points.</param>
        /// <returns>Envelope, which contains all points.</returns>
        public static ESRI.ArcLogistics.Geometry.Envelope? GetCollectionExtent(IList <ESRI.ArcLogistics.Geometry.Point> points)
        {
            ESRI.ArcLogistics.Geometry.Envelope?result = null;

            if (points.Count > 0)
            {
                ESRI.ArcLogistics.Geometry.Envelope rect = new ESRI.ArcLogistics.Geometry.Envelope();
                rect.SetEmpty();

                bool atLeastOnePointHavePosition = false;
                foreach (ESRI.ArcLogistics.Geometry.Point point in points)
                {
                    rect.Union(point);
                    atLeastOnePointHavePosition = true;
                }

                if (atLeastOnePointHavePosition)
                {
                    // Increase extent.
                    double heigthInc = EXTENT_INDENT * rect.Height;
                    double widthInc  = EXTENT_INDENT * rect.Width;
                    if (heigthInc == 0)
                    {
                        heigthInc = ZOOM_ON_STREET;
                    }
                    if (widthInc == 0)
                    {
                        widthInc = ZOOM_ON_STREET;
                    }

                    rect.left   -= widthInc;
                    rect.right  += widthInc;
                    rect.top    += heigthInc;
                    rect.bottom -= heigthInc;

                    result = rect;
                }
            }

            return(result);
        }
        /// <summary>
        /// Get extent for point collection.
        /// </summary>
        /// <param name="points">Points.</param>
        /// <returns>Envelope, which contains all points.</returns>
        public static ESRI.ArcLogistics.Geometry.Envelope? GetCollectionExtent(IList<ESRI.ArcLogistics.Geometry.Point> points)
        {
            ESRI.ArcLogistics.Geometry.Envelope? result = null;

            if (points.Count > 0)
            {
                ESRI.ArcLogistics.Geometry.Envelope rect = new ESRI.ArcLogistics.Geometry.Envelope();
                rect.SetEmpty();

                bool atLeastOnePointHavePosition = false;
                foreach (ESRI.ArcLogistics.Geometry.Point point in points)
                {
                    rect.Union(point);
                    atLeastOnePointHavePosition = true;
                }

                if (atLeastOnePointHavePosition)
                {
                    // Increase extent.
                    double heigthInc = EXTENT_INDENT * rect.Height;
                    double widthInc = EXTENT_INDENT * rect.Width;
                    if (heigthInc == 0)
                    {
                        heigthInc = ZOOM_ON_STREET;
                    }
                    if (widthInc == 0)
                    {
                        widthInc = ZOOM_ON_STREET;
                    }

                    rect.left -= widthInc;
                    rect.right += widthInc;
                    rect.top += heigthInc;
                    rect.bottom -= heigthInc;

                    result = rect;
                }
            }

            return result;
        }
        /// <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;
        }
        /// <summary>
        /// Zoom to candidate depends on locator type.
        /// </summary>
        /// <param name="mapCtrl">Map control.</param>
        /// <param name="addressCandidate">Candidate to zoom.</param>
        /// <param name="locatorType">Type of locator, which return this candidate.</param>
        private static void _ZoomToCandidate(MapControl mapCtrl, AddressCandidate addressCandidate, LocatorType locatorType)
        {
            Debug.Assert(mapCtrl != null);
            Debug.Assert(addressCandidate != null);

            double extentInc = 0;

            // Get extent size.
            switch (locatorType)
            {
                case LocatorType.CityState:
                    {
                        extentInc = ZOOM_ON_CITY_STATE_CANDIDATE;
                        break;
                    }
                case LocatorType.Zip:
                    {
                        extentInc = ZOOM_ON_ZIP_CANDIDATE;
                        break;
                    }
                case LocatorType.Street:
                    {
                        extentInc = ZOOM_ON_STREET_CANDIDATE;
                        break;
                    }
                default:
                    {
                        Debug.Assert(false);
                        break;
                    }
            }

            // Make extent rectangle.
            ESRI.ArcLogistics.Geometry.Envelope rect = new ESRI.ArcLogistics.Geometry.Envelope();
            rect.SetEmpty();
            rect.Union(addressCandidate.GeoLocation);

            rect.left -= extentInc;
            rect.right += extentInc;
            rect.top += extentInc;
            rect.bottom -= extentInc;

            ESRI.ArcGIS.Client.Geometry.Envelope extent = GeometryHelper.CreateExtent(rect,
                mapCtrl.Map.SpatialReferenceID);
            mapCtrl.ZoomTo(extent);
        }
Example #6
0
        /// <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);
        }