Inheritance: INotifyPropertyChanged
Ejemplo n.º 1
0
        static string _doubleFormat = "F6"; // XML precision

        #endregion Fields

        #region Methods

        public static bool WriteCEXML(ref ParcelData parcelData, string xmlFileName, ref Configuration configuration, ESRI.ArcGIS.Client.Geometry.SpatialReference spatialReference, ref PointDictionary pointDictionary, ref MapPoint projectedStartPoint, double scale, double rotation)
        {
            DocumentEntry documentType = parcelData.DocumentEntries.CurrentItem as DocumentEntry; ;

              XmlWriterSettings settings = new XmlWriterSettings();
              settings.Indent = true;
              settings.IndentChars = "  ";
              settings.NewLineChars = "\r\n";
              settings.NewLineHandling = NewLineHandling.Replace;

              XmlWriter writer = XmlWriter.Create(xmlFileName, settings);
              if (writer == null)
            return false;

              writer.WriteStartDocument();
              writer.WriteStartElement("geodata", "GeoSurveyPacketData", @"http://www.geodata.com.au/schemas/GeoSurvey/ESRI/1.0/");
              writer.WriteElementString("schemaVersion", "2.0");

              WriteUnits(ref writer, ref spatialReference, ref configuration);
              WriteJobParameters(ref writer, ref configuration);
              WritePlans(ref writer, ref parcelData, ref pointDictionary, ref projectedStartPoint, scale, rotation, ref configuration, ref documentType);
              WritePoints(ref writer);
              WriteControl(ref writer);

              writer.WriteEndElement();
              writer.WriteEndDocument();
              writer.Dispose();             // force write of item.

              return true;
        }
Ejemplo n.º 2
0
        private static void WriteLines(ref XmlWriter writer, ref ParcelData parcelData, ref DocumentEntry documentType, ref Configuration configuration)
        {
            writer.WriteStartElement("lines");

            // Write non radial lines
            ObservableCollection <ParcelLineRow> parcelRecord = parcelData.GetRecordInfo();
            Int32 firstId = -1, index = 0, count = 0;

            foreach (ParcelLineRow record in parcelRecord)
            {
                if (!IncompleteLine(record))
                {
                    count++;
                }
            }

            foreach (ParcelLineRow record in parcelRecord)
            {
                if (IncompleteLine(record))
                {
                    continue;
                }

                index++;
                if ((firstId == -1) && (record.Category == LineCategory.Boundary))
                {
                    firstId = record.GetFrom();
                }
                Int32 overrideTo = count == index && count != 1 ? firstId : -1;

                if (record.Category != LineCategory.Radial)
                {
                    WriteLine(ref writer, record, ref documentType, overrideTo);
                }
            }

            // Write radial lines
            foreach (ParcelLineRow record in parcelRecord)
            {
                if (record.CenterPoint == null)
                {
                    continue;
                }

                ParcelLineRow radialRecord = new ParcelLineRow(ref configuration);

                radialRecord.From     = record.From;
                radialRecord.To       = record.CenterPoint.ToString();
                radialRecord.Bearing  = GeometryUtil.RadianToDegree(record.RadialBearing1.GetValueOrDefault(0)).ToString();
                radialRecord.Distance = record.Radius;
                radialRecord.Category = LineCategory.Radial;
                WriteLine(ref writer, radialRecord, ref documentType, -1);

                radialRecord.From    = record.To;
                radialRecord.Bearing = GeometryUtil.RadianToDegree(record.RadialBearing2.GetValueOrDefault(0)).ToString();
                WriteLine(ref writer, radialRecord, ref documentType, -1);
            }

            writer.WriteEndElement(); // lines
        }
Ejemplo n.º 3
0
        private void ResetRotationScale()
        {
            ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;

            parcelData.RotationValue = 0.0;
            parcelData.ScaleValue    = 1.0;
        }
