コード例 #1
0
        public static async Task <MapPoint> CycloramaToMapPointAsync(double x, double y, double z)
        {
            MapView          mapView             = MapView.Active;
            Map              map                 = mapView?.Map;
            SpatialReference mapSpatialReference = map?.SpatialReference;
            SpatialReference gsSpatialReference  = await CycloramaSpatialReferenceAsync();

            MapPoint point = null;

            await QueuedTask.Run(() =>
            {
                MapPoint mapPoint = MapPointBuilder.CreateMapPoint(x, y, z, gsSpatialReference);

                if ((mapSpatialReference != null) && (gsSpatialReference != null) &&
                    (gsSpatialReference.Wkid != mapSpatialReference.Wkid))
                {
                    ProjectionTransformation projection = ProjectionTransformation.Create(gsSpatialReference, mapSpatialReference);
                    point = GeometryEngine.Instance.ProjectEx(mapPoint, projection) as MapPoint;
                }
                else
                {
                    point = (MapPoint)mapPoint.Clone();
                }
            });

            return(point);
        }
コード例 #2
0
        /// <summary>
        /// Convert Freehand Polyline to a Freehand Polygon
        /// </summary>
        /// <param name="freeline">Freehandly drawn polyline</param>
        /// <returns>A freehand polygon</returns>
        public static Polygon FreehandToPolygon(Polyline freeline)
        {
            if (freeline == null)
            {
                return(null);
            }

            Polygon polygonFromFreeline = null;

            //  Reference the PointCollection of the drawn Freehand Polyline
            ObservableCollection <PointCollection> pointsCollection = freeline.Paths;

            if (pointsCollection.Count > 0)
            {
                if (pointsCollection[0].Count > 0)
                {
                    // Get the first Point and "close" the shape and form a polygon.
                    MapPoint startingPt = pointsCollection[0][0];
                    pointsCollection[0].Add(startingPt.Clone());

                    polygonFromFreeline = new ESRI.ArcGIS.Client.Geometry.Polygon();
                    polygonFromFreeline.SpatialReference = freeline.SpatialReference;
                    polygonFromFreeline.Rings.Add(pointsCollection[0]);
                }
            }

            return(polygonFromFreeline);
        }
コード例 #3
0
        protected async Task InitializeAsync(RecordingLocation location, double angle, double hFov, Color color)
        {
            _angle         = angle;
            _hFov          = hFov;
            Color          = color;
            _isInitialized = true;

            double             x        = location.X;
            double             y        = location.Y;
            Settings           settings = Settings.Instance;
            MySpatialReference spatRel  = settings.CycloramaViewerCoordinateSystem;

            await QueuedTask.Run(() =>
            {
                Map map = MapView.Active?.Map;
                SpatialReference mapSpatialReference = map?.SpatialReference;
                SpatialReference spatialReference    = spatRel?.ArcGisSpatialReference ?? mapSpatialReference;
                MapPoint point = MapPointBuilder.CreateMapPoint(x, y, spatialReference);

                if ((mapSpatialReference != null) && (spatialReference.Wkid != mapSpatialReference.Wkid))
                {
                    ProjectionTransformation projection = ProjectionTransformation.Create(spatialReference, mapSpatialReference);
                    _mapPoint = GeometryEngine.Instance.ProjectEx(point, projection) as MapPoint;
                }
                else
                {
                    _mapPoint = (MapPoint)point.Clone();
                }
            });

            MapViewCameraChangedEvent.Subscribe(OnMapViewCameraChanged);
            await RedrawConeAsync();
        }
コード例 #4
0
            /// ----------------------------------------------------------------------------------------
            /// <summary>
            /// Get the possible node.
            /// </summary>
            /// <returns> A list of possible node. </returns>
            /// ----------------------------------------------------------------------------------------
            public List <Node> GetPossibleNode()
            {
                List <Node> nodes = new List <Node>();
                MapPoint    mapPt = new MapPoint();

                // Top
                mapPt.X = _currentPoint.X;
                mapPt.Y = _currentPoint.Y + 1;
                if (!_map.IsWall(mapPt))
                {
                    nodes.Add(new Node(this, mapPt.Clone()));
                }

                // Right
                mapPt.X = _currentPoint.X + 1;
                mapPt.Y = _currentPoint.Y;
                if (!_map.IsWall(mapPt))
                {
                    nodes.Add(new Node(this, mapPt.Clone()));
                }

                // Left
                mapPt.X = _currentPoint.X - 1;
                mapPt.Y = _currentPoint.Y;
                if (!_map.IsWall(mapPt))
                {
                    nodes.Add(new Node(this, mapPt.Clone()));
                }

                // Bottom
                mapPt.X = _currentPoint.X;
                mapPt.Y = _currentPoint.Y - 1;
                if (!_map.IsWall(mapPt))
                {
                    nodes.Add(new Node(this, mapPt.Clone()));
                }

                return(nodes);
            }
