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
        /// <summary>
        /// snapping specific for a tool. Called before layer specific snapping is applied.
        /// </summary>
        /// <returns></returns>
        private void Snap(IGeometry snapSource, ICoordinate worldPos)
        {
            SnapResult = null;
            var sourceFeature = SelectTool.SelectedFeatureInteractors[0].SourceFeature;

            if (!Equals(sourceFeature.Geometry, snapSource))
            {
                return;
            }

            SnapRole snapRole;

            if (Mode == EditMode.Add)
            {
                snapRole = SnapRole.FreeAtObject;
                if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                {
                    snapRole = SnapRole.Free;
                }
            }
            else
            {
                snapRole = SnapRole.AllTrackers;
            }

            ISnapRule snapRule = new SnapRule {
                Obligatory = true, SnapRole = snapRole, PixelGravity = 4
            };

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

            using (mockRepository.Record())
            {
                Expect.Call(feature.Geometry).Return(lineString).Repeat.Any();
            }

            using (mockRepository.Playback())
            {
                var features = new [] { feature };
                var layers   = new[] { new VectorLayer() };

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

                SnapResult snapResults = snapRule.Execute(null, features, layers, 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);
            }
        }
        private static void SetFeatureEditorForNetworkCoverage(INetworkCoverageGroupLayer networkCoverageGroupLayer)
        {
            ISnapRule networkCoverageSnapRule = new SnapRule
            {
                Criteria        = (layer, feature) => feature is IBranch && ((IBranch)feature).Network == networkCoverageGroupLayer.NetworkCoverage.Network,
                SnapRole        = SnapRole.FreeAtObject,
                Obligatory      = true,
                PixelGravity    = 40,
                NewFeatureLayer = networkCoverageGroupLayer.LocationLayer
            };

            networkCoverageGroupLayer.FeatureEditor = new NetworkLocationFeatureEditor(networkCoverageGroupLayer);

            var locationFeatureEditor = new NetworkLocationFeatureEditor(networkCoverageGroupLayer)
            {
                SnapRules = { networkCoverageSnapRule }
            };

            networkCoverageGroupLayer.LocationLayer.FeatureEditor = locationFeatureEditor;
        }
Exemplo n.º 5
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);
            }
        }