예제 #1
0
        private List <MapDatabase.Layer> SaveLayers()
        {
            List <MapDatabase.Layer> _Layers = new List <MapDatabase.Layer>();

            foreach (InkCanvas _InkCanvas in _canvasList.Children)
            {
                MapDatabase.Layer _Layer = new MapDatabase.Layer();
                foreach (Image _Image in _InkCanvas.Children.OfType <Image>())
                {
                    Image             img       = _Image;
                    ImageSource       imgSource = img.Source;
                    BitmapImage       bmp       = imgSource as BitmapImage;
                    string            path      = bmp.UriSource.OriginalString;
                    double            x         = InkCanvas.GetLeft(_Image);
                    double            y         = InkCanvas.GetTop(_Image);
                    double            width     = _Image.ActualWidth;
                    double            height    = _Image.ActualHeight;
                    MapDatabase.Image imga      = new MapDatabase.Image
                    {
                        Path   = path,
                        X      = x,
                        Y      = y,
                        Width  = width,
                        Height = height
                    };

                    _Layer.Images.Add(imga);
                }

                List <MapDatabase.Polygon> _Polygons = _Layer.Polygons;
                foreach (Stroke _Stroke in _InkCanvas.Strokes)
                {
                    List <Point> _Points = new List <Point>();
                    foreach (StylusPoint _StylusPoint in _Stroke.StylusPoints)
                    {
                        Point _Point = new Point();
                        _Point.X = (int)_StylusPoint.X;
                        _Point.Y = (int)_StylusPoint.Y;
                        _Points.Add(_Point);
                    }
                    MapDatabase.Polygon _Polygon = new MapDatabase.Polygon();
                    _Polygon.Color  = _Stroke.DrawingAttributes.Color;
                    _Polygon.Points = _Points;
                    _Polygons.Add(_Polygon);
                }
                _Layers.Add(_Layer);
            }
            return(_Layers);
        }
예제 #2
0
        public void SetDataInControl4CurCanvas()
        {
            try
            {
                _currentInkCanvas.Strokes.Clear();

                //Set start locations of terrorists and counterterrorist

                /*InkCanvas.SetLeft(_counterTerroristStartPos, _mapDatabase.CounterTerroristStartPos.X);
                 * InkCanvas.SetTop(_counterTerroristStartPos, _mapDatabase.CounterTerroristStartPos.Y);
                 * InkCanvas.SetLeft(_terroristStartPos, _mapDatabase.TerroristStartPos.X);
                 * InkCanvas.SetTop(_terroristStartPos, _mapDatabase.TerroristStartPos.Y);*/

                for (int i = 0; i < _mapDatabase.Layers.Count; i++)
                {
                    MapDatabase.Layer layer     = _mapDatabase.Layers[i];
                    InkCanvas         inkCanvas = (InkCanvas)_canvasList.Children[i];
                    // _currentInkCanvas = inkCanvas;
                    foreach (MapDatabase.Image image in layer.Images)
                    {
                        Image img = new Image();
                        img.Stretch = Stretch.Fill;
                        if (!File.Exists(image.Path))
                        {
                            throw new FileNotFoundException(image.Path);
                        }

                        BitmapImage bitmapImage = new BitmapImage();
                        bitmapImage.BeginInit();
                        bitmapImage.UriSource = new Uri(image.Path, UriKind.Absolute);
                        bitmapImage.EndInit();
                        img.Source = bitmapImage;

                        img.Width  = image.Width;
                        img.Height = image.Height;
                        InkCanvas.SetLeft(img, image.X);
                        InkCanvas.SetTop(img, image.Y);
                        inkCanvas.Children.Add(img);
                    }

                    foreach (MapDatabase.Polygon polygon in layer.Polygons)
                    {
                        //Create a collection of points of the current polygon
                        StylusPointCollection stylusPointCollection = new StylusPointCollection();
                        foreach (Point point in polygon.Points)
                        {
                            StylusPoint stylusPoint = new StylusPoint(point.X, point.Y);
                            stylusPointCollection.Add(stylusPoint);
                        }

                        //Add polygon as a new stroke
                        Stroke stroke = new Stroke(stylusPointCollection);
                        stroke.DrawingAttributes.Color = polygon.Color;
                        inkCanvas.Strokes.Add(stroke);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageBox.Show(ex);
            }
        }
        private List<MapDatabase.Layer> SaveLayers()
        {
            List<MapDatabase.Layer> _Layers = new List<MapDatabase.Layer>();
            foreach (InkCanvas _InkCanvas in _canvasList.Children)
            {
                MapDatabase.Layer _Layer = new MapDatabase.Layer();
                foreach (Image _Image in _InkCanvas.Children.OfType<Image>())
                {
                    Image img = _Image;
                    ImageSource imgSource = img.Source;
                    BitmapImage bmp = imgSource as BitmapImage;
                    string path = bmp.UriSource.OriginalString;
                    double x = InkCanvas.GetLeft(_Image);
                    double y = InkCanvas.GetTop(_Image);
                    double width = _Image.ActualWidth;
                    double height = _Image.ActualHeight;
                    MapDatabase.Image imga = new MapDatabase.Image
                    {
                        Path = path,
                        X = x,
                        Y = y,
                        Width = width,
                        Height = height
                    };

                    _Layer.Images.Add(imga);
                }

                List<MapDatabase.Polygon> _Polygons = _Layer.Polygons;
                foreach (Stroke _Stroke in _InkCanvas.Strokes)
                {
                    List<Point> _Points = new List<Point>();
                    foreach (StylusPoint _StylusPoint in _Stroke.StylusPoints)
                    {
                        Point _Point = new Point();
                        _Point.X = (int)_StylusPoint.X;
                        _Point.Y = (int)_StylusPoint.Y;
                        _Points.Add(_Point);
                    }
                    MapDatabase.Polygon _Polygon = new MapDatabase.Polygon();
                    _Polygon.Color = _Stroke.DrawingAttributes.Color;
                    _Polygon.Points = _Points;
                    _Polygons.Add(_Polygon);
                }
                _Layers.Add(_Layer);
            }
            return _Layers;
        }