コード例 #5
0
        public async Task UpdateAsync(double x, double y, double size)
        {
            Settings           settings = Settings.Instance;
            MySpatialReference spatRel  = settings.CycloramaViewerCoordinateSystem;

            await QueuedTask.Run(() =>
            {
                MapView thisView = MapView.Active;
                Map map          = thisView?.Map;
                SpatialReference mapSpatialReference = map?.SpatialReference;
                SpatialReference spatialReference    = spatRel?.ArcGisSpatialReference ?? mapSpatialReference;
                MapPoint point = MapPointBuilder.CreateMapPoint(x, y, spatialReference);
                MapPoint mapPoint;

                if (mapSpatialReference != null && spatialReference.Wkid != mapSpatialReference.Wkid)
                {
                    ProjectionTransformation projection = ProjectionTransformation.Create(spatialReference, mapSpatialReference);
                    mapPoint = GeometryEngine.Instance.ProjectEx(point, projection) as MapPoint;
                }
                else
                {
                    mapPoint = (MapPoint)point.Clone();
                }

                if (mapPoint != null && !mapPoint.IsEmpty)
                {
                    CIMColor cimColor          = ColorFactory.Instance.CreateColor(Color.Black);
                    CIMMarker cimMarker        = SymbolFactory.Instance.ConstructMarker(cimColor, size, SimpleMarkerStyle.Cross);
                    CIMPointSymbol pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(cimMarker);
                    CIMSymbolReference pointSymbolReference = pointSymbol.MakeSymbolReference();
                    IDisposable disposeCross = thisView.AddOverlay(mapPoint, pointSymbolReference);

                    _disposeCross?.Dispose();
                    _disposeCross = disposeCross;
                }
            });
        }
