コード例 #1
0
        public void TestZoomTo_ToSmallFeatureOnX()
        {
            //(y) nord south 150 m is 150/(1000*60*2) = 0,00125
            //(x) east vest 250 m is 200/(1000*60) = 0,00416
            //Arrange
            var place = new GeoSearchAddress()
            {
                presentationString = "SomePlace"
            };
            var incommingEnvelope = Make.Esri.Envelope
                                    .XMax(42.0021 - 0.00416)
                                    .XMin(41.9979)
                                    .YMax(42)
                                    .YMin(41)
                                    .Build;
            var geometry = Make.Esri.Geometry.WithEnvelope(incommingEnvelope).Build;
            var factory  = Make.Factory(place).ConvertWKTToGeometryReturns(geometry).Build;
            var placeFinderController = new PlaceFinderController(factory);
            var expetedEnvelope       = Make.Esri.Envelope
                                        .XMax(42.0021)
                                        .XMin(41.9979)
                                        .YMax(42.0006)
                                        .YMin(41.9994)
                                        .Build;

            //Act
            placeFinderController.SearchTextChange(place.presentationString);
            placeFinderController.ZoomTo(place);

            //Assert
            Validator.Map(factory.MxDocument.FocusMap)
            .NewExtentIsSet(expetedEnvelope)
            .MapIsRefresh
            .Validate();
        }
コード例 #2
0
        public void TestZoomTo_ToSmallFeatureOnXNegativeX()
        {
            //Arrange
            var place = new GeoSearchAddress()
            {
                presentationString = "SomePlace"
            };
            var centroid          = Make.Esri.Point.Coords(-250.0, -150.0).Build;
            var incommingEnvelope = Make.Esri.Envelope
                                    .XMax(centroid.X + 1)
                                    .XMin(centroid.X - 1)
                                    .YMax(centroid.Y + 150)
                                    .YMin(centroid.Y - 150)
                                    .WithCentroid(centroid)
                                    .Build;
            var geometry = Make.Esri.Geometry.WithEnvelope(incommingEnvelope).Build;
            var factory  = Make.Factory(place).ConvertWKTToGeometryReturns(geometry).Build;
            var placeFinderController = new PlaceFinderController(factory);
            var expectedEnvelope      = Make.Esri.Envelope
                                        .XMax(centroid.X + 125)
                                        .XMin(centroid.X - 125)
                                        .YMax(centroid.Y + 75)
                                        .YMin(centroid.Y - 75)
                                        .Build;

            //Act
            placeFinderController.SearchTextChange(place.presentationString);
            placeFinderController.ZoomTo(place);

            //Assert
            Validator.Map(factory.MxDocument.FocusMap)
            .NewExtentIsSet(expectedEnvelope)
            .MapIsRefresh
            .Validate();
        }
コード例 #3
0
 private void ZoomTo(GeoSearchAddress selected)
 {
     if (PlaceFinderController != null)
     {
         searchResultComboBox.Focus();
         PlaceFinderController.ZoomTo(selected);
         searchTextBox.Text = selected.presentationString;
     }
 }
コード例 #4
0
        public GeosearchServiceBuilder WithResult(GeoSearchAddress resultAddress)
        {
            var geoSearchAddressData = new GeoSearchAddressData();

            geoSearchAddressData.data = new List <GeoSearchAddress> {
                resultAddress, new GeoSearchAddress {
                    presentationString = "AnotherPlace"
                }
            };
            Build.Stub(m => m.Request(Arg <SearchRequestParams> .Is.Anything)).Return(geoSearchAddressData);
            return(this);
        }
