コード例 #1
0
ファイル: DeleteToolTest.cs プロジェクト: lishxi/_SharpMap
        public void NopDeleteDoesNotTriggerBeginEdit()
        {
            MapControl mapControl = new MapControl();

            SelectTool selectTool = mapControl.SelectTool;

            VectorLayer vectorLayer = new VectorLayer();
            FeatureCollection layer2Data = new FeatureCollection();
            vectorLayer.DataSource = layer2Data;
            layer2Data.FeatureType = typeof(Feature);

            layer2Data.Add(new Point(4, 5));
            layer2Data.Add(new Point(0, 1));
            mapControl.Map.Layers.Add(vectorLayer);

            var featureMutator = mocks.StrictMock<IFeatureInteractor>();
            var editableObject = mocks.StrictMock<IEditableObject>();

            featureMutator.Expect(fm => fm.EditableObject).Return(editableObject).Repeat.Any();
            featureMutator.Expect(fm => fm.AllowDeletion()).Return(false).Repeat.Any();
            featureMutator.Expect(fm => fm.Delete()).Repeat.Never();
            editableObject.Expect(eo => eo.BeginEdit(null)).IgnoreArguments().Repeat.Never(); //never expect BeginEdit!
            editableObject.Expect(eo => eo.EndEdit()).IgnoreArguments().Repeat.Never();
            
            mocks.ReplayAll();
            
            selectTool.Select((IFeature)layer2Data.Features[0]);

            selectTool.SelectedFeatureInteractors.Clear();
            selectTool.SelectedFeatureInteractors.Add(featureMutator); //inject our own feature editor

            mapControl.DeleteTool.DeleteSelection();

            mocks.VerifyAll();
        }
コード例 #2
0
        [Test] //not working in UI?
        public void CanRemovePointFromLine()
        {
            var mapControl = new MapControl();

            var vectorLayer = new VectorLayer();
            var layerData = new FeatureCollection();
            vectorLayer.DataSource = layerData;
            layerData.FeatureType = typeof(CloneableFeature);

            layerData.Add(new LineString(new[] { new Coordinate(0, 0), new Coordinate(50, 0), new Coordinate(100, 0) }));

            mapControl.Map.Layers.Add(vectorLayer);

            var firstFeature = (IFeature)layerData.Features[0];
            mapControl.SelectTool.Select(firstFeature);

            var curveTool = mapControl.GetToolByType<CurvePointTool>();

            curveTool.IsActive = true;
            curveTool.Mode = CurvePointTool.EditMode.Remove;
            var args = new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0);
            curveTool.OnMouseMove(new Coordinate(50, 0), new MouseEventArgs(MouseButtons.None, 1, 0, 0, 0));
            curveTool.OnMouseDown(new Coordinate(50, 0), args); // delete tracker

            Assert.AreEqual(2, firstFeature.Geometry.Coordinates.Length);
            Assert.AreEqual(100.0, firstFeature.Geometry.Coordinates[1].X);
        }
コード例 #3
0
        private static IFeatureCollection CreateFeatureCollection(params IGeometry[] geometrys)
        {
            IGeometryFactory geomFactory;

            if (geometrys == null || geometrys.Length == 0 || geometrys[0] == null)
            {
                geomFactory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(0);
            }
            else
            {
                geomFactory = geometrys[0].Factory;
            }

            var res = new FeatureCollection <uint>(new GeometryFeatureFactory(geomFactory));

            if (geometrys != null)
            {
                foreach (var geometry in geometrys)
                {
                    if (geometry != null)
                    {
                        res.Add((GeometryFeature)res.Factory.Create(geometry));
                    }
                }
            }
            return(res);
        }
