private void DrawEllipse()
        {
            try
            {
                var param = new GeometryEngine.GeodesicEllipseParameter();

                param.Center          = new Coordinate(Point1);
                param.AxisDirection   = GetRadiansFrom360Degrees(GetAzimuthAsDegrees());
                param.LinearUnit      = GetLinearUnit(LineDistanceType);
                param.OutGeometryType = GeometryType.Polygon;
                param.SemiAxis1Length = MajorAxisDistance;
                param.SemiAxis2Length = MinorAxisDistance;
                param.VertexCount     = VertexCount;

                var geom = GeometryEngine.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

                AddGraphicToMap(geom, new CIMRGBColor()
                {
                    R = 255, B = 0, G = 0, Alpha = 25
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// Method used to draw the rings at the desired interval
        /// Rings are constructed as geodetic circles
        /// </summary>
        private void DrawRings()
        {
            double radius = 0.0;

            try
            {
                for (int x = 0; x < numberOfRings; x++)
                {
                    // set the current radius
                    radius += Distance;

                    var param = new GeometryEngine.GeodesicEllipseParameter();

                    param.Center          = new Coordinate(Point1);
                    param.AxisDirection   = 0.0;
                    param.LinearUnit      = GetLinearUnit(LineDistanceType);
                    param.OutGeometryType = GeometryType.Polyline;
                    param.SemiAxis1Length = radius;
                    param.SemiAxis2Length = radius;
                    param.VertexCount     = VertexCount;

                    var geom = GeometryEngine.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

                    AddGraphicToMap(geom);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 3
0
        private async Task DrawEllipse()
        {
            try
            {
                while (MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry.Extent != null)
                {
                    // Accept user point
                    MapPoint userpoint = await MyMapView.Editor.RequestPointAsync() as MapPoint;

                    MapPoint point = GeometryEngine.NormalizeCentralMeridian(userpoint) as MapPoint;

                    // create the geodesic ellipse
                    var radius1   = (double)comboRadius1.SelectedItem;
                    var radius2   = (double)comboRadius2.SelectedItem;
                    var axis      = sliderAxis.Value;
                    var maxLength = (double)comboSegmentLength.SelectedItem;
                    var param     = new GeodesicEllipseParameters(point, radius1, radius2, LinearUnits.Miles)
                    {
                        AxisDirection    = axis,
                        MaxPointCount    = 10000,
                        MaxSegmentLength = maxLength
                    };
                    var ellipse = GeometryEngine.GeodesicEllipse(param);

                    //show geometries on map
                    _graphicsOverlay.Graphics.Clear();
                    _graphicsOverlay.Graphics.Add(new Graphic(point, _pinSymbol));
                    _graphicsOverlay.Graphics.Add(new Graphic(ellipse));

                    // geodesic sector
                    if ((bool)chkSector.IsChecked)
                    {
                        var sectorParams = new GeodesicSectorParameters(point, radius1, radius2, LinearUnits.Miles)
                        {
                            AxisDirection    = axis,
                            MaxPointCount    = 10000,
                            MaxSegmentLength = maxLength,
                            SectorAngle      = sliderSectorAxis.Value,
                            StartDirection   = sliderSectorStart.Value
                        };
                        var sector = GeometryEngine.GeodesicSector(sectorParams);

                        _graphicsOverlay.Graphics.Add(new Graphic(sector, _sectorSymbol));
                    }
                }
            }
            catch (TaskCanceledException) { }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Error").ShowAsync();
            }
        }
Exemplo n.º 4
0
        private async void EllipseButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                while (mapView.Extent != null)
                {
                    // Accept user point
                    var point = await mapView.Editor.RequestPointAsync();

                    // create the geodesic ellipse
                    var radius1   = (double)comboRadius1.SelectedItem;
                    var radius2   = (double)comboRadius2.SelectedItem;
                    var axis      = sliderAxis.Value;
                    var maxLength = (double)comboSegmentLength.SelectedItem;
                    var param     = new GeodesicEllipseParameters(point, radius1, radius2, LinearUnits.Miles)
                    {
                        AxisDirection    = axis,
                        MaxPointCount    = 10000,
                        MaxSegmentLength = maxLength
                    };
                    var ellipse = GeometryEngine.GeodesicEllipse(param);

                    //show geometries on map
                    _graphicsLayer.Graphics.Clear();
                    _graphicsLayer.Graphics.Add(new Graphic(point, _pinSymbol));
                    _graphicsLayer.Graphics.Add(new Graphic(ellipse));

                    // geodesic sector
                    if ((bool)chkSector.IsChecked)
                    {
                        var sectorParams = new GeodesicSectorParameters(point, radius1, radius2, LinearUnits.Miles)
                        {
                            AxisDirection    = axis,
                            MaxPointCount    = 10000,
                            MaxSegmentLength = maxLength,
                            SectorAngle      = sliderSectorAxis.Value,
                            StartDirection   = sliderSectorStart.Value
                        };
                        var sector = GeometryEngine.GeodesicSector(sectorParams);

                        _graphicsLayer.Graphics.Add(new Graphic(sector, _sectorSymbol));
                    }
                }
            }
            catch (TaskCanceledException)
            {
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
        private void ConstructGeoCircle()
        {
            var param = new GeometryEngine.GeodesicEllipseParameter();

            param.Center          = new Coordinate(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polyline;
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount     = VertexCount;

            maxDistance = Math.Max(maxDistance, Distance);

            var geom = GeometryEngine.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            AddGraphicToMap(geom);
        }
        private void UpdateFeedbackWithEllipse(bool HasMinorAxis = true)
        {
            if (!HasPoint1)
            {
                return;
            }

            var minorAxis = MinorAxisDistance;

            if (!HasMinorAxis || minorAxis == 0.0)
            {
                minorAxis = MajorAxisDistance;
            }

            if (minorAxis > MajorAxisDistance)
            {
                minorAxis = MajorAxisDistance;
            }
            try
            {
                var param = new GeometryEngine.GeodesicEllipseParameter();

                param.Center          = new Coordinate(Point1);
                param.AxisDirection   = GetRadiansFrom360Degrees(GetAzimuthAsDegrees());
                param.LinearUnit      = GetLinearUnit(LineDistanceType);
                param.OutGeometryType = GeometryType.Polyline;
                param.SemiAxis1Length = MajorAxisDistance;
                param.SemiAxis2Length = minorAxis;
                param.VertexCount     = VertexCount;

                var geom = GeometryEngine.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

                ClearTempGraphics();
                AddGraphicToMap(Point1, ColorFactory.Green, true, 5.0);
                AddGraphicToMap(geom, ColorFactory.Grey, true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        /// <summary>
        /// Create geodetic circle
        /// </summary>
        private Geometry CreateCircle(bool isFeedback)
        {
            if (Point1 == null || double.IsNaN(Distance) || Distance <= 0.0)
            {
                return(null);
            }

            var param = new GeometryEngine.GeodesicEllipseParameter();

            param.Center          = new Coordinate(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polygon;
            if (isFeedback)
            {
                param.OutGeometryType = GeometryType.Polyline;
            }
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount     = VertexCount;

            var geom = GeometryEngine.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            CIMColor color = new CIMRGBColor()
            {
                R = 255, B = 0, G = 0, Alpha = 25
            };

            if (isFeedback)
            {
                color = ColorFactory.GreyRGB;
                ClearTempGraphics();
                AddGraphicToMap(Point1, ColorFactory.GreenRGB, true, 5.0);
            }
            AddGraphicToMap(geom, color, IsTempGraphic: isFeedback);

            return(geom as Geometry);
        }
        private void UpdateFeedbackWithGeoCircle()
        {
            if (Point1 == null || double.IsNaN(Distance) || Distance <= 0.0)
            {
                return;
            }

            var param = new GeometryEngine.GeodesicEllipseParameter();

            param.Center          = new Coordinate(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polyline;
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount     = VertexCount;

            var geom = GeometryEngine.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            ClearTempGraphics();
            AddGraphicToMap(Point1, ColorFactory.GreenRGB, true, 5.0);
            AddGraphicToMap(geom, ColorFactory.GreyRGB, true);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Create keyframes centered around a point.
        /// </summary>
        /// <param name="point">The center point around which the keyframes are created.</param>
        internal Task CreateKeyframesAroundPoint(MapPoint point)
        {
            return(QueuedTask.Run(() =>
            {
                var mapView = MapView.Active;
                var degrees = Animation.Settings.Degrees;
                if (mapView == null || degrees == 0)
                {
                    return;
                }

                //Get the camera track from the active map's animation.
                //There will always be only one camera track in the animation.
                var cameraTrack = mapView.Map.Animation.Tracks.OfType <CameraTrack>().First();
                var camera = mapView.Camera;

                //Calculate the number of keys to create.
                var keyEvery = (degrees < 0) ? -10 : 10; //10 degrees
                var numOfKeys = Math.Floor(degrees / keyEvery);
                var remainder = degrees % keyEvery;

                //To maintain a constant speed we need to divide the total time we want the animation to take by the number of degrees of rotation.
                var duration = Animation.Settings.Duration;
                double timeInterval = duration / Math.Abs(degrees);
                double currentTimeSeconds = GetInsertTime(mapView.Map.Animation);

                //Get the distance from the current location to the point we want to rotate around to get the radius.
                var cameraPoint = MapPointBuilder.CreateMapPoint(camera.X, camera.Y, camera.SpatialReference);
                var radius = GeometryEngine.GeodesicDistance(cameraPoint, point);
                var radian = ((camera.Heading - 90) / 180.0) * Math.PI;

                //If the spatial reference of the point is projected and the unit is not in meters we need to convert the Z values to meters.
                if (!point.SpatialReference.IsGeographic && point.SpatialReference.Unit.ConversionFactor != 1.0)
                {
                    point = MapPointBuilder.CreateMapPoint(point.X, point.Y,
                                                           point.Z * point.SpatialReference.Unit.ConversionFactor, point.SpatialReference);
                }

                //For all geodesic calculations we will use WGS84 so we will project the point if it is not already.
                if (point.SpatialReference.Wkid != SpatialReferences.WGS84.Wkid)
                {
                    var transformation = ProjectionTransformation.Create(point.SpatialReference, SpatialReferences.WGS84);
                    point = GeometryEngine.ProjectEx(point, transformation) as MapPoint;
                }

                //Create an ellipse around the center point.
                var parameter = new GeometryEngine.GeodesicEllipseParameter();
                parameter.Center = point.Coordinate;
                parameter.SemiAxis1Length = radius;
                parameter.SemiAxis2Length = radius;
                parameter.AxisDirection = radian;
                parameter.LinearUnit = LinearUnit.Meters;
                parameter.OutGeometryType = GeometryType.Polyline;
                parameter.VertexCount = 36;
                var ellipse = GeometryEngine.GeodesicEllipse(parameter, point.SpatialReference) as Polyline;

                //For each key we will progressively rotate around the ellipse and calculate the camera position at each.
                for (int i = 0; i <= numOfKeys; i++)
                {
                    var percentAlong = ((Math.Abs(keyEvery) * i) % 360) / 360.0;
                    if (keyEvery > 0)
                    {
                        percentAlong = 1 - percentAlong;
                    }

                    //Get the camera at the position around the ellipse.
                    camera = OffsetCamera(camera, ellipse, point, percentAlong);

                    //Increment the time by the amount of time per key.
                    if (i != 0)
                    {
                        currentTimeSeconds += (timeInterval * Math.Abs(keyEvery));
                    }

                    //Create a new keyframe for the camera.
                    cameraTrack.CreateKeyframe(camera, TimeSpan.FromSeconds(currentTimeSeconds), AnimationTransition.FixedArc);
                }

                //For any degree rotation left over create a keyframe. For example 155, would have a keyframe every 10 degrees and then one for the final 5 degrees.
                if (remainder != 0.0)
                {
                    var percentAlong = ((Math.Abs(keyEvery) * numOfKeys + Math.Abs(remainder)) % 360) / 360.0;
                    if (remainder > 0)
                    {
                        percentAlong = 1 - percentAlong;
                    }

                    OffsetCamera(camera, ellipse, point, percentAlong);

                    //Increment the time and create the keyframe.
                    currentTimeSeconds += (timeInterval * Math.Abs(remainder));
                    cameraTrack.CreateKeyframe(camera, TimeSpan.FromSeconds(currentTimeSeconds), AnimationTransition.FixedArc);
                }
            }));
        }