コード例 #5
0
        public void ZoomTo(GeoSearchAddress selectedAddress)
        {
            if (string.IsNullOrEmpty(selectedAddress.presentationString))
            {
                //TODO move message to a resource file
                throw new PlaceFinderException("Der er ikke udfyldt et sted");
            }

            //get the last search address
            var geoSearchAddress = currentSearch.FirstOrDefault(x => x.Equals(selectedAddress));

            if (geoSearchAddress == null)
            {
                //TODO move message to a resource file
                throw new PlaceFinderException("Stedet blev ikke fundet");
            }
            //create a polygon of the address
            var geometry = CreatePolyFromAddress(geoSearchAddress);
            var envelope = geometry.Envelope;

            var activeView = ((IActiveView)_factory.MxDocument.FocusMap);

            //verify that the map has e spatial reference
            if (activeView.FocusMap.SpatialReference == null || activeView.FocusMap.SpatialReference.FactoryCode == 0)
            {
                //TODO move message to a resource file
                throw new PlaceFinderException("Spatial reference of map is not set");
            }

            //get the smallest allowed zoom ratio and calculate it to degrees
            var smallestAllowedZoomToInMetersOnX = Settings.Default.smallestAllowedZoomToInMetersOnX / (1000 * 60);
            var smallestAllowedZoomToInMetersOnY = Settings.Default.smallestAllowedZoomToInMetersOnY / (1000 * 60 * 2);

            if (Math.Abs(envelope.XMax - envelope.XMin) < smallestAllowedZoomToInMetersOnX || Math.Abs(envelope.YMax - envelope.YMin) < smallestAllowedZoomToInMetersOnY)
            {
                //get the center of the current envelope
                var centroidEx = ((IGeometry5)envelope).CentroidEx;
                //resize the envelope to the minimum size
                envelope.XMax = centroidEx.X + smallestAllowedZoomToInMetersOnX / 2;
                envelope.YMax = centroidEx.Y + smallestAllowedZoomToInMetersOnY / 2;
                envelope.XMin = centroidEx.X - smallestAllowedZoomToInMetersOnX / 2;
                envelope.YMin = centroidEx.Y - smallestAllowedZoomToInMetersOnY / 2;
            }

            //project the envelope to the spatial reference of the map
            envelope.Project(activeView.FocusMap.SpatialReference);
            //add the envelpe as extent on the map
            activeView.Extent = envelope;
            //refres the map to zoom
            activeView.Refresh();
        }
コード例 #6
0
        public FactoryBuilder(GeoSearchAddress resultAddress)
        {
            var geosearchService = Make.GeosearchService.WithResult(resultAddress).Build;

            Build.Stub(factory => factory.GeosearchService).Return(geosearchService);
            var mxDocument = Make.Esri.MxDocument.Build;

            Build.Stub(factory => factory.MxDocument).Return(mxDocument);
            var placeFinderDockableWindow = Make.PlaceFinderDockableWindow.Build;

            Build.Stub(factory => factory.PlaceFinderDockableWindow).Return(placeFinderDockableWindow);
            var spatialReferenceFactory3 = Make.Esri.SpatialReferenceFactory.Build;

            Build.Stub(factory => factory.SpatialReferenceFactory).Return(spatialReferenceFactory3);
            var geometry = Make.Esri.Geometry.Build;

            ConvertWKTToGeometryReturns(geometry);
        }
コード例 #7
0
        private IGeometry CreatePolyFromAddress(GeoSearchAddress geoAddress)
        {
            if (geoAddress == null)
            {
                return(null);
            }

            //convert the address WKT geometry to esri geometry
            var convertWktToGeometry = _factory.ConvertWKTToGeometry(geoAddress.geometryWkt);

            //create the spatial reference of wgs1984 reflection that of the request services
            var coordinateSystem        = esriSRGeoCSType.esriSRGeoCS_WGS1984;
            var spatialReferenceFactory = _factory.SpatialReferenceFactory;
            var spatialReference        = spatialReferenceFactory.CreateSpatialReference((int)coordinateSystem);

            convertWktToGeometry.SpatialReference = spatialReference;

            return(convertWktToGeometry);
        }
コード例 #8
0
        private IGeometry CreatePolyFromAddress(GeoSearchAddress geoAddress)
        {
            if (geoAddress == null)
            {
                return(null);
            }

            //convert the address WKT geometry to esri geometry
            var convertWktToGeometry = _factory.ConvertWKTToGeometry(geoAddress.geometryWkt);

            //create the spatial reference of etrs89 (the default of the service)
            int epsgId = Interface.Properties.Settings.Default.EPSGCode;

            var spatialReferenceFactory = _factory.SpatialReferenceFactory;
            var spatialReference        = spatialReferenceFactory.CreateSpatialReference(epsgId);

            convertWktToGeometry.SpatialReference = spatialReference;

            return(convertWktToGeometry);
        }
