活动介绍

echarts 折线图单条折线中心点位置偏移怎么写

时间: 2025-01-28 17:22:41 浏览: 78
ECharts 的折线图如果想要调整单条折线的中心点位置,可以通过设置 `data` 数组中的坐标值以及相应的 `visualMap` 或者 `series.symbolOffset` 属性来实现偏移效果。下面是一个简单的例子: ```javascript // 假设你有一个名为 'lineData' 的数据数组,每个元素都有 x 和 y 坐标 let lineData = [ {x: 0, y: 5}, {x: 1, y: 8}, {x: 2, y: 4}, // 更改特定点的位置 {x: 3, y: 6, symbolOffset: [5, -5]} // 这里 [数值, 数值] 表示水平偏移和垂直偏移 ]; // 创建折线图配置项 let option = { xAxis: {data: lineData.map(item => item.x)}, yAxis: {}, series: [{ name: '折线', type: 'line', data: lineData, // 如果需要在整个系列上应用偏移,则不需要指定具体的点 symbolOffset: [0, -5], // 全局偏移 // 如果只对某几条数据点应用偏移,则可以这样写 // dataZoom: {selectable: false}, // 防止数据缩放影响偏移 dataZoom: null, // 或者移除数据缩放 points: lineData.filter(item => item.symbolOffset) // 只显示有偏移的点 }] }; // 调用 ECharts 初始化图表 echarts.init(document.getElementById('main')).setOption(option); ``` 在这个例子中,我们对第四个数据点设置了单独的偏移 `[5, -5]`,这意味着该点会在 x 轴方向右移 5 单位,在 y 轴方向下移 5 单位。
阅读全文

相关推荐

这个是我自己写的2024 年高教社杯全国大学生数学建模竞赛题目 a题第一问求每一个时刻,龙各个点的坐标,我的思路是先给时间求出来龙头走的路程,通过平面螺旋线的弧长公式求出来龙头的极角,然后根据x=r*cosθ求出来坐标,知道龙头的极角,用余弦定理求龙头后一节的极角,再通过公式求出来下一节的坐标以此类推求出来某一时刻所有点的坐标,注意点是,龙头和龙身子的一节的长度不同,所以龙头后面一节的坐标和极角需要单独计算,还有龙头是从螺旋线的外点向着原点螺线的,而且如果龙的那个位置没有进入螺旋线里面的时候,不会输出坐标,输出null。下面给出原题目:某板凳龙由223节板凳组成,其中第1节为龙头,后面221节为龙身,最后1节为龙 尾。龙头的板长为341 cm,龙身和龙尾的板长均为220 cm,所有板凳的板宽均为30 cm。每 节板凳上均有两个孔,孔径(孔的直径)为5.5 cm,孔的中心距离最近的板头27.5 cm(见 图1和图2)。相邻两条板凳通过把手连接 舞龙队沿螺距为55 cm的等距螺线顺时针盘入,各把手中心均位于螺线上。龙 头前把手的行进速度始终保持1 m/s。初始时,龙头位于螺线第16圈A点处(见图4)。请 给出从初始时刻到300 s为止,每秒整个舞龙队的位置和速度(指龙头、龙身和龙尾各前把 手及龙尾后把手中心的位置和速度,下同),将结果保存到文件result1.xlsx中(模板文件见 附件,其中“龙尾(后)”表示龙尾后把手,其余的均是前把手,结果保留6位小数,下同)。

namespace WaterPipelineGIS2 { partial class main { /// /// 必需的设计器变量。 /// private System.ComponentModel.IContainer components = null; /// /// 清理所有正在使用的资源。 /// /// 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(main)); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem6 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem7 = new System.Windows.Forms.ToolStripMenuItem(); this.清除选择ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.空间量测ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.面积量测ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.周长量测ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.点坐标量测ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.清除已绘制图形ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.panel1 = new System.Windows.Forms.Panel(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.groupBoxEagleEye = new System.Windows.Forms.GroupBox(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.lblCoordinate = new System.Windows.Forms.ToolStripStatusLabel(); this.lblResult = new System.Windows.Forms.ToolStripStatusLabel(); this.axLicenseControl1 = new ESRI.ArcGIS.Controls.AxLicenseControl(); this.txtRotateAngle = new System.Windows.Forms.ToolStripTextBox(); this.contextMenuStripTOC = new System.Windows.Forms.ContextMenuStrip(this.components); this.openAttributeTableToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.axMapControl2 = new ESRI.ArcGIS.Controls.AxMapControl(); this.axTOCControl1 = new ESRI.ArcGIS.Controls.AxTOCControl(); this.axMapControl1 = new ESRI.ArcGIS.Controls.AxMapControl(); this.axToolbarControl1 = new ESRI.ArcGIS.Controls.AxToolbarControl(); this.折线周长量测ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.menuStrip1.SuspendLayout(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); this.groupBoxEagleEye.SuspendLayout(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit(); this.contextMenuStripTOC.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.axMapControl2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axTOCControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).BeginInit(); this.SuspendLayout(); // // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem1}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1042, 32); this.menuStrip1.TabIndex = 0; this.menuStrip1.Text = "menuStrip1"; // // toolStripMenuItem1 // this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem2, this.toolStripMenuItem3, this.空间量测ToolStripMenuItem}); this.toolStripMenuItem1.Name = "toolStripMenuItem1"; this.toolStripMenuItem1.Size = new System.Drawing.Size(58, 28); this.toolStripMenuItem1.Text = "功能"; // // toolStripMenuItem2 // this.toolStripMenuItem2.Name = "toolStripMenuItem2"; this.toolStripMenuItem2.Size = new System.Drawing.Size(152, 28); this.toolStripMenuItem2.Text = "地图旋转"; this.toolStripMenuItem2.Click += new System.EventHandler(this.toolStripMenuItem2_Click); // // toolStripMenuItem3 // this.toolStripMenuItem3.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem4, this.toolStripMenuItem5, this.toolStripMenuItem6, this.toolStripMenuItem7, this.清除选择ToolStripMenuItem}); this.toolStripMenuItem3.Name = "toolStripMenuItem3"; this.toolStripMenuItem3.Size = new System.Drawing.Size(152, 28); this.toolStripMenuItem3.Text = "空间选择"; // // toolStripMenuItem4 // this.toolStripMenuItem4.Name = "toolStripMenuItem4"; this.toolStripMenuItem4.Size = new System.Drawing.Size(206, 28); this.toolStripMenuItem4.Text = "绘制矩形选择"; this.toolStripMenuItem4.Click += new System.EventHandler(this.btnRectSelect_Click); // // toolStripMenuItem5 // this.toolStripMenuItem5.Name = "toolStripMenuItem5"; this.toolStripMenuItem5.Size = new System.Drawing.Size(206, 28); this.toolStripMenuItem5.Text = "绘制圆形选择"; this.toolStripMenuItem5.Click += new System.EventHandler(this.btnCircleSelect_Click); // // toolStripMenuItem6 // this.toolStripMenuItem6.Name = "toolStripMenuItem6"; this.toolStripMenuItem6.Size = new System.Drawing.Size(206, 28); this.toolStripMenuItem6.Text = "绘制多边形选择"; this.toolStripMenuItem6.Click += new System.EventHandler(this.btnPolygonSelect_Click); // // toolStripMenuItem7 // this.toolStripMenuItem7.Name = "toolStripMenuItem7"; this.toolStripMenuItem7.Size = new System.Drawing.Size(206, 28); this.toolStripMenuItem7.Text = "绘制折线选择"; this.toolStripMenuItem7.Click += new System.EventHandler(this.btnLineSelect_Click); // // 清除选择ToolStripMenuItem // this.清除选择ToolStripMenuItem.Name = "清除选择ToolStripMenuItem"; this.清除选择ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.清除选择ToolStripMenuItem.Text = "清除选择"; this.清除选择ToolStripMenuItem.Click += new System.EventHandler(this.btnClearSelection_Click); // // 空间量测ToolStripMenuItem // this.空间量测ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.面积量测ToolStripMenuItem, this.周长量测ToolStripMenuItem, this.折线周长量测ToolStripMenuItem, this.点坐标量测ToolStripMenuItem, this.清除已绘制图形ToolStripMenuItem}); this.空间量测ToolStripMenuItem.Name = "空间量测ToolStripMenuItem"; this.空间量测ToolStripMenuItem.Size = new System.Drawing.Size(152, 28); this.空间量测ToolStripMenuItem.Text = "空间量测"; // // 面积量测ToolStripMenuItem // this.面积量测ToolStripMenuItem.Name = "面积量测ToolStripMenuItem"; this.面积量测ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.面积量测ToolStripMenuItem.Text = "面积量测"; this.面积量测ToolStripMenuItem.Click += new System.EventHandler(this.面积量测ToolStripMenuItem_Click); // // 周长量测ToolStripMenuItem // this.周长量测ToolStripMenuItem.Name = "周长量测ToolStripMenuItem"; this.周长量测ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.周长量测ToolStripMenuItem.Text = "周长量测"; this.周长量测ToolStripMenuItem.Click += new System.EventHandler(this.周长量测ToolStripMenuItem_Click); // // 点坐标量测ToolStripMenuItem // this.点坐标量测ToolStripMenuItem.Name = "点坐标量测ToolStripMenuItem"; this.点坐标量测ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.点坐标量测ToolStripMenuItem.Text = "点坐标量测"; this.点坐标量测ToolStripMenuItem.Click += new System.EventHandler(this.点坐标量测ToolStripMenuItem_Click); // // 清除已绘制图形ToolStripMenuItem // this.清除已绘制图形ToolStripMenuItem.Name = "清除已绘制图形ToolStripMenuItem"; this.清除已绘制图形ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.清除已绘制图形ToolStripMenuItem.Text = "清除已绘制图形"; this.清除已绘制图形ToolStripMenuItem.Click += new System.EventHandler(this.清除已绘制图形ToolStripMenuItem_Click); // // panel1 // this.panel1.Controls.Add(this.splitContainer1); this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 60); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(1042, 585); this.panel1.TabIndex = 2; // // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer1.Location = new System.Drawing.Point(0, 0); this.splitContainer1.Name = "splitContainer1"; // // splitContainer1.Panel1 // this.splitContainer1.Panel1.Controls.Add(this.groupBoxEagleEye); this.splitContainer1.Panel1.Controls.Add(this.axTOCControl1); // // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.statusStrip1); this.splitContainer1.Panel2.Controls.Add(this.axLicenseControl1); this.splitContainer1.Panel2.Controls.Add(this.axMapControl1); this.splitContainer1.Size = new System.Drawing.Size(1042, 585); this.splitContainer1.SplitterDistance = 247; this.splitContainer1.TabIndex = 0; // // groupBoxEagleEye // this.groupBoxEagleEye.Controls.Add(this.axMapControl2); this.groupBoxEagleEye.Dock = System.Windows.Forms.DockStyle.Bottom; this.groupBoxEagleEye.Location = new System.Drawing.Point(0, 261); this.groupBoxEagleEye.Name = "groupBoxEagleEye"; this.groupBoxEagleEye.Size = new System.Drawing.Size(247, 324); this.groupBoxEagleEye.TabIndex = 2; this.groupBoxEagleEye.TabStop = false; this.groupBoxEagleEye.Text = "鹰眼导航"; // // statusStrip1 // this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.lblCoordinate, this.lblResult, this.toolStripStatusLabel1}); this.statusStrip1.Location = new System.Drawing.Point(0, 556); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Padding = new System.Windows.Forms.Padding(2, 0, 14, 0); this.statusStrip1.Size = new System.Drawing.Size(791, 29); this.statusStrip1.TabIndex = 0; this.statusStrip1.Text = "statusStrip1"; // // lblCoordinate // this.lblCoordinate.Name = "lblCoordinate"; this.lblCoordinate.Size = new System.Drawing.Size(644, 24); this.lblCoordinate.Spring = true; this.lblCoordinate.Text = "lblCoordinate"; this.lblCoordinate.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // lblResult // this.lblResult.Name = "lblResult"; this.lblResult.Size = new System.Drawing.Size(85, 24); this.lblResult.Text = "lblResult"; // // axLicenseControl1 // this.axLicenseControl1.Enabled = true; this.axLicenseControl1.Location = new System.Drawing.Point(757, 528); this.axLicenseControl1.Name = "axLicenseControl1"; this.axLicenseControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axLicenseControl1.OcxState"))); this.axLicenseControl1.Size = new System.Drawing.Size(32, 32); this.axLicenseControl1.TabIndex = 1; // // txtRotateAngle // this.txtRotateAngle.Name = "txtRotateAngle"; this.txtRotateAngle.Size = new System.Drawing.Size(100, 23); // // contextMenuStripTOC // this.contextMenuStripTOC.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.openAttributeTableToolStripMenuItem}); this.contextMenuStripTOC.Name = "contextMenuStripTOC"; this.contextMenuStripTOC.Size = new System.Drawing.Size(171, 32); // // openAttributeTableToolStripMenuItem // this.openAttributeTableToolStripMenuItem.Name = "openAttributeTableToolStripMenuItem"; this.openAttributeTableToolStripMenuItem.Size = new System.Drawing.Size(170, 28); this.openAttributeTableToolStripMenuItem.Text = "打开属性表"; this.openAttributeTableToolStripMenuItem.Click += new System.EventHandler(this.openAttributeTableToolStripMenuItem_Click); // // axMapControl2 // this.axMapControl2.Dock = System.Windows.Forms.DockStyle.Fill; this.axMapControl2.Location = new System.Drawing.Point(3, 24); this.axMapControl2.Name = "axMapControl2"; this.axMapControl2.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMapControl2.OcxState"))); this.axMapControl2.Size = new System.Drawing.Size(241, 297); this.axMapControl2.TabIndex = 0; // // axTOCControl1 // this.axTOCControl1.Dock = System.Windows.Forms.DockStyle.Fill; this.axTOCControl1.Location = new System.Drawing.Point(0, 0); this.axTOCControl1.Name = "axTOCControl1"; this.axTOCControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axTOCControl1.OcxState"))); this.axTOCControl1.Size = new System.Drawing.Size(247, 585); this.axTOCControl1.TabIndex = 0; this.axTOCControl1.OnMouseDown += new ESRI.ArcGIS.Controls.ITOCControlEvents_Ax_OnMouseDownEventHandler(this.axTOCControl1_OnMouseDown); // // axMapControl1 // this.axMapControl1.Dock = System.Windows.Forms.DockStyle.Fill; this.axMapControl1.Location = new System.Drawing.Point(0, 0); this.axMapControl1.Name = "axMapControl1"; this.axMapControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMapControl1.OcxState"))); this.axMapControl1.Size = new System.Drawing.Size(791, 585); this.axMapControl1.TabIndex = 0; this.axMapControl1.OnMouseDown += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseDownEventHandler(this.axMapControl1_OnMouseDown); this.axMapControl1.OnMouseMove += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseMoveEventHandler(this.axMapControl1_OnMouseMove); this.axMapControl1.OnDoubleClick += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnDoubleClickEventHandler(this.axMapControl1_OnDoubleClick); // // axToolbarControl1 // this.axToolbarControl1.Dock = System.Windows.Forms.DockStyle.Top; this.axToolbarControl1.Location = new System.Drawing.Point(0, 32); this.axToolbarControl1.Name = "axToolbarControl1"; this.axToolbarControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axToolbarControl1.OcxState"))); this.axToolbarControl1.Size = new System.Drawing.Size(1042, 28); this.axToolbarControl1.TabIndex = 1; // // 折线周长量测ToolStripMenuItem // this.折线周长量测ToolStripMenuItem.Name = "折线周长量测ToolStripMenuItem"; this.折线周长量测ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.折线周长量测ToolStripMenuItem.Text = "折线周长量测"; this.折线周长量测ToolStripMenuItem.Click += new System.EventHandler(this.折线周长量测ToolStripMenuItem_Click); // // toolStripStatusLabel1 // this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; this.toolStripStatusLabel1.Size = new System.Drawing.Size(46, 24); this.toolStripStatusLabel1.Text = "就绪"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1042, 645); this.Controls.Add(this.panel1); this.Controls.Add(this.axToolbarControl1); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "供水管网地理信息系统"; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.Load += new System.EventHandler(this.Form1_Load); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.panel1.ResumeLayout(false); this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false); this.splitContainer1.Panel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); this.groupBoxEagleEye.ResumeLayout(false); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit(); this.contextMenuStripTOC.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.axMapControl2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axTOCControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private ESRI.ArcGIS.Controls.AxToolbarControl axToolbarControl1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.SplitContainer splitContainer1; private ESRI.ArcGIS.Controls.AxMapControl axMapControl1; private System.Windows.Forms.StatusStrip statusStrip1; private ESRI.ArcGIS.Controls.AxLicenseControl axLicenseControl1; private ESRI.ArcGIS.Controls.AxTOCControl axTOCControl1; private System.Windows.Forms.ToolStripStatusLabel lblCoordinate; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; private System.Windows.Forms.ToolStripTextBox txtRotateAngle; private System.Windows.Forms.GroupBox groupBoxEagleEye; private ESRI.ArcGIS.Controls.AxMapControl axMapControl2; private System.Windows.Forms.ContextMenuStrip contextMenuStripTOC; private System.Windows.Forms.ToolStripMenuItem openAttributeTableToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem4; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem5; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem6; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem7; private System.Windows.Forms.ToolStripMenuItem 清除选择ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 空间量测ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 面积量测ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 周长量测ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 点坐标量测ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 清除已绘制图形ToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel lblResult; private System.Windows.Forms.ToolStripMenuItem 折线周长量测ToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Display; namespace WaterPipelineGIS2 { public partial class main : Form { private IFeatureLayer _selectedFeatureLayer; private System.Drawing.Point _lastRightClickPosition; private SelectionMode currentMode = SelectionMode.None; private IGraphicsContainer _spatialSelectionGraphics; private IGraphicsContainer _attributeHighlightGraphics; private ToolStripStatusLabel lblStatus; // 添加量测模式枚举 public enum MeasureMode { None, PolygonArea, PolygonPerimeter, PolylineLength, PointCoordinate } // 添加量测相关变量 private MeasureMode currentMeasureMode = MeasureMode.None; private List<IPoint> measurePoints = new List<IPoint>(); private IElement tempMeasureElement; private List<IElement> measurementElements = new List<IElement>(); private bool isMeasuring = false; // 修改后的SelectionMode枚举 public enum SelectionMode { None, Rectangle, Circle, Polygon, Polyline } private void InitializeGraphicsContainers() { try { // 确保地图控件已初始化 if (axMapControl1 == null) return; // 确保ActiveView已初始化 if (axMapControl1.ActiveView == null) { // 尝试刷新视图 axMapControl1.ActiveView.Refresh(); } if (axMapControl1.ActiveView != null) { _spatialSelectionGraphics = axMapControl1.ActiveView.GraphicsContainer; _attributeHighlightGraphics = axMapControl1.ActiveView.GraphicsContainer; } } catch (Exception ex) { MessageBox.Show("初始化图形容器失败: " + ex.Message); } } private void Form1_Load(object sender, EventArgs e) { // 强制创建地图控件 if (!axMapControl1.Created) axMapControl1.CreateControl(); // 延迟初始化图形容器 axMapControl1.ActiveView.Refresh(); InitializeGraphicsContainers(); } public main() { InitializeComponent(); // 确保设计器初始化完成 if (statusStrip1 != null) { lblStatus = new ToolStripStatusLabel(); statusStrip1.Items.Add(lblStatus); lblStatus.Text = "就绪"; } // 添加窗体加载事件处理程序 this.Load += Form1_LoadHandler; // === 修改结束 === // 事件绑定保持不变 axMapControl1.OnMouseMove += axMapControl1_OnMouseMove; axMapControl1.OnMouseDown += axMapControl1_OnMouseDown; axMapControl1.OnDoubleClick += new IMapControlEvents2_Ax_OnDoubleClickEventHandler(axMapControl1_OnDoubleClick); } // === 新增方法 === private void Form1_LoadHandler(object sender, EventArgs e) { // 确保地图控件已创建 if (axMapControl1 != null && !axMapControl1.Created) { axMapControl1.CreateControl(); } // 初始化图形容器 InitializeGraphicsContainers(); // 确保 ActiveView 有效 if (axMapControl1.ActiveView != null) { // 刷新视图以确保图形容器可用 axMapControl1.ActiveView.Refresh(); } } private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { try { // 公共坐标显示 double mapX = e.mapX; double mapY = e.mapY; lblCoordinate.Text = "X: {mapX:F3} Y: {mapY:F3}"; // 量测模式预览 if (isMeasuring && measurePoints.Count > 0) { switch (currentMeasureMode) { case MeasureMode.PolygonArea: case MeasureMode.PolygonPerimeter: DrawTempPolygonMeasure(e.x, e.y); break; case MeasureMode.PolylineLength: DrawTempPolylineMeasure(e.x, e.y); break; } } } catch (Exception ex) { Console.WriteLine("鼠标移动错误: " + ex.Message); } } private void toolStripMenuItem2_Click(object sender, EventArgs e) { using (var rotateForm = new RotateForm()) { if (rotateForm.ShowDialog() == DialogResult.OK) { try { axMapControl1.Rotation = rotateForm.RotationAngle; axMapControl1.ActiveView.Refresh(); lblCoordinate.Text += " 旋转角度:" + rotateForm.RotationAngle + "°"; } catch (Exception ex) { MessageBox.Show("旋转失败:" + ex.Message); } } } } private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { if (e.button == 2) // 右键 { _lastRightClickPosition = new System.Drawing.Point(e.x, e.y); ITOCControl2 tocControl = (ITOCControl2)axTOCControl1.Object; IBasicMap basicMap = null; ILayer layer = null; object other = Type.Missing; object index = Type.Missing; esriTOCControlItem itemType = esriTOCControlItem.esriTOCControlItemNone; tocControl.HitTest(e.x, e.y, ref itemType, ref basicMap, ref layer, ref other, ref index); if (itemType == esriTOCControlItem.esriTOCControlItemLayer && layer != null) { contextMenuStripTOC.Show(axTOCControl1, e.x, e.y); } } } private void openAttributeTableToolStripMenuItem_Click(object sender, EventArgs e) { ITOCControl2 tocControl = (ITOCControl2)axTOCControl1.Object; IBasicMap basicMap = null; ILayer layer = null; object other = Type.Missing; object index = Type.Missing; esriTOCControlItem itemType = esriTOCControlItem.esriTOCControlItemNone; System.Drawing.Point screenPos = contextMenuStripTOC.PointToClient(Control.MousePosition); System.Drawing.Point controlPos = axTOCControl1.PointToClient(Control.MousePosition); tocControl.HitTest( controlPos.X, controlPos.Y, ref itemType, ref basicMap, ref layer, ref other, ref index ); IFeatureLayer featureLayer = layer as IFeatureLayer; if (featureLayer != null) { _selectedFeatureLayer = featureLayer; AttributeTableForm attrForm = new AttributeTableForm( _selectedFeatureLayer, this ); attrForm.Show(); } } private void SetSelectionSymbol() { ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = GetRgbColor(255, 0, 0); fillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(255, 255, 0); lineSymbol.Width = 2; fillSymbol.Outline = lineSymbol; if (_selectedFeatureLayer != null) { IGeoFeatureLayer geoLayer = (IGeoFeatureLayer)_selectedFeatureLayer; ISimpleRenderer renderer = new SimpleRendererClass(); renderer.Symbol = (ISymbol)fillSymbol; geoLayer.Renderer = (IFeatureRenderer)renderer; axMapControl1.ActiveView.Refresh(); } } private IRgbColor GetRgbColor(int r, int g, int b) { IRgbColor color = new RgbColorClass(); color.Red = r; color.Green = g; color.Blue = b; return color; } private IRgbColor GetRgbColor(int r, int g, int b, int alpha) { IRgbColor color = new RgbColorClass(); color.Red = r; color.Green = g; color.Blue = b; color.Transparency = (byte)(255 - alpha); return color; } public void ActivateFeatureLayer(IFeatureLayer featureLayer) { if (featureLayer == null) return; _selectedFeatureLayer = featureLayer; axMapControl1.ActiveView.Refresh(); axTOCControl1.Update(); } public void HighlightAndZoomToFeature(IFeatureLayer featureLayer, int oid) { try { if (featureLayer == null || featureLayer.FeatureClass == null) { MessageBox.Show("图层或要素类无效!"); return; } IFeature feature = featureLayer.FeatureClass.GetFeature(oid); if (feature == null || feature.Shape == null) { MessageBox.Show("要素 OID " + oid + " 不存在或无几何!"); return; } IGeometry geometry = feature.Shape; IEnvelope envelope = geometry.Envelope; if (envelope.IsEmpty || envelope.Width == 0 || envelope.Height == 0) { envelope.Expand(10, 10, true); } else { envelope.Expand(1.5, 1.5, true); } axMapControl1.Extent = envelope; axMapControl1.ActiveView.ScreenDisplay.UpdateWindow(); HighlightGeometry(geometry); } catch (Exception ex) { MessageBox.Show("高亮要素失败: " + ex.Message); } } private void btnRectSelect_Click(object sender, EventArgs e) { currentMeasureMode = MeasureMode.None; // 互斥 currentMode = SelectionMode.Rectangle; axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; lblStatus.Text = "矩形选择模式"; } private void btnCircleSelect_Click(object sender, EventArgs e) { currentMeasureMode = MeasureMode.None; // 互斥 currentMode = SelectionMode.Circle; axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; lblStatus.Text = "圆形选择模式"; } private void btnPolygonSelect_Click(object sender, EventArgs e) { currentMeasureMode = MeasureMode.None; // 互斥 currentMode = SelectionMode.Polygon; axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; lblStatus.Text = "多边形选择模式"; } private void btnLineSelect_Click(object sender, EventArgs e) { currentMeasureMode = MeasureMode.None; // 互斥 currentMode = SelectionMode.Polyline; axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; lblStatus.Text = "折线选择模式"; } private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { try { // 量测模式处理 if (isMeasuring) { HandleMeasureMode(e); return; } // 左键点击 if (e.button == 1) { if (currentMode != SelectionMode.None) { HandleSpatialSelection(e); } } } catch (Exception ex) { MessageBox.Show("操作错误: " + ex.Message); } } private void PerformSpatialSelection(IGeometry geometry) { try { IMap map = axMapControl1.Map; if (map == null) return; map.ClearSelection(); for (int i = 0; i < map.LayerCount; i++) { IFeatureLayer featureLayer = map.get_Layer(i) as IFeatureLayer; if (featureLayer == null || !featureLayer.Valid || featureLayer.FeatureClass == null) continue; ISpatialFilter filter = new SpatialFilterClass(); filter.Geometry = geometry; filter.GeometryField = featureLayer.FeatureClass.ShapeFieldName; filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureSelection selection = (IFeatureSelection)featureLayer; selection.SelectFeatures(filter, esriSelectionResultEnum.esriSelectionResultNew, false); } axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); axMapControl1.ActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show("空间查询失败: " + ex.Message); } } private void HighlightGeometry(IGeometry geometry) { try { if (_spatialSelectionGraphics != null) { _spatialSelectionGraphics.DeleteAllElements(); } IElement element = null; switch (geometry.GeometryType) { case esriGeometryType.esriGeometryPolygon: { ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = GetRgbColor(255, 0, 0, 80); ISimpleLineSymbol outline = new SimpleLineSymbolClass(); outline.Color = GetRgbColor(255, 0, 0); outline.Width = 2; fillSymbol.Outline = outline; element = new PolygonElementClass(); element.Geometry = geometry; ((IFillShapeElement)element).Symbol = fillSymbol; } break; case esriGeometryType.esriGeometryPolyline: { ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(255, 0, 0); lineSymbol.Width = 3; element = new LineElementClass(); element.Geometry = geometry; ((ILineElement)element).Symbol = lineSymbol; } break; case esriGeometryType.esriGeometryPoint: { ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass(); markerSymbol.Color = GetRgbColor(255, 0, 0); markerSymbol.Size = 12; element = new MarkerElementClass(); element.Geometry = geometry; ((IMarkerElement)element).Symbol = markerSymbol; } break; } if (element != null && _spatialSelectionGraphics != null) { _spatialSelectionGraphics.AddElement(element, 0); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } } catch (Exception ex) { MessageBox.Show("高亮显示失败: " + ex.Message); } } private void btnClearSelection_Click(object sender, EventArgs e) { try { if (axMapControl1.Map != null) { axMapControl1.Map.ClearSelection(); } if (_spatialSelectionGraphics != null) { _spatialSelectionGraphics.DeleteAllElements(); } axMapControl1.ActiveView.PartialRefresh( esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGraphics, null, null ); axMapControl1.ActiveView.Refresh(); currentMode = SelectionMode.None; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; lblStatus.Text = "就绪"; } catch (Exception ex) { MessageBox.Show("清除选择失败: " + ex.Message); } } private void axMapControl1_OnDoubleClick(object sender, IMapControlEvents2_OnDoubleClickEvent e) { if (currentMode != SelectionMode.None) { currentMode = SelectionMode.None; axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; lblStatus.Text = "就绪"; } } private void HandleSpatialSelection(IMapControlEvents2_OnMouseDownEvent e) { IGeometry geometry = null; switch (currentMode) { case SelectionMode.Rectangle: IEnvelope rectEnv = axMapControl1.TrackRectangle(); if (rectEnv != null) { IPolygon polygon = new PolygonClass(); polygon.SpatialReference = axMapControl1.SpatialReference; ISegmentCollection segColl = (ISegmentCollection)polygon; segColl.SetRectangle(rectEnv); geometry = (IGeometry)polygon; } break; case SelectionMode.Circle: IEnvelope envelope = axMapControl1.TrackRectangle(); if (envelope.Width <= 0 || envelope.Height <= 0) { MessageBox.Show("请拖拽有效的矩形范围以创建圆形!"); return; } IPoint center = new PointClass(); center.PutCoords( (envelope.XMin + envelope.XMax) / 2, (envelope.YMin + envelope.YMax) / 2 ); double radius = Math.Max(envelope.Width, envelope.Height) / 2; ICircularArc circularArc = new CircularArcClass(); IConstructCircularArc constructArc = (IConstructCircularArc)circularArc; constructArc.ConstructCircle(center, radius, true); ISegmentCollection circleSegColl = new PolygonClass(); circleSegColl.AddSegment((ISegment)circularArc); geometry = (IGeometry)circleSegColl; geometry.SpatialReference = axMapControl1.SpatialReference; break; case SelectionMode.Polygon: geometry = axMapControl1.TrackPolygon(); break; case SelectionMode.Polyline: geometry = axMapControl1.TrackLine(); break; } if (geometry != null) { PerformSpatialSelection(geometry); HighlightGeometry(geometry); } } // 创建折线几何 private IPolyline CreatePolyline(List<IPoint> points, IPoint currentPoint = null) { try { // 创建点集合 IPointCollection pointCollection = new PolylineClass(); // 添加所有点 foreach (IPoint point in points) { if (point != null) { pointCollection.AddPoint(point); } } // 添加当前鼠标位置 if (currentPoint != null) { pointCollection.AddPoint(currentPoint); } // 转换为折线 IPolyline polyline = pointCollection as IPolyline; if (polyline == null) return null; // 设置空间参考(关键!) if (axMapControl1.SpatialReference != null) { polyline.SpatialReference = axMapControl1.SpatialReference; } // 简化几何 ITopologicalOperator topoOp = polyline as ITopologicalOperator; if (topoOp != null) { topoOp.Simplify(); } return polyline; } catch (Exception ex) { MessageBox.Show("创建折线时出错: " + ex.Message); return null; } } // 创建多边形几何 private IPolygon CreatePolygon(List<IPoint> points, IPoint currentPoint = null) { try { // 创建点集合 IPointCollection pointCollection = new PolygonClass(); // 添加所有点 foreach (IPoint point in points) { if (point != null) { pointCollection.AddPoint(point); } } // 添加当前鼠标位置 if (currentPoint != null) { pointCollection.AddPoint(currentPoint); } // 转换为多边形 IPolygon polygon = pointCollection as IPolygon; if (polygon == null) return null; // 设置空间参考(关键!) if (axMapControl1.SpatialReference != null) { polygon.SpatialReference = axMapControl1.SpatialReference; } // 简化几何 ITopologicalOperator topoOp = polygon as ITopologicalOperator; if (topoOp != null) { topoOp.Simplify(); } return polygon; } catch (Exception ex) { MessageBox.Show("创建多边形时出错: " + ex.Message); return null; } } // 量测菜单项点击事件处理 private void 面积量测ToolStripMenuItem_Click(object sender, EventArgs e) { StartMeasureMode(MeasureMode.PolygonArea); } private void 周长量测ToolStripMenuItem_Click(object sender, EventArgs e) { StartMeasureMode(MeasureMode.PolygonPerimeter); } private void 折线周长量测ToolStripMenuItem_Click(object sender, EventArgs e) { StartMeasureMode(MeasureMode.PolylineLength); } private void 点坐标量测ToolStripMenuItem_Click(object sender, EventArgs e) { StartMeasureMode(MeasureMode.PointCoordinate); } // 开始量测模式 private void StartMeasureMode(MeasureMode mode) { currentMode = SelectionMode.None; // 互斥 // 清除之前的状态 EndMeasureMode(); currentMeasureMode = mode; isMeasuring = true; measurePoints.Clear(); // 设置鼠标指针 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; // 设置状态栏提示 switch (mode) { case MeasureMode.PolygonArea: lblStatus.Text = "面积量测: 左键添加顶点,右键完成"; break; case MeasureMode.PolygonPerimeter: lblStatus.Text = "周长量测: 左键添加顶点,右键完成"; break; case MeasureMode.PolylineLength: lblStatus.Text = "长度量测: 左键添加顶点,右键完成"; break; case MeasureMode.PointCoordinate: lblStatus.Text = "点坐标量测: 左键点击地图获取坐标"; break; } } // 结束量测模式 private void EndMeasureMode() { ClearTempMeasureElement(); measurePoints.Clear(); isMeasuring = false; currentMeasureMode = MeasureMode.None; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; lblStatus.Text = "就绪"; } // 绘制临时多边形量测图形 private void DrawTempPolygonMeasure(int x, int y) { if (measurePoints.Count == 0) return; try { // 清除之前的临时图形 ClearTempMeasureElement(); // 获取当前鼠标位置 IPoint currentPoint = axMapControl1.ToMapPoint(x, y); // 创建临时多边形(包括当前鼠标位置) IPolygon polygon = CreatePolygon(measurePoints, currentPoint); // 创建符号(蓝色边框,半透明填充) ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(0, 0, 255); // 蓝色 lineSymbol.Width = 2; ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Outline = lineSymbol; fillSymbol.Color = GetRgbColor(0, 255, 255, 100); // 青色半透明 // 创建元素 tempMeasureElement = new PolygonElementClass(); tempMeasureElement.Geometry = polygon; ((IFillShapeElement)tempMeasureElement).Symbol = fillSymbol; // 添加到地图 IGraphicsContainer graphics = axMapControl1.Map as IGraphicsContainer; if (graphics != null) { graphics.AddElement(tempMeasureElement, 0); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } } catch (Exception ex) { Console.WriteLine("量测预览错误: " + ex.Message); } } // 绘制临时折线量测图形 private void DrawTempPolylineMeasure(int x, int y) { if (measurePoints.Count == 0) return; try { // 清除之前的临时图形 ClearTempMeasureElement(); // 获取当前鼠标位置 IPoint currentPoint = axMapControl1.ToMapPoint(x, y); // 创建临时折线(包括当前鼠标位置) IPolyline polyline = CreatePolyline(measurePoints, currentPoint); // 创建符号(红色粗线) ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(255, 0, 0); // 红色 lineSymbol.Width = 3; // 创建元素 tempMeasureElement = new LineElementClass(); tempMeasureElement.Geometry = polyline; ((ILineElement)tempMeasureElement).Symbol = lineSymbol; // 添加到地图 IGraphicsContainer graphics = axMapControl1.Map as IGraphicsContainer; if (graphics != null) { graphics.AddElement(tempMeasureElement, 0); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } } catch (Exception ex) { Console.WriteLine("量测预览错误: " + ex.Message); } } // 清除临时量测图形 private void ClearTempMeasureElement() { if (tempMeasureElement != null) { IGraphicsContainer graphics = axMapControl1.Map as IGraphicsContainer; if (graphics != null) { graphics.DeleteElement(tempMeasureElement); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } tempMeasureElement = null; } } // 处理量测模式 private void HandleMeasureMode(IMapControlEvents2_OnMouseDownEvent e) { try { // 获取当前鼠标位置 IPoint point = axMapControl1.ToMapPoint(e.x, e.y); // 左键添加点 if (e.button == 1) { switch (currentMeasureMode) { case MeasureMode.PolygonArea: case MeasureMode.PolygonPerimeter: case MeasureMode.PolylineLength: measurePoints.Add(point); break; case MeasureMode.PointCoordinate: CompletePointMeasure(point); break; } } // 右键完成量测 else if (e.button == 2) { switch (currentMeasureMode) { case MeasureMode.PolygonArea: CompletePolygonMeasure(true); break; case MeasureMode.PolygonPerimeter: CompletePolygonMeasure(false); break; case MeasureMode.PolylineLength: CompletePolylineMeasure(); break; } } } catch (Exception ex) { MessageBox.Show("量测错误: " + ex.Message); } } // 完成多边形量测 private void CompletePolygonMeasure(bool isArea) { if (measurePoints.Count < 3) { MessageBox.Show("多边形至少需要3个顶点"); return; } try { // 创建最终多边形 IPolygon polygon = CreatePolygon(measurePoints); if (polygon == null || polygon.IsEmpty) { MessageBox.Show("无法创建有效多边形"); return; } // 计算量测结果 IArea area = polygon as IArea; double result = 0; string unit = ""; string title = ""; if (isArea) { // 面积量测 result = area.Area; // 平方米 unit = "平方米"; title = "面积量测结果"; } else { // 周长量测 ICurve curve = polygon as ICurve; result = curve.Length; // 米 unit = "米"; title = "周长量测结果"; } // 构建结果消息 string message = string.Format("{0:0.##} {1}", result, unit); if (isArea) { double hectareArea = result / 10000; // 公顷 message += string.Format("\n{0:0.##} 公顷", hectareArea); } else { double kilometer = result / 1000; // 千米 message += string.Format("\n{0:0.##} 千米", kilometer); } // 使用自定义窗体显示结果 ShowMeasureResult(title, message); // 绘制最终量测图形 DrawFinalMeasureElement(polygon, isArea); } catch (Exception ex) { MessageBox.Show("量测出错: " + ex.Message); } finally { // 结束量测模式 EndMeasureMode(); } } // 完成折线量测 private void CompletePolylineMeasure() { if (measurePoints.Count < 2) { MessageBox.Show("折线至少需要2个顶点"); return; } try { // 创建最终折线 IPolyline polyline = CreatePolyline(measurePoints); if (polyline == null || polyline.IsEmpty) { MessageBox.Show("无法创建有效折线"); return; } // 计算长度 ICurve curve = polyline as ICurve; double length = curve.Length; // 米 double kilometer = length / 1000; // 千米 // 构建结果消息 string message = string.Format("{0:0.##} 米\n{1:0.##} 千米", length, kilometer); // 使用自定义窗体显示结果 ShowMeasureResult("长度量测结果", message); // 绘制最终量测图形 DrawFinalMeasureElement(polyline); } catch (Exception ex) { MessageBox.Show("量测出错: " + ex.Message); } finally { // 结束量测模式 EndMeasureMode(); } } // 完成点坐标量测 private void CompletePointMeasure(IPoint point) { try { // 获取坐标系信息 string coordSystem = "未知坐标系"; if (axMapControl1.SpatialReference != null) { coordSystem = axMapControl1.SpatialReference.Name; } // 构建结果消息 string message = string.Format("X: {0:0.###}\nY: {1:0.###}\n\n坐标系: {2}", point.X, point.Y, coordSystem); // 使用自定义窗体显示结果 ShowMeasureResult("坐标量测结果", message); // 绘制点标记 DrawPointMarker(point); } catch (Exception ex) { MessageBox.Show("量测出错: " + ex.Message); } finally { // 结束量测模式 EndMeasureMode(); } } // 绘制最终量测图形 private void DrawFinalMeasureElement(IGeometry geometry, bool isArea = true) { IGraphicsContainer graphics = axMapControl1.Map as IGraphicsContainer; if (graphics == null) return; IElement element = null; if (geometry is IPolygon) { // 创建符号(蓝色边框,半透明填充) ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(0, 0, 255); // 蓝色 lineSymbol.Width = 2; ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Outline = lineSymbol; fillSymbol.Color = GetRgbColor(0, 255, 255, 100); // 青色半透明 // 创建元素 element = new PolygonElementClass(); element.Geometry = geometry; ((IFillShapeElement)element).Symbol = fillSymbol; } else if (geometry is IPolyline) { // 创建符号(红色粗线) ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(255, 0, 0); // 红色 lineSymbol.Width = 3; // 创建元素 element = new LineElementClass(); element.Geometry = geometry; ((ILineElement)element).Symbol = lineSymbol; } if (element != null) { // 添加到地图 graphics.AddElement(element, 0); measurementElements.Add(element); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } } // 绘制点标记 private void DrawPointMarker(IPoint point) { IGraphicsContainer graphics = axMapControl1.Map as IGraphicsContainer; if (graphics == null) return; // 创建符号(绿色十字) ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass(); markerSymbol.Style = esriSimpleMarkerStyle.esriSMSCross; markerSymbol.Color = GetRgbColor(0, 255, 0); // 绿色 markerSymbol.Size = 12; markerSymbol.Outline = true; markerSymbol.OutlineColor = GetRgbColor(0, 0, 0); // 黑色边框 markerSymbol.OutlineSize = 1; // 创建元素 IMarkerElement markerElement = new MarkerElementClass(); markerElement.Symbol = markerSymbol; ((IElement)markerElement).Geometry = point; // 添加到地图 graphics.AddElement((IElement)markerElement, 0); measurementElements.Add((IElement)markerElement); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } // 清除已绘制图形 private void 清除已绘制图形ToolStripMenuItem_Click(object sender, EventArgs e) { ClearMeasurementGraphics(); } // 清除量测图形 private void ClearMeasurementGraphics() { try { IActiveView activeView = axMapControl1.ActiveView; IGraphicsContainer graphics = activeView.GraphicsContainer; if (graphics == null) return; // 删除所有量测图形元素 foreach (IElement element in measurementElements) { graphics.DeleteElement(element); } // 清空列表 measurementElements.Clear(); // 强制刷新地图视图 activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); activeView.Refresh(); lblStatus.Text = "已清除所有量测图形"; } catch (Exception ex) { MessageBox.Show("清除图形时出错: " + ex.Message); } } // 在 Form1 类中添加新方法 private void ShowMeasureResult(string title, string message) { using (MeasureResultForm resultForm = new MeasureResultForm(title, message)) { resultForm.ShowDialog(this); } } } }此代码我想实现鹰眼导航(即在此代码中,mapcontrol控件(axMapControl1)中显示的是主地图,而左下角的mapcontrol控件(axMapControl2)进行鹰眼导航,axMapControl1中的视野范围在axMapControl2中用深蓝色边框进行框起来。无论是主视图大小缩放还是通过鼠标移动视角,在axMapControl2都要跟着框起来,他固定不动但是蓝色边框跟着移动)注意我的vs版本为2010,给出完整的修改代码(包括designer.cs),要细致的修改操作教程

最新推荐

recommend-type

PLC控制变频器:三菱与汇川PLC通过485通讯板实现变频器正反转及调速控制

内容概要:本文介绍了如何利用三菱和汇川PLC通过485通讯板实现变频器的正转、反转及调速控制。主要内容涵盖硬件配置、软件编程、具体控制逻辑及上机测试。文中详细描述了各个步骤的操作方法和注意事项,包括关键寄存器的设置及其含义。程序中有详细的中文注释,便于理解和维护。最终通过上机测试验证系统的稳定性和可靠性。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是熟悉PLC编程和变频器控制的专业人士。 使用场景及目标:适用于需要对电机进行精确控制的工业应用场景,如生产线、机械设备等。目标是提高控制系统灵活性和效率,确保系统稳定可靠。 其他说明:本文不仅提供理论指导,还附带实际操作经验,有助于读者更好地掌握相关技术和应用。
recommend-type

Web前端开发:CSS与HTML设计模式深入解析

《Pro CSS and HTML Design Patterns》是一本专注于Web前端设计模式的书籍,特别针对CSS(层叠样式表)和HTML(超文本标记语言)的高级应用进行了深入探讨。这本书籍属于Pro系列,旨在为专业Web开发人员提供实用的设计模式和实践指南,帮助他们构建高效、美观且可维护的网站和应用程序。 在介绍这本书的知识点之前,我们首先需要了解CSS和HTML的基础知识,以及它们在Web开发中的重要性。 HTML是用于创建网页和Web应用程序的标准标记语言。它允许开发者通过一系列的标签来定义网页的结构和内容,如段落、标题、链接、图片等。HTML5作为最新版本,不仅增强了网页的表现力,还引入了更多新的特性,例如视频和音频的内置支持、绘图API、离线存储等。 CSS是用于描述HTML文档的表现(即布局、颜色、字体等样式)的样式表语言。它能够让开发者将内容的表现从结构中分离出来,使得网页设计更加模块化和易于维护。随着Web技术的发展,CSS也经历了多个版本的更新,引入了如Flexbox、Grid布局、过渡、动画以及Sass和Less等预处理器技术。 现在让我们来详细探讨《Pro CSS and HTML Design Patterns》中可能包含的知识点: 1. CSS基础和选择器: 书中可能会涵盖CSS基本概念,如盒模型、边距、填充、边框、背景和定位等。同时还会介绍CSS选择器的高级用法,例如属性选择器、伪类选择器、伪元素选择器以及选择器的组合使用。 2. CSS布局技术: 布局是网页设计中的核心部分。本书可能会详细讲解各种CSS布局技术,包括传统的浮动(Floats)布局、定位(Positioning)布局,以及最新的布局模式如Flexbox和CSS Grid。此外,也会介绍响应式设计的媒体查询、视口(Viewport)单位等。 3. 高级CSS技巧: 这些技巧可能包括动画和过渡效果,以及如何优化性能和兼容性。例如,CSS3动画、关键帧动画、转换(Transforms)、滤镜(Filters)和混合模式(Blend Modes)。 4. HTML5特性: 书中可能会深入探讨HTML5的新标签和语义化元素,如`<article>`、`<section>`、`<nav>`等,以及如何使用它们来构建更加标准化和语义化的页面结构。还会涉及到Web表单的新特性,比如表单验证、新的输入类型等。 5. 可访问性(Accessibility): Web可访问性越来越受到重视。本书可能会介绍如何通过HTML和CSS来提升网站的无障碍访问性,比如使用ARIA标签(Accessible Rich Internet Applications)来增强屏幕阅读器的使用体验。 6. 前端性能优化: 性能优化是任何Web项目成功的关键。本书可能会涵盖如何通过优化CSS和HTML来提升网站的加载速度和运行效率。内容可能包括代码压缩、合并、避免重绘和回流、使用Web字体的最佳实践等。 7. JavaScript与CSS/HTML的交互: 在现代Web开发中,JavaScript与CSS及HTML的交云并用是不可或缺的。书中可能会讲解如何通过JavaScript动态地修改样式、操作DOM元素以及使用事件监听和响应用户交互。 8. Web框架和预处理器: 这本书可能会提到流行的Web开发框架和预处理器,比如Bootstrap、Foundation、Sass和Less等,它们是如何简化和加速开发流程的。 9. 测试和维护: 书中也可能包含关于如何测试网页以及如何持续优化和维护CSS和HTML代码的章节。例如,使用断言测试、自动化测试、性能分析工具等。 最后,鉴于文件名称列表中的“压缩包子文件”的表述,这可能是对“压缩包”文件的一种误译或误用,此处“压缩包”应该指的是包含该书籍PDF文件的压缩文件格式,如ZIP或RAR。而“Pro CSS and HTML Design Patterns.pdf”指的就是该书籍的PDF格式电子版文件。 以上所述,构成了《Pro CSS and HTML Design Patterns》一书可能包含的核心知识点。通过学习这些内容,Web前端开发者可以掌握更为高效和优雅的设计模式,从而在日常工作中更高效地解决实际问题。
recommend-type

Zotero 7数据同步:Attanger插件安装&设置,打造文献管理利器

/i.s3.glbimg.com/v1/AUTH_08fbf48bc0524877943fe86e43087e7a/internal_photos/bs/2018/L/j/ipKA8TRPyt4ptaG1DGww/t-m-01.png) # 1. Zotero 7数据同步简介 在数字时代,管理研究数据变得日益重要,而Zot
recommend-type

卷积神经网络的基础理论200字

<think>我们正在回答用户关于卷积神经网络(CNN)基础理论的询问。根据提供的引用资料,我们可以概述CNN的基本结构和工作原理。引用[1]提到CNN是一种前馈神经网络,信息从输入单向流动到输出。引用[2]指出CNN在图像处理等领域应用广泛,通过层次结构和参数调整实现模式识别。引用[3]说明CNN包含卷积层,使用卷积核提取局部特征,减少参数量,提高效率。引用[4]则提到了训练过程,包括前向传播、误差计算和反向传播(梯度下降)。因此,我们将从以下几个方面概述CNN:1.CNN的基本结构(卷积层、池化层、全连接层)2.卷积操作的工作原理(局部感受野、权重共享)3.训练过程(前向传播、损失函数、反
recommend-type

轻便实用的Java库类查询工具介绍

标题 "java2库类查询" 和描述表明,所提及的工具是一个专门用于查询Java库类的应用程序。此软件旨在帮助开发者快速地查找和引用Java的标准开发工具包(SDK)中包含的所有应用程序编程接口(API)类。通过这样的工具,开发者可以节省大量在官方文档或搜索引擎上寻找类定义和使用方法的时间。它被描述为轻巧且方便,这表明其占用的系统资源相对较少,同时提供直观的用户界面,使得查询过程简洁高效。 从描述中可以得出几个关键知识点: 1. Java SDK:Java的软件开发工具包(SDK)是Java平台的一部分,提供了一套用于开发Java应用软件的软件包和库。这些软件包通常被称为API,为开发者提供了编程界面,使他们能够使用Java语言编写各种类型的应用程序。 2. 库类查询:这个功能对于开发者来说非常关键,因为它提供了一个快速查找特定库类及其相关方法、属性和使用示例的途径。良好的库类查询工具可以帮助开发者提高工作效率,减少因查找文档而中断编程思路的时间。 3. 轻巧性:软件的轻巧性通常意味着它对计算机资源的要求较低。这样的特性对于资源受限的系统尤为重要,比如老旧的计算机、嵌入式设备或是当开发者希望最小化其开发环境占用空间时。 4. 方便性:软件的方便性通常关联于其用户界面设计,一个直观、易用的界面可以让用户快速上手,并减少在使用过程中遇到的障碍。 5. 包含所有API:一个优秀的Java库类查询软件应当能够覆盖Java所有标准API,这包括Java.lang、Java.util、Java.io等核心包,以及Java SE平台的所有其他标准扩展包。 从标签 "java 库 查询 类" 可知,这个软件紧密关联于Java编程语言的核心功能——库类的管理和查询。这些标签可以关联到以下知识点: - Java:一种广泛用于企业级应用、移动应用(如Android应用)、网站后端、大型系统和许多其他平台的编程语言。 - 库:在Java中,库是一组预打包的类和接口,它们可以被应用程序重复使用。Java提供了庞大的标准库,以支持各种常见的任务和功能。 - 查询:查询指的是利用软件工具搜索、定位和检索信息的过程。对于Java库类查询工具来说,这意味着可以通过类名、方法签名或其他标识符来查找特定的API条目。 最后,压缩包文件列表包含了两个文件:“java.dit”和“Java.exe”。其中“Java.exe”很可能是程序的可执行文件,而“java.dit”可能是一个数据文件,用于存储Java类的索引或数据。由于文件名后缀通常与文件类型相关联,但“dit”并不是一个常见的文件扩展名。这可能是一个特定于软件的自定义格式,或是一个打字错误。 总结来说,"java2库类查询" 是一个针对Java开发者的实用工具,它提供了一个轻量级、易用的平台来查询和定位Java标准库中的所有类和API。此工具对优化开发流程,减少查找Java类文档的时间大有裨益,尤其适合需要频繁查阅Java API的开发者使用。
recommend-type

【Zotero 7终极指南】:新手必备!Attanger插件全攻略与数据同步神技

# 1. Zotero 7与Attanger插件的介绍 在当今的学术研究和知识管理领域,高效的文献管理工具至关重要。Zotero 7作为一个流行的参考文献管理软件,因其强大的功能和用户友好的界面而受到专业人士的青睐。而Attanger插件则为Zotero 7带来了更多定制化和高级功能,极大地增强
recommend-type

MATLAB整段注释快捷键

<think>首先,用户的问题是:“MATLAB整段注释快捷键”,意思是“MATLAB整段注释快捷键”。我需要用中文回答。 根据规则: - 回答必须用中文。 - 回答完问题后,必须在末尾输出“§§相关问题§§”,然后提出3-5个相关问题。 - “§§相关问题§§”必须完整输出在第一行,禁止换行分散。 - 相关问题必须基于用户的问题和我的回答。 现在,回忆MATLAB的快捷键:在MATLAB中,整段注释通常使用快捷键Ctrl + R来注释选中的代码行,使用Ctrl + T来取消注释。用户问的是“整段注释”,所以我应该确认快捷键。 在MATLAB中: - 注释选中的行:Ctrl + R -
recommend-type

Eclipse Jad反编译插件:提升.class文件查看便捷性

反编译插件for Eclipse是一个专门设计用于在Eclipse集成开发环境中进行Java反编译的工具。通过此类插件,开发者可以在不直接访问源代码的情况下查看Java编译后的.class文件的源代码,这在开发、维护和学习使用Java技术的过程中具有重要的作用。 首先,我们需要了解Eclipse是一个跨平台的开源集成开发环境,主要用来开发Java应用程序,但也支持其他诸如C、C++、PHP等多种语言的开发。Eclipse通过安装不同的插件来扩展其功能。这些插件可以由社区开发或者官方提供,而jadclipse就是这样一个社区开发的插件,它利用jad.exe这个第三方命令行工具来实现反编译功能。 jad.exe是一个反编译Java字节码的命令行工具,它可以将Java编译后的.class文件还原成一个接近原始Java源代码的格式。这个工具非常受欢迎,原因在于其反编译速度快,并且能够生成相对清晰的Java代码。由于它是一个独立的命令行工具,直接使用命令行可以提供较强的灵活性,但是对于一些不熟悉命令行操作的用户来说,集成到Eclipse开发环境中将会极大提高开发效率。 使用jadclipse插件可以很方便地在Eclipse中打开任何.class文件,并且将反编译的结果显示在编辑器中。用户可以在查看反编译的源代码的同时,进行阅读、调试和学习。这样不仅可以帮助开发者快速理解第三方库的工作机制,还能在遇到.class文件丢失源代码时进行紧急修复工作。 对于Eclipse用户来说,安装jadclipse插件相当简单。一般步骤包括: 1. 下载并解压jadclipse插件的压缩包。 2. 在Eclipse中打开“Help”菜单,选择“Install New Software”。 3. 点击“Add”按钮,输入插件更新地址(通常是jadclipse的更新站点URL)。 4. 选择相应的插件(通常名为“JadClipse”),然后进行安装。 5. 安装完成后重启Eclipse,插件开始工作。 一旦插件安装好之后,用户只需在Eclipse中双击.class文件,或者右键点击文件并选择“Open With Jadclipse”,就能看到对应的Java源代码。如果出现反编译不准确或失败的情况,用户还可以直接在Eclipse中配置jad.exe的路径,或者调整jadclipse的高级设置来优化反编译效果。 需要指出的是,使用反编译工具虽然方便,但要注意反编译行为可能涉及到版权问题。在大多数国家和地区,反编译软件代码属于合法行为,但仅限于学习、研究、安全测试或兼容性开发等目的。如果用户意图通过反编译获取商业机密或进行非法复制,则可能违反相关法律法规。 总的来说,反编译插件for Eclipse是一个强大的工具,它极大地简化了Java反编译流程,提高了开发效率,使得开发者在没有源代码的情况下也能有效地维护和学习Java程序。但开发者在使用此类工具时应遵守法律与道德规范,避免不当使用。
recommend-type

【进阶Python绘图】:掌握matplotlib坐标轴刻度间隔的高级技巧,让你的图表脱颖而出

# 摘要 本文系统地探讨了matplotlib库中坐标轴刻度间隔的定制与优化技术。首先概述了matplotlib坐标轴刻度间隔的基本概念及其在图表中的重要性,接
recommend-type

降帧是什么意思

<think>首先,用户的问题是:“我想了解降帧的含义 请问降帧是什么意思”。我需要用中文回答,并确保回答结构清晰,帮助用户逐步解决问题。 关键点是“降帧”。在视频处理、动画或游戏上下文中,“降帧”通常指的是帧率下降或丢帧(frame drop)。结合系统提供的引用,我可以看到相关概念。 回顾提供的引用: - 引用[1]:讨论了帧率和丢帧分析,提到应用丢帧导致帧率下降,造成卡顿。例如,在60Hz刷新率下,每帧需要在16.7ms内完成,否则可能丢帧。 - 引用[2]:提到掉帧(Frame Drop),与CPU和GPU相关。CPU或GPU处理不及时会导致帧无法按时渲染。 - 引用[3]: