Example #1
0
        private void map_MouseMove(object sender, MouseEventArgs e)
        {
            Map.Cursor = Cursors.Hand;
            if (originPoint != null && _isMeasuring)
            {
                _graphicCount = GraphicsLayer.Graphics.Count;
                int      g        = _graphicCount - 1;
                MapPoint p        = Map.ScreenToMap(e.GetPosition(Map));
                MapPoint midpoint = new MapPoint((p.X + originPoint.X) / 2, (p.Y + originPoint.Y) / 2);
                ESRI.ArcGIS.Client.Geometry.PointCollection polypoints = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                ESRI.ArcGIS.Client.Geometry.Polygon         poly       = new ESRI.ArcGIS.Client.Geometry.Polygon();
                if (Type == MeasureType.Area && _points.Count > 2)
                {
                    Graphic graphic = GraphicsLayer.Graphics[0];
                    poly       = graphic.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon;
                    polypoints = poly.Rings[0];
                    int lastPt = polypoints.Count - 1;
                    polypoints[lastPt] = p;
                }
                GraphicsLayer.Graphics[g - 2].Geometry = midpoint;
                (GraphicsLayer.Graphics[g - 1].Geometry as ESRI.ArcGIS.Client.Geometry.Polyline).Paths[0][1] = p;
                GraphicsLayer.Graphics[g].Geometry = midpoint;
                double angle = Math.Atan2((p.X - originPoint.X), (p.Y - originPoint.Y)) / Math.PI * 180 - 90;
                if (angle > 90 || angle < -90)
                {
                    angle -= 180;
                }
                RotatingTextSymbol symb = GraphicsLayer.Graphics[g].Symbol as RotatingTextSymbol;
                symb.Angle = angle;

                double dist      = Geodesic.GetSphericalDistance(originPoint, p);
                double distRound = RoundToSignificantDigit(dist);
                symb.Text = Convert.ToString(RoundToSignificantDigit(ConvertDistance(dist, DistanceUnits)));
                GraphicsLayer.Graphics[g].Symbol = symb;
                _segmentLength   = distRound;
                _tempTotalLength = totalLength + distRound;
                RotatingTextSymbol totSym;
                if (Type == MeasureType.Distance)
                {
                    totSym      = GraphicsLayer.Graphics[0].Symbol as RotatingTextSymbol;
                    totSym.Text = string.Format("Length Total:\n{0} {1}", RoundToSignificantDigit(ConvertDistance(_tempTotalLength, DistanceUnits)), DistanceUnits.ToString());
                    GraphicsLayer.Graphics[0].Symbol = totSym;
                }
                else
                {
                    totSym = GraphicsLayer.Graphics[1].Symbol as RotatingTextSymbol;
                    if (polypoints != null && polypoints.Count > 2)
                    {
                        double lastLen = Geodesic.GetSphericalDistance(polypoints[0], polypoints[polypoints.Count - 1]);
                        poly = GraphicsLayer.Graphics[0].Geometry as ESRI.ArcGIS.Client.Geometry.Polygon;
                        MapPoint anchor = poly.Extent.GetCenter();
                        ESRI.ArcGIS.Client.Geometry.PointCollection temppoints = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                        foreach (MapPoint point in poly.Rings[0])
                        {
                            temppoints.Add(point);
                        }
                        temppoints.Add(poly.Rings[0][0]);
                        ESRI.ArcGIS.Client.Geometry.PointCollection pts = ToKmMapPoint(temppoints);
                        double area = GetArea(pts);
                        //double area = GetArea(ToKMMapPoint(polypoints));
                        totSym.Text = string.Format("Area:\n{0} {1}", RoundToSignificantDigit(area), AreaUnits.ToString());
                        GraphicsLayer.Graphics[1].Geometry = anchor;
                        GraphicsLayer.Graphics[1].Symbol   = totSym;
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// AngleProperty property changed handler.
        /// </summary>
        /// <param name="d">ownerclass that changed its Angle.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs.</param>
        private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RotatingTextSymbol dp = d as RotatingTextSymbol;

            dp.OnPropertyChanged("Text");
        }