private void mapViewer_Loaded(object sender, RoutedEventArgs e) { mapViewer.Init(); FileStream fsRead = new FileStream("./db/map.json", FileMode.Open); int fsLen = (int)fsRead.Length; byte[] heByte = new byte[fsLen]; int r = fsRead.Read(heByte, 0, heByte.Length); string json = System.Text.Encoding.GetEncoding("gb2312").GetString(heByte); AgvMap plan = JsonConvert.DeserializeObject <AgvMap>(json); mapViewer.SetMap(plan); mapViewer.setAgvs(); }
public void SetMap(AgvMap map) { _map = map; bgMapLayer.Children.Clear(); cardLayer.Children.Clear(); if (_map != null) { var path = new Path(); path.StrokeThickness = 3.0; path.Stroke = Brushes.Blue; var pathGeometry = new PathGeometry(); foreach (AgvMapPath p in _map.Paths) { Point point1 = new Point(p.Position1X, p.Position1Y); var pathFigure = new PathFigure { StartPoint = point1 }; Point point2 = new Point(p.Position2X, p.Position2Y); pathFigure.Segments.Add(new LineSegment { Point = point2 }); pathGeometry.Figures.Add(pathFigure); } path.Data = pathGeometry; bgMapLayer.Children.Add(path); foreach (AgvMapCard c in _map.Cards) { CardMarker cm = new CardMarker(c.CardId); cm.SetValue(Canvas.LeftProperty, (double)c.PositionX - cm.OffsetX); cm.SetValue(Canvas.TopProperty, (double)c.PositionY - cm.OffsetY); //cm.Visibility = Visibility.Visible; cardLayer.Children.Add(cm); } } }