コード例 #6
0
        /// <summary>
        /// Updates the measurements and message shown on the popup based on the in-progress
        /// geometry, including the passed-in point
        /// </summary>
        /// <param name="mapPoint"></param>
        private void updateMeasurements(MapPoint mapPoint)
        {
            if (_currentDrawVertices != null)
            {
                double length = 0d;
                double area   = 0d;

                string measurement1 = null;
                string measurement2 = null;

                switch (AssociatedObject.DrawMode)
                {
                case DrawMode.Freehand:
                    // Copy the set of vertices and add the passed-in point to it
                    PointCollection tmpPts = _currentDrawVertices.Clone();
                    tmpPts.Add(mapPoint.Clone());

                    // Check whether a polyline or polygon is being drawn
                    FreehandDrawMode freehandeMode = AttachedProperties.GetFreehandDrawMode(AssociatedObject);
                    if (freehandeMode == FreehandDrawMode.Polyline)
                    {
                        // Get the length of the line and update the measurement text
                        Polyline line = new Polyline()
                        {
                            SpatialReference = _currentDrawVertices[0].SpatialReference
                        };
                        line.Paths.Add(tmpPts);
                        length       = line.Length();
                        measurement1 = string.Format(Strings.LengthLabelFormat, getLengthString(length));
                    }
                    else if (freehandeMode == FreehandDrawMode.Polygon)
                    {
                        // Close the polygon by duplicating the first vertex and adding it to the end
                        tmpPts.Add(tmpPts[0].Clone());
                        Polygon polygon = new Polygon {
                            SpatialReference = _currentDrawVertices[0].SpatialReference
                        };
                        polygon.Rings.Add(tmpPts);

                        // Get the perimeter of the polygon and update the measurement text
                        length       = polygon.Perimeter();
                        measurement1 = string.Format(Strings.PerimeterLabelFormat, getLengthString(length));
                    }
                    break;

                case DrawMode.Polyline:
                    // Create a line containing the segement of the polyline currently being drawn.

                    // First, get the most recently drawn point
                    tmpPts = new PointCollection();
                    tmpPts.Add(_currentDrawVertices[_currentDrawVertices.Count - 1].Clone());

                    // Add the passed-in point
                    tmpPts.Add(mapPoint.Clone());

                    // Create a polyline with the points
                    Polyline polyline = new Polyline()
                    {
                        SpatialReference = _currentDrawVertices[0].SpatialReference
                    };
                    polyline.Paths.Add(tmpPts);

                    // Calculate the length and update the segment measurement text
                    length       = polyline.Length();
                    measurement1 = string.Format(Strings.SegmentLengthLabelFormat, getLengthString(length));

                    // If there already two or more points in the polyline, calculate total length as well
                    if (_currentDrawVertices.Count > 1)
                    {
                        // Copy the current set of vertices and add the passed-in point
                        tmpPts = _currentDrawVertices.Clone();
                        tmpPts.Add(mapPoint.Clone());

                        // Create a polyline with the points
                        polyline = new Polyline()
                        {
                            SpatialReference = _currentDrawVertices[0].SpatialReference
                        };
                        polyline.Paths.Add(tmpPts);

                        // Get the length
                        length = polyline.Length();
                    }

                    // Update measurement text showing the total length of the line
                    measurement2 = string.Format(Strings.TotalLengthLabelFormat, getLengthString(length));

                    break;

                case DrawMode.Rectangle:
                    // Create an envelope from the initial point and the passed-in piont
                    Envelope env = new Envelope(_currentDrawVertices[0], mapPoint)
                    {
                        SpatialReference = mapPoint.SpatialReference
                    };

                    // Get the perimeter and area of the envelope
                    length = env.Perimeter();
                    area   = env.Area();

                    // Update the measurement text
                    measurement1 = string.Format(Strings.PerimeterLabelFormat, getLengthString(length));
                    measurement2 = string.Format(Strings.AreaLabelFormat, getAreaString(area));
                    break;

                case DrawMode.Circle:
                case DrawMode.Ellipse:
                    // Get the initial (center) point and the current point
                    tmpPts = new PointCollection();
                    tmpPts.Add(_currentDrawVertices[0].Clone());
                    //tmpPts.Add(_currentDrawVertices[_currentDrawVertices.Count - 1].Clone());
                    tmpPts.Add(mapPoint.Clone());

                    // Create a line with the points
                    polyline = new Polyline()
                    {
                        SpatialReference = _currentDrawVertices[0].SpatialReference
                    };
                    polyline.Paths.Add(tmpPts);

                    // Calculate the length of the line.  This is the radius.
                    length = polyline.Length();

                    // For circles, this info is sufficient to calculate perimeter anda area
                    if (AssociatedObject.DrawMode == DrawMode.Circle)
                    {
                        // Calculate perimeter (circumference) and area
                        double circumference = 2 * length * Math.PI;
                        area = Math.PI * Math.Pow(length, 2);

                        // Display measures
                        measurement1 = string.Format(Strings.PerimeterLabelFormat, getLengthString(circumference));
                        measurement2 = string.Format(Strings.AreaLabelFormat, getAreaString(area));
                    }
                    else     // Ellipse
                    {
                        // insufficient info for perimeter & area, so just display radius
                        measurement1 = string.Format(Strings.RadiusLabelFormat, getLengthString(length));
                    }
                    break;

                case DrawMode.Polygon:
                    // Can only calculate perimeter and area if there are already two or more
                    // vertices in the polygon
                    if (_currentDrawVertices.Count > 1)
                    {
                        // Copy the existing vertices and add the passed-in point
                        tmpPts = _currentDrawVertices.Clone();
                        tmpPts.Add(mapPoint.Clone());

                        // Create a polygon from the points
                        Polygon p = new Polygon()
                        {
                            SpatialReference = mapPoint.SpatialReference
                        };
                        p.Rings.Add(tmpPts);

                        // Calculate the perimeter as well as the area
                        length = p.Perimeter();
                        area   = p.Area();

                        // Update measurement text
                        measurement1 = string.Format(Strings.PerimeterLabelFormat, getLengthString(length));
                        measurement2 = string.Format(Strings.AreaLabelFormat, getAreaString(area));
                    }
                    break;

                default:
                    break;
                }

                // Update the draw popup with the measurement text
                if (measurement1 != null)
                {
                    PopupText = _drawInstructions + "\n" + measurement1;
                }

                if (measurement2 != null)
                {
                    PopupText += "\n" + measurement2;
                }
            }
        }