Example #1
0
        /// <summary>
        /// Get extent near point.
        /// </summary>
        /// <param name="position">Dropping position.</param>
        /// <returns>Extent near point.</returns>
        private Envelope _GetExtentNearDroppedPoint(System.Windows.Point position)
        {
            Debug.Assert(_mapView != null);

            System.Windows.Point leftTopPoint     = new System.Windows.Point(position.X - ROUTE_WIDTH, position.Y + ROUTE_WIDTH);
            System.Windows.Point rightBottomPoint = new System.Windows.Point(position.X + ROUTE_WIDTH, position.Y - ROUTE_WIDTH);
            ESRI.ArcGIS.Client.Geometry.MapPoint leftTopMapPoint     = _mapView.mapCtrl.map.ScreenToMap(leftTopPoint);
            ESRI.ArcGIS.Client.Geometry.MapPoint rightBottomMapPoint = _mapView.mapCtrl.map.ScreenToMap(rightBottomPoint);

            ESRI.ArcLogistics.Geometry.Point leftTopPointOnMap = new ESRI.ArcLogistics.Geometry.Point(
                leftTopMapPoint.X, leftTopMapPoint.Y);
            ESRI.ArcLogistics.Geometry.Point rightBottomPointOnMap = new ESRI.ArcLogistics.Geometry.Point(
                rightBottomMapPoint.X, rightBottomMapPoint.Y);

            // Project point from Web Mercator to WGS84 if spatial reference of map is Web Mercator.
            if (_mapView.mapCtrl.Map.SpatialReferenceID.HasValue)
            {
                leftTopPointOnMap = WebMercatorUtil.ProjectPointFromWebMercator(leftTopPointOnMap,
                                                                                _mapView.mapCtrl.Map.SpatialReferenceID.Value);
                rightBottomPointOnMap = WebMercatorUtil.ProjectPointFromWebMercator(rightBottomPointOnMap,
                                                                                    _mapView.mapCtrl.Map.SpatialReferenceID.Value);
            }

            Envelope extent = new Envelope(leftTopPointOnMap.X, leftTopPointOnMap.Y,
                                           rightBottomPointOnMap.X, rightBottomPointOnMap.Y);

            return(extent);
        }
        /// <summary>
        /// Create extent envelope
        /// </summary>
        /// <param name="envelope">Extent envelope in WGS84</param>
        /// <param name="spatialReferenceID">Map spatial reference ID</param>
        /// <returns>Extent envelope in map spatial reference</returns>
        public static ESRI.ArcGIS.Client.Geometry.Envelope CreateExtent(ESRI.ArcLogistics.Geometry.Envelope envelope,
                                                                        int?spatialReferenceID)
        {
            // Project extent to map spatial reference
            ESRI.ArcLogistics.Geometry.Point leftTop     = new ESRI.ArcLogistics.Geometry.Point(envelope.left, envelope.top);
            ESRI.ArcLogistics.Geometry.Point rightBottom = new ESRI.ArcLogistics.Geometry.Point(envelope.right, envelope.bottom);

            // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator
            if (spatialReferenceID.HasValue)
            {
                leftTop     = WebMercatorUtil.ProjectPointToWebMercator(leftTop, spatialReferenceID.Value);
                rightBottom = WebMercatorUtil.ProjectPointToWebMercator(rightBottom, spatialReferenceID.Value);
            }

            // Create map extent envelope
            ESRI.ArcGIS.Client.Geometry.Envelope extent = new ESRI.ArcGIS.Client.Geometry.Envelope();

            extent.XMin = leftTop.X;
            extent.XMax = rightBottom.X;
            extent.YMin = rightBottom.Y;
            extent.YMax = leftTop.Y;

            // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator
            if (spatialReferenceID.HasValue)
            {
                extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(spatialReferenceID.Value);
            }

            return(extent);
        }
