private static void filterSelected(ILayer layer, IMapView2D view, IExtents worldBounds) { if (layer == null) { return; } FeatureLayer filterLayer = layer as FeatureLayer; if (filterLayer != null) { if (layer.Enabled && filterLayer.AreFeaturesSelectable && layer.IsVisibleWhen(isInView(view.WorldWidth))) { SpatialBinaryExpression spatialExpression = SpatialBinaryExpression.Intersects(new FeaturesCollectionExpression(filterLayer.Features), new ExtentsExpression(worldBounds)); filterLayer.SelectedFilter = filterLayer.SelectedFilter == null ? new FeatureQueryExpression(new AllAttributesExpression(), spatialExpression, null) : new FeatureQueryExpression(filterLayer.SelectedFilter, spatialExpression); } } IEnumerable <ILayer> layers = layer as IEnumerable <ILayer>; if (layers != null) { foreach (ILayer child in layers) { filterSelected(child, view, worldBounds); } } }
public void InitalizingMapPresenterWithNonEmptyMapHasUndefinedView() { MockRepository mocks = new MockRepository(); Map map = new Map(_factories.GeoFactory); map.AddLayer(DataSourceHelper.CreateFeatureFeatureLayer(_factories.GeoFactory)); IMapView2D mapView = mocks.Stub <IMapView2D>(); SetupResult.For(mapView.Dpi).Return(ScreenHelper.Dpi); mapView.ViewSize = new Size2D(1000, 1000); mocks.ReplayAll(); TestPresenter2D mapPresenter = new TestPresenter2D(map, mapView); //Assert.Equal(map.Center[Ordinates.X], mapPresenter.GeoCenter[Ordinates.X]); //Assert.Equal(map.Center[Ordinates.Y], mapPresenter.GeoCenter[Ordinates.Y]); Assert.Equal(0, mapPresenter.WorldWidth); Assert.Equal(0, mapPresenter.WorldHeight); Assert.Equal(0, mapPresenter.WorldUnitsPerPixel); Assert.Equal(1, mapPresenter.WorldAspectRatio); Assert.Equal(0, mapPresenter.PixelWorldWidth); Assert.Equal(0, mapPresenter.PixelWorldHeight); Assert.Equal(null, mapPresenter.ToViewTransform); Assert.Equal(null, mapPresenter.ToWorldTransform); }
private void testBeginZoomIn(ActionContext <IMapView2D, Point2D> context) { IMapView2D view = context.MapView; view.Selection.Clear(); view.Selection.AddPoint(context.CurrentPoint); }
private static Rectangle2D endSelection(ActionContext <IMapView2D, Point2D> context) { IMapView2D view = context.MapView; view.Selection.Close(); return(view.Selection.Path.Bounds); }
public void ConfigureMapView(IMapView2D mapView) { mapView.ViewSize = OutputSize; if (RealWorldBounds == null) mapView.ZoomToExtents(); else mapView.ZoomToWorldBounds(RealWorldBounds); }
private static void ContinuePan(ActionContext <IMapView2D, Point2D> context) { IMapView2D view = context.MapView; Point2D previousPoint = context.PreviousPoint; Point2D currentPoint = context.CurrentPoint; Point2D difference = previousPoint - currentPoint; view.Offset(difference); }
public void ConfigureMapView(IMapView2D mapView) { mapView.ViewSize = OutputSize; if (RealWorldBounds == null) { mapView.ZoomToExtents(); } else { mapView.ZoomToWorldBounds(RealWorldBounds); } }
private static void beginSelection(ActionContext <IMapView2D, Point2D> context) { IMapView2D view = context.MapView; // NOTE: changed Point.Empty to null if (view.GeoCenter == null) { throw new InvalidOperationException("No visible region is set for this view."); } view.Selection.Clear(); view.Selection.AddPoint(context.CurrentPoint); }
private void testEndZoomIn(ActionContext <IMapView2D, Point2D> context) { IMapView2D view = context.MapView; if (view.Selection.Path.Points.Count == 1) { zoomByFactor(view, context.CurrentPoint, 1.2); // 0.83333333333333337 } else { view.Selection.Close(); context.MapView.ZoomToViewBounds(view.Selection.Path.Bounds); } }
private TestPresenter2D createPresenter(MockRepository mocks, Double width, Double height) { Map map = new Map(_factories.GeoFactory); map.AddLayer(DataSourceHelper.CreateFeatureFeatureLayer(_factories.GeoFactory)); //map.AddLayer(DataSourceHelper.CreateGeometryFeatureLayer()); IMapView2D mapView = mocks.Stub <IMapView2D>(); SetupResult.For(mapView.Dpi).Return(ScreenHelper.Dpi); mapView.ViewSize = new Size2D(width, height); TestPresenter2D mapPresenter = new TestPresenter2D(map, mapView); return(mapPresenter); }
private static void zoomByFactor(ActionContext <IMapView2D, Point2D> context, Double zoomFactor) { IMapView2D view = context.MapView; zoomFactor = 1 / zoomFactor; Size2D viewSize = view.ViewSize; Point2D viewCenter = new Point2D((viewSize.Width / 2), (viewSize.Height / 2)); Point2D viewDifference = context.CurrentPoint - viewCenter; Point2D zoomUpperLeft = new Point2D(viewDifference.X * zoomFactor, viewDifference.Y * zoomFactor); Size2D zoomBoundsSize = new Size2D(viewSize.Width * zoomFactor, viewSize.Height * zoomFactor); Rectangle2D zoomViewBounds = new Rectangle2D(zoomUpperLeft, zoomBoundsSize); view.ZoomToViewBounds(zoomViewBounds); }
/// <summary> /// Close the view's selection and set the map's GeometryFilter. /// </summary> /// <param name="context"> /// An <see cref="ActionContext{IMapView2D, Point2D}"/> which provides /// information about where, and on which view, the action occurred. /// </param> private static void EndQuery(ActionContext <IMapView2D, Point2D> context) { IMapView2D view = context.MapView; Rectangle2D viewBounds = endSelection(context); // Create a BoundingBox for the view's selection using the map's world space IExtents worldBounds = context.Map.GeometryFactory.CreateExtents( view.ToWorld(viewBounds.LowerLeft), view.ToWorld(viewBounds.UpperRight)); // Apply the GeometryFilter derived from the view's selection for (Int32 i = context.Map.Layers.Count - 1; i >= 0; i--) { filterSelected(context.Map.Layers[i], view, worldBounds); } }
public void GettingGeoCenterOnUndefinedViewFails() { MockRepository mocks = new MockRepository(); Map map = new Map(_factories.GeoFactory); IMapView2D mapView = mocks.Stub <IMapView2D>(); SetupResult.For(mapView.Dpi).Return(ScreenHelper.Dpi); mapView.ViewSize = new Size2D(200, 400); mocks.ReplayAll(); TestPresenter2D mapPresenter = new TestPresenter2D(map, mapView); // Changed to null from Point.Empty Assert.Throws <InvalidOperationException>(delegate { Assert.Equal(null, mapPresenter.GeoCenter); }); }
private static void zoomByFactor(IMapView2D view, Point2D zoomCenter, Double zoomFactor) { zoomFactor = 1 / zoomFactor; Size2D viewSize = view.ViewSize; Point2D viewCenter = new Point2D((viewSize.Width / 2), (viewSize.Height / 2)); Point2D viewDifference = zoomCenter - viewCenter; Size2D zoomBoundsSize = new Size2D(viewSize.Width * zoomFactor, viewSize.Height * zoomFactor); Double widthDifference = zoomBoundsSize.Width - viewSize.Width; Double heightDifference = zoomBoundsSize.Height - viewSize.Height; Point2D zoomUpperLeft = new Point2D(viewDifference.X * zoomFactor - widthDifference / 2, viewDifference.Y * zoomFactor - heightDifference / 2); Rectangle2D zoomViewBounds = new Rectangle2D(zoomUpperLeft, zoomBoundsSize); view.ZoomToViewBounds(zoomViewBounds); }
public void TransformingPointFromWorldToViewOnUndefinedViewFails() { MockRepository mocks = new MockRepository(); Map map = new Map(_factories.GeoFactory); IMapView2D mapView = mocks.Stub <IMapView2D>(); SetupResult.For(mapView.Dpi).Return(ScreenHelper.Dpi); mapView.ViewSize = new Size2D(200, 400); mocks.ReplayAll(); TestPresenter2D mapPresenter = new TestPresenter2D(map, mapView); Assert.Throws <InvalidOperationException>(delegate { Assert.Equal(Point2D.Empty, mapPresenter.ToView( _factories.GeoFactory.CoordinateFactory. Create(50, 50))); }); }
public void InitalizingMapPresenterWithEmptyMapHasUndefinedView() { MockRepository mocks = new MockRepository(); Map map = new Map(_factories.GeoFactory); IMapView2D mapView = mocks.Stub <IMapView2D>(); SetupResult.For(mapView.Dpi).Return(ScreenHelper.Dpi); mapView.ViewSize = new Size2D(200, 400); mocks.ReplayAll(); TestPresenter2D mapPresenter = new TestPresenter2D(map, mapView); Assert.Equal(0, mapPresenter.WorldWidth); Assert.Equal(0, mapPresenter.WorldHeight); Assert.Equal(0, mapPresenter.WorldUnitsPerPixel); Assert.Equal(1, mapPresenter.WorldAspectRatio); Assert.Equal(0, mapPresenter.PixelWorldWidth); Assert.Equal(0, mapPresenter.PixelWorldHeight); Assert.Equal(null, mapPresenter.ToViewTransform); Assert.Equal(null, mapPresenter.ToWorldTransform); }
public void ConfigureMapView(IMapView2D mapView) { mapView.ViewSize = OutputSize; mapView.BackgroundColor = BackgroundColor; mapView.ZoomToWorldBounds(RealWorldBounds); }
public TestPresenter2D(Map map, IMapView2D mapView) : base(map, mapView) { }
private static void filterSelected(ILayer layer, IMapView2D view, IExtents worldBounds) { if (layer == null) { return; } FeatureLayer filterLayer = layer as FeatureLayer; if (filterLayer != null) { if (layer.Enabled && filterLayer.AreFeaturesSelectable && layer.IsVisibleWhen(isInView(view.WorldWidth))) { SpatialBinaryExpression spatialExpression = SpatialBinaryExpression.Intersects(new FeaturesCollectionExpression(filterLayer.Features), new ExtentsExpression(worldBounds)); filterLayer.SelectedFilter = filterLayer.SelectedFilter == null ? new FeatureQueryExpression(new AllAttributesExpression(), spatialExpression, null) : new FeatureQueryExpression(filterLayer.SelectedFilter, spatialExpression); } } IEnumerable<ILayer> layers = layer as IEnumerable<ILayer>; if (layers != null) { foreach (ILayer child in layers) { filterSelected(child, view, worldBounds); } } }