private void renderMap()
        {
            //calculating viewport
            PointF centerTile          = TileCoordinatesConverter.GetTileIndex(Zoom, CenterCoord);
            SizeF  viewportSizeInTiles = new SizeF((float)Size.Width / (float)tileManager.TileSize.Width, (float)Size.Height / (float)tileManager.TileSize.Height);

            topLeftTile     = new PointF(centerTile.X - viewportSizeInTiles.Width / 2.0f, centerTile.Y - viewportSizeInTiles.Height / 2.0f);
            bottomRightTile = new PointF(centerTile.X + viewportSizeInTiles.Width / 2.0f, centerTile.Y + viewportSizeInTiles.Height / 2.0f);

            //generate bitmap with tiles
            bitmap = new Bitmap(Size.Width, Size.Height);
            Graphics g = Graphics.FromImage(bitmap);

            for (int x = roundDownCoordinates(topLeftTile).X; x <= roundDownCoordinates(bottomRightTile).X; x++)
            {
                for (int y = roundDownCoordinates(topLeftTile).Y; y <= roundDownCoordinates(bottomRightTile).Y; y++)
                {
                    Tile tile = tileManager.GetTile(zoom, x, y);
                    if (tile != null)
                    {
                        g.DrawImageUnscaled(tile.Picture, getLocationForTileIndex(tile.X, tile.Y));
                    }
                }
            }
            //render overlay items
            foreach (OverlayItem item in overlayItems)
            {
                if (item.Icon != null)
                {
                    ImageAttributes attr = new ImageAttributes();
                    attr.SetColorKey(item.Transparent, item.Transparent);
                    Point loc = getLocationForCoordinates(item.Coord);
                    loc.X -= item.Offset.X;
                    loc.Y -= item.Offset.Y;
                    Rectangle destRect = new Rectangle(loc, item.Icon.Size);
                    g.DrawImage(item.Icon, destRect, 0, 0, item.Icon.Size.Width, item.Icon.Size.Height, GraphicsUnit.Pixel, attr);
                }
            }
            //render polygons
            foreach (PointF[] pointArray in polygonItems)
            {
                List <Point> locArray = new List <Point>();
                foreach (PointF p in pointArray)
                {
                    locArray.Add(getLocationForCoordinates(p));
                }
                g.DrawPolygon(polygonPen, locArray.ToArray());
            }

            g.Dispose();
            this.Invalidate();
            displayedAreaChanged(TopLeftDisplay, BottomRightDisplay, Zoom);
        }
 void OpenStreetMapViewer_MouseWheel(object sender, MouseEventArgs e)
 {
     if (e.Delta > 0)
     {
         Zoom       += 1;
         CenterCoord = TileCoordinatesConverter.GetCoordinates(zoom, getTileCoordinatesFromLocation(e.Location));
     }
     if (e.Delta < 0)
     {
         Zoom -= 1;
     }
 }
        private void OpenStreetMapViewer_MouseMove(object sender, MouseEventArgs e)
        {
            // pointed coordinate
            PointF pointTile = new PointF((float)e.X / (float)tileManager.TileSize.Width + topLeftTile.X, (float)e.Y / (float)tileManager.TileSize.Height + topLeftTile.Y);

            coordinatePointed(TileCoordinatesConverter.GetCoordinates(zoom, pointTile));
            actMousePosition = e.Location;

            //tooltip hide/ show
            if (toolTip != null)
            {
                if (e.X < toolTip.Left || e.X > toolTip.Right || e.Y < toolTip.Top || e.Y > toolTip.Bottom)
                {
                    removeToolTip();
                }
            }
            else if (startedAction == ActionType.none)
            {
                int offset = 5;
                foreach (OverlayItem item in overlayItems)
                {
                    Point loc = getLocationForCoordinates(item.Coord);
                    if (loc.X >= e.X - offset &&
                        loc.X <= e.X + offset &&
                        loc.Y >= e.Y - offset &&
                        loc.Y <= e.Y + offset)
                    {
                        addToolTip(loc, item.ToolTip);
                        break;
                    }
                }
            }

            // repaint
            if (startedAction != ActionType.none)
            {
                Invalidate();
            }
        }
 private void OpenStreetMapViewer_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (startedAction == ActionType.mark && ModifierKeys == markModifiers)
         {
             PointF pointTile = TileCoordinatesConverter.GetCoordinates(zoom, getTileCoordinatesFromLocation(e.Location));
             float  xMin      = Math.Min(lastClickedCoord.X, pointTile.X);
             float  xMax      = Math.Max(lastClickedCoord.X, pointTile.X);
             float  yMin      = Math.Min(lastClickedCoord.Y, pointTile.Y);
             float  yMax      = Math.Max(lastClickedCoord.Y, pointTile.Y);
             TopLeftCoord     = new PointF(xMin, yMax);
             BottomRightCoord = new PointF(xMax, yMin);
             coordinatesMarked(new PointF(xMin, yMax), new PointF(xMax, yMin));
         }
         if (startedAction == ActionType.move && ModifierKeys == moveModifiers)
         {
             PointF pointTile = TileCoordinatesConverter.GetCoordinates(zoom, getTileCoordinatesFromLocation(e.Location));
             PointF diff      = new PointF(lastClickedCoord.X - pointTile.X, lastClickedCoord.Y - pointTile.Y);
             CenterCoord = new PointF(CenterCoord.X + diff.X, CenterCoord.Y + diff.Y);
         }
     }
     startedAction = ActionType.none;
 }
 private void OpenStreetMapViewer_MouseDown(object sender, MouseEventArgs e)
 {
     if (startedAction == ActionType.none && e.Button == MouseButtons.Left)
     {
         lastClickedCoord = TileCoordinatesConverter.GetCoordinates(zoom, getTileCoordinatesFromLocation(e.Location));
         lastMouseClick   = e.Location;
         if (ModifierKeys == markModifiers)
         {
             startedAction = ActionType.mark;
         }
         else if (ModifierKeys == moveModifiers)
         {
             startedAction = ActionType.move;
         }
         else
         {
             startedAction = ActionType.none;
         }
     }
     else
     {
         startedAction = ActionType.none;
     }
 }
 private void OpenStreetMapViewer_MouseClick(object sender, MouseEventArgs e)
 {
     coordinateClicked(TileCoordinatesConverter.GetCoordinates(zoom, getTileCoordinatesFromLocation(e.Location)));
 }
        private Point getLocationForCoordinates(PointF coord)
        {
            PointF tileIndex = TileCoordinatesConverter.GetTileIndex(Zoom, coord);

            return(getLocationForTileIndex(tileIndex.X, tileIndex.Y));
        }