public void SimpleMapTest() { // Arrange var mappingBuilder = new MapResolver(); mappingBuilder.RegisterMap(new FakePersonMapDefinition()); // Act var result = mappingBuilder.Map<FakePersonEntity, FakePersonDto>(new FakePersonDto() { Name = "Bruno", LastName = "Bologna" }); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(FakePersonEntity)); Assert.AreEqual("Bruno", result.Name); Assert.AreEqual("Bologna", result.LastName); }
public void SimpleMapTest() { // Arrange var mappingBuilder = new MapResolver(); mappingBuilder.RegisterMap(new FakePersonMapDefinition()); // Act var result = mappingBuilder.Map<FakePersonEntity, FakePersonDto>(new FakePersonDto() { Name = "Bruno", LastName = "Bologna" }); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(FakePersonEntity)); Assert.AreEqual("Bruno", result.Name); Assert.AreEqual("Bologna", result.LastName); }
private void Draw() { IsDrawn = true; Map.Children.Clear(); if (DesignerProperties.GetIsInDesignMode(this)) { Map.Children.Add(new TextBlock { Text = "Designer preview is not currently available", Foreground = Brushes.White, FontWeight = FontWeights.Bold, FontSize = 12, Effect = new DropShadowEffect { ShadowDepth = 2, RenderingBias = RenderingBias.Performance } }); return; } var map = MapResolver.Get(Source); if (map == null) { return; } var desiredSize = new Size(map.DesiredWidth, map.DesiredHeight); var r = desiredSize.Width / desiredSize.Height; var wr = ActualWidth / desiredSize.Width; var hr = ActualHeight / desiredSize.Height; double s; if (wr < hr) { IsWidthDominant = true; Map.Width = ActualWidth; Map.Height = Map.Width / r; s = wr; OriginalPosition = new Point(0, (ActualHeight - Map.Height) * .5); Canvas.SetLeft(Map, OriginalPosition.X); Canvas.SetTop(Map, OriginalPosition.Y); } else { IsWidthDominant = false; Map.Height = ActualHeight; Map.Width = r * ActualHeight; s = hr; OriginalPosition = new Point((ActualWidth - Map.Width) * .5, 0d); Canvas.SetLeft(Map, OriginalPosition.X); Canvas.SetTop(Map, OriginalPosition.Y); } var t = new ScaleTransform(s, s); foreach (var land in map.Data) { var p = new Path { Data = Geometry.Parse(land.Data), RenderTransform = t }; land.Shape = p; Lands[land.Id] = land; Map.Children.Add(p); p.MouseEnter += POnMouseEnter; p.MouseLeave += POnMouseLeave; p.MouseMove += POnMouseMove; p.MouseDown += POnMouseDown; p.SetBinding(Shape.StrokeProperty, new Binding { Path = new PropertyPath(LandStrokeProperty), Source = this }); p.SetBinding(Shape.StrokeThicknessProperty, new MultiBinding { Converter = new ScaleStrokeConverter(), Bindings = { new Binding("LandStrokeThickness") { Source = this }, new Binding("ScaleX") { Source = t } } }); } ShowMeSomeHeat(); }
private void Draw() { IsDrawn = true; Map.Children.Clear(); if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) { Map.Children.Add(new TextBlock { Text = "Designer preview is not currently available", Foreground = new SolidColorBrush(Colors.White), FontWeight = FontWeights.Bold, FontSize = 12, //Effect = new DropShadowEffect //{ // ShadowDepth = 2, // RenderingBias = RenderingBias.Performance //} }); return; } var map = MapResolver.Get(Source); if (map == null) { return; } var desiredSize = new Size(map.DesiredWidth, map.DesiredHeight); var r = desiredSize.Width / desiredSize.Height; var wr = ActualWidth / desiredSize.Width; var hr = ActualHeight / desiredSize.Height; double s; if (wr < hr) { IsWidthDominant = true; Map.Width = ActualWidth; Map.Height = Map.Width / r; s = wr; OriginalPosition = new Point(0, (ActualHeight - Map.Height) * .5); Canvas.SetLeft(Map, OriginalPosition.X); Canvas.SetTop(Map, OriginalPosition.Y); } else { IsWidthDominant = false; Map.Height = ActualHeight; Map.Width = r * ActualHeight; s = hr; OriginalPosition = new Point((ActualWidth - Map.Width) * .5, 0d); Canvas.SetLeft(Map, OriginalPosition.X); Canvas.SetTop(Map, OriginalPosition.Y); } var t = new ScaleTransform() { ScaleX = s, ScaleY = s }; foreach (var land in map.Data) { var p = new Path { Data = GeometryHelper.Parse(land.Data), RenderTransform = t }; land.Shape = p; Lands[land.Id] = land; Map.Children.Add(p); //p.MouseEnter += POnMouseEnter; //p.MouseLeave += POnMouseLeave; //p.MouseMove += POnMouseMove; //p.MouseDown += POnMouseDown; p.SetBinding(Shape.StrokeProperty, new Binding { Path = new PropertyPath("LandStroke"), Source = this }); var behavior = new MultiBindingBehavior() { Converter = new ScaleStrokeConverter(), PropertyName = "StrokeThickness" }; behavior.Items.Add(new MultiBindingItem() { Parent = behavior.Items, Value = new Binding() { Path = new PropertyPath("LandStrokeThickness"), Source = this } }); behavior.Items.Add(new MultiBindingItem() { Parent = behavior.Items, Value = new Binding() { Path = new PropertyPath("ScaleX"), Source = t } }); Interaction.SetBehaviors(p, new BehaviorCollection() { behavior }); } ShowMeSomeHeat(); }
/// <summary> /// Initializes a new instance of the <see cref="CustomeGeoMap"/> class. /// </summary> public CustomeGeoMap() { Canvas = new Canvas(); Map = new Canvas(); Canvas.ClipToBounds = true; Map.ClipToBounds = true; Canvas.Children.Add(Map); Content = Canvas; Canvas.SetBinding(WidthProperty, new Binding { Path = new PropertyPath(ActualWidthProperty), Source = this }); Canvas.SetBinding(HeightProperty, new Binding { Path = new PropertyPath(ActualHeightProperty), Source = this }); Lands = new Dictionary <string, MapData>(); SetCurrentValue(DefaultLandFillProperty, new SolidColorBrush(Color.FromArgb(200, 255, 255, 255))); SetCurrentValue(LandStrokeProperty, new SolidColorBrush(Color.FromArgb(30, 55, 55, 55))); SetCurrentValue(LandStrokeThicknessProperty, 1.3d); SetCurrentValue(AnimationsSpeedProperty, TimeSpan.FromMilliseconds(500)); SetCurrentValue(BackgroundProperty, new SolidColorBrush(Color.FromArgb(150, 96, 125, 138))); SetCurrentValue(GradientStopCollectionProperty, new GradientStopCollection { new GradientStop(Color.FromArgb(100, 2, 119, 188), 0d), new GradientStop(Color.FromRgb(2, 119, 188), 1d), }); SetCurrentValue(HeatMapProperty, new Dictionary <string, double>()); SetCurrentValue(GeoMapTooltipProperty, new DefaultGeoMapTooltip { Visibility = Visibility.Hidden }); Canvas.Children.Add(GeoMapTooltip); SizeChanged += (sender, e) => { Draw(); }; MouseWheel += (sender, e) => { if (!EnableZoomingAndPanning) { return; } e.Handled = true; var rt = Map.RenderTransform as ScaleTransform; var p = rt == null ? 1 : rt.ScaleX; p += e.Delta > 0 ? .05 : -.05; p = p < 1 ? 1 : p; var o = e.GetPosition(this); if (e.Delta > 0) { Map.RenderTransformOrigin = new Point(o.X / ActualWidth, o.Y / ActualHeight); } Map.RenderTransform = new ScaleTransform(p, p); }; MouseDown += (sender, e) => { if (!EnableZoomingAndPanning) { return; } DragOrigin = e.GetPosition(this); }; MouseUp += (sender, e) => { if (!EnableZoomingAndPanning) { return; } var end = e.GetPosition(this); var delta = new Point(DragOrigin.X - end.X, DragOrigin.Y - end.Y); var l = Canvas.GetLeft(Map) - delta.X; var t = Canvas.GetTop(Map) - delta.Y; if (DisableAnimations) { Canvas.SetLeft(Map, l); Canvas.SetTop(Map, t); } else { Map.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(l, AnimationsSpeed)); Map.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(t, AnimationsSpeed)); } }; Loaded += (sender, e) => { lvcMap = MapResolver.Get(Source); Draw(); }; }