/// <summary>
 /// Add the given layer to the snap list. This list determines which layers the current layer will be snapped to.
 /// </summary>
 /// <param name="layer">The layer that gets added to the list of layers that can be used for snapping.</param>
 public void AddLayerToSnap(IFeatureLayer layer)
 {
     if (SnapLayers == null)
     {
         InitializeSnapLayers();
     }
     SnapLayers.Add(layer);
 }
示例#2
0
 /// <summary>
 /// Add the given layer to the snap list. This list determines which layers the current layer will be snapped to.
 /// </summary>
 /// <param name="layer">The layer that gets added to the list of layers that can be used for snapping.</param>
 public void AddLayerToSnap(IFeatureLayer layer)
 {
     if (SnapLayers == null)
     {
         InitializeSnapLayers();
     }
     if (!SnapLayers.Contains(layer))
     {
         SnapLayers.Add(layer);
     }
 }
示例#3
0
        /// <summary>
        /// Remove the given layer from the snap list. This list determines which layers the current layer will be snapped to.
        /// </summary>
        /// <param name="layer">The layer that gets removed from the list of layers that can be used for snapping.</param>
        public void RemoveLayerFromSnap(IFeatureLayer layer)
        {
            if (SnapLayers == null)
            {
                InitializeSnapLayers();
                return;
            }

            if (SnapLayers.Contains(layer))
            {
                SnapLayers.Remove(layer);
            }
        }
        /// <summary>
        /// Computes a snapped coordinate.  If the mouse is near a snappable object, the output
        /// location of the mouse will be the coordinates of the object rather than the actual
        /// mouse coords.
        /// </summary>
        /// <param name="e">The event args.</param>
        /// <param name="snappedCoord">set if a coordinate is found.</param>
        /// <returns>true if snap found.</returns>
        protected bool ComputeSnappedLocation(GeoMouseArgs e, ref Coordinate snappedCoord)
        {
            if (SnapLayers == null || e == null || Map == null)
            {
                return(false);
            }

            Rectangle mouseRect = new(e.X - SnapTol, e.Y - SnapTol, SnapTol * 2, SnapTol * 2);

            Extent pix = Map.PixelToProj(mouseRect);

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

            Envelope env = pix.ToEnvelope();

            foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible))
            {
                foreach (IFeature feat in layer.DataSet.Features)
                {
                    foreach (Coordinate c in feat.Geometry.Coordinates)
                    {
                        // If the mouse envelope contains the current coordinate, we found a snap location.
                        if (env.Contains(c))
                        {
                            snappedCoord   = c;
                            SnappedFeature = feat;
                            return(true);
                        }
                    }
                }
            }

            SnappedFeature = null;
            return(false);
        }
示例#5
0
        /// <summary>
        /// Computes a snapped coordinate.  If the mouse is near a snappable object, the output
        /// location of the mouse will be the coordinates of the object rather than the actual
        /// mouse coords.
        /// </summary>
        /// <param name="e">The event args.</param>
        /// <returns>SnapInfo</returns>
        protected virtual SnapInfo ComputeSnappedLocation(GeoMouseArgs e)
        {
            SnapInfo snapInfo = null;

            if (SnapLayers == null || e == null || Map == null || SnapMode == SnapMode.None)
            {
                return(snapInfo);
            }

            Rectangle mouseRect = new Rectangle(e.X - SnapTol, e.Y - SnapTol, SnapTol * 2, SnapTol * 2);

            Extent extent = Map.PixelToProj(mouseRect);

            if (extent == null)
            {
                return(snapInfo);
            }
            if (SnapMode == SnapMode.None)
            {
                return(snapInfo);
            }
            Tuple <IFeature, Coordinate> tuple = null;
            SnapMode snapMode = SnapMode.None;

            if ((SnapMode & SnapMode.Point) > 0)
            {
                foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible))
                {
                    tuple = ComputSnapPointModeFeature(layer, extent);
                    if (tuple != null)
                    {
                        snapMode = SnapMode.Point;
                        goto Success;
                    }
                }
            }
            if ((SnapMode & SnapMode.End) > 0)
            {
                foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible))
                {
                    tuple = ComputSnapEndModeFeature(layer, extent);
                    if (tuple != null)
                    {
                        snapMode = SnapMode.End;
                        goto Success;
                    }
                }
            }
            if ((SnapMode & SnapMode.Vertex) > 0)
            {
                foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible))
                {
                    tuple = ComputSnapVertexModeFeature(layer, extent);
                    if (tuple != null)
                    {
                        snapMode = SnapMode.Vertex;
                        goto Success;
                    }
                }
            }
            if ((SnapMode & SnapMode.Edege) > 0)
            {
                foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible))
                {
                    tuple = ComputSnapEdegeModeFeature(layer, extent, e.GeographicLocation);
                    if (tuple != null)
                    {
                        snapMode = SnapMode.Edege;
                        goto Success;
                    }
                }
            }