Ejemplo n.º 4
0
        static string _doubleFormat = "F6"; // XML precision

        static public bool WriteCEXML(ref ParcelData parcelData, string xmlFileName, ref Configuration configuration, ESRI.ArcGIS.Client.Geometry.SpatialReference spatialReference, ref PointDictionary pointDictionary, ref MapPoint projectedStartPoint, double scale, double rotation)
        {
            DocumentEntry documentType = parcelData.DocumentEntries.CurrentItem as DocumentEntry;;

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent          = true;
            settings.IndentChars     = "  ";
            settings.NewLineChars    = "\r\n";
            settings.NewLineHandling = NewLineHandling.Replace;

            XmlWriter writer = XmlWriter.Create(xmlFileName, settings);

            if (writer == null)
            {
                return(false);
            }

            writer.WriteStartDocument();
            writer.WriteStartElement("geodata", "GeoSurveyPacketData", @"http://www.geodata.com.au/schemas/GeoSurvey/ESRI/1.0/");
            writer.WriteElementString("schemaVersion", "2.0");

            WriteUnits(ref writer, ref spatialReference, ref configuration);
            WriteJobParameters(ref writer, ref configuration);
            WritePlans(ref writer, ref parcelData, ref pointDictionary, ref projectedStartPoint, scale, rotation, ref configuration, ref documentType);
            WritePoints(ref writer);
            WriteControl(ref writer);

            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Dispose();       // force write of item.

            return(true);
        }
Ejemplo n.º 5
0
        private void CancelScaleRotate()
        {
            bool redraw = _srPoint != null;

            ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;

            _srPoint       = null; // Stop mouse move from working;
            _oldRotation   = parcelData.ScaleValue;
            _srSnapPointId = -1;

            if (redraw)
            {
                CalculateAndAddLineGraphics(); // Redraw so we don't have snap graphic shown
            }
        }
Ejemplo n.º 6
0
        // This routine does not write out points, but it does write the start location

        private static void WriteConstructionData(ref XmlWriter writer, ref ParcelData parcelData, ref PointDictionary pointDictionary, ref MapPoint projectedStartPoint, ref Configuration configuration, ParcelLineRow record)
        {
            Int32 pointId = record.GetFrom();

            if (!pointDictionary.ContainsKey(pointId))
            {
                return;
            }

            // Rather than using the point from the dictionary, the client should pass in a projected point.
            // ESRI.ArcGIS.Client.Geometry.MapPoint startPoint = pointDictionary[pointId];

            ESRI.ArcGIS.Client.Geometry.MapPoint startPoint = projectedStartPoint;
            if (startPoint == null)
            {
                return;
            }

            writer.WriteStartElement("constructionData");
            writer.WriteStartElement("constructionAdjustment");
            writer.WriteStartElement("startPoint");

            double xM = startPoint.X;
            double yM = startPoint.Y;

            if (configuration.HasSpatialReferenceUnit)
            {
                xM *= configuration.SpatialReferenceUnitsPerMeter;
                yM *= configuration.SpatialReferenceUnitsPerMeter;
            }

            writer.WriteElementString("unjoinedPointNo", pointId.ToString());
            writer.WriteElementString("x", xM.ToString(_doubleFormat));
            writer.WriteElementString("y", yM.ToString(_doubleFormat));

            writer.WriteEndElement(); // startPoint

            if (parcelData.CompassRuleApplied)
            {
                writer.WriteElementString("type", "0"); // compass rule = 0
            }
            writer.WriteEndElement();                   // constructionAdjustment
            writer.WriteEndElement();                   // constructionData
        }
