新建示例
1:新建项目
新建一个网站,选择MapXtreme 6.7.1 Web Application
在App_Code中,我们新建一个类,起名叫:LayerManager.cs
2:把上节函数放到类LayerManager中
把上一节的函数代码全copy过来,还有using的名称空间
3:打开MapForm.cs,在Page_Load代码里,添加如下代码

Code
string tableName = "tableName", layerName = "layerName";//随便定义两个名字
LayerManager.CreateLayer(tableName, layerName);//创建图层
LayerManager.AddPoint(layerName, GetDPoint(60,60), 35, Color.Red);//创建一个红色五角星的点
LayerManager.AddLine(layerName, GetDPoint(160, 160), GetDPoint(300, 160), 59, Color.Red);//创建一条红色单箭头的线
LayerManager.ShowValue(tableName, "value");//显示标注
说明:
里面有一个GetDPoint(int x,int y)函数,主要是传入客户端的坐标,返回地图的经纬度
GetDPoint 函数如下

Code
private DPoint GetDPoint(int x,int y)

{
DPoint dp = new DPoint();
System.Drawing.Point point = new System.Drawing.Point(x, y);//客户端坐标(相对地图)
Map map = MapInfo.Engine.Session.Current.MapFactory[0];
map.DisplayTransform.FromDisplay(point, out dp);//转成相应的经纬度坐标
return dp;
}
4:完整的页面代码如下

Code
public partial class _Default : System.Web.UI.Page


{
private void Page_Load(object sender, System.EventArgs e)

{
// If the StateManager doesn't exist in the session put it else get it.
if (StateManager.GetStateManagerFromSession() == null)
StateManager.PutStateManagerInSession(new AppStateManager());

// Now Restore State
StateManager.GetStateManagerFromSession().ParamsDictionary[StateManager.ActiveMapAliasKey] = MapControl1.MapAlias;
StateManager.GetStateManagerFromSession().RestoreState();

string tableName = "tableName", layerName = "layerName";//随便定义两个名字
LayerManager.CreateLayer(tableName, layerName);//创建图层
LayerManager.AddPoint(layerName, GetDPoint(60,60), 35, Color.Red);//创建一个红色五角星的点
LayerManager.AddLine(layerName, GetDPoint(160, 160), GetDPoint(300, 160), 59, Color.Red);//创建一条红色单箭头的线
LayerManager.ShowValue(tableName, "value");//显示标注
}
private DPoint GetDPoint(int x,int y)

{
DPoint dp = new DPoint();
System.Drawing.Point point = new System.Drawing.Point(x, y);//客户端坐标(相对地图)
Map map = MapInfo.Engine.Session.Current.MapFactory[0];
map.DisplayTransform.FromDisplay(point, out dp);//转成相应的经纬度坐标
return dp;
}
// At the time of unloading the page, save the state
private void Page_UnLoad(object sender, System.EventArgs e)

{
StateManager.GetStateManagerFromSession().SaveState();
}
}
5:运行结果
OK,保存,浏览,即可在页面上看到在相应的地方上,创建了一个五角星和一个红色单向箭头线
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
2007-11-02 数据绑定控件单选框