Success:
            if (tuple != null)
            {
                snapInfo = new SnapInfo()
                {
                    Feature    = tuple.Item1,
                    Coordinate = tuple.Item2,
                    SnapMode   = snapMode
                };
            }
            return(snapInfo);
        }
示例#6
0
        /// <summary>
        /// Computes a snapped coordinate.  If the mouse is near a snappable object, the output
        /// location of the mouse will be the coordinates of the object rather than the actual
        /// mouse coords.
        /// </summary>
        /// <param name="e">The event args.</param>
        /// <param name="snappedCoord">set if a coordinate is found</param>
        /// <returns>true if snap found</returns>
        protected bool ComputeSnappedLocation(GeoMouseArgs e, ref Coordinate snappedCoord)
        {
            SnappingType      = string.Empty;
            SnappedCoordIndex = 0;

            if (SnapLayers == null || e == null || Map == null)
            {
                return(false);
            }

            if (!DoSnapping)
            {
                return(false);
            }

            Rectangle mouseRect = new Rectangle(e.X - SnapTol, e.Y - SnapTol, SnapTol * 2, SnapTol * 2);

            Extent pix = Map.PixelToProj(mouseRect);

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

            Envelope mouseEnv = pix.ToEnvelope();

            NetTopologySuite.Geometries.Point mouse_onEarth = new NetTopologySuite.Geometries.Point(snappedCoord);

            foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible))
            {
                foreach (IFeature feat in layer.DataSet.Features)
                {
                    IGeometry featGeom = feat.Geometry;

                    // If the feature is partially or totaly visible in the view.
                    if (Map.ViewExtents.Intersects(featGeom.EnvelopeInternal))
                    {
                        bool doCoord_Snap;

                        // System.Console.WriteLine(feat.Fid);
                        int coordCounter = 0;
                        foreach (Coordinate c in feat.Geometry.Coordinates)
                        {
                            doCoord_Snap = true;

                            if (layer.SnapVertices)
                            {
                                if (coordCounter == 0 && !layer.SnapStartPoint)
                                {
                                    doCoord_Snap = false;
                                }
                                if (coordCounter == (feat.Geometry.Coordinates.Length - 1) && !layer.SnapEndPoint)
                                {
                                    doCoord_Snap = false;
                                }

                                if (doCoord_Snap)
                                {
                                    // If the mouse envelope contains the current coordinate, we found a snap location.
                                    if (mouseEnv.Contains(c))
                                    {
                                        snappedCoord      = c;
                                        SnappedCoordIndex = coordCounter;
                                        SnappedFeature    = feat;
                                        SnappingType      = SnappingTypeVertex;
                                        return(true);
                                    }
                                }
                            }

                            if (coordCounter > 0 && layer.SnapEdges && feat.FeatureType != FeatureType.Point && feat.FeatureType != FeatureType.MultiPoint)
                            {
                                double edge_Distance = 0;
                                if (layer.DataSet.CoordinateType.Equals(CoordinateType.Z))
                                {
                                    edge_Distance = feat.Geometry.Coordinates[coordCounter - 1].Distance3D(c);
                                }
                                else
                                {
                                    edge_Distance = feat.Geometry.Coordinates[coordCounter - 1].Distance(c);
                                }

                                if (edge_Distance > 0)
                                {
                                    List <Coordinate> edgeCoords = new List <Coordinate>();
                                    edgeCoords.Add(feat.Geometry.Coordinates[coordCounter - 1]);
                                    edgeCoords.Add(c);

                                    LineString edge = new LineString(edgeCoords.ToArray());

                                    if (mouse_onEarth.Distance(edge) <= (mouseEnv.Width / 2))
                                    {
                                        NetTopologySuite.LinearReferencing.LengthIndexedLine indexedEedge = new NetTopologySuite.LinearReferencing.LengthIndexedLine(edge);
                                        double proj_Index = indexedEedge.Project(mouse_onEarth.Coordinate);

                                        if (proj_Index > (mouseEnv.Width / 2) && proj_Index < (edge.Length - (mouseEnv.Width / 2)))
                                        {
                                            snappedCoord       = indexedEedge.ExtractPoint(proj_Index);
                                            SnappedCoordKeeped = snappedCoord;
                                            SnappedCoordIndex  = coordCounter;
                                            SnappedFeature     = feat;
                                            SnappingType       = SnappingTypeEdge;
                                            return(true);
                                        }
                                    }
                                }
                            }

                            coordCounter++;
                        }
                    }
                }
            }

            SnappedFeature = null;
            return(false);
        }