/// <summary>
        /// Handles the Mouse-Up situation.
        /// </summary>
        /// <param name="e">The GeoMouseArcs class describes the mouse condition along with geographic coordinates.</param>
        protected override void OnMouseUp(GeoMouseArgs e)
        {
            if (_standBy)
            {
                return;
            }
            if (_featureSet == null || _featureSet.IsDisposed)
            {
                return;
            }

            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
            {
                // Add the current point to the featureset
                if (_featureSet.FeatureType == FeatureType.Point)
                {
                    // Begin snapping changes
                    Coordinate snappedCoord = _coordinateDialog.Coordinate;
                    ComputeSnappedLocation(e, ref snappedCoord);
                    // End snapping changes

                    Topology.Point pt = new Topology.Point(snappedCoord); // Snapping changes
                    Feature        f  = new Feature(pt);
                    _featureSet.Features.Add(f);
                    _featureSet.ShapeIndices = null; // Reset shape indices
                    _featureSet.UpdateExtent();
                    _layer.AssignFastDrawnStates();
                    _featureSet.InvalidateVertices();
                    return;
                }

                if (e.Button == MouseButtons.Right)
                {
                    _context.Show((Control)Map, e.Location);
                }
                else
                {
                    if (_coordinates == null)
                    {
                        _coordinates = new List <Coordinate>();
                    }

                    // Begin snapping changes
                    Coordinate snappedCoord = e.GeographicLocation;
                    ComputeSnappedLocation(e, ref snappedCoord);
                    // End snapping changes

                    _coordinates.Add(snappedCoord); // Snapping changes
                    if (_coordinates.Count > 1)
                    {
                        Point     p1      = Map.ProjToPixel(_coordinates[_coordinates.Count - 1]);
                        Point     p2      = Map.ProjToPixel(_coordinates[_coordinates.Count - 2]);
                        Rectangle invalid = SymbologyGlobal.GetRectangle(p1, p2);
                        invalid.Inflate(20, 20);
                        Map.Invalidate(invalid);
                    }
                }
            }
            base.OnMouseUp(e);
        }
Beispiel #2
0
        /// <summary>
        /// Finish the shape.
        /// </summary>
        /// <param name="sender">The object sender.</param>
        /// <param name="e">An empty EventArgs class.</param>
        public void FinishShape(object sender, EventArgs e)
        {
            if (_featureSet != null && !_featureSet.IsDisposed)
            {
                Feature f = null;
                if (_featureSet.FeatureType == FeatureType.MultiPoint)
                {
                    f = new Feature(new MultiPoint(_coordinates.CastToPointArray()));
                }

                if (_featureSet.FeatureType == FeatureType.Line || _featureSet.FeatureType == FeatureType.Polygon)
                {
                    // if (_coordinates == null || _coordinates.Count < 2) return;
                    FinishPart(sender, e);

                    if (_parts == null || _parts.Count <= 0)
                    {
                        return;
                    }
                    Shape shp = new Shape(_featureSet.FeatureType);
                    foreach (List <Coordinate> part in _parts)
                    {
                        // In order to avoid exceptions
                        if (part != null && part.Count >= 2)
                        {
                            shp.AddPart(part, _featureSet.CoordinateType);
                        }
                    }

                    f = new Feature(shp);
                }

                if (f != null)
                {
                    _featureSet.Features.Add(f);
                }

                _featureSet.ShapeIndices = null; // Reset shape indices
                _featureSet.UpdateExtent();
                _layer.AssignFastDrawnStates();
                _featureSet.InvalidateVertices();
            }

            _coordinates = new List <Coordinate>();
            _parts       = new List <List <Coordinate> >();
        }