コード例 #1
0
ファイル: MapControl.cs プロジェクト: Deltares/Riskeer
        private void InitializeMap()
        {
            map = new DotSpatialMap
            {
                ProjectionModeDefine = ActionMode.Never,
                Dock = DockStyle.Fill,
                ZoomOutFartherThanMaxExtent = true,
                Projection = MapDataConstants.FeatureBasedMapDataCoordinateSystem
            };

            MapFunctionPan mapFunctionPan = map.MapFunctions.OfType <MapFunctionPan>().First();

            mapFunctionPan.FunctionActivated += MapFunctionActivateFunction;
            mapFunctionPan.MouseDown         += MapFunctionPanOnMouseDown;
            mapFunctionPan.MouseUp           += MapFunctionOnMouseUp;

            mapFunctionSelectionZoom = new MapFunctionSelectionZoom(map);
            map.MapFunctions.Add(mapFunctionSelectionZoom);
            mapFunctionSelectionZoom.FunctionActivated += MapFunctionActivateFunction;
            mapFunctionSelectionZoom.MouseDown         += MapFunctionSelectionZoomOnMouseDown;
            mapFunctionSelectionZoom.MouseUp           += MapFunctionOnMouseUp;

            mouseCoordinatesMapExtension = new RdNewMouseCoordinatesMapExtension(map);

            tableLayoutPanel.Controls.Add(map, 0, 0);
        }
コード例 #2
0
        public void OnDraw_Dragging_DrawRectangle()
        {
            // Setup
            var       random = new Random(21);
            int       startX = random.Next(1, 100);
            int       startY = random.Next(1, 100);
            Rectangle rectangleFromPoints = Opp.RectangleFromPoints(new Point(startX, startY), new Point(startX, startY));

            rectangleFromPoints.Width  -= 1;
            rectangleFromPoints.Height -= 1;

            var map        = mockingRepository.Stub <IMap>();
            var mapFrame   = mockingRepository.Stub <IMapFrame>();
            var inGraphics = mockingRepository.Stub <Graphics>();

            inGraphics.Expect(e => e.DrawRectangle(Pens.White, rectangleFromPoints));
            inGraphics.Expect(e => e.DrawRectangle(Arg <Pen> .Matches(p => p.Color.Equals(Color.Black) && p.DashStyle.Equals(DashStyle.Dash)), Arg.Is(rectangleFromPoints)));

            mockingRepository.ReplayAll();

            var mapFunction = new MapFunctionSelectionZoom(map);

            var clipRectangle = new Rectangle(0, 0, 0, 0);

            mapFunction.DoMouseDown(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, startX, startY, 0), map));

            // Call
            mapFunction.Draw(new MapDrawArgs(inGraphics, clipRectangle, mapFrame));

            // Assert
            mockingRepository.VerifyAll();
        }
コード例 #3
0
        public void OnMouseMove_Dragging_DrawNewRectangle(int startPointX, int startPointY, int endPointX, int endPointY)
        {
            // Setup
            int x  = Math.Min(Math.Min(startPointX, 0), endPointX);
            int y  = Math.Min(Math.Min(startPointY, 0), endPointY);
            int mx = Math.Max(Math.Max(startPointX, 0), endPointX);
            int my = Math.Max(Math.Max(startPointY, 0), endPointY);
            var expectedRectangle = new Rectangle(x, y, mx - x, my - y);

            var map = mockingRepository.Stub <IMap>();

            map.Stub(e => e.PixelToProj(Arg <Point> .Is.Anything)).Return(null);
            map.Expect(e => e.Invalidate(Arg <Rectangle> .Matches(m => m.Equals(expectedRectangle))));
            mockingRepository.ReplayAll();

            var mapFunction = new MapFunctionSelectionZoom(map);

            mapFunction.DoMouseDown(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, startPointX, startPointY, 0), map));

            // Call
            mapFunction.DoMouseMove(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 0, endPointX, endPointY, 0), map));

            // Assert
            Assert.IsTrue(map.IsBusy);
            mockingRepository.VerifyAll();
        }
コード例 #4
0
        public void OnMouseUp_NotDragging_ResetExtents(int startPointX, int startPointY)
        {
            // Setup
            var map      = mockingRepository.Stub <IMap>();
            var mapFrame = mockingRepository.Stub <IMapFrame>();

            map.MapFrame = mapFrame;

            double geoStartPointX = startPointX;
            double geoStartPointY = startPointY;

            map.Expect(e => e.PixelToProj(new Point(startPointX, startPointY))).Return(new Coordinate(geoStartPointX, geoStartPointY));
            map.Expect(e => e.Invalidate());
            mapFrame.Expect(e => e.ResetExtents());
            mockingRepository.ReplayAll();

            var mapFunction = new MapFunctionSelectionZoom(map);

            // Call
            mapFunction.DoMouseUp(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, startPointX, startPointY, 0), map));

            // Assert
            Assert.IsFalse(map.IsBusy);
            mockingRepository.VerifyAll();
        }
