示例#1
0
文件: ZonesPoi.cs 项目: TNOCS/csTouch
        private void AddZone(Zone z)
        {
            try
            {
                var tbd = (from g in ZoneLayer.Graphics
                           where g.Attributes.ContainsKey("poi") && (Guid)g.Attributes["poi"] == Poi.Id
                           where g.Attributes.ContainsKey("zone") && (string)g.Attributes["zone"] == z.Title
                           select g).ToList();

                if (tbd.Any()) return;

                Execute.OnUIThread(() =>
                {
                    z.Graphic = new Graphic();
                    z.Graphic.Attributes["poi"] = Poi.Id;
                    z.Graphic.Attributes["zone"] = z.Title;

                    if (IsAreaFilled)
                    {
                        if (z.Color != null)
                        {
                            z.Graphic.Symbol = new SimpleFillSymbol
                            {
                                BorderBrush = Brushes.Black,
                                BorderThickness = 2,
                                Fill = new SolidColorBrush(z.MediaColor(0x30))
                            };
                        }
                        var poly = new Polygon { Rings = new ObservableCollection<PointCollection> { z.Points.ToPointCollection() } };
                        z.Graphic.Geometry = poly;
                    }
                    else
                    {
                        if (z.Color != null)
                        {
                            z.Graphic.Symbol = new LineSymbol
                            {
                                Width = 2,
                                Color = new SolidColorBrush(z.MediaColor())
                            };
                        }
                        var poly = new Polyline { Paths = new ObservableCollection<PointCollection> { z.Points.ToPointCollection() } };
                        z.Graphic.Geometry = poly;
                    }
                    ZoneLayer.Graphics.Add(z.Graphic);
                });
            }
            catch (Exception e)
            {
                Logger.Log("Zone Model", "Error adding zone", e.Message, Logger.Level.Error, true);
            }
        }