コード例 #9
0
        public void TestZoomTo()
        {
            //Arrange
            var place = new GeoSearchAddress()
            {
                presentationString = "SomePlace"
            };
            IFactory factory = Make.Factory(place).Build;
            var      placeFinderController = new PlaceFinderController(factory);
            var      expetedEnvelope       = Make.Esri.Envelope.Build;

            //Act
            placeFinderController.SearchTextChange(place.presentationString);
            placeFinderController.ZoomTo(place);

            //Assert
            Validator.Map(factory.MxDocument.FocusMap)
            .NewExtentIsSet(expetedEnvelope)
            .MapIsRefresh
            .Validate();
        }
コード例 #10
0
ファイル: Make.cs プロジェクト: steenhulthin/stedfinder
 public static FactoryBuilder Factory(GeoSearchAddress resultAddress)
 {
     return(new FactoryBuilder(resultAddress));
 }
コード例 #11
0
        public void ZoomTo(GeoSearchAddress selectedAddress)
        {
            Debug.WriteLine("ZoomTo entry: " + selectedAddress);
            if (selectedAddress == null || string.IsNullOrEmpty(selectedAddress.presentationString))
            {
                throw new PlaceFinderException(Properties.Resources.noPlaceSelected);
            }

            //get the last search address
            var geoSearchAddress = currentSearch.FirstOrDefault(x => x.Equals(selectedAddress));

            if (geoSearchAddress == null)
            {
                throw new PlaceFinderException(Properties.Resources.placeNotRelocatedInList);
            }
            //create a polygon of the address
            var geometry = CreatePolyFromAddress(geoSearchAddress);
            var envelope = geometry.Envelope;

            // This check is performed to avoid nullpointer exception when testing with Rhino mocks
            // (Envelope for the geometry is not available at this point)
            if (envelope != null && envelope.LowerLeft != null)
            {
                Debug.WriteLine("Envelope for zoom");
                Debug.Indent();
                Debug.WriteLine("Geometry LowerLeft: " + envelope.LowerLeft.X + ", " + envelope.LowerLeft.Y);
                Debug.WriteLine("Geometry Extent: " + envelope.Width + ", " + envelope.Height);
            }

            var activeView = ((IActiveView)_factory.MxDocument.FocusMap);

            //verify that the map has e spatial reference
            if (activeView.FocusMap.SpatialReference == null || activeView.FocusMap.SpatialReference.FactoryCode == 0)
            {
                throw new PlaceFinderException(Properties.Resources.noSpatialReference);
            }

            //get the smallest allowed zoom ratio and calculate it to degrees
            var smallestAllowedZoomToInMetersOnX = Settings.Default.smallestAllowedZoomToInMetersOnX;
            var smallestAllowedZoomToInMetersOnY = Settings.Default.smallestAllowedZoomToInMetersOnY;

            if (Math.Abs(envelope.XMax - envelope.XMin) < smallestAllowedZoomToInMetersOnX || Math.Abs(envelope.YMax - envelope.YMin) < smallestAllowedZoomToInMetersOnY)
            {
                //get the center of the current envelope
                var centroidEx = ((IGeometry5)envelope).CentroidEx;
                //resize the envelope to the minimum size
                envelope.XMax = centroidEx.X + smallestAllowedZoomToInMetersOnX / 2;
                envelope.YMax = centroidEx.Y + smallestAllowedZoomToInMetersOnY / 2;
                envelope.XMin = centroidEx.X - smallestAllowedZoomToInMetersOnX / 2;
                envelope.YMin = centroidEx.Y - smallestAllowedZoomToInMetersOnY / 2;
            }

            // This check is performed to avoid nullpointer exception when testing with Rhino mocks
            // (Envelope for the geometry is not available at this point)
            if (envelope != null && envelope.LowerLeft != null)
            {
                Debug.WriteLine("Adapted LowerLeft: " + envelope.LowerLeft.X + ", " + envelope.LowerLeft.Y);
                Debug.WriteLine("Adapted Extent: " + envelope.Width + ", " + envelope.Height);
                Debug.Unindent();
            }

            //project the envelope to the spatial reference of the map
            envelope.Project(activeView.FocusMap.SpatialReference);
            //add the envelpe as extent on the map
            activeView.Extent = envelope;
            //refres the map to zoom
            activeView.Refresh();
        }