コード例 #5
0
        public void OnMouseUp_DraggingToOtherLocation_ZoomsToCoordinates(int startPointX, int startPointY, int endPointX, int endPointY)
        {
            // Setup
            double geoStartPointX = startPointX;
            double geoStartPointY = startPointY;
            double geoEndPointX   = endPointX;
            double geoEndPointY   = endPointY;

            var map = mockingRepository.Stub <IMap>();

            map.Expect(e => e.PixelToProj(new Point(startPointX, startPointY))).Return(new Coordinate(geoStartPointX, geoStartPointY));
            map.Expect(e => e.PixelToProj(new Point(endPointX, endPointY))).Return(new Coordinate(geoEndPointX, geoEndPointY));
            map.Expect(e => e.Invalidate());
            mockingRepository.ReplayAll();

            Extent expectedExtend = new Envelope(geoStartPointX, geoEndPointX, geoStartPointY, geoEndPointY).ToExtent();

            var mapFunction = new MapFunctionSelectionZoom(map);

            mapFunction.DoMouseDown(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, startPointX, startPointY, 0), map));

            // Call
            mapFunction.DoMouseUp(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, endPointX, endPointY, 0), map));

            // Assert
            Assert.AreEqual(expectedExtend, map.ViewExtents);
            Assert.IsFalse(map.IsBusy);
            mockingRepository.VerifyAll();
        }
コード例 #6
0
        public void OnMouseDown_Always_SetsMapBusy()
        {
            // Setup
            var map = mockingRepository.Stub <IMap>();

            map.MapFrame = mockingRepository.Stub <IMapFrame>();
            mockingRepository.ReplayAll();

            var mapFunction = new MapFunctionSelectionZoom(map);

            // Call
            mapFunction.DoMouseDown(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0), map));

            // Assert
            Assert.IsTrue(map.IsBusy);
            mockingRepository.VerifyAll();
        }
コード例 #7
0
        public void Constructor_Always_ExpectedValues()
        {
            // Setup
            var map = mockingRepository.Stub <IMap>();

            mockingRepository.ReplayAll();

            // Call
            var mapFunction = new MapFunctionSelectionZoom(map);

            // Assert
            Assert.IsInstanceOf <MapFunctionZoom>(mapFunction);
            const YieldStyles expectedYieldStyle = YieldStyles.LeftButton | YieldStyles.RightButton | YieldStyles.Scroll;

            Assert.AreEqual(expectedYieldStyle, mapFunction.YieldStyle);
            mockingRepository.VerifyAll();
        }
コード例 #8
0
        public void OnDraw_NotDragging_NoDrawing()
        {
            // Setup
            var map        = mockingRepository.Stub <IMap>();
            var mapFrame   = mockingRepository.Stub <IMapFrame>();
            var inGraphics = mockingRepository.Stub <Graphics>();

            inGraphics.Expect(e => e.DrawRectangle(new Pen(Color.Empty), 0, 0, 0, 0)).IgnoreArguments().Repeat.Never();
            mockingRepository.ReplayAll();

            var mapFunction = new MapFunctionSelectionZoom(map);

            var clipRectangle = new Rectangle(0, 0, 0, 0);

            // Call
            mapFunction.Draw(new MapDrawArgs(inGraphics, clipRectangle, mapFrame));

            // Assert
            mockingRepository.VerifyAll();
        }
コード例 #9
0
        public void OnMouseMove_DraggingWithMiddleMouseButtonDown_DoesNotPan()
        {
            // Setup
            var map = mockingRepository.Stub <IMap>();

            map.MapFrame = mockingRepository.Stub <IMapFrame>();
            mockingRepository.ReplayAll();

            var mapFunction = new MapFunctionSelectionZoom(map);

            mapFunction.DoMouseDown(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Middle, 1, 10, 10, 0), map));

            // Call
            Rectangle view = map.MapFrame.View;

            mapFunction.DoMouseMove(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Middle, 1, 20, 20, 0), map));

            // Assert
            Assert.AreEqual(view, map.MapFrame.View);
            mockingRepository.VerifyAll();
        }
コード例 #10
0
        public void OnMouseDown_NotZoomedSameLocation_DoesNotZoom()
        {
            // Setup
            var map = mockingRepository.Stub <IMap>();

            mockingRepository.ReplayAll();

            const int startPointX = 0;
            const int startPointY = 0;
            var       mapFunction = new MapFunctionSelectionZoom(map);

            mapFunction.DoMouseDown(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, startPointX, startPointY, 0), map));

            // Call
            mapFunction.DoMouseUp(new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 0, startPointX, startPointY, 0), map));

            // Assert
            Assert.IsNull(map.ViewExtents);
            Assert.IsFalse(map.IsBusy);
            mockingRepository.VerifyAll();
        }