예제 #1
0
        private void ParcelMap_MouseMove(object sender, MouseEventArgs e)
        {
            if (ParcelLineInfoWindow.IsOpen == true &&
                ParcelLineInfoWindow.Visibility == System.Windows.Visibility.Visible)
            {
                const double hideDistance = 25;
                double       width        = ParcelLineInfoWindow.ActualWidth;
                double       height       = ParcelLineInfoWindow.ActualHeight;

                var    anchorScreenPoint = ParcelMap.MapToScreen(ParcelLineInfoWindow.Anchor);
                double x1       = anchorScreenPoint.X - width / 2 - hideDistance;
                double y1       = anchorScreenPoint.Y - height - hideDistance - 10; // -ve for info indicator
                double x2       = anchorScreenPoint.X + width / 2 + hideDistance;
                double y2       = anchorScreenPoint.Y + hideDistance;
                var    envelope = new ESRI.ArcGIS.Client.Geometry.Envelope(x1, y1, x2, y2);

                Point pointLoc = e.GetPosition(this);
                if (!envelope.Intersects(new ESRI.ArcGIS.Client.Geometry.Envelope(pointLoc.X, pointLoc.Y, pointLoc.X, pointLoc.Y)))
                {
                    ParcelLineInfoWindow.IsOpen = false;
                    ParcelMap.Focus(); // Cause any non-committed cell in the popup window to lose its focus. This will commit the cell.
                }
            }

            if ((_srPoint == null) || !PDE_Tools.IsExpanded)
            {
                return;
            }

            ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;

            ESRI.ArcGIS.Client.Geometry.MapPoint currentPoint = ParcelMap.ScreenToMap(e.GetPosition(this));

            if (RotationButton.IsChecked == true)
            {
                double rotation = GeometryUtil.Angle(_srPoint, currentPoint, _originPoint) + _oldRotation;
                while (rotation < -Math.PI)
                {
                    rotation += Math.PI * 2;
                }
                while (rotation > Math.PI)
                {
                    rotation -= Math.PI * 2;
                }

                parcelData.RotationValue = rotation;
            }
            else if (ScaleButton.IsChecked == true)
            {
                parcelData.ScaleValue = GeometryUtil.Scale(_srPoint, currentPoint, _originPoint) * _oldScale;
            }

            // If we have a snap point, adjust scale/rotation if we can snap point.
            if (_srSnapPointId != -1)
            {
                bool isRotating = RotationButton.IsChecked.GetValueOrDefault(false);
                bool isScaling  = ScaleButton.IsChecked.GetValueOrDefault(false);

                double distanceToPoint = _srDistanceToPoint * parcelData.ScaleValue;
                double bearingToPoint  = _srBearingToPoint - parcelData.RotationValue;
                if (bearingToPoint >= 2 * Math.PI)
                {
                    bearingToPoint -= 2 * Math.PI;
                }

                ESRI.ArcGIS.Client.Geometry.MapPoint snapPointSR = GeometryUtil.ConstructPoint(_originPoint, bearingToPoint, distanceToPoint);
                if (snapPointSR != null)
                {
                    ESRI.ArcGIS.Client.Geometry.Polyline snapLine;
                    SnapPointToCacheObjects(snapPointSR, isScaling, out snapLine); // if scaling, skip zero distance so
                    if (snapLine != null)                                          // we don't snap to origin point.
                    {
                        bool ok = false;
                        ESRI.ArcGIS.Client.Geometry.MapPoint intersectPoint = null;
                        if (isRotating)
                        {
                            ok = GeometryUtil.ConstructPointLineCurveIntersection(snapLine, _originPoint, bearingToPoint, distanceToPoint, out intersectPoint); // distanceToPoint is radius here
                            if (ok)                                                                                                                             // Only snap if the mouse location is within snap solution
                            {
                                ok = GeometryUtil.LineLength(intersectPoint, currentPoint) <= _xmlConfiguation.SnapTolerance;
                            }
                            if (ok)
                            {
                                parcelData.RotationValue = GeometryUtil.Angle(_srSnapPoint, intersectPoint, _originPoint);
                            }
                        }
                        else if (isScaling)
                        {
                            ESRI.ArcGIS.Client.Geometry.MapPoint endPoint   = GeometryUtil.ConstructPoint(_originPoint, bearingToPoint, distanceToPoint + _xmlConfiguation.SnapTolerance);
                            ESRI.ArcGIS.Client.Geometry.Polyline sourceLine = GeometryUtil.Line(_originPoint, endPoint);
                            ok = GeometryUtil.ConstructPointLineLineIntersection(snapLine, sourceLine, out intersectPoint);
                            if (ok) // Only snap if the mouse location is within snap solution
                            {
                                ok = GeometryUtil.LineLength(intersectPoint, currentPoint) <= _xmlConfiguation.SnapTolerance;
                            }
                            if (ok)
                            {
                                double scale = GeometryUtil.Scale(_srSnapPoint, intersectPoint, _originPoint);
                                if (scale > 0.0)
                                {
                                    parcelData.ScaleValue = scale;
                                }
                            }
                        }

                        // Test code for debugging.
                        //
                        //GraphicsLayer testGraphicsLayer = ParcelMap.Layers["TestGraphicLayer"] as GraphicsLayer;
                        //testGraphicsLayer.ClearGraphics();
                        //if (intersectPoint != null)
                        //{
                        //  ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
                        //  {
                        //    Geometry = intersectPoint,
                        //    Symbol = LayoutRoot.Resources["TestMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
                        //  };
                        //  testGraphicsLayer.Graphics.Add(graphic);
                        //}
                    }
                }
            }

            // Only redraw if there have been an update;
            // Otherwise runtime does not process mouse up and over flashes.
            if ((parcelData.ScaleValue != _moveScale) || (parcelData.RotationValue != _moveRotation))
            {
                CalculateAndAddLineGraphics();
                _moveScale    = parcelData.ScaleValue;
                _moveRotation = parcelData.RotationValue;
            }
        }