public Form3() { InitializeComponent(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form3)); this.components = new System.ComponentModel.Container(); this.mapBox1 = new SharpMap.Forms.MapBox(); this.mapZoomToolStrip1 = new SharpMap.Forms.ToolBar.MapZoomToolStrip(this.components); this.toolsbIdentity = new System.Windows.Forms.ToolStripButton(); this.mapZoomToolStrip1.SuspendLayout(); // // mapBox1 // this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.None; this.mapBox1.BackColor = System.Drawing.Color.White; this.mapBox1.Cursor = System.Windows.Forms.Cursors.Default; this.mapBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.mapBox1.FineZoomFactor = 10D; this.mapBox1.Location = new System.Drawing.Point(0, 0); this.mapBox1.MapQueryMode = SharpMap.Forms.MapBox.MapQueryType.LayerByIndex; this.mapBox1.Name = "mapBox1"; this.mapBox1.QueryGrowFactor = 5F; this.mapBox1.QueryLayerIndex = 0; this.mapBox1.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(210)))), ((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244))))); this.mapBox1.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244))))); this.mapBox1.ShowProgressUpdate = false; this.mapBox1.Size = new System.Drawing.Size(580, 407); this.mapBox1.TabIndex = 0; this.mapBox1.Text = "mapBox1"; this.mapBox1.WheelZoomMagnitude = -2D; this.mapBox1.MapQueried += new SharpMap.Forms.MapBox.MapQueryHandler(this.mapBox1_MapQueried); // // mapZoomToolStrip1 // this.mapZoomToolStrip1.Enabled = false; this.mapZoomToolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolsbIdentity }); this.mapZoomToolStrip1.Location = new System.Drawing.Point(0, 0); this.mapZoomToolStrip1.MapControl = this.mapBox1; this.mapZoomToolStrip1.Name = "mapZoomToolStrip1"; this.mapZoomToolStrip1.Size = new System.Drawing.Size(580, 25); this.mapZoomToolStrip1.TabIndex = 2; this.mapZoomToolStrip1.Text = "mapZoomToolStrip1"; // // toolsbIdentity // this.toolsbIdentity.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.toolsbIdentity.Image = ((System.Drawing.Image)(resources.GetObject("identify"))); this.toolsbIdentity.ImageTransparentColor = System.Drawing.Color.Magenta; this.toolsbIdentity.Name = "toolsbIdentity"; this.toolsbIdentity.Size = new System.Drawing.Size(23, 22); this.toolsbIdentity.Text = "查询"; this.toolsbIdentity.Click += new System.EventHandler(this.toolsbIdentity_Click); this.Controls.Add(this.mapZoomToolStrip1); this.Controls.Add(this.mapBox1); this.mapZoomToolStrip1.ResumeLayout(false); this.mapZoomToolStrip1.PerformLayout(); this.mapBox1.Map.Layers.Clear(); SharpMap.Layers.VectorLayer vlayer = new SharpMap.Layers.VectorLayer("states"); string start = Application.StartupPath; string path = @"D:\workspace\Code\2016\ExcelReader\ExcelReader\bin\Debug\tmp.shp"; vlayer.DataSource = new SharpMap.Data.Providers.ShapeFile(path); vlayer.Style.Fill = new SolidBrush(Color.GreenYellow); vlayer.Style.Outline = System.Drawing.Pens.Gray; vlayer.Style.EnableOutline = true; mapBox1.Map.Layers.Add(vlayer); SharpMap.Layers.LabelLayer labelLayer = new LabelLayer("label"); labelLayer.DataSource = vlayer.DataSource; labelLayer.Enabled = true; labelLayer.LabelColumn = "mapNo"; labelLayer.Style = new SharpMap.Styles.LabelStyle(); labelLayer.Style.ForeColor = Color.Black; labelLayer.Style.Font = new System.Drawing.Font(FontFamily.GenericSerif, 13); labelLayer.Style.Offset = new PointF(3, 3); labelLayer.Style.Halo = new Pen(Color.Yellow, 2); labelLayer.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; labelLayer.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; labelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection; labelLayer.Style.CollisionDetection = true; labelLayer.MaxVisible = 200000; mapBox1.Map.Layers.Add(labelLayer); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); }
private void radioButton_Click(object sender, EventArgs e) { Cursor mic = mapBox1.Cursor; mapBox1.Cursor = Cursors.WaitCursor; Cursor = Cursors.WaitCursor; try { //mapImage.ActiveTool = MapImage.Tools.None; string text = ((RadioButton)sender).Text; switch (text) { case "Shapefile": mapBox1.Map = ShapefileSample.InitializeMap(tbAngle.Value); break; case "GradientTheme": mapBox1.Map = GradiantThemeSample.InitializeMap(tbAngle.Value); break; case "WFS Client": mapBox1.Map = WfsSample.InitializeMap(tbAngle.Value); break; case "WMS Client": mapBox1.Map = TiledWmsSample.InitializeMap(); //mapBox1.Map = WmsSample.InitializeMap(tbAngle.Value); break; case "OGR - MapInfo": case "OGR - S-57": mapBox1.Map = OgrSample.InitializeMap(tbAngle.Value); break; case "GDAL - GeoTiff": case "GDAL - '.DEM'": case "GDAL - '.ASC'": case "GDAL - '.VRT'": mapBox1.Map = GdalSample.InitializeMap(tbAngle.Value); mapBox1.ActiveTool = MapBox.Tools.Pan; break; case "TileLayer - OSM": case "TileLayer - OSM with XLS": case "TileLayer - Bing Roads": case "TileLayer - Bing Aerial": case "TileLayer - Bing Hybrid": case "TileLayer - GoogleMap": case "TileLayer - GoogleSatellite": case "TileLayer - GoogleTerrain": case "TileLayer - GoogleLabels": /* * tbAngle.Visible = text.Equals("TileLayer - GoogleLabels"); * if (!tbAngle.Visible) tbAngle.Value = 0; */ mapBox1.Map = TileLayerSample.InitializeMap(tbAngle.Value); ((RadioButton)sender).Text = mapBox1.Map.Layers[0].LayerName; break; case "PostGis": mapBox1.Map = PostGisSample.InitializeMap(tbAngle.Value); break; case "SpatiaLite": mapBox1.Map = SpatiaLiteSample.InitializeMap(tbAngle.Value); break; case "Oracle": mapBox1.Map = OracleSample.InitializeMap(tbAngle.Value); break; default: break; } mapBox1.Map.Size = Size; mapBox1.Refresh(); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error"); } Cursor = Cursors.Default; mapBox1.Cursor = mic; }
private void Form2_Load(object sender, EventArgs e) { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2)); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.ZoomWindowToolStripButton = new System.Windows.Forms.ToolStripButton(); this.ZoomInToolStripButton = new System.Windows.Forms.ToolStripButton(); this.ZoomOutToolStripButton = new System.Windows.Forms.ToolStripButton(); this.PanToolStripButton = new System.Windows.Forms.ToolStripButton(); this.PreviousToolStripButton = new System.Windows.Forms.ToolStripButton(); this.NextToolStripButton = new System.Windows.Forms.ToolStripButton(); this.QueryToolStripButton = new System.Windows.Forms.ToolStripButton(); this.toolStrip1.SuspendLayout(); // // toolStrip1 // this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ZoomWindowToolStripButton, this.ZoomInToolStripButton, this.ZoomOutToolStripButton, this.PanToolStripButton, this.PreviousToolStripButton, this.NextToolStripButton, this.QueryToolStripButton }); this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Name = "toolStrip1"; this.toolStrip1.Size = new System.Drawing.Size(735, 31); this.toolStrip1.TabIndex = 1; this.toolStrip1.Text = "toolStrip1"; // // toolStripButton1 // this.ZoomWindowToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.ZoomWindowToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("globe"))); this.ZoomWindowToolStripButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; this.ZoomWindowToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.ZoomWindowToolStripButton.Name = "toolStripButton1"; this.ZoomWindowToolStripButton.Size = new System.Drawing.Size(28, 28); this.ZoomWindowToolStripButton.Text = "全图"; this.ZoomWindowToolStripButton.Click += new EventHandler(ZoomWindowToolStripButton_Click); // // toolStripButton2 // this.ZoomInToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.ZoomInToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("zoomin"))); this.ZoomInToolStripButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; this.ZoomInToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.ZoomInToolStripButton.Name = "toolStripButton2"; this.ZoomInToolStripButton.Size = new System.Drawing.Size(26, 28); this.ZoomInToolStripButton.Text = "放大"; this.ZoomInToolStripButton.Click += new EventHandler(ZoomInToolStripButton_Click); // // toolStripButton3 // this.ZoomOutToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.ZoomOutToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("zoomout"))); this.ZoomOutToolStripButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; this.ZoomOutToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.ZoomOutToolStripButton.Name = "toolStripButton3"; this.ZoomOutToolStripButton.Size = new System.Drawing.Size(26, 28); this.ZoomOutToolStripButton.Text = "缩小"; this.ZoomOutToolStripButton.Click += new EventHandler(ZoomOutToolStripButton_Click); // // toolStripButton4 // this.PanToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.PanToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("hand"))); this.PanToolStripButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; this.PanToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.PanToolStripButton.Name = "toolStripButton4"; this.PanToolStripButton.Size = new System.Drawing.Size(28, 28); this.PanToolStripButton.Text = "平移"; this.PanToolStripButton.Click += new EventHandler(PanToolStripButton_Click); // // toolStripButton6 // this.PreviousToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.PreviousToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("previous"))); this.PreviousToolStripButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; this.PreviousToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.PreviousToolStripButton.Name = "toolStripButton6"; this.PreviousToolStripButton.Size = new System.Drawing.Size(28, 28); this.PreviousToolStripButton.Text = "前一视图"; this.PreviousToolStripButton.Click += new EventHandler(PreviousToolStripButton_Click); // // toolStripButton7 // this.NextToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.NextToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("next"))); this.NextToolStripButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; this.NextToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.NextToolStripButton.Name = "toolStripButton7"; this.NextToolStripButton.Size = new System.Drawing.Size(28, 28); this.NextToolStripButton.Text = "后一视图"; this.NextToolStripButton.Click += new EventHandler(NextToolStripButton_Click); // // toolStripButton8 // this.QueryToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.QueryToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("identify"))); this.QueryToolStripButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None; this.QueryToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.QueryToolStripButton.Name = "toolStripButton8"; this.QueryToolStripButton.Size = new System.Drawing.Size(28, 28); this.QueryToolStripButton.Text = "查询"; this.QueryToolStripButton.Click += new EventHandler(QueryToolStripButton_Click); this.Controls.Add(this.toolStrip1); // // button2 // this.button2 = new System.Windows.Forms.Button(); this.button2.Location = new System.Drawing.Point(158, 99); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 0; this.button2.Text = "button2"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new EventHandler(button2_Click); this.Controls.Add(this.button2); // // mapBox1 // this.mapBox1 = new SharpMap.Forms.MapBox(); this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.None; this.mapBox1.BackColor = System.Drawing.Color.White; this.mapBox1.Cursor = System.Windows.Forms.Cursors.Default; this.mapBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.mapBox1.FineZoomFactor = 10D; this.mapBox1.Location = new System.Drawing.Point(0, 78); this.mapBox1.MapQueryMode = SharpMap.Forms.MapBox.MapQueryType.LayerByIndex; this.mapBox1.Name = "mapBox1"; this.mapBox1.QueryGrowFactor = 5F; this.mapBox1.QueryLayerIndex = 0; this.mapBox1.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(210)))), ((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244))))); this.mapBox1.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244))))); this.mapBox1.ShowProgressUpdate = false; this.mapBox1.Size = new System.Drawing.Size(527, 317); this.mapBox1.TabIndex = 0; this.mapBox1.Text = "mapBox1"; this.mapBox1.WheelZoomMagnitude = -2D; this.mapBox1.MapQueried += new SharpMap.Forms.MapBox.MapQueryHandler(mapBox1_MapQueried); this.mapBox1.Map.MapViewOnChange += new SharpMap.Map.MapViewChangedHandler(Map_MapViewOnChange); this.mapBox1.MouseDown += new MapBox.MouseEventHandler(mapBox1_MouseDown); this.mapBox1.MouseUp += new MapBox.MouseEventHandler(mapBox1_MouseUp); this.Controls.Add(this.mapBox1); this.toolStrip1.ResumeLayout(false); this.toolStrip1.PerformLayout(); this.mapBox1.Map.Layers.Clear(); SharpMap.Layers.VectorLayer vlayer = new SharpMap.Layers.VectorLayer("states"); string start = Application.StartupPath; string path = @"E:\workspace\Code\2016\ExcelReader\ExcelReader\bin\Debug\tmp.shp"; vlayer.DataSource = new SharpMap.Data.Providers.ShapeFile(path); vlayer.Style.Fill = new SolidBrush(Color.GreenYellow); vlayer.Style.Outline = System.Drawing.Pens.Gray; vlayer.Style.EnableOutline = true; mapBox1.Map.Layers.Add(vlayer); SharpMap.Layers.LabelLayer labelLayer = new LabelLayer("label"); labelLayer.DataSource = vlayer.DataSource; labelLayer.Enabled = true; labelLayer.LabelColumn = "mapNo"; labelLayer.Style = new SharpMap.Styles.LabelStyle(); labelLayer.Style.ForeColor = Color.Black; labelLayer.Style.Font = new System.Drawing.Font(FontFamily.GenericSerif, 13); labelLayer.Style.Offset = new PointF(3, 3); labelLayer.Style.Halo = new Pen(Color.Yellow, 2); labelLayer.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; labelLayer.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; labelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection; labelLayer.Style.CollisionDetection = true; labelLayer.MaxVisible = 200000; mapBox1.Map.Layers.Add(labelLayer); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); }