コード例 #4
0
ファイル: DeleteToolTest.cs プロジェクト: lishxi/_SharpMap
        public void CanDeleteWithoutEditableObject()
        {
            MapControl mapControl = new MapControl();

            //mapControl.ActivateTool(selectTool);

            VectorLayer vectorLayer = new VectorLayer();
            FeatureCollection layer2Data = new FeatureCollection();
            vectorLayer.DataSource = layer2Data;
            layer2Data.FeatureType = typeof(Feature);
            
            layer2Data.Add(new Point(4, 5));
            layer2Data.Add(new Point(0, 1));
            mapControl.Map.Layers.Add(vectorLayer);

            mapControl.SelectTool.Select((IFeature)layer2Data.Features[0]);

            mapControl.DeleteTool.DeleteSelection();
        }
コード例 #5
0
        public void AddFeatureUsingGeometry()
        {
            EventedList<SampleFeature> features = new EventedList<SampleFeature>();

            FeatureCollection featureCollection = new FeatureCollection {Features = features};

            IGeometry geometry = GeometryFromWKT.Parse("LINESTRING (20 20, 20 30, 30 30, 30 20, 40 20)");
            featureCollection.Add(geometry);

            Assert.AreEqual(1, features.Count);
            Assert.IsTrue(features[0].Geometry is ILineString);
        }
コード例 #6
0
ファイル: SelectToolTest.cs プロジェクト: lishxi/_SharpMap
        public void FindNearestFeature()
        {
            MapControl mapControl = new MapControl();

            VectorLayer layer1 = new VectorLayer();
            FeatureCollection layer1Data = new FeatureCollection();
            layer1.DataSource = layer1Data;
            layer1Data.FeatureType = typeof (Feature);
            layer1Data.Add(new Point(5, 5));
            layer1Data.Add(new Point(1, 1));

            VectorLayer layer2 = new VectorLayer();
            FeatureCollection layer2Data = new FeatureCollection();
            layer2.DataSource = layer2Data;
            layer2Data.FeatureType = typeof(Feature);
            layer2Data.Add(new Point(4, 5));
            layer2Data.Add(new Point(0, 1));

            mapControl.Map.Layers.Add(layer1);
            mapControl.Map.Layers.Add(layer2);

            ILayer outLayer;
            IFeature feature = mapControl.SelectTool.FindNearestFeature(new Coordinate(4, 4), 2.2f, out outLayer, null);

            // expect coordinate in topmost layer
            Assert.AreEqual(outLayer, layer1);
            Assert.AreEqual(5, feature.Geometry.Coordinate.X);
            Assert.AreEqual(5, feature.Geometry.Coordinate.Y);

            layer2.Visible = false;

            feature = mapControl.SelectTool.FindNearestFeature(new Coordinate(4, 4), 2.2f, out outLayer, null);

            Assert.AreEqual(outLayer, layer1);
            Assert.AreEqual(5, feature.Geometry.Coordinate.X);
            Assert.AreEqual(5, feature.Geometry.Coordinate.Y);
        }
コード例 #7
0
ファイル: SelectToolTest.cs プロジェクト: lishxi/_SharpMap
        public void TestAddSelection()
        {
            var mapControl = new MapControl();
            var layerData = new FeatureCollection();

            var layer = new VectorLayer {Visible = false, DataSource = layerData};
            var feature = new Node {Geometry = new Point(0, 0)};
            layerData.FeatureType = typeof(Node);
            layerData.Add(feature);

            mapControl.Map.Layers.Add(layer);

            Assert.AreEqual(0, mapControl.SelectTool.SelectedTrackersCount);

            mapControl.SelectTool.AddSelection(new IFeature[0]);

            Assert.AreEqual(0, mapControl.SelectTool.SelectedTrackersCount, "No features should be added as none are passed");

            mapControl.SelectTool.AddSelection(new[] { feature });

            Assert.AreEqual(0, mapControl.SelectTool.SelectedTrackersCount, "No features should be added as none are visible");

            layer.Visible = true;
            mapControl.SelectTool.AddSelection(new[] { feature });

            Assert.AreEqual(1, mapControl.SelectTool.SelectedTrackersCount);
        }