Example #1
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);
        }
Example #2
0
        public void CreateFromCollection()
        {
            EventedList<SampleFeature> features = new EventedList<SampleFeature>();

            features.Add(new SampleFeature());
            features.Add(new SampleFeature());
            features.Add(new SampleFeature());

            features[0].Geometry = GeometryFromWKT.Parse("LINESTRING (20 20, 20 30, 30 30, 30 20, 40 20)");
            features[1].Geometry = GeometryFromWKT.Parse("LINESTRING (30 30, 30 40, 40 40, 40 30, 50 30)");
            features[2].Geometry = GeometryFromWKT.Parse("LINESTRING (40 40, 40 50, 50 50, 50 40, 60 40)");

            FeatureCollection featureCollection = new FeatureCollection {Features = features};

            Map map = new Map();
            
            VectorLayer vectorLayer = new VectorLayer();
            vectorLayer.DataSource = featureCollection;
            
            map.Layers.Add(vectorLayer);

            Assert.AreEqual(3, vectorLayer.DataSource.GetFeatureCount());
            Assert.AreEqual("LineString", vectorLayer.DataSource.GetGeometryByID(0).GeometryType);

            // ShowMap(map);
        }
        public void AddingInvalidTypeGivesArgumentException()
        {
            IList list = new List<IFeature>();    
            FeatureCollection featureCollection = new FeatureCollection(list,typeof(string));

            // TODO: WHERE ARE ASSERTS????!~?!?!?!#@$!@#
        }
        public void AddingValidTypeIsOk()
        {
            IList list = new List<IFeature>();
            FeatureCollection featureCollection = new FeatureCollection(list, typeof(NetworkLocation));

            // TODO: WHERE ARE ASSERTS????!~?!?!?!#@$!@#
        }
Example #5
0
        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();
        }
Example #6
0
        public FeatureCoverageLayer()
        {
            this.featureCollection = new FeatureCollection();

            // Use the VectorLayer with the custom featureRenderer to render this feature coverage (using values form the data store)
            featureCoverageRenderer = new FeatureCoverageRenderer();
        }
Example #7
0
        public FeatureCoverageLayer(FeatureCoverageRenderer renderer)
        {
            featureCollection = new FeatureCollection();

            // Use the VectorLayer with the custom featureRenderer to render this feature coverage (using values form the data store)
            Renderer = renderer;
            CustomRenderers.Add(renderer);

            AutoUpdateThemeOnDataSourceChanged = true;
        }
Example #8
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);
        }
        public void FilterFeaturesUsingStartTime()
        {
            var features = new[]
                              {
                                  new TimeDependentFeature {Time = new DateTime(2000, 1, 1)},
                                  new TimeDependentFeature {Time = new DateTime(2001, 1, 1)}
                              };

            var featureCollection = new FeatureCollection(features, typeof(TimeDependentFeature))
                                        {
                                            TimeSelectionStart = new DateTime(2001, 1, 1)
                                        };

            featureCollection.Features.Count
                .Should().Be.EqualTo(1);
        }
Example #10
0
        public void FeatureCollectionTimesMustBeExtractedFromFeature()
        {
            var features = new[]
                               {
                                   new TimeDependentFeature {Time = new DateTime(2000, 1, 1)},
                                   new TimeDependentFeature {Time = new DateTime(2001, 1, 1)},
                                   new TimeDependentFeature {Time = new DateTime(2002, 1, 1)}
                               };

            var featureCollection = new FeatureCollection(features, typeof (TimeDependentFeature));

            featureCollection.Times
                .Should().Have.SameSequenceAs(new[]
                                                  {
                                                      new DateTime(2000, 1, 1),
                                                      new DateTime(2001, 1, 1),
                                                      new DateTime(2002, 1, 1)
                                                  });
        }
Example #11
0
        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();
        }
Example #12
0
        public SelectTool()
        {
            orgClickTime = DateTime.Now;
            FeatureEditors = new List<IFeatureEditor>();
            Name = "Select";

            trackingLayer.Name = "trackers";
            FeatureCollection trackerProvider = new FeatureCollection {Features = trackers};

            trackingLayer.DataSource = trackerProvider;

            CustomTheme iTheme = new CustomTheme(GetTrackerStyle);
            trackingLayer.Theme = iTheme;
        }
Example #13
0
        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);
        }
Example #14
0
        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);
        }
Example #15
0
        private VectorLayer AddFeatureToDragLayers(IFeature sourceFeature, IFeature cloneFeature)
        {
            var sourceLayer = (VectorLayer) Map.GetLayerByFeature(sourceFeature);
            // NOTE: sourceLayer should never return null 
            if (null == sourceLayer)
            {
                throw new ArgumentOutOfRangeException("sourceFeature", "Movetool unable to find sourcelayer; internal corruption caused by removed feature?");
            }
            var dragLayer = GetDragLayer(sourceLayer.Name);
            if (null == dragLayer)
            {
                dragLayer = new VectorLayer(sourceLayer);

                foreach (var customRenderer in sourceLayer.CustomRenderers)
                {
                    var renderer = customRenderer as ICloneable;
                    if (null != renderer)
                    {
                        dragLayer.CustomRenderers.Add((IFeatureRenderer)renderer.Clone());
                    }
                }

                MapControlHelper.PimpStyle(dragLayer.Style, true);

                var dragFeatures = new FeatureCollection();
                dragLayer.DataSource = dragFeatures;
                dragLayer.Map = Map;
                if (sourceLayer.DataSource is FeatureCollection)
                {
                    ((FeatureCollection)dragLayer.DataSource).FeatureType = sourceLayer.DataSource.FeatureType;
                }
                DragLayers.Add(dragLayer);
            }

            if(sourceLayer.Visible && !dragLayer.DataSource.Contains(cloneFeature))
            {
                dragLayer.DataSource.Features.Add(cloneFeature);
                dragLayer.RenderRequired = true;
            }

            return dragLayer;
        }