Example #3
0
        /// <summary>
        /// Gets map extent for stop with selected radius around.
        /// </summary>
        /// <param name="stop">Stop to getting position.</param>
        /// <param name="extentRadiusInUnits">Extent radius [units].</param>
        /// <returns>Map extent for stop.</returns>
        private EnvelopeN _GetExtent(Stop stop, double extentRadiusInUnits)
        {
            Debug.Assert(null != stop);
            Debug.Assert(0 < extentRadiusInUnits);

            AppGeometry.Point point = stop.MapLocation.Value;
            double            stopX = point.X;
            double            stopY = point.Y;

            double extentRadius = DistCalc.GetExtentRadius(stopX, stopY, extentRadiusInUnits);

            // project extent to map spatial reference
            AppGeometry.Point leftTop =
                new AppGeometry.Point(stopX - extentRadius, stopY + extentRadius);
            AppGeometry.Point rightBottom =
                new AppGeometry.Point(stopX + extentRadius, stopY - extentRadius);

            int spatialRefId = _mapInfo.SpatialReference.WKID;

            leftTop =
                WebMercatorUtil.ProjectPointToWebMercator(leftTop, spatialRefId);
            rightBottom =
                WebMercatorUtil.ProjectPointToWebMercator(rightBottom, spatialRefId);

            // create extent in correct projection
            EnvelopeN extent = new EnvelopeN();

            extent.XMin = leftTop.X;
            extent.XMax = rightBottom.X;
            extent.YMin = rightBottom.Y;
            extent.YMax = leftTop.Y;

            return(extent);
        }
        /// <summary>
        /// Create map point and project to webmercator if needed.
        /// </summary>
        /// <param name="point">Source point.</param>
        /// <returns>Map point in correct projection.</returns>
        private ArcGISGeometry.MapPoint _CreateProjectedMapPoint(ArcLogisticsGeometry.Point point)
        {
            ArcLogisticsGeometry.Point projectedPoint = new ArcLogisticsGeometry.Point(point.X, point.Y);

            if (ParentLayer != null && ParentLayer.SpatialReferenceID != null)
            {
                projectedPoint = WebMercatorUtil.ProjectPointToWebMercator(projectedPoint, ParentLayer.SpatialReferenceID.Value);
            }

            ArcGISGeometry.MapPoint mapPoint = new ArcGISGeometry.MapPoint(projectedPoint.X, projectedPoint.Y);
            return(mapPoint);
        }