Ejemplo n.º 7
0
        private static void WritePlans(ref XmlWriter writer, ref ParcelData parcelData, ref PointDictionary pointDictionary, ref MapPoint projectedStartPoint, double scale, double rotation, ref Configuration configuration, ref DocumentEntry documentType)
        {
            ObservableCollection <ParcelLineRow> parcelRecord = parcelData.GetRecordInfo();

            writer.WriteStartElement("plans");
            writer.WriteStartElement("plan");
            writer.WriteElementString("name", parcelData.PlanName);
            writer.WriteElementString("description", documentType.Name);
            writer.WriteElementString("angleUnits", XMLDirectionUnit(parcelData.Configuration.EntryFormat));
            writer.WriteElementString("distanceUnits", GeometryUtil.PacketUnitString(configuration.EntryUnitsPerMeter));
            writer.WriteElementString("directionFormat", XMLDirectionType(parcelData.Configuration.EntryFormat));
            writer.WriteElementString("areaUnits", XMLAreaUnit(parcelData.Configuration.AreaUnit));
            writer.WriteElementString("lineParameters", "ChordBearingAndChordLengthAndRadius");

            WriteParcel(ref writer, ref parcelData, ref pointDictionary, ref projectedStartPoint, scale, rotation, ref configuration, ref documentType);

            writer.WriteEndElement();
            writer.WriteEndElement();
        }
Ejemplo n.º 8
0
        // This routine does not write out points, but it does write the start location
        private static void WriteConstructionData(ref XmlWriter writer, ref ParcelData parcelData, ref PointDictionary pointDictionary, ref MapPoint projectedStartPoint, ref Configuration configuration, ParcelLineRow record)
        {
            Int32 pointId = record.GetFrom();
              if (!pointDictionary.ContainsKey(pointId))
            return;

              // Rather than using the point from the dictionary, the client should pass in a projected point.
              // ESRI.ArcGIS.Client.Geometry.MapPoint startPoint = pointDictionary[pointId];

              ESRI.ArcGIS.Client.Geometry.MapPoint startPoint = projectedStartPoint;
              if (startPoint == null)
            return;

              writer.WriteStartElement("constructionData");
              writer.WriteStartElement("constructionAdjustment");
              writer.WriteStartElement("startPoint");

              double xM = startPoint.X;
              double yM = startPoint.Y;
              if (configuration.HasSpatialReferenceUnit)
              {
            xM *= configuration.SpatialReferenceUnitsPerMeter;
            yM *= configuration.SpatialReferenceUnitsPerMeter;
              }

               writer.WriteElementString("unjoinedPointNo", pointId.ToString());
              writer.WriteElementString("x", xM.ToString(_doubleFormat));
              writer.WriteElementString("y", yM.ToString(_doubleFormat));

              writer.WriteEndElement(); // startPoint

              if (parcelData.CompassRuleApplied)
            writer.WriteElementString("type", "0");  // compass rule = 0

              writer.WriteEndElement(); // constructionAdjustment
              writer.WriteEndElement(); // constructionData
        }
Ejemplo n.º 9
0
        private static void WritePlans(ref XmlWriter writer, ref ParcelData parcelData, ref PointDictionary pointDictionary, ref MapPoint projectedStartPoint, double scale, double rotation, ref Configuration configuration, ref DocumentEntry documentType)
        {
            ObservableCollection<ParcelLineRow> parcelRecord = parcelData.GetRecordInfo();

              writer.WriteStartElement("plans");
              writer.WriteStartElement("plan");
              writer.WriteElementString("name", parcelData.PlanName);
              writer.WriteElementString("description", documentType.Name);
              writer.WriteElementString("angleUnits", XMLDirectionUnit(parcelData.Configuration.EntryFormat));
              writer.WriteElementString("distanceUnits", GeometryUtil.PacketUnitString(configuration.EntryUnitsPerMeter));
              writer.WriteElementString("directionFormat", XMLDirectionType(parcelData.Configuration.EntryFormat));
              writer.WriteElementString("areaUnits", XMLAreaUnit(parcelData.Configuration.AreaUnit));
              writer.WriteElementString("lineParameters", "ChordBearingAndChordLengthAndRadius");

              WriteParcel(ref writer, ref parcelData, ref pointDictionary, ref projectedStartPoint, scale, rotation, ref configuration, ref documentType);

              writer.WriteEndElement();
              writer.WriteEndElement();
        }
