Ejemplo n.º 1
0
        private void FinalizePolygon()
        {
            Debug.WriteLine("Finishing polygon...");

            ICoordinate firstCoordinate = _points[0];
            ICoordinate lastCoordinate  = _points.Last();

            Point first = MapAroundControl.MapToClient(firstCoordinate);
            Point last  = MapAroundControl.MapToClient(lastCoordinate);


            var rectangle = MapAroundControl.GetViewBox();

            DrawLine(rectangle, Color.Green, first, last);

            _isFinalized = true;

            Polygon polygon        = new Polygon(_points);
            Feature polygonFeature = new Feature(FeatureType.Polygon)
            {
                Polygon = polygon
            };

            _userRegionLayer.AddPolygon(polygonFeature);
            _points.Clear();
            ClearRasterLayers();
            MapAroundControl.RedrawMap();
        }
Ejemplo n.º 2
0
 private void RedrawMap()
 {
     if (MapAroundControl.InvokeRequired)
     {
         MapAroundControl.BeginInvoke(new Action(RedrawMap));
     }
     else
     {
         MapAroundControl.RedrawMap();
     }
 }
Ejemplo n.º 3
0
        private void GetCellMapButton_Click(object sender, EventArgs e)
        {
            BoundingRectangle rectangle = MapAroundControl.GetViewBox();
            double            width     = rectangle.Width;
            double            height    = rectangle.Height;

            double           cellSize = 4E-5;
            MapAroundCellMap cellMap  = new MapAroundCellMap(_mapAroundMap, rectangle, cellSize, cellSize);

            cellMap.AddPolygonObstaclesLayer((FeatureLayer)FindLayerByAlias("buildings"));
            //cellMap.AddPolygonObstaclesLayer((FeatureLayer)FindLayerByAlias("User region layer"));
            CellMapDrawerForm drawerForm = new CellMapDrawerForm(cellMap);

            drawerForm.Show();
        }
Ejemplo n.º 4
0
 private void OnMiddleClick(Point point)
 {
     if (_pathFindingUiActive == false)
     {
         return;
     }
     if (_backgroundTask == null || _backgroundTask.Status != TaskStatus.Running)
     {
         if (_startPoint == null)
         {
             _startPoint = MapAroundControl.ClientToMap(point);
         }
         else
         {
             _endPoint = MapAroundControl.ClientToMap(point);
             StartPathFinding();
         }
     }
 }
Ejemplo n.º 5
0
        private void SetViewBox() // Метод поиска ViewBox
        {
            BoundingRectangle rectangle = _mapAroundMap.CalculateBoundingRectangle();

            _initialRectangle = rectangle;
            if (rectangle.IsEmpty())
            {
                return;                      // Расчет  области данных карты
            }
            // Поправка, для того, что бы вписать данные в контрол
            double deltaY = rectangle.Width * MapAroundControl.Height / 2 /
                            MapAroundControl.Width - rectangle.Height / 2;

            // Установка нового ViewBox
            MapAroundControl.SetViewBox(new BoundingRectangle(rectangle.MinX, rectangle.MinY - deltaY,
                                                              rectangle.MaxX, rectangle.MaxY + deltaY));

            _mapAroundMap.FeatureRenderer.FlushTitles(MapAroundControl.CreateGraphics(), rectangle, 1);

            InitCellMap();
            InitPathLayer();
            InitHpaStar();
        }
Ejemplo n.º 6
0
        private void OnRightClick(Point point)
        {
            ICoordinate coordinate = MapAroundControl.ClientToMap(point);

            if (_isFinalized)
            {
                Debug.WriteLine("Clearing picture box");

                ClearRasterLayers();

                _points.Clear();
                _isFinalized = false;
            }

            if (_points.Count == 0)
            {
                _points.Add(coordinate);
            }
            else
            {
                Point firstPoint = MapAroundControl.MapToClient(_points[0]);
                int   firstDx    = Math.Abs(firstPoint.X - point.X);
                int   firstDy    = Math.Abs(firstPoint.Y - point.Y);

                if (firstDx < PolygonFinalizePixelDelta && firstDy < PolygonFinalizePixelDelta)
                {
                    FinalizePolygon();
                    return;
                }

                Point prevPoint = MapAroundControl.MapToClient(_points.Last());

                var rectangle = MapAroundControl.GetViewBox();
                DrawLine(rectangle, Color.Red, point, prevPoint);
                _points.Add(coordinate);
            }
        }
Ejemplo n.º 7
0
        private void DrawLine(BoundingRectangle rectangle, Color color, Point p0, Point p1)
        {
            int x0 = p0.X;
            int y0 = p0.Y;
            int x1 = p1.X;
            int y1 = p1.Y;

            var rectMinPixel = MapAroundControl.MapToClient(rectangle.Min);
            var rectMaxPixel = MapAroundControl.MapToClient(rectangle.Max);
            int bitmapWidth  = Math.Abs(rectMinPixel.X - rectMaxPixel.X);
            int bitmapHeight = Math.Abs(rectMinPixel.Y - rectMaxPixel.Y);

            int minX = Math.Min(p0.X, p1.X);
            int minY = Math.Min(p0.Y, p1.Y);
            int maxX = Math.Max(p0.X, p1.X);
            int maxY = Math.Max(p0.Y, p1.Y);

            if (bitmapWidth == 0)
            {
                bitmapWidth = 1;
            }
            if (bitmapHeight == 0)
            {
                bitmapHeight = 1;
            }

            Bitmap      bitmap = new Bitmap(bitmapWidth, bitmapHeight);
            RasterLayer layer;

            layer       = new RasterLayer();
            layer.Alias = $"region_line_{_rasterLayers.Count}";
            _rasterLayers.Add(layer);
            _mapAroundMap.AddLayer(layer);

            layer.AddRasterPreview(bitmap, rectangle, bitmap.Width, bitmap.Height);
            layer.Visible = true;


            //Rectangle lockRect = new Rectangle(minX, minY, maxX - minX, maxY - minY);
            Rectangle  lockRect   = new Rectangle(0, 0, bitmapWidth, bitmapHeight);
            BitmapData bitmapData = bitmap.LockBits(lockRect, ImageLockMode.WriteOnly, bitmap.PixelFormat);

            byte[] pixelBytes = { color.B, color.G, color.R, color.A };

            bool PlotPoint(int x, int y)
            {
                int plotX = x;
                int plotY = y;

                if (plotX < 0 || plotY < 0 || plotX >= bitmap.Width || plotY >= bitmap.Height)
                {
                    return(true);
                }

                int positionByte = (y * bitmap.Width + x) * pixelBytes.Length;

                Marshal.Copy(pixelBytes, 0, bitmapData.Scan0 + positionByte, pixelBytes.Length);
                //bitmap.SetPixel(plotX, plotY, color);
                return(true);
            }

            BresenhamLinePlotter plotter = new BresenhamLinePlotter();

            plotter.CastLine(new Vector2Int(x0, y0), new Vector2Int(x1, y1), PlotPoint);

            bitmap.UnlockBits(bitmapData);

            MapAroundControl.RedrawMap();
        }