void AddMark(Point pt) { Color clr = Colors.DarkRed; C1VectorPlacemark mark = new C1VectorPlacemark() { GeoPoint = pt, Label = new TextBlock() { RenderTransform = new TranslateTransform() { Y = -5 }, IsHitTestVisible = false, FontSize = 18, Foreground = new SolidColorBrush(Colors.White), Margin = new Thickness(0, 20, 0, 18), Text = idx.ToString() }, LabelPosition = LabelPosition.Top, Geometry = Utils.CreateBaloon(), Fill = root.Resources["MarkFill"] as SolidColorBrush }; mark.PointerPressed += mark_PointerPressed; mark.ManipulationStarted += mark_ManipulationStarted; mark.ManipulationDelta += mark_ManipulationDelta; mark.ManipulationCompleted += mark_ManipulationCompleted; mark.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY; vl.Children.Add(mark); vl.LabelVisibility = LabelVisibility.Visible; mark.DoubleTapped += mark_DoubleTapped; idx++; }
void mark_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) { if (!isCapture) { return; } isCapture = false; if (current != null) { vl.Children.Add(current); var currentPosition = e.Container.C1TransformToVisual(c1Maps1).TransformPoint(e.Position); current.GeoPoint = this.c1Maps1.ScreenToGeographic(new Point(currentPosition.X - offsetX, currentPosition.Y - offsetY)); var timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, 120); timer.Tick += (s, e1) => { timer.Stop(); if (root.Children.Contains(placeHolder)) { root.Children.Remove(placeHolder); } if (placeHolder != null) { placeHolder.Children.Clear(); placeHolder = null; } }; timer.Start(); } current = null; offsetX = 0; offsetY = 0; e.Handled = true; }
void AddMark(Point pt) { Color clr = Utils.GetRandomColor(128, 192); C1VectorPlacemark mark = new C1VectorPlacemark() { GeoPoint = pt, Label = new TextBlock() { RenderTransform = new TranslateTransform() { Y = -5 }, IsHitTestVisible = false, Text = idx.ToString() }, LabelPosition = LabelPosition.Top, Geometry = Utils.CreateBaloon(), Stroke = new SolidColorBrush(Colors.DarkGray), Fill = new SolidColorBrush(clr), }; mark.MouseLeftButtonDown += new MouseButtonEventHandler(mark_MouseLeftButtonDown); mark.MouseLeftButtonUp += new MouseButtonEventHandler(mark_MouseLeftButtonUp); mark.MouseMove += new MouseEventHandler(mark_MouseMove); vl.Children.Add(mark); vl.LabelVisibility = LabelVisibility.Visible; idx++; }
private void C1VectorPlacemark_Loaded(object sender, RoutedEventArgs e) { C1VectorPlacemark pl = (C1VectorPlacemark)sender; City city = (City)pl.DataContext; ToolTipService.SetToolTip(pl, city.Name + ":\n" + city.Population.ToString()); }
private void AddMark(Point position) { Color clr = Colors.DarkRed; C1VectorPlacemark mark = new C1VectorPlacemark() { GeoPoint = position, LabelPosition = LabelPosition.Top, Geometry = Utils.CreateBaloon(), Fill = new SolidColorBrush(clr), }; vl.Children.Add(mark); vl.LabelVisibility = LabelVisibility.Visible; }
private TextBlock InitLabel(C1VectorPlacemark place) { TextBlock text = place.Label as TextBlock; text.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); var desiredSize = text.DesiredSize; double left = 0; double top = 2; if (text != null) { switch (place.LabelPosition) { case LabelPosition.Center: left = left - 0.5 * desiredSize.Width; top = top - 0.5 * desiredSize.Height; break; case LabelPosition.Bottom: left = left - 0.5 * desiredSize.Width; break; case LabelPosition.Top: left = left - 0.5 * desiredSize.Width; top = top - desiredSize.Height; break; case LabelPosition.Left: left = left - desiredSize.Width; top = top - 0.5 * desiredSize.Height; break; case LabelPosition.Right: top = top - 0.5 * desiredSize.Height; break; } Canvas.SetLeft(text, left); Canvas.SetTop(text, top); } return(text); }
private Path InitShape(C1VectorPlacemark place) { Path path = new Path() { Fill = place.Fill, Stroke = place.Stroke, StrokeThickness = place.StrokeThickness, StrokeDashArray = place.StrokeDashArray, StrokeStartLineCap = place.StrokeStartLineCap, StrokeEndLineCap = place.StrokeEndLineCap, StrokeDashCap = place.StrokeDashCap, StrokeLineJoin = place.StrokeLineJoin, StrokeDashOffset = place.StrokeDashOffset, StrokeMiterLimit = place.StrokeMiterLimit, Data = place.Geometry }; shapes.Add(place, path); return(path); }
void mark_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) { current = sender as C1VectorPlacemark; if (current == null || !isCapture) { return; } vl.Children.Remove(current); if (placeHolder == null) { placeHolder = new Canvas(); Shape shape = null; if (shapes.Keys.Contains(current)) { shape = shapes[current]; } else { shape = InitShape(current); } placeHolder.Children.Add(shape); var textBlock = InitLabel(current); placeHolder.Children.Add(textBlock); var pt = this.c1Maps1.GeographicToScreen(this.current.GeoPoint); var currentPosition = e.Container.C1TransformToVisual(c1Maps1).TransformPoint(e.Position); offsetX = currentPosition.X - pt.X; offsetY = currentPosition.Y - pt.Y; placeHolder.RenderTransform = new TranslateTransform() { X = pt.X, Y = pt.Y }; } if (!this.root.Children.Contains(placeHolder)) { this.root.Children.Add(placeHolder); } e.Handled = true; }
public static void UpdataMapMark(C1VectorLayer vectorLayer, C1VectorLayer scaleLayer, bool isPhone) #endif { vectorLayer.Children.Clear(); #if WINDOWS_UWP if (!isPhone) { scaleLayer.Children.Clear(); } #endif var regionSalesCollection = new ListCollectionView(DataService.GetService().GetRegionWiseSales()); regionSalesCollection.SortDescriptions.Add(new SortDescription("Sales", ListSortDirection.Descending)); #if WPF double maxValue = (regionSalesCollection.GetItemAt(0) as RegionSaleItem).Sales; #elif WINDOWS_UWP double maxValue = (regionSalesCollection.ElementAt(0) as RegionSaleItem).Sales; #endif foreach (RegionSaleItem sales in regionSalesCollection) { C1VectorPlacemark mark = new C1VectorPlacemark(); mark.Label = string.Format("{0:C}", sales.Sales); mark.LabelPosition = LabelPosition.Center; mark.Geometry = CreateMarkBySale(sales.Sales, maxValue); mark.Fill = sales.Profit > 0 ? new SolidColorBrush(Colors.Orange) : new SolidColorBrush(Colors.RoyalBlue); mark.GeoPoint = sales.Locat; vectorLayer.Children.Add(mark); #if WINDOWS_UWP if (!isPhone) { C1VectorPlacemark clone = new C1VectorPlacemark(); clone.Label = mark.Label; clone.LabelPosition = mark.LabelPosition; clone.Geometry = mark.Geometry; clone.Fill = mark.Fill; clone.GeoPoint = sales.Locat; scaleLayer.Children.Add(clone); } #endif } }
public void SetStores(IEnumerable <Store> shops) { _stores = shops.ToList(); foreach (var shop in shops) { var mark = new C1VectorPlacemark { Tag = shop.City, GeoPoint = new Point(shop.Location.X, shop.Location.Y), Label = new TextBlock() { IsHitTestVisible = false, Text = shop.City }, LabelPosition = LabelPosition.Top, Geometry = CreateBaloon(), Fill = new SolidColorBrush(Colors.LimeGreen), Opacity = 0.7 }; mark.MouseLeftButtonDown += Mark_MouseLeftButtonDown; _layer.Children.Add(mark); } }
void Grid_Loaded(object sender, RoutedEventArgs e) { Color fc = Colors.LightGray;// Color.FromArgb(0xff, 0xC0, 0x50, 0x4d); Color bk = Color.FromArgb(0xff, 0x44, 0x44, 0x44); Color bb = Colors.Black; maps.Foreground = new SolidColorBrush(fc); maps.Background = new SolidColorBrush(bk); maps.BorderBrush = new SolidColorBrush(bb); vl = new C1VectorLayer(); SolidColorBrush stroke = new SolidColorBrush(Colors.LightGray); for (int lon = -180; lon <= 180; lon += 30) { DoubleCollection dc = new DoubleCollection(); dc.Add(1); dc.Add(2); C1VectorPolyline pl = new C1VectorPolyline() { Stroke = stroke }; PointCollection pc = new PointCollection(); pc.Add(new Point(lon, -85)); pc.Add(new Point(lon, +85)); pl.Points = pc; vl.Children.Insert(0, pl); string lbl = Math.Abs(lon).ToString() + Strings.Degree; if (lon > 0) { lbl += Strings.East; } else if (lon < 0) { lbl += Strings.West; } C1VectorPlacemark pm = new C1VectorPlacemark() { GeoPoint = new Point(lon, 0), Label = lbl, LabelPosition = LabelPosition.Top }; vl.Children.Add(pm); } for (int lat = -80; lat <= 80; lat += 20) { DoubleCollection dc = new DoubleCollection(); dc.Add(1); dc.Add(2); C1VectorPolyline pl = new C1VectorPolyline() { Stroke = stroke }; PointCollection pc = new PointCollection(); pc.Add(new Point(-180, lat)); pc.Add(new Point(180, lat)); pl.Points = pc; vl.Children.Insert(0, pl); string lbl = Math.Abs(lat).ToString() + Strings.Degree; if (lat > 0) { lbl += Strings.North; } else if (lat < 0) { lbl += Strings.South; } C1VectorPlacemark pm = new C1VectorPlacemark() { GeoPoint = new Point(0, lat), Label = lbl, LabelPosition = LabelPosition.Right }; vl.Children.Add(pm); } maps.Layers.Add(vl); }
public Grid() { InitializeComponent(); Color fc = Colors.LightGray;// Color.FromArgb(0xff, 0xC0, 0x50, 0x4d); Color bk = Color.FromArgb(0xff, 0x44, 0x44, 0x44); Color bb = Colors.Black; maps.Foreground = new SolidColorBrush(fc); maps.Background = new SolidColorBrush(bk); maps.BorderBrush = new SolidColorBrush(bb); vl = new C1VectorLayer(); SolidColorBrush stroke = new SolidColorBrush(Colors.LightGray); for (int lon = -180; lon <= 180; lon += 30) { DoubleCollection dc = new DoubleCollection(); dc.Add(1); dc.Add(2); C1VectorPolyline pl = new C1VectorPolyline() { Stroke=stroke, StrokeDashArray=dc}; PointCollection pc = new PointCollection(); pc.Add( new Point(lon, -85)); pc.Add( new Point(lon, +85)); pl.Points = pc; vl.Children.Insert(0,pl); string lbl = Math.Abs(lon).ToString() + "°"; if (lon > 0) lbl += "E"; else if (lon < 0) lbl += "W"; C1VectorPlacemark pm = new C1VectorPlacemark() { GeoPoint = new Point(lon,0), Label = lbl, LabelPosition = LabelPosition.Top }; vl.Children.Add(pm); } for (int lat = -80; lat <= 80; lat += 20) { DoubleCollection dc = new DoubleCollection(); dc.Add(1); dc.Add(2); C1VectorPolyline pl = new C1VectorPolyline() { Stroke = stroke, StrokeDashArray=dc }; PointCollection pc = new PointCollection(); pc.Add(new Point(-180,lat)); pc.Add(new Point(180, lat)); pl.Points = pc; vl.Children.Insert(0,pl); string lbl = Math.Abs(lat).ToString() + "°"; if (lat > 0) lbl += "N"; else if( lat<0) lbl += "S"; C1VectorPlacemark pm = new C1VectorPlacemark() { GeoPoint = new Point(0, lat), Label = lbl, LabelPosition = LabelPosition.Right }; vl.Children.Add(pm); } maps.Layers.Add(vl); }
void mark_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { C1VectorPlacemark pm = (C1VectorPlacemark)sender; if (Keyboard.Modifiers == ModifierKeys.Shift) { e.Handled = true; if (pm.CaptureMouse()) { current = pm; offset = e.GetPosition(current); } } else if (Keyboard.Modifiers == ModifierKeys.Alt) { e.Handled = true; vl.Children.Remove(pm); } }
void mark_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { C1VectorPlacemark pm = (C1VectorPlacemark)sender; if (pm != null) pm.ReleaseMouseCapture(); current = null; }
public Grid() { InitializeComponent(); Color fc = Colors.LightGray;// Color.FromArgb(0xff, 0xC0, 0x50, 0x4d); Color bk = Color.FromArgb(0xff, 0x44, 0x44, 0x44); Color bb = Colors.Black; maps.Foreground = new SolidColorBrush(fc); maps.Background = new SolidColorBrush(bk); maps.BorderBrush = new SolidColorBrush(bb); vl = new C1VectorLayer(); SolidColorBrush stroke = new SolidColorBrush(Colors.LightGray); for (int lon = -180; lon <= 180; lon += 30) { DoubleCollection dc = new DoubleCollection(); dc.Add(1); dc.Add(2); C1VectorPolyline pl = new C1VectorPolyline() { Stroke = stroke, StrokeDashArray = dc }; PointCollection pc = new PointCollection(); pc.Add(new Point(lon, -85)); pc.Add(new Point(lon, +85)); pl.Points = pc; vl.Children.Insert(0, pl); string lbl = Math.Abs(lon).ToString() + "°"; if (lon > 0) { lbl += "E"; } else if (lon < 0) { lbl += "W"; } C1VectorPlacemark pm = new C1VectorPlacemark() { GeoPoint = new Point(lon, 0), Label = lbl, LabelPosition = LabelPosition.Top }; vl.Children.Add(pm); } for (int lat = -80; lat <= 80; lat += 20) { DoubleCollection dc = new DoubleCollection(); dc.Add(1); dc.Add(2); C1VectorPolyline pl = new C1VectorPolyline() { Stroke = stroke, StrokeDashArray = dc }; PointCollection pc = new PointCollection(); pc.Add(new Point(-180, lat)); pc.Add(new Point(180, lat)); pl.Points = pc; vl.Children.Insert(0, pl); string lbl = Math.Abs(lat).ToString() + "°"; if (lat > 0) { lbl += "N"; } else if (lat < 0) { lbl += "S"; } C1VectorPlacemark pm = new C1VectorPlacemark() { GeoPoint = new Point(0, lat), Label = lbl, LabelPosition = LabelPosition.Right }; vl.Children.Add(pm); } maps.Layers.Add(vl); }