Ejemplo n.º 10
0
        private static void WriteParcel(ref XmlWriter writer, ref ParcelData parcelData, ref PointDictionary pointDictionary, ref MapPoint projectedStartPoint, double scale, double rotation, ref Configuration configuration, ref DocumentEntry documentType)
        {
            ObservableCollection<ParcelLineRow> parcelRecord = parcelData.GetRecordInfo();
              if (parcelRecord.Count == 0)
            return;

              if (rotation < 0)
            rotation += 360;

              writer.WriteStartElement("parcels");
              writer.WriteStartElement("parcel");
              writer.WriteElementString("name", parcelData.ParcelName);
              if (scale != 1.0)
            writer.WriteElementString("scale", scale.ToString(_doubleFormat));
              if (rotation != 0.0)
            writer.WriteElementString("rotation", rotation.ToString(_doubleFormat));

              string statedArea = "statedArea";
              if (parcelData.StatedArea != "")
            writer.WriteElementString(statedArea, parcelData.StatedArea);
              else if (parcelData.MiscloseArea > 0)
            writer.WriteElementString(statedArea, parcelData.MiscloseArea.ToString("F2"));
              writer.WriteElementString("joined", "false");
              writer.WriteElementString("parcelNo", "1");
              writer.WriteElementString("type", documentType.Type.ToString());
              if ((parcelData.MiscloseDistance != 0.0) && (parcelData.MiscloseBearing != 0.0))
              {
            writer.WriteElementString("miscloseDistance", parcelData.MiscloseDistance.ToString(_doubleFormat));
            writer.WriteElementString("miscloseBearing", parcelData.MiscloseBearing.ToString(_doubleFormat));
              }

              // Write document type EA object
              if (documentType.HasEA)
              {
            writer.WriteStartElement("extendedAttributes");
            writer.WriteStartElement("extendedAttribute");
            writer.WriteElementString("name", documentType.EAField);
            writer.WriteElementString("value", documentType.EAValue);
            writer.WriteElementString("type", "VT_BSTR");
            writer.WriteEndElement();
            writer.WriteEndElement();
              }

              WriteConstructionData(ref writer, ref parcelData, ref pointDictionary, ref projectedStartPoint, ref configuration, parcelRecord[0]);

              WriteLines(ref writer, ref parcelData, ref documentType, ref configuration);

              writer.WriteEndElement(); // parcel
              writer.WriteEndElement(); // parcels
        }
Ejemplo n.º 11
0
        private static void WriteLines(ref XmlWriter writer, ref ParcelData parcelData, ref DocumentEntry documentType, ref Configuration configuration)
        {
            writer.WriteStartElement("lines");

              // Write non radial lines
              ObservableCollection<ParcelLineRow> parcelRecord = parcelData.GetRecordInfo();
              Int32 firstId = -1, index = 0, count = 0;
              foreach (ParcelLineRow record in parcelRecord)
            if (!IncompleteLine(record))
              count++;

              foreach (ParcelLineRow record in parcelRecord)
              {
            if (IncompleteLine(record))
              continue;

            index++;
            if ((firstId == -1) && (record.Category == LineCategory.Boundary))
              firstId = record.GetFrom();
            Int32 overrideTo = count == index && count != 1 ? firstId : -1;

            if (record.Category != LineCategory.Radial)
              WriteLine(ref writer, record, ref documentType, overrideTo);
              }

              // Write radial lines
              foreach (ParcelLineRow record in parcelRecord)
              {
            if (record.CenterPoint == null)
              continue;

            ParcelLineRow radialRecord = new ParcelLineRow(ref configuration);

            radialRecord.From = record.From;
            radialRecord.To = record.CenterPoint.ToString();
            radialRecord.Bearing = GeometryUtil.RadianToDegree(record.RadialBearing1.GetValueOrDefault(0)).ToString();
            radialRecord.Distance = record.Radius;
            radialRecord.Category = LineCategory.Radial;
            WriteLine(ref writer, radialRecord, ref documentType, -1);

            radialRecord.From = record.To;
            radialRecord.Bearing = GeometryUtil.RadianToDegree(record.RadialBearing2.GetValueOrDefault(0)).ToString();
            WriteLine(ref writer, radialRecord, ref documentType, -1);
              }

              writer.WriteEndElement(); // lines
        }
