Exemplo n.º 1
0
        ///// <summary>
        ///// snapping specific for a tool. Called before layer specific snappping is applied.
        ///// </summary>
        ///// <param name="sourceLayer"></param>
        ///// <param name="snapSource"></param>
        ///// <param name="worldPos"></param>
        ///// <param name="Envelope"></param>
        ///// <returns></returns>
        public void Snap(ILayer sourceLayer, IGeometry snapSource, ICoordinate worldPos, IEnvelope Envelope)
        {
            SnapResult = null;
            IFeature sourceFeature = MapControl.SelectTool.FeatureEditors[0].SourceFeature;
            if (sourceFeature.Geometry != snapSource)
                return;
            SnapRole snapRole = SnapRole.FreeAtObject;
            if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                snapRole = SnapRole.Free;
            ISnapRule snapRule = new SnapRule
                                     {
                                         SourceLayer = sourceLayer,
                                         TargetLayer = sourceLayer,
                                         Obligatory = true,
                                         SnapRole = snapRole,
                                         PixelGravity = 4
                                     };

            SnapResult = MapControl.SnapTool.ExecuteSnapRule(
                                                snapRule,
                                                sourceFeature,
                                                sourceFeature.Geometry,
                                                new List<IFeature>
                                                    {
                                                        sourceFeature
                                                    },
                                                worldPos,
                                                -1);
        }
Exemplo n.º 2
0
        public void SnapToLineStringUsingFreeAtObject()
        {
            MockRepository mockRepository = new MockRepository();
            IFeature feature = mockRepository.CreateMock<IFeature>();

            using (mockRepository.Record())
            {
                Expect.Call(feature.Geometry).Return(lineString).Repeat.Any();
            }
            using (mockRepository.Playback())
            {
                VectorLayer lineStringLayer = new VectorLayer
                {
                    DataSource = new FeatureCollection
                    {
                        Features = new List<IFeature> { feature }
                    }
                };

                IPoint snapSource = new Point(5, 5);
                SnapRule snapRule = new SnapRule
                                        {
                                            TargetLayer = lineStringLayer,
                                            SnapRole = SnapRole.FreeAtObject,
                                            Obligatory = true,
                                            PixelGravity = 40
                                        };

                ISnapResult snapResults = snapRule.Execute(null, snapSource, null,
                                                             snapSource.Coordinates[0],
                                                             CreateEnvelope(snapSource, 10),
                                                             0);
                Assert.IsNotNull(snapResults);  
                Assert.IsNotNull(snapResults.Location);
                Assert.AreEqual(0, snapResults.Location.Y);
                Assert.AreEqual(5, snapResults.Location.X);
            }
        }