Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        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;
        }