Ejemplo n.º 12
0
        private void ConfigureApplication(ref Configuration xmlConfiguation)
        {
            Title  = xmlConfiguation.Title;
            Width  = xmlConfiguation.Width;
            Height = xmlConfiguation.Height;

            ParcelLines.MaxHeight = _xmlConfiguation.MaxGridHeight;

            // insert layer before [graphical] layers defined in xaml
            Int32  layerIndex = 0;
            String lastUnit   = "";

            foreach (LayerDefinition definition in xmlConfiguation.DisplayLayers)
            {
                if (definition.Type == "dynamic")
                {
                    ArcGISDynamicMapServiceLayer dynamicMS = new ArcGISDynamicMapServiceLayer();
                    dynamicMS.Url = definition.Url;
                    dynamicMS.ID  = definition.Id;
                    dynamicMS.InitializationFailed += Layer_InitializationFailed;
                    ParcelMap.Layers.Insert(layerIndex++, dynamicMS);
                    if ((dynamicMS.Units != null) && (dynamicMS.Units != "") && !xmlConfiguation.HasSpatialReferenceUnit)
                    {
                        lastUnit = dynamicMS.Units;
                    }
                }

                if (definition.Type == "feature")
                {
                    FeatureLayer featureMS = new FeatureLayer();
                    featureMS.Url = definition.Url + "/" + definition.Id.ToString();
                    featureMS.ID  = definition.Id;
                    featureMS.InitializationFailed += Layer_InitializationFailed;
                    featureMS.Mode = FeatureLayer.QueryMode.OnDemand;
                    ParcelMap.Layers.Insert(layerIndex++, featureMS);
                    // FOOBAR FeatureLayer does not support unit?
                }

                if (definition.Type == "tiled")
                {
                    ArcGISTiledMapServiceLayer tiledMS = new ArcGISTiledMapServiceLayer();
                    tiledMS.Url = definition.Url;
                    tiledMS.ID  = definition.Id;
                    tiledMS.InitializationFailed += Layer_InitializationFailed;
                    ParcelMap.Layers.Insert(layerIndex++, tiledMS);
                    if ((tiledMS.Units != null) && (tiledMS.Units != "") && !xmlConfiguation.HasSpatialReferenceUnit)
                    {
                        lastUnit = tiledMS.Units;
                    }
                }

                if (definition.Type == "image")
                {
                    ArcGISImageServiceLayer imageS = new ArcGISImageServiceLayer();
                    imageS.Url = definition.Url;
                    imageS.ID  = definition.Id;
                    imageS.InitializationFailed += Layer_InitializationFailed;
                    ParcelMap.Layers.Insert(layerIndex++, imageS);
                }
            }

            if (!xmlConfiguation.HasSpatialReferenceUnit)
            {
                xmlConfiguation.MapSpatialReferenceUnits = lastUnit;
            }

            ESRI.ArcGIS.Client.Geometry.Envelope extent = null;
            if (xmlConfiguation.IsExtentSet())
            {
                extent = new ESRI.ArcGIS.Client.Geometry.Envelope(xmlConfiguation.XMin, xmlConfiguation.YMin, xmlConfiguation.XMax, xmlConfiguation.YMax);
            }
            else
            {
                // Map will not zoom to, etc with out some value set.
                // Ideally we would like to set the extent to the full extent of the first
                // layer, but since they layer has hot been drawn yet null is returned.
                extent = new ESRI.ArcGIS.Client.Geometry.Envelope(100, 100, 100, 100);
            }

            // if zero, the first inserted layer is used
            if ((xmlConfiguation.SpatialReferenceWKT != null) && (xmlConfiguation.SpatialReferenceWKT != ""))
            {
                extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(xmlConfiguation.SpatialReferenceWKT);
            }
            else if (xmlConfiguation.SpatialReferenceWKID != 0)
            {
                extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(xmlConfiguation.SpatialReferenceWKID);
            }

            ParcelMap.Extent = extent;

            ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;

            parcelData.Configuration = xmlConfiguation;

            QueryLabel.Text = xmlConfiguation.QueryLabel;
        }
