예제 #1
0
        /// <summary>
        /// Convert from ArcLogistics polygon to ArcGIS polygon.
        /// </summary>
        /// <param name="sourcePolygon">ArcLogistics polygon</param>
        /// <param name="spatialReferenceID">Map spatial reference.</param>
        /// <returns>ArcGIS polygon.</returns>
        internal static ESRI.ArcGIS.Client.Geometry.Polygon ConvertToArcGISPolygon(Polygon sourcePolygon,
            int? spatialReferenceID)
        {
            ESRI.ArcGIS.Client.Geometry.Polygon resultPolygon = new ESRI.ArcGIS.Client.Geometry.Polygon();

            // Project polygon from WGS84 to Web Mercator if spatial reference of map is Web Mercator.
            if (spatialReferenceID != null)
            {
                sourcePolygon = WebMercatorUtil.ProjectPolygonToWebMercator(sourcePolygon, spatialReferenceID.Value);
            }

            int[] groups = sourcePolygon.Groups;
            for (int groupIndex = 0; groupIndex < groups.Length; ++groupIndex)
            {
                ESRI.ArcLogistics.Geometry.Point[] points = sourcePolygon.GetGroupPoints(groupIndex);

                ESRI.ArcGIS.Client.Geometry.PointCollection pointsCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                for (int index = 0; index < points.Length; index++)
                {
                    ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(points[index].X, points[index].Y);
                    pointsCollection.Add(mapPoint);
                }

                resultPolygon.Rings.Add(pointsCollection);
            }

            return resultPolygon;
        }
예제 #2
0
        /// <summary>
        /// Pan Geometry.
        /// </summary>
        /// <param name="geometry">Geometry to pan.</param>
        /// <param name="dx">Pan dx.</param>
        /// <param name="dy">Pan dy.</param>
        /// <returns>New geometry.</returns>
        private object _PanGeometry(object geometry, double dx, double dy)
        {
            Debug.Assert(geometry != null);

            Point[] points = null;

            if (geometry is Point)
            {
                Point? pt = geometry as Point?;
                points = new Point[] { pt.Value };
            }
            else if (geometry is PolyCurve)
            {
                PolyCurve polyCurve = geometry as PolyCurve;
                points = polyCurve.GetPoints(0, polyCurve.TotalPointCount);
            }
            else
                throw new NotSupportedException();

            if (points.Length == 1 || !(_editedGraphic is EditMarkerGraphicObject))
            {
                for (int index = 0; index < points.Length; index++)
                {
                    double newX = points[index].X + dx;
                    double newY = points[index].Y + dy;
                    Point point = new Point(newX, newY);
                    points[index] = point;
                }
            }
            else
            {
                _PanByEditMarker(points, dx, dy, geometry as PolyCurve);
            }

            // Create new geometry.
            object newGeometry = null;

            if (geometry is Point)
            {
                newGeometry = points[0];
            }
            else if (geometry is Polygon)
            {
                newGeometry = new Polygon((geometry as Polygon).Groups, points);
            }
            else if (geometry is Polyline)
            {
                newGeometry = new Polyline((geometry as Polyline).Groups, points);
            }
            else
                throw new NotSupportedException();

            return newGeometry;
        }
예제 #3
0
        /// <summary>
        /// React on polygon tool complete.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _PolygonToolOnComplete(object sender, EventArgs e)
        {
            if (_dataGridControl.SelectedItems.Count == 1 || _currentItem != null)
            {
                Debug.Assert(_polygonTool.Geometry.Rings.Count == 1);
                ESRI.ArcGIS.Client.Geometry.PointCollection pointsCollection = _polygonTool.Geometry.Rings[0];

                ESRI.ArcLogistics.Geometry.Point[] points = new Point[pointsCollection.Count];

                for (int index = 0; index < pointsCollection.Count; index++)
                {
                    ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = pointsCollection[index];
                    Point point = new Point(mapPoint.X, mapPoint.Y);

                    // 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);
                    }

                    points[index] = point;
                }

                if (_isInEditedMode)
                    _mapCtrl.ClearEditMarkers();

                ESRI.ArcLogistics.Geometry.Polygon polygon = new Polygon(points);

                if (_type == typeof(Zone))
                {
                    Zone zone = (Zone)_currentItem;
                    zone.Geometry = polygon;
                }
                else
                {
                    Barrier barrier = (Barrier)_currentItem;
                    barrier.Geometry = polygon;

                    _ShowBarrierEditor(barrier, polygon.GetPoint(polygon.TotalPointCount - 1));
                }

                App.Current.Project.Save();

                if (_isInEditedMode)
                    _mapCtrl.FillEditMarkers(_currentItem);

                _mapCtrl.map.UpdateLayout();
            }
        }