Exemple #1
0
        public static void UpdateUI(RouteMap control)
        {
            if (control.MarksEllipseList == null)
            {
                control.MarksEllipseList = new List <CustomControls.RouteMark>();
            }


            // set map image
            control.MapImage = new BitmapImage(new Uri("pack://application:,,,/RouteMarksViewer;component/assets/icons/map.png"));
            if (control.CurrentMap.Count > 0)
            {
                if (control.CurrentMap[0].MapImage != "" && File.Exists(AppDomain.CurrentDomain.BaseDirectory + "maps/" + control.CurrentMap[0].MapImage))
                {
                    control.MapImage = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "maps/" + control.CurrentMap[0].MapImage));
                }
            }

            // remove deleted
            for (int i = control.MarksEllipseList.Count - 1; i >= 0; i--)
            {
                if (control.CurrentMap.FirstOrDefault(o => o.MarkId == control.MarksEllipseList[i].MarkId) == null)
                {
                    foreach (UIElement mark in control.ImageCanvas.Children)
                    {
                        if (mark is RouteMark && (mark as RouteMark).MarkId == control.MarksEllipseList[i].MarkId)
                        {
                            control.ImageCanvas.Children.Remove(mark);
                            break;
                        }
                    }
                    control.MarksEllipseList.Remove(control.MarksEllipseList[i]);
                }
            }


            //set marks in stack (if without coords) or on map
            int skip_mark_count = 0;

            for (int i = 0; i < control.CurrentMap.Count; i++)
            {
                CustomControls.RouteMark mark_ellipse = new RouteMark();

                mark_ellipse.LabelMarkText = control.CurrentMap[i].Mark != null ? control.CurrentMap[i].Mark.Name : "Mark " + (i + 1);

                mark_ellipse.Name   = "Mark_" + Convert.ToString(i);
                mark_ellipse.MarkId = control.CurrentMap[i].MarkId;
                try
                {
                    mark_ellipse.FillOfEllipse = control.CurrentMap[i].MarkColor == null ? Brushes.White : new SolidColorBrush(
                        (Color)ColorConverter.ConvertFromString(control.CurrentMap[i].MarkColor));
                }
                catch
                {
                    mark_ellipse.FillOfEllipse = Brushes.White;
                }
                mark_ellipse.MarkWidth  = control.MARK_ELLIPSE_DEFAULT_WIDTH;
                mark_ellipse.MarkHeight = control.MARK_ELLIPSE_DEFAULT_HEIGHT;
                TextBlock textBlock_tooltip = new TextBlock();
                textBlock_tooltip.Foreground = Brushes.Black;
                textBlock_tooltip.Text       = control.CurrentMap[i].Mark != null ? control.CurrentMap[i].Mark.Name : "Mark " + (i + 1);
                mark_ellipse.ToolTip         = textBlock_tooltip;

                bool not_has_in_mark_list = false;
                if (control.MarksEllipseList.FirstOrDefault(o => o.MarkId == control.CurrentMap[i].MarkId) == null)
                {
                    control.MarksEllipseList.Add(mark_ellipse);
                    not_has_in_mark_list = true;
                }
                else
                {
                    skip_mark_count++;
                }

                if (control.CurrentMap[i].CoordX == 0 && control.CurrentMap[i].CoordY == 0)
                {
                    mark_ellipse.Margin = new Thickness(0, 20 * (i - skip_mark_count), 0, 0);
                    control.ImageCanvas.Children.Add(mark_ellipse);
                }
                else if (not_has_in_mark_list)
                {
                    control.ImageCanvas.Children.Add(mark_ellipse);
                }
            }
        }
Exemple #2
0
        private static void CurrentMap_PropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            RouteMap control = obj as RouteMap;

            UpdateUI(control);
        }