diff --git a/Demo.WindowsForms/Forms/StaticImage.Designer.cs b/Demo.WindowsForms/Forms/StaticImage.Designer.cs index 0eda39e5..7e5693ae 100644 --- a/Demo.WindowsForms/Forms/StaticImage.Designer.cs +++ b/Demo.WindowsForms/Forms/StaticImage.Designer.cs @@ -35,13 +35,14 @@ private void InitializeComponent() this.label1 = new System.Windows.Forms.Label(); this.checkBoxWorldFile = new System.Windows.Forms.CheckBox(); this.checkBoxRoutes = new System.Windows.Forms.CheckBox(); - ((System.ComponentModel.ISupportInitialize) (this.numericUpDown1)).BeginInit(); + this.checkBoxKMZ = new System.Windows.Forms.CheckBox(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.SuspendLayout(); // // button1 // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.button1.Location = new System.Drawing.Point(497, 29); + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button1.Location = new System.Drawing.Point(366, 29); this.button1.Margin = new System.Windows.Forms.Padding(2); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(84, 32); @@ -52,19 +53,19 @@ private void InitializeComponent() // // progressBar1 // - this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.progressBar1.Location = new System.Drawing.Point(6, 6); this.progressBar1.Margin = new System.Windows.Forms.Padding(2); this.progressBar1.Name = "progressBar1"; - this.progressBar1.Size = new System.Drawing.Size(484, 93); + this.progressBar1.Size = new System.Drawing.Size(353, 93); this.progressBar1.TabIndex = 2; // // numericUpDown1 // - this.numericUpDown1.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.numericUpDown1.Location = new System.Drawing.Point(535, 6); + this.numericUpDown1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDown1.Location = new System.Drawing.Point(404, 6); this.numericUpDown1.Margin = new System.Windows.Forms.Padding(2); this.numericUpDown1.Name = "numericUpDown1"; this.numericUpDown1.Size = new System.Drawing.Size(47, 20); @@ -72,8 +73,8 @@ private void InitializeComponent() // // button2 // - this.button2.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.button2.Location = new System.Drawing.Point(497, 67); + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button2.Location = new System.Drawing.Point(366, 67); this.button2.Margin = new System.Windows.Forms.Padding(2); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(84, 32); @@ -84,9 +85,9 @@ private void InitializeComponent() // // label1 // - this.label1.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(494, 8); + this.label1.Location = new System.Drawing.Point(363, 8); this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(37, 13); @@ -95,31 +96,43 @@ private void InitializeComponent() // // checkBoxWorldFile // - this.checkBoxWorldFile.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.checkBoxWorldFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.checkBoxWorldFile.AutoSize = true; - this.checkBoxWorldFile.Location = new System.Drawing.Point(497, 106); + this.checkBoxWorldFile.Location = new System.Drawing.Point(179, 116); this.checkBoxWorldFile.Name = "checkBoxWorldFile"; - this.checkBoxWorldFile.Size = new System.Drawing.Size(96, 17); + this.checkBoxWorldFile.Size = new System.Drawing.Size(67, 17); this.checkBoxWorldFile.TabIndex = 6; - this.checkBoxWorldFile.Text = "make Worldfile"; + this.checkBoxWorldFile.Text = "Worldfile"; this.checkBoxWorldFile.UseVisualStyleBackColor = true; // // checkBoxRoutes // - this.checkBoxRoutes.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.checkBoxRoutes.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.checkBoxRoutes.AutoSize = true; - this.checkBoxRoutes.Location = new System.Drawing.Point(7, 106); + this.checkBoxRoutes.Location = new System.Drawing.Point(7, 116); this.checkBoxRoutes.Name = "checkBoxRoutes"; this.checkBoxRoutes.Size = new System.Drawing.Size(147, 17); this.checkBoxRoutes.TabIndex = 7; this.checkBoxRoutes.Text = "Use area of routes in map"; this.checkBoxRoutes.UseVisualStyleBackColor = true; // + // checkBoxKMZ + // + this.checkBoxKMZ.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.checkBoxKMZ.AutoSize = true; + this.checkBoxKMZ.Location = new System.Drawing.Point(300, 116); + this.checkBoxKMZ.Name = "checkBoxKMZ"; + this.checkBoxKMZ.Size = new System.Drawing.Size(49, 17); + this.checkBoxKMZ.TabIndex = 8; + this.checkBoxKMZ.Text = "KMZ"; + this.checkBoxKMZ.UseVisualStyleBackColor = true; + // // StaticImage // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(588, 130); + this.ClientSize = new System.Drawing.Size(457, 140); + this.Controls.Add(this.checkBoxKMZ); this.Controls.Add(this.checkBoxRoutes); this.Controls.Add(this.checkBoxWorldFile); this.Controls.Add(this.label1); @@ -132,9 +145,9 @@ private void InitializeComponent() this.MinimumSize = new System.Drawing.Size(16, 164); this.Name = "StaticImage"; this.Padding = new System.Windows.Forms.Padding(4); - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Static Map maker"; - ((System.ComponentModel.ISupportInitialize) (this.numericUpDown1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -149,5 +162,6 @@ private void InitializeComponent() private System.Windows.Forms.Label label1; private System.Windows.Forms.CheckBox checkBoxWorldFile; private System.Windows.Forms.CheckBox checkBoxRoutes; + private System.Windows.Forms.CheckBox checkBoxKMZ; } } \ No newline at end of file diff --git a/Demo.WindowsForms/Forms/StaticImage.cs b/Demo.WindowsForms/Forms/StaticImage.cs index 4202aff5..8dced468 100644 --- a/Demo.WindowsForms/Forms/StaticImage.cs +++ b/Demo.WindowsForms/Forms/StaticImage.cs @@ -10,6 +10,9 @@ using System.Drawing.Drawing2D; using System.Drawing.Imaging; using GMap.NET.MapProviders; +using System.IO.Compression; +using System.Text; +using System.Globalization; namespace Demo.WindowsForms { @@ -60,7 +63,7 @@ void bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) this.Text = "Static Map maker"; progressBar1.Value = 0; button1.Enabled = true; - numericUpDown1.Enabled = true; + numericUpDown1.Enabled = true; Main.MainMap.Refresh(); } @@ -77,9 +80,7 @@ void bg_DoWork(object sender, DoWorkEventArgs e) MapInfo info = (MapInfo)e.Argument; if(!info.Area.IsEmpty) { - //var types = GMaps.Instance.GetAllLayersOfType(info.Type); - - string bigImage = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "GMap at zoom " + info.Zoom + " - " + info.Type + "-" + DateTime.Now.Ticks + ".png"; + string bigImage = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "GMap at zoom " + info.Zoom + " - " + info.Type + "-" + DateTime.Now.Ticks + ".jpg"; e.Result = bigImage; // current area @@ -88,7 +89,7 @@ void bg_DoWork(object sender, DoWorkEventArgs e) GPoint pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y); GMap.NET.GSize maxOfTiles = info.Type.Projection.GetTileMatrixMaxXY(info.Zoom); - int padding = info.MakeWorldFile ? 0 : 22; + int padding = info.MakeWorldFile || info.MakeKmz ? 0 : 22; { using(Bitmap bmpDestination = new Bitmap((int)(pxDelta.X + padding * 2), (int)(pxDelta.Y + padding * 2))) { @@ -235,12 +236,12 @@ void bg_DoWork(object sender, DoWorkEventArgs e) px.Offset(padding, padding); px.Offset(-topLeftPx.X, -topLeftPx.Y); px.Offset(r.Offset.X, r.Offset.Y); - + gfx.ResetTransform(); gfx.TranslateTransform(-r.LocalPosition.X, -r.LocalPosition.Y); gfx.TranslateTransform((int)px.X, (int)px.Y); - - r.OnRender(gfx); + + r.OnRender(gfx); } } @@ -251,18 +252,18 @@ void bg_DoWork(object sender, DoWorkEventArgs e) { if(!string.IsNullOrEmpty(m.ToolTipText)) { - var pr = m.Position; - GPoint px = info.Type.Projection.FromLatLngToPixel(pr.Lat, pr.Lng, info.Zoom); - - px.Offset(padding, padding); - px.Offset(-topLeftPx.X, -topLeftPx.Y); - px.Offset(m.Offset.X, m.Offset.Y); - - gfx.ResetTransform(); - gfx.TranslateTransform(-m.LocalPosition.X, -m.LocalPosition.Y); - gfx.TranslateTransform((int)px.X, (int)px.Y); - - m.ToolTip.OnRender(gfx); + var pr = m.Position; + GPoint px = info.Type.Projection.FromLatLngToPixel(pr.Lat, pr.Lng, info.Zoom); + + px.Offset(padding, padding); + px.Offset(-topLeftPx.X, -topLeftPx.Y); + px.Offset(m.Offset.X, m.Offset.Y); + + gfx.ResetTransform(); + gfx.TranslateTransform(-m.LocalPosition.X, -m.LocalPosition.Y); + gfx.TranslateTransform((int)px.X, (int)px.Y); + + m.ToolTip.OnRender(gfx); } } } @@ -270,7 +271,7 @@ void bg_DoWork(object sender, DoWorkEventArgs e) } // draw info - if (!info.MakeWorldFile) + if(!info.MakeWorldFile) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); { @@ -316,7 +317,7 @@ void bg_DoWork(object sender, DoWorkEventArgs e) } } - bmpDestination.Save(bigImage, ImageFormat.Png); + bmpDestination.Save(bigImage, ImageFormat.Jpeg); } } @@ -344,6 +345,52 @@ void bg_DoWork(object sender, DoWorkEventArgs e) world.Close(); } } + + if(info.MakeKmz) + { + var kmzFile = Path.GetDirectoryName(bigImage) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(bigImage) + ".kmz"; + e.Result = kmzFile; + + using(ZipStorer zip = ZipStorer.Create(kmzFile, "GMap.NET")) + { + zip.AddFile(ZipStorer.Compression.Store, bigImage, "files/map.jpg", "map"); + + using(var readme = new MemoryStream( + Encoding.UTF8.GetBytes( + string.Format(CultureInfo.InvariantCulture, @" + + + {8} + + {6} + {7} + 0 + 0 + 0 + 69327.55500845652 + + 91ffffff + + files/map.jpg + + + + {0},{1},0 {2},{3},0 {4},{5},0 {6},{7},0 + + + +", info.Area.Left, info.Area.Bottom, + info.Area.Right, info.Area.Bottom, + info.Area.Right, info.Area.Top, + info.Area.Left, info.Area.Top, + kmzFile)))) + { + + zip.AddStream(ZipStorer.Compression.Store, "doc.kml", readme, DateTime.Now, "kml"); + zip.Close(); + } + } + } } } @@ -385,9 +432,9 @@ private void button1_Click(object sender, EventArgs e) numericUpDown1.Enabled = false; progressBar1.Value = 0; button1.Enabled = false; - Main.MainMap.HoldInvalidation = true; - - bg.RunWorkerAsync(new MapInfo(area.Value, (int)numericUpDown1.Value, Main.MainMap.MapProvider, checkBoxWorldFile.Checked)); + Main.MainMap.HoldInvalidation = true; + + bg.RunWorkerAsync(new MapInfo(area.Value, (int)numericUpDown1.Value, Main.MainMap.MapProvider, checkBoxWorldFile.Checked, checkBoxKMZ.Checked)); } } @@ -406,13 +453,15 @@ public struct MapInfo public int Zoom; public GMapProvider Type; public bool MakeWorldFile; + public bool MakeKmz; - public MapInfo(RectLatLng Area, int Zoom, GMapProvider Type, bool makeWorldFile) + public MapInfo(RectLatLng Area, int Zoom, GMapProvider Type, bool makeWorldFile, bool MakeKmz) { this.Area = Area; this.Zoom = Zoom; this.Type = Type; this.MakeWorldFile = makeWorldFile; + this.MakeKmz = MakeKmz; } } } diff --git a/GMap.NET.Core/GMap.NET.Core.csproj b/GMap.NET.Core/GMap.NET.Core.csproj index dba9156f..e7a5a3a6 100644 --- a/GMap.NET.Core/GMap.NET.Core.csproj +++ b/GMap.NET.Core/GMap.NET.Core.csproj @@ -264,6 +264,7 @@ +