Example #5
0
        /// <summary>
        /// Does object reverse geocoding safelly.
        /// </summary>
        /// <param name="point">Point to geocoding.</param>
        /// <returns>Address by point or NULL.</returns>
        private Address _ReverseGeocodeSave(AppGeometry.Point point)
        {
            Debug.Assert(null != point); // created

            Address geocodedAddress = null;

            try
            {
                geocodedAddress = App.Current.Geocoder.ReverseGeocode(point);
            }
            catch (Exception ex)
            {
                // store exception
                _detectedException = ex;
            }

            return(geocodedAddress);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Get rect from extent envelope
        /// </summary>
        /// <param name="envelope">Extent envelope in map spatial reference</param>
        /// <param name="spatialReferenceID">Map spatial reference ID</param>
        /// <returns>Extent envelope in WGS84</returns>
        public static ESRI.ArcLogistics.Geometry.Envelope CreateRect(ESRI.ArcGIS.Client.Geometry.Envelope env,
                                                                     int?spatialReferenceID)
        {
            // Project extent to map spatial reference
            ESRI.ArcLogistics.Geometry.Point leftTop     = new ESRI.ArcLogistics.Geometry.Point(env.XMin, env.YMax);
            ESRI.ArcLogistics.Geometry.Point rightBottom = new ESRI.ArcLogistics.Geometry.Point(env.XMax, env.YMin);

            // Project point from Web Mercator to WGS84 if spatial reference of map is Web Mercator
            if (spatialReferenceID.HasValue)
            {
                leftTop     = WebMercatorUtil.ProjectPointFromWebMercator(leftTop, spatialReferenceID.Value);
                rightBottom = WebMercatorUtil.ProjectPointFromWebMercator(rightBottom, spatialReferenceID.Value);
            }

            ESRI.ArcLogistics.Geometry.Envelope rect = new ESRI.ArcLogistics.Geometry.Envelope(
                leftTop.X, leftTop.Y, rightBottom.X, rightBottom.Y);

            return(rect);
        }
Example #7
0
        /// <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 stop with selected radius around.
        /// </summary>
        /// <param name="stop">Stop to getting position.</param>
        /// <param name="extentRadiusInUnits">Extent radius [units].</param>
        /// <returns>Map extent for stop.</returns>
        private EnvelopeN _GetExtent(Stop stop, double extentRadiusInUnits)
        {
            Debug.Assert(null != stop);
            Debug.Assert(0 < extentRadiusInUnits);

            AppGeometry.Point point = stop.MapLocation.Value;
            double stopX = point.X;
            double stopY = point.Y;

            double extentRadius = DistCalc.GetExtentRadius(stopX, stopY, extentRadiusInUnits);

            // project extent to map spatial reference
            AppGeometry.Point leftTop =
                new AppGeometry.Point(stopX - extentRadius, stopY + extentRadius);
            AppGeometry.Point rightBottom =
                new AppGeometry.Point(stopX + extentRadius, stopY - extentRadius);

            int spatialRefId = _mapInfo.SpatialReference.WKID;
            leftTop =
                WebMercatorUtil.ProjectPointToWebMercator(leftTop, spatialRefId);
            rightBottom =
                WebMercatorUtil.ProjectPointToWebMercator(rightBottom, spatialRefId);

            // create extent in correct projection
            EnvelopeN extent = new EnvelopeN();
            extent.XMin = leftTop.X;
            extent.XMax = rightBottom.X;
            extent.YMin = rightBottom.Y;
            extent.YMax = leftTop.Y;

            return extent;
        }
        /// <summary>
        /// React on reverse geocoding complete.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _AddressByPointToolOnComplete(object sender, EventArgs e)
        {
            Debug.Assert(_mapCtrl != null);
            Debug.Assert(_addressByPointTool != null);

            ESRI.ArcLogistics.Geometry.Point point = new ESRI.ArcLogistics.Geometry.Point(
                _addressByPointTool.X.Value, _addressByPointTool.Y.Value);

            // Project point from Web Mercator to WGS84 if spatial reference of map is Web Mercator
            if (_mapCtrl.Map.SpatialReferenceID.HasValue)
            {
                point = WebMercatorUtil.ProjectPointFromWebMercator(point, _mapCtrl.Map.SpatialReferenceID.Value);
            }

            System.Windows.Point systemPoint = new System.Windows.Point(point.X, point.Y);

            if (_geocodableGrid.SelectedItems.Count == 1 || _currentItem != null)
            {
                if (IsGeocodingInProcess)
                {
                    _EndGeocoding(false);
                }

                _DoReverseGeocode(systemPoint);

                _mapCtrl.map.UpdateLayout();

                _isAddressChanged = false;
            }
            else
            {
                Debug.Assert(false);
            }

            _mapCtrl.HideZoomToCandidatePopup();
        }
        /// <summary>
        /// Create map point and project to webmercator if needed.
        /// </summary>
        /// <param name="point">Source point.</param>
        /// <returns>Map point in correct projection.</returns>
        private ArcGISGeometry.MapPoint _CreateProjectedMapPoint(ArcLogisticsGeometry.Point point)
        {
            ArcLogisticsGeometry.Point projectedPoint = new ArcLogisticsGeometry.Point(point.X, point.Y);

            if (ParentLayer != null && ParentLayer.SpatialReferenceID != null)
            {
                projectedPoint = WebMercatorUtil.ProjectPointToWebMercator(projectedPoint, ParentLayer.SpatialReferenceID.Value);
            }

            ArcGISGeometry.MapPoint mapPoint = new ArcGISGeometry.MapPoint(projectedPoint.X, projectedPoint.Y);
            return mapPoint;
        }
        /// <summary>
        /// Get extent near point.
        /// </summary>
        /// <param name="position">Dropping position.</param>
        /// <returns>Extent near point.</returns>
        private Envelope _GetExtentNearDroppedPoint(System.Windows.Point position)
        {
            Debug.Assert(_mapView != null);

            System.Windows.Point leftTopPoint = new System.Windows.Point(position.X - ROUTE_WIDTH, position.Y + ROUTE_WIDTH);
            System.Windows.Point rightBottomPoint = new System.Windows.Point(position.X + ROUTE_WIDTH, position.Y - ROUTE_WIDTH);
            ESRI.ArcGIS.Client.Geometry.MapPoint leftTopMapPoint = _mapView.mapCtrl.map.ScreenToMap(leftTopPoint);
            ESRI.ArcGIS.Client.Geometry.MapPoint rightBottomMapPoint = _mapView.mapCtrl.map.ScreenToMap(rightBottomPoint);

            ESRI.ArcLogistics.Geometry.Point leftTopPointOnMap = new ESRI.ArcLogistics.Geometry.Point(
                leftTopMapPoint.X, leftTopMapPoint.Y);
            ESRI.ArcLogistics.Geometry.Point rightBottomPointOnMap = new ESRI.ArcLogistics.Geometry.Point(
                rightBottomMapPoint.X, rightBottomMapPoint.Y);

            // Project point from Web Mercator to WGS84 if spatial reference of map is Web Mercator.
            if (_mapView.mapCtrl.Map.SpatialReferenceID.HasValue)
            {
                leftTopPointOnMap = WebMercatorUtil.ProjectPointFromWebMercator(leftTopPointOnMap,
                    _mapView.mapCtrl.Map.SpatialReferenceID.Value);
                rightBottomPointOnMap = WebMercatorUtil.ProjectPointFromWebMercator(rightBottomPointOnMap,
                    _mapView.mapCtrl.Map.SpatialReferenceID.Value);
            }

            Envelope extent = new Envelope(leftTopPointOnMap.X, leftTopPointOnMap.Y,
                rightBottomPointOnMap.X, rightBottomPointOnMap.Y);
            return extent;
        }
Example #12
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);
        }