/// <summary> /// Updates the map item geometric characteristics to the specified map bounds and scale. /// </summary> /// <param name="bounds">The map bounds.</param> /// <param name="scale">The map scale.</param> internal override void Update(MapRectangle bounds, MapScale scale) { // If the object has been disposed throw an exception. if (this.disposed) throw new ObjectDisposedException("marker"); // Compute the marker center. PointF center = new PointF( (float)((this.Location.X - bounds.Left) * scale.Width), (float)((bounds.Top - this.Location.Y) * scale.Height) ); // Lock the current path. lock (this.sync) { // Reset the graphics path. this.path.Reset(); // Add a circle to the path. this.path.AddEllipse((float)(center.X - this.Size.Width / 2.0), (float)(center.Y - this.Size.Height / 2.0), this.Size.Width, this.Size.Height); // Set the region bounds. this.bounds = this.path.GetBounds().Ceiling(); } }
/// <summary> /// Draws the item on the specified graphics object within the specified map bounds and scale. /// </summary> /// <param name="graphics">The graphics.</param> /// <param name="bounds">The bounds.</param> /// <param name="scale">The scale.</param> internal override void Draw(Graphics graphics, MapRectangle bounds, MapScale scale) { // Create the brush. using (SolidBrush brush = new SolidBrush(this.BackgroundColor)) { // Create the pen. using (Pen pen = new Pen(this.BorderColor)) { this.Draw(graphics, bounds, scale, brush, pen); } } }
/// <summary> /// Draws the item on the specified graphics object within the specified map bounds and scale. /// </summary> /// <param name="graphics">The graphics</param> /// <param name="bounds">The bounds.</param> /// <param name="scale">The scale.</param> /// <param name="brush">The brush.</param> /// <param name="pen">The pen.</param> internal override void Draw(Graphics graphics, MapRectangle bounds, MapScale scale, Brush brush, Pen pen) { // Create a new graphics path. using (GraphicsPath path = new GraphicsPath()) { // Compute the marker center. PointF center = new PointF( (float)((this.Location.X - bounds.Left) * scale.Width), (float)((bounds.Top - this.Location.Y) * scale.Height) ); // Add a circle to the path. path.AddEllipse((float)(center.X - this.Size.Width / 2.0), (float)(center.Y - this.Size.Height / 2.0), this.Size.Width, this.Size.Height); // Fill the path. if (null != brush) graphics.FillPath(brush, path); // Draw the path. if (null != pen) graphics.DrawPath(pen, path); } }
/// <summary> /// Draws the item on the specified graphics object within the specified map bounds and scale. /// </summary> /// <param name="graphics">The graphics</param> /// <param name="bounds">The bounds.</param> /// <param name="scale">The scale.</param> /// <param name="brush">The brush.</param> /// <param name="pen">The pen.</param> internal override void Draw(Graphics graphics, MapRectangle bounds, MapScale scale, Brush brush, Pen pen) { // Create a new graphics path. using (GraphicsPath path = new GraphicsPath()) { // For all shape parts. for (int indexPart = 0; indexPart < shape.Parts.Count; indexPart++) { // Update the list of points for each part polygon. for (int indexPoint = 0; indexPoint < shape.Parts[indexPart].Points.Count; indexPoint++) { this.points[indexPart][indexPoint].X = (float)((shape.Parts[indexPart].Points[indexPoint].X - bounds.Left) * scale.Width); this.points[indexPart][indexPoint].Y = (float)((bounds.Top - shape.Parts[indexPart].Points[indexPoint].Y) * scale.Height); } // Add the polygon to the graphics path. path.AddPolygon(this.points[indexPart]); } // Fill the path. if (null != brush) graphics.FillPath(brush, path); // Draw the path. if (null != pen) graphics.DrawPath(pen, path); } }
/// <summary> /// Updates the map item geometric characteristics to the specified map bounds and scale. /// </summary> /// <param name="bounds">The map bounds.</param> /// <param name="scale">The map scale.</param> internal override void Update(MapRectangle bounds, MapScale scale) { // If the object has been disposed throw an exception. if (this.disposed) throw new ObjectDisposedException("region"); lock (this.sync) { // Reset the graphics path. this.path.Reset(); // For all shape parts. for (int indexPart = 0; indexPart < shape.Parts.Count; indexPart++) { // Update the list of points for each part polygon. for (int indexPoint = 0; indexPoint < shape.Parts[indexPart].Points.Count; indexPoint++) { this.points[indexPart][indexPoint].X = (float)((shape.Parts[indexPart].Points[indexPoint].X - bounds.Left) * scale.Width); this.points[indexPart][indexPoint].Y = (float)((bounds.Top - shape.Parts[indexPart].Points[indexPoint].Y) * scale.Height); } // Add the polygon to the graphics path. this.path.AddPolygon(this.points[indexPart]); } // Set the region bounds. this.bounds = this.path.GetBounds().Ceiling(); } }
/// <summary> /// Draws the item on the specified graphics object within the specified map bounds and scale. /// </summary> /// <param name="graphics">The graphics.</param> /// <param name="bounds">The bounds.</param> /// <param name="scale">The scale.</param> internal abstract void Draw(Graphics graphics, MapRectangle bounds, MapScale scale);
/// <summary> /// Updates the map item geometric characteristics to the specified map bounds and scale. /// </summary> /// <param name="bounds">The map bounds.</param> /// <param name="scale">The map scale.</param> internal abstract void Update(MapRectangle bounds, MapScale scale);
/// <summary> /// Draws the item on the specified graphics object within the specified map bounds and scale. /// </summary> /// <param name="graphics">The graphics</param> /// <param name="bounds">The bounds.</param> /// <param name="scale">The scale.</param> /// <param name="brush">The brush.</param> /// <param name="pen">The pen.</param> internal abstract void Draw(Graphics graphics, MapRectangle bounds, MapScale scale, Brush brush, Pen pen);
/// <summary> /// Saves the current map as an image to the specified file. /// </summary> /// <param name="fileName">The file name.</param> /// <param name="properties">The export properties.</param> /// <param name="format">The image format.</param> public void SaveMap(string fileName, ExportProperties properties, ImageFormat format) { // Create a new bitmap. Bitmap bitmap = new Bitmap(properties.Size.Width, properties.Size.Height); // Compute the map scale. MapScale mapScale = new MapScale( properties.Size.Width / this.mapBounds.Width, properties.Size.Height / this.mapBounds.Height ); // Compute the grid. MapSize majorGridSize = new MapSize(1.0, 1.0); MapSize minorGridSize = new MapSize(1.0, 1.0); Point majorGridBegin; Point majorGridEnd; Point minorGridBegin; Point minorGridEnd; // Compute the grid size. majorGridSize = new MapSize( Math.Pow(10.0, Math.Floor(Math.Log10(this.mapSize.Width))), Math.Pow(10.0, Math.Floor(Math.Log10(this.mapSize.Height))) ); // Adjust the horizontal grid. if (majorGridSize.Width > 10.0) { // Select the first value than results in a displayed width greater than the minimum width. for (int index = 0; index < MapControl.majorGridValues.Length; index++) { if (majorGridValues[index] * mapScale.Width >= MapControl.majorGridMinimumSize.Width) { majorGridSize.Width = MapControl.majorGridValues[index]; minorGridSize.Width = MapControl.minorGridValues[index]; break; } } // Limit the grid size to the highest value. if (majorGridSize.Width > MapControl.majorGridValues[MapControl.majorGridValues.Length - 1]) { majorGridSize.Width = MapControl.majorGridValues[MapControl.majorGridValues.Length - 1]; minorGridSize.Width = MapControl.minorGridValues[MapControl.majorGridValues.Length - 1]; } } else { // Select the first factor that results in a displayed width greater than the minimum width. for (int index = 0; index < MapControl.majorGridFactor.Length; index++) { if (majorGridSize.Width * MapControl.majorGridFactor[index] >= MapControl.majorGridMinimumSize.Width) { majorGridSize.Width *= MapControl.majorGridFactor[index]; minorGridSize.Width = majorGridSize.Width * minorGridFactor[index]; break; } } } // Adjust the vertical grid. if (majorGridSize.Height > 10.0) { // Select the first value than results in a displayed height greater than the minimum height. for (int index = 0; index < MapControl.majorGridValues.Length; index++) { if (MapControl.majorGridValues[index] * mapScale.Height >= MapControl.majorGridMinimumSize.Height) { majorGridSize.Height = MapControl.majorGridValues[index]; minorGridSize.Height = MapControl.minorGridValues[index]; break; } } // Limit the grid size to the highest value. if (majorGridSize.Height > MapControl.majorGridValues[MapControl.majorGridValues.Length - 1]) { majorGridSize.Height = MapControl.majorGridValues[MapControl.majorGridValues.Length - 1]; minorGridSize.Height = MapControl.minorGridValues[MapControl.majorGridValues.Length - 1]; } } else { // Select the first factor that results in a displayed height greater than the minimum height. for (int index = 0; index < MapControl.majorGridFactor.Length; index++) { if (majorGridSize.Height * MapControl.majorGridFactor[index] >= MapControl.majorGridMinimumSize.Height) { majorGridSize.Height *= MapControl.majorGridFactor[index]; minorGridSize.Height = majorGridSize.Height * MapControl.minorGridFactor[index]; break; } } } // Compute the major grid begin and end. majorGridBegin = new Point( this.mapBounds.Left % majorGridSize.Width == 0 ? (int)Math.Ceiling(this.mapBounds.Left / majorGridSize.Width) + 1 : (int)Math.Ceiling(this.mapBounds.Left / majorGridSize.Width), this.mapBounds.Top % majorGridSize.Height == 0 ? (int)Math.Floor(this.mapBounds.Top / majorGridSize.Height) - 1 : (int)Math.Floor(this.mapBounds.Top / majorGridSize.Height) ); majorGridEnd = new Point( this.mapBounds.Right % majorGridSize.Width == 0 ? (int)Math.Floor(this.mapBounds.Right / majorGridSize.Width) - 1 : (int)Math.Floor(this.mapBounds.Right / majorGridSize.Width), this.mapBounds.Bottom % majorGridSize.Height == 0 ? (int)Math.Ceiling(this.mapBounds.Bottom / majorGridSize.Height) + 1 : (int)Math.Ceiling(this.mapBounds.Bottom / majorGridSize.Height) ); // Compute the minor grid begin and end. minorGridBegin = new Point( this.mapBounds.Left % minorGridSize.Width == 0 ? (int)Math.Ceiling(this.mapBounds.Left / minorGridSize.Width) + 1 : (int)Math.Ceiling(this.mapBounds.Left / minorGridSize.Width), this.mapBounds.Top % minorGridSize.Height == 0 ? (int)Math.Floor(this.mapBounds.Top / minorGridSize.Height) - 1 : (int)Math.Floor(this.mapBounds.Top / minorGridSize.Height) ); minorGridEnd = new Point( this.mapBounds.Right % minorGridSize.Width == 0 ? (int)Math.Floor(this.mapBounds.Right / minorGridSize.Width) - 1 : (int)Math.Floor(this.mapBounds.Right / minorGridSize.Width), this.mapBounds.Bottom % minorGridSize.Height == 0 ? (int)Math.Ceiling(this.mapBounds.Bottom / minorGridSize.Height) + 1 : (int)Math.Ceiling(this.mapBounds.Bottom / minorGridSize.Height) ); // Compute the horizontal major grid. double[] majorGridHorizontalCoordinate = new double[majorGridEnd.X - majorGridBegin.X + 1]; float[] majorGridHorizontalPoint = new float[majorGridHorizontalCoordinate.Length]; for (int index = 0; index < majorGridHorizontalPoint.Length; index++) { majorGridHorizontalCoordinate[index] = (majorGridBegin.X + index) * majorGridSize.Width; majorGridHorizontalPoint[index] = (float)((majorGridHorizontalCoordinate[index] - this.mapBounds.Left) * mapScale.Width); } // Compute the vertical major grid. double[] majorGridVerticalCoordinate = new double[majorGridBegin.Y - majorGridEnd.Y + 1]; float[] majorGridVerticalPoint = new float[majorGridVerticalCoordinate.Length]; for (int index = 0; index < majorGridVerticalPoint.Length; index++) { majorGridVerticalCoordinate[index] = (majorGridEnd.Y + index) * majorGridSize.Height; majorGridVerticalPoint[index] = (float)((this.mapBounds.Top - majorGridVerticalCoordinate[index]) * mapScale.Height); } // Draw the bitmap. using (Graphics graphics = Graphics.FromImage(bitmap)) { // Set the smooting mode. graphics.SmoothingMode = properties.Smoothing; using (SolidBrush brush = new SolidBrush(properties.BackgroundColor)) { using (Pen pen = new Pen(properties.RegionNormalBorderColor)) { // Fill the background. graphics.FillRectangle(brush, 0, 0, properties.Size.Width, properties.Size.Height); // Change the brush color. brush.Color = properties.RegionNormalBackgroundColor; // Get an exclusive reader lock to the regions list. this.regions.Lock(); try { // Draw the map regions. foreach (MapRegion region in this.regions) { // Draw the region. region.Draw(graphics, this.mapBounds, mapScale, brush, properties.Borders ? pen : null); } } finally { this.regions.Unlock(); } // Draw the major grid. if (properties.MajorGrid) { // Set the pen color. pen.Color = properties.MajorGridColor; // Set the brush color. brush.Color = Color.Black; // Draw the horizontal grid. if (null != majorGridHorizontalPoint) { for (int index = 0; index < majorGridHorizontalPoint.Length; index++) { // Draw the grid line. graphics.DrawLine(pen, majorGridHorizontalPoint[index], 0, majorGridHorizontalPoint[index], properties.Size.Height - 1); // Draw the coordinates. graphics.DrawString( majorGridHorizontalCoordinate[index].LongitudeToString(), this.fontGrid, brush, new Point((int)majorGridHorizontalPoint[index], 0)); } } // Draw the vertical grid. if (null != majorGridVerticalPoint) { for (int index = 0; index < majorGridVerticalPoint.Length; index++) { // Draw the grid line. graphics.DrawLine(pen, 0, majorGridVerticalPoint[index], properties.Size.Width - 1, majorGridVerticalPoint[index]); // Draw the coordinates. graphics.DrawString( majorGridVerticalCoordinate[index].LatitudeToString(), this.fontGrid, brush, new Point(0, (int)majorGridVerticalPoint[index])); } } } // If the show markers flag is set. if (properties.Markers) { // Change the pen and brush colors. pen.Color = properties.MarkerNormalBorderColor; brush.Color = properties.MarkerNormalBackgroundColor; // Try lockLock the markers collection. if (this.markers.TryLock()) { try { // Draw the normal markers. foreach (MapMarker marker in this.markers) { if (!marker.Emphasized) { marker.Draw(graphics, this.mapBounds, mapScale, brush, pen); } } // Change the pen and brush colors. pen.Color = properties.MarkerEmphasisBorderColor; brush.Color = properties.MarkerEmphasisBackgroundColor; // Draw the emphasized markers. foreach (MapMarker marker in this.markers) { if (marker.Emphasized) { marker.Draw(graphics, this.mapBounds, mapScale, brush, pen); } } } finally { this.markers.Unlock(); } } } } } } // Check the directory exists. if (Directory.EnsureFileDirectoryExists(fileName)) { // Save the bitmap to file. bitmap.Save(fileName, format); } }
/// <summary> /// An event handler called when the map size has changed. /// </summary> private void OnMapSizeChanged() { // Compute the map scale. this.mapScale = new MapScale( this.ClientSize.Width / mapBounds.Width, this.ClientSize.Height / mapBounds.Height ); // Compute the bitmap size. this.bitmapSize = this.ClientSize; // If the map is not streched. if (!this.showStreched) { // If the width scale is greater. if (this.mapScale.Width > this.mapScale.Height) { // Align along the width. this.mapScale.Height = this.mapScale.Width; this.bitmapSize.Height = (int)Math.Round(this.mapBounds.Height * this.mapScale.Height); } else { // Align along the height. this.mapScale.Width = this.mapScale.Height; this.bitmapSize.Width = (int)Math.Round(this.mapBounds.Width * this.mapScale.Width); } } // Update the bitmap location. this.bitmapLocation = this.Convert(this.mapBounds.Location); // Update the map grid. this.OnUpdateGrid(); // Update the map items. this.OnUpdateItems(); }