Ejemplo n.º 13
0
        private void ScaleRotate(Point srcPoint)
        {
            if (!PDE_Tools.IsExpanded)
            {
                return;
            }

            ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;

            _moveScale    = _oldScale = parcelData.ScaleValue;
            _moveRotation = _oldRotation = parcelData.RotationValue;
            _srPoint      = ParcelMap.ScreenToMap(srcPoint);
            _srSnapPoint  = null;

            double spX = _srPoint.X;
            double spY = _srPoint.Y;

            // Find _startPoint in list of points. If "close" snap to that point.
            // Otherwise user can free form scale or rotate parcel lines.

            double shortestDistance = double.MaxValue;
            Int32  shortestId       = -1;

            ESRI.ArcGIS.Client.Geometry.MapPoint foundPoint = null;
            foreach (KeyValuePair <Int32, ESRI.ArcGIS.Client.Geometry.MapPoint> kvp in _calculatedPoints)
            {
                double x        = kvp.Value.X;
                double y        = kvp.Value.Y;
                double distance = GeometryUtil.LineLength(spX, spY, x, y);
                if ((distance < shortestDistance) && (distance < _xmlConfiguation.SnapTolerance))
                {
                    shortestDistance = distance;
                    shortestId       = kvp.Key;
                    foundPoint       = new ESRI.ArcGIS.Client.Geometry.MapPoint(x, y);
                }
            }

            if (BearingDistanceToPoint(shortestId, out _srBearingToPoint, out _srDistanceToPoint, out _srSnapPoint))
            {
                // BearingDistanceToPoint will fail if shortestId == -1

                _srSnapPointId = shortestId;
                if (RotationButton.IsChecked == true)
                {
                    double radialSearch = _srDistanceToPoint * parcelData.ScaleValue;

                    // We seem to be getting some numerical precision error when rotating... this does not
                    // really matter here; we only need to re-buffer if the changes are > 0.1.

                    // if the user re-rotate with the same rotate point, try to avoid re-caching.
                    if ((_originPoint == null) || (_lastGeometryCP == null) ||
                        (Math.Abs(_lastSearchDistance - radialSearch) > 0.1) || !_lastBufferBasedOnCurve ||
                        (_lastGeometryCP.X != _originPoint.X) || (_lastGeometryCP.Y != _originPoint.Y))
                    {
                        ESRI.ArcGIS.Client.Geometry.MapPoint offsetOriginPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(_originPoint.X - radialSearch, _originPoint.Y);

                        // Create a geometry circle from the anchor/rotating point to the snap point.
                        // We will create create a cache of all these points within the buffer distance
                        // of this circle.

                        ESRI.ArcGIS.Client.Geometry.MapPoint endPoint;
                        ESRI.ArcGIS.Client.Geometry.Polyline circle = GeometryUtil.ConstructArcSegment(offsetOriginPoint, 0.0, 0.001, radialSearch, false, SweepDirection.Counterclockwise, out endPoint);

                        _lastGeometryCP         = _originPoint;
                        _lastSearchDistance     = radialSearch;
                        _lastBufferBasedOnCurve = true;

                        CacheSnapObjects(circle, radialSearch);
                    }
                }
                else if (ScaleButton.IsChecked == true)
                {
                    double mapDistanceBuffer = _srDistanceToPoint * 1.5 * parcelData.ScaleValue;

                    // if the user re-scales with the same scale point, try to avoid re-caching.
                    if ((_originPoint == null) || (_lastGeometryCP == null) ||
                        (_lastSearchDistance < mapDistanceBuffer) || _lastBufferBasedOnCurve ||
                        (_lastGeometryCP.X != _originPoint.X) || (_lastGeometryCP.Y != _originPoint.Y))
                    {
                        // Create a line from the anchor/rotating point to the snap point * 1.5 of the distance.
                        // We will create create a cache of all these points within the buffer distance
                        // of this line.

                        ESRI.ArcGIS.Client.Geometry.MapPoint endPoint;
                        ESRI.ArcGIS.Client.Geometry.Polyline snapLine = GeometryUtil.Line(_originPoint,
                                                                                          _srBearingToPoint - parcelData.RotationValue,
                                                                                          mapDistanceBuffer,
                                                                                          out endPoint);
                        if (snapLine != null)
                        {
                            _lastGeometryCP         = _originPoint;
                            _lastSearchDistance     = mapDistanceBuffer;
                            _lastBufferBasedOnCurve = false;

                            CacheSnapObjects(snapLine, mapDistanceBuffer);
                        }
                    }
                }
                // else no snapping.

                CalculateAndAddLineGraphics(); // Redraw so we have snap graphic shown
            }
            else                               // BearingDistanceToPoint returns false if id = -1
            {
                _srSnapPointId = -1;
            }
        }
Ejemplo n.º 14
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;
            }
        }
Ejemplo n.º 15
0
        private static void WriteParcel(ref XmlWriter writer, ref ParcelData parcelData, ref PointDictionary pointDictionary, ref MapPoint projectedStartPoint, double scale, double rotation, ref Configuration configuration, ref DocumentEntry documentType)
        {
            ObservableCollection <ParcelLineRow> parcelRecord = parcelData.GetRecordInfo();

            if (parcelRecord.Count == 0)
            {
                return;
            }

            if (rotation < 0)
            {
                rotation += 360;
            }

            writer.WriteStartElement("parcels");
            writer.WriteStartElement("parcel");
            writer.WriteElementString("name", parcelData.ParcelName);
            if (scale != 1.0)
            {
                writer.WriteElementString("scale", scale.ToString(_doubleFormat));
            }
            if (rotation != 0.0)
            {
                writer.WriteElementString("rotation", rotation.ToString(_doubleFormat));
            }

            string statedArea = "statedArea";

            if (parcelData.StatedArea != "")
            {
                writer.WriteElementString(statedArea, parcelData.StatedArea);
            }
            else if (parcelData.MiscloseArea > 0)
            {
                writer.WriteElementString(statedArea, parcelData.MiscloseArea.ToString("F2"));
            }
            writer.WriteElementString("joined", "false");
            writer.WriteElementString("parcelNo", "1");
            writer.WriteElementString("type", documentType.Type.ToString());
            if ((parcelData.MiscloseDistance != 0.0) && (parcelData.MiscloseBearing != 0.0))
            {
                writer.WriteElementString("miscloseDistance", parcelData.MiscloseDistance.ToString(_doubleFormat));
                writer.WriteElementString("miscloseBearing", parcelData.MiscloseBearing.ToString(_doubleFormat));
            }

            // Write document type EA object
            if (documentType.HasEA)
            {
                writer.WriteStartElement("extendedAttributes");
                writer.WriteStartElement("extendedAttribute");
                writer.WriteElementString("name", documentType.EAField);
                writer.WriteElementString("value", documentType.EAValue);
                writer.WriteElementString("type", "VT_BSTR");
                writer.WriteEndElement();
                writer.WriteEndElement();
            }

            WriteConstructionData(ref writer, ref parcelData, ref pointDictionary, ref projectedStartPoint, ref configuration, parcelRecord[0]);

            WriteLines(ref writer, ref parcelData, ref documentType, ref configuration);

            writer.WriteEndElement(); // parcel
            writer.WriteEndElement(); // parcels
        }