예제 #1
0
        //声明回调函数方法
        private static void OnSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            PWMap map = (PWMap)sender;

            try
            {
                System.IO.Stream       sm   = Assembly.GetExecutingAssembly().GetManifestResourceStream("PW.Controls.Maps." + map.MapSource + ".xml");
                System.Xml.XmlDocument docc = new System.Xml.XmlDocument();
                docc.Load(sm);
                XDocument doc  = XDocument.Parse(docc.InnerXml);
                var       xdoc = from t in doc.Descendants("LiveChartsMap")              //定位到节点 
                                 select new
                {
                    Width  = t.Element("Width").Value,
                    Height = t.Element("Height").Value,
                    Shapes = t.Element("Shapes").Elements()
                };
                if (map.mycanvas != null)
                {
                    map.mainCanvas.Width  = double.Parse(xdoc.ElementAt(0).Width);
                    map.mainCanvas.Height = double.Parse(xdoc.ElementAt(0).Height);

                    map.mycanvas.Children.Clear();
                    map.nameView.Children.Clear();
                    foreach (var item in xdoc.ElementAt(0).Shapes)
                    {
                        Path path = new Path();
                        // path.Fill = new SolidColorBrush(Colors.Green);
                        path.Data               = Geometry.Parse(item.Element("Path").Value);
                        path.ToolTip            = item.Element("Text") == null || string.IsNullOrEmpty(item.Element("Text").Value) ? item.Element("Name").Value : item.Element("Text").Value;
                        path.MouseLeftButtonUp += Path_MouseLeftButtonUp;
                        path.Tag = item.Element("Name").Value;
                        map.mycanvas.Children.Add(path);

                        if (item.Element("Top") != null)
                        {
                            StackPanel sp = new StackPanel();
                            TextBlock  tb = new TextBlock();
                            tb.Text = item.Element("Text") == null || string.IsNullOrEmpty(item.Element("Text").Value) ?item.Element("Name").Value: item.Element("Text").Value;
                            sp.Children.Add(tb);
                            Canvas.SetLeft(sp, double.Parse(item.Element("Left").Value));
                            Canvas.SetTop(sp, double.Parse(item.Element("Top").Value));
                            map.nameView.Children.Add(sp);
                        }
                    }
                    //<StackPanel Name="spSymbleXZ" Canvas.Left="178" Canvas.Top="390">
                    //    <TextBlock Text="西藏" />
                    //</StackPanel>
                }
            }
            catch (Exception ex)
            {
            }
        }
예제 #2
0
        //声明回调函数方法
        private static void OnDataChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            PWMap map = (PWMap)sender;

            try
            {
                if (map.MapData != null && map.MapData.Rows.Count > 0)
                {
                    map.loadData(map, map.MapData);
                }
            }
            catch (Exception ex)
            {
            }
        }
예제 #3
0
        void loadData(PWMap map, DataTable dt)
        {
            List <Color> list = new List <Color>();

            list.Add((Color)ColorConverter.ConvertFromString("#880cd8f1"));
            list.Add((Color)ColorConverter.ConvertFromString("#88397aed"));
            list.Add((Color)ColorConverter.ConvertFromString("#88ffda4b"));
            list.Add((Color)ColorConverter.ConvertFromString("#88f62c61"));
            double sum = int.Parse(dt.Compute("Sum(cntm)+Sum(cntf)", "true").ToString());

            foreach (var item in map.mycanvas.Children)
            {
                if (item is Path)
                {
                    Path      path = item as Path;
                    DataRow[] rows = dt.Select("name='" + path.ToolTip.ToString() + "'");
                    if (rows != null && rows.Length > 0)
                    {
                        double rate = (int.Parse(rows[0]["cntm"].ToString()) + int.Parse(rows[0]["cntf"].ToString())) / sum * 100;
                        if (rate >= 1 && rate < 4)
                        {
                            path.Fill = new SolidColorBrush(list[0]);
                        }
                        else if (rate >= 4 && rate < 7)
                        {
                            path.Fill = new SolidColorBrush(list[1]);
                        }
                        else if (rate >= 7 && rate < 10)
                        {
                            path.Fill = new SolidColorBrush(list[2]);
                        }
                        else if (rate >= 10)
                        {
                            path.Fill = new SolidColorBrush(list[3]);
                        }
                        path.ToolTip = path.ToolTip.ToString() + "(" + rate + ")" + "(" + (int.Parse(rows[0]["cntm"].ToString()) + int.Parse(rows[0]["cntf"].ToString())) + ")";
                    }
                }
            }
        }