MapXtreme 2005 学习心得 一些基础函数代码(四)
2023-09-14 08:59:38 时间
/// summary
/// 添加线[代码和创建点的相差无几]
/// by 路过秋天
/// param name="layerName" 图层名 /param
/// param name="startPoint" 线段起点坐标 /param
/// param name="endPoint" 线段终点坐标 /param
/// param name="shortCode" 线的shortCode(线的型状也有多种,比如单箭头,双箭头等) /param
/// param name="color" 线的颜色 /param
/// /summary
public static void AddLine(string layerName, DPoint startPoint, DPoint endPoint, int shortCode, Color color)
{
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[0];
//获取图层和表
FeatureLayer workLayer = (MapInfo.Mapping.FeatureLayer)myMap.Layers[layerName];
MapInfo.Data.Table table = workLayer.Table;
//创建线
FeatureGeometry line = MultiCurve.CreateLine(workLayer.CoordSys, startPoint, endPoint);
//以下两行是图形的样式
MapInfo.Styles.SimpleLineStyle slsLine = new MapInfo.Styles.SimpleLineStyle(new LineWidth(3, LineWidthUnit.Pixel), shortCode, color);
MapInfo.Styles.CompositeStyle lineStyle = new MapInfo.Styles.CompositeStyle(slsLine);
//接下来创建一行数据
MapInfo.Data.Feature ptLine = new MapInfo.Data.Feature(table.TableInfo.Columns);
ptLine.Geometry = line;
ptLine.Style = lineStyle;
ptLine["index"] = new Random().Next(999); ;
ptLine["value"] = "this is a line";
//将线图元加入图层
table.InsertFeature(ptLine);
}
三:显示标注文本
1:显示标注文本函数代码:ShowValue
/// summary
/// 显示标注
/// by 路过秋天
/// param name="tableName" 标注的表名 /param
/// param name="columnName" 标注的列名 /param
/// /summary
public static void ShowValue(string tableName, string columnName)
{
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[0];
//新建标注图层并绑定数据(整个过程有点像DataGrid控件指定数据源控件SqlDataSource,而数据源控件又绑定了DataTable)
LabelLayer labelLayer = new LabelLayer();
myMap.Layers.Add(labelLayer);
//指定要标注的数据表
MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(tableName);
LabelSource source = new LabelSource(table);//绑定Table
labelLayer.Sources.Append(source);//加载指定数据
//指定哪个字段作为显示标注(在非必备的自定义列里挑一个,比如我们就挑"value"列)
source.DefaultLabelProperties.Caption = columnName;
//标注样式等属性,注意这段注释的代码,是指在一定的缩放比例范围内才显示文本,要是不注释掉,可能折腾半天也看不到为啥显示不出来文本
//source.DefaultLabelProperties.Visibility.Enabled = true;
//source.DefaultLabelProperties.Visibility.VisibleRangeEnabled = true;
//source.DefaultLabelProperties.Visibility.VisibleRange = new VisibleRange(0.01, 10, MapInfo.Geometry.DistanceUnit.Mile);
source.DefaultLabelProperties.Visibility.AllowDuplicates = true;
source.DefaultLabelProperties.Visibility.AllowOverlap = true;
source.DefaultLabelProperties.Visibility.AllowOutOfView = true;
source.Maximum = 50;
source.DefaultLabelProperties.Layout.UseRelativeOrientation = true;
source.DefaultLabelProperties.Layout.RelativeOrientation = MapInfo.Text.RelativeOrientation.FollowPath;
source.DefaultLabelProperties.Layout.Angle = 33.0;
source.DefaultLabelProperties.Layout.Offset = 7;
source.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.CenterCenter;
MapInfo.Styles.Font font = new MapInfo.Styles.Font("黑体", 12);
font.ForeColor = System.Drawing.Color.Red;
source.DefaultLabelProperties.Style.Font = font;
}
先上这四个最基本的函数,如果把这几个函数放一个类中,别忘了加名称空间
using MapInfo.Geometry;using MapInfo.Mapping;
using MapInfo.Styles;
using MapInfo.Data;
using MapInfo.Text;
using System.Drawing;
相关文章
- Python基础14-内置模块
- php代码审计基础篇
- C语言编程基础入门经典100题(1-10)-简书_c语言简单代码
- java的基础代码_java编程入门基础教程
- 机器学习基础:缺失值的处理技巧(附Python代码)
- WPF实现基础控件之托盘的示例代码分享
- 数论基础专题小结
- ES6-语法基础
- pandas基础:数据显示格式转换(续)
- 基础算法篇——区间合并
- 自研代码率超70%,国产大数据基础软件第一股星环科技成功上市!
- 微搭低代码从入门到精通07-基础布局组件
- Go语言学习笔记2一 Golang的基础2
- PostgreSQL 基础与实践
- linux基础:脚本基础介绍
- WEB基础:Apache Calcite 实现方言转换的代码
- MySQL DATABASE基础代码:入门指南(mysql数据库基础代码)
- 从零开始学习大数据 Linux基础,打造数据时代的核心竞争力(大数据linux基础)
- 教程学习Oracle 11g:开启基础教程之旅(oracle11g基础)
- jQuery改变CSS样式基础代码
- C#基础之数组排序、对象大小比较实现代码
- 第二章PHP入门基础之php代码写法
- (跨浏览器基础事件/浏览器检测/判断浏览器)经验代码分享
- php四种基础算法代码实例