1、在工程中使用时提示无法找到dll,可能是由于添加引用的时候“复制到本地”是true,而vs没有c盘下对应目录的读取权限,就会出错。解决方法是将对应dll拷贝出来,或者是该设置项改为false。

2、InitializeComponent()提示dll加载有问题,是由于Mapxtreme的二进制与当前工程不兼容造成,我的Mapxtreme是x86的,工程的“目标平台”也要改为x86。

3、附上我写的两个地图操作类

using System;
using System.Collections.Generic;
using System.Text;
using MapInfo.Engine;
using MapInfo.Geometry;
using MapInfo.Mapping;
using MapInfo.Windows.Controls;
using MapInfo.Windows.Dialogs;
using System.Drawing;
using System.Windows.Forms;
using MapInfo.Data;
using MapInfo.Styles;
using System.Collections;namespace AUV_PROJECT
{public enum MapState{Range,//测距Move,//移动Path,//路径规划};public class MapWrapper{MapOperation mo;//地图操作类private double EARTH_RADIUS = 6378137;//赤道半径(单位m)private MapState state;//当前状态private MapControl mc;//封装的地图控件private List<DPoint> rangePoint = new List<DPoint>();//测距功能要用到的点,屏幕坐标public MapWrapper(MapControl mapControl){this.state = MapState.Move;//默认设置为移动,此时可以拖动地图this.mc = mapControl;SetupMap();mc.Map.Zoom = new Distance(10000, DistanceUnit.Meter);//设置默认比例尺//在地图上创建临时绘图层mo = new MapOperation(mc.Map);mo.CreatTmpTable();mo.ClearFeature();}public MapState State{get{return state;}set{state = value;}}private void SetupMap()//装载地图文件{string s = @"D:\map\";Session.Current.TableSearchPath.Path = s;string geoSetName = "中国海图.gst";try{mc.Map.Load(new MapGeosetLoader(s + geoSetName));}catch (Exception){//MessageBox.Show("Geoset " + geoSetName + " not found.");}mc.Map.Center = new DPoint(121.71, 30.55);}public Distance Zoom{get{return mc.Map.Zoom;}set{mc.Map.Zoom = value;}}//点击按钮移动地图,通过调整地图中心实现public void Move(double x, double y){DPoint p = mc.Map.Center;p.x += x;p.y += y;mc.Map.Center = p;}public DPoint Screen2MapCoord(System.Drawing.Point screenP){//将鼠标xy坐标转为mapX的地图经纬度坐标System.Drawing.PointF DisplayPoint = new PointF(screenP.X, screenP.Y);MapInfo.Geometry.DPoint MapPoint = new MapInfo.Geometry.DPoint();MapInfo.Geometry.DisplayTransform converter = this.mc.Map.DisplayTransform;converter.FromDisplay(DisplayPoint, out MapPoint);return MapPoint;}//添加测距点public void AddRangePoint(System.Drawing.Point p){DPoint tmp = Screen2MapCoord(p);rangePoint.Add(tmp);}public int GetRangePointCount(){return rangePoint.Count;}//绘制测距矢量线public void DrawRangeVectorLine(System.Drawing.Point p){if (rangePoint.Count > 0){Graphics g = mc.CreateGraphics();Pen rangePen = new Pen(new SolidBrush(Color.Red), 3);//绘制列表中最后一个点和传入点(当前鼠标位置)//g.DrawLine(rangePen, rangePoint[rangePoint.Count - 1], p);rangePen.Dispose();}}//居中功能public void DoCentral(DPoint p){mc.Map.Center = p;}//居中功能public void DoCentral(System.Drawing.Point p){mc.Map.Center = Screen2MapCoord(p);}//获取测距总距离public double GetTotleRange(){double range = 0;DPoint lastP = new DPoint();for (int i = 0; i < rangePoint.Count; i++){if (i == 0){lastP = rangePoint[i];continue;}range += Range(lastP.x, lastP.y, rangePoint[i].x, rangePoint[i].y);lastP = rangePoint[i];}return range;}//测距功能(更改map临时图层)public void DoRange(){//mo.ClearFeature();if (rangePoint.Count > 0)//最少需要1个点{DPoint lastP = new DPoint();for (int i = 0; i < rangePoint.Count; i++){if (i == 0){lastP = rangePoint[i];mo.DrawPoint(lastP, 20, Color.FromArgb(0, 255, 0));continue;}DPoint start = lastP;DPoint end = rangePoint[i];mo.DrawLine(new DPoint[] { start, end });//绘制线段                    //计算中点DPoint middP = new DPoint((start.x + end.x) / 2, (start.y + end.y) / 2);//画端点mo.DrawPoint(end, 10, Color.FromArgb(0,0,0));//输出距离文字double range = Range(start.x, start.y, end.x, end.y);//g.RotateTransform(  (float)( deg(Math.Atan2(end.y - start.y, end.x - start.x)+90) ) );mo.DrawText(range.ToString("F0") + "m", middP, 14);//g.ResetTransform();lastP = rangePoint[i];}}}//测距功能(gdi)public void DoRange2(){//if (rangePoint.Count > 1)//最少需要两个点//{//    Graphics g = mc.CreateGraphics();//    Pen rangePen = new Pen(new SolidBrush(Color.Red), 3);//线段笔画//    Pen pointPen = new Pen(new SolidBrush(Color.Green), 3);//端点笔画//    System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);//距离文字字体//    SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.Black);//距离文字画刷//    //g.DrawLines(rangePen, rangePoint.ToArray());//    System.Drawing.Point lastP = new System.Drawing.Point();//    for (int i = 0; i < rangePoint.Count; i++)//    {//        g.DrawEllipse(pointPen, rangePoint[i].X, rangePoint[i].Y, 5, 5);//绘制端点//        if (i == 0)//        {//            lastP = rangePoint[i];//            continue;//        }//        g.DrawLine(rangePen, lastP, rangePoint[i]);//绘制线段                    //        //计算中点//        System.Drawing.Point middP = new System.Drawing.Point((rangePoint[i].X + lastP.X) / 2, (rangePoint[i].Y + lastP.Y) / 2);//        //输出距离文字//        DPoint start = Screen2MapCoord(lastP);//        DPoint end = Screen2MapCoord(rangePoint[i]);//        double range = Range(start.x, start.y, end.x, end.y);//        //g.RotateTransform(  (float)( deg(Math.Atan2(end.y - start.y, end.x - start.x)+90) ) );//        g.DrawString(range.ToString("F0") + "m", drawFont, drawBrush, middP);//        //g.ResetTransform();//        lastP = rangePoint[i];//    }//}}//停止测距public void StopRange(){state = MapState.Move;rangePoint.Clear();mo.ClearFeature();}/** * 转化为弧度(rad) * */private double rad(double d){return d * Math.PI / 180.0;}private double deg(double r){return r * 180 / Math.PI;}/** * 基于余弦定理求两经纬度距离 * @param lon1 第一点的精度 * @param lat1 第一点的纬度 * @param lon2 第二点的精度 * @param lat3 第二点的纬度 * @return 返回的距离,单位km * */private double Range(double lon1, double lat1, double lon2, double lat2){double radLat1 = rad(lat1);double radLat2 = rad(lat2);double radLon1 = rad(lon1);double radLon2 = rad(lon2);if (radLat1 < 0)radLat1 = Math.PI / 2 + Math.Abs(radLat1);// south  if (radLat1 > 0)radLat1 = Math.PI / 2 - Math.Abs(radLat1);// north  if (radLon1 < 0)radLon1 = Math.PI * 2 - Math.Abs(radLon1);// west  if (radLat2 < 0)radLat2 = Math.PI / 2 + Math.Abs(radLat2);// south  if (radLat2 > 0)radLat2 = Math.PI / 2 - Math.Abs(radLat2);// north  if (radLon2 < 0)radLon2 = Math.PI * 2 - Math.Abs(radLon2);// west  double x1 = EARTH_RADIUS * Math.Cos(radLon1) * Math.Sin(radLat1);double y1 = EARTH_RADIUS * Math.Sin(radLon1) * Math.Sin(radLat1);double z1 = EARTH_RADIUS * Math.Cos(radLat1);double x2 = EARTH_RADIUS * Math.Cos(radLon2) * Math.Sin(radLat2);double y2 = EARTH_RADIUS * Math.Sin(radLon2) * Math.Sin(radLat2);double z2 = EARTH_RADIUS * Math.Cos(radLat2);double d = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));//余弦定理求夹角  double theta = Math.Acos((EARTH_RADIUS * EARTH_RADIUS + EARTH_RADIUS * EARTH_RADIUS - d * d) / (2 * EARTH_RADIUS * EARTH_RADIUS));double dist = theta * EARTH_RADIUS;return dist;}}
}
using System;
using System.Collections.Generic;
using System.Text;
using MapInfo.Engine;
using MapInfo.Geometry;
using MapInfo.Mapping;
using MapInfo.Windows.Controls;
using MapInfo.Windows.Dialogs;
using System.Drawing;
using System.Windows.Forms;
using MapInfo.Data;
using MapInfo.Styles;
using System.Collections;namespace AUV_PROJECT
{class MapOperation{public MapInfo.Mapping.Map map;public Catalog Cat;public MapInfo.Data.Table tblTemp;private string tmpTableName = "temp";public MapOperation(Map map){this.map = map;Cat = MapInfo.Engine.Session.Current.Catalog;tblTemp = Cat.GetTable(tmpTableName);}//创建临时图层public void CreatTmpTable(){TableInfoMemTable tblInfoTemp = new TableInfoMemTable(tmpTableName);   //创建GPS终端小车集图层if (tblTemp != null) //Table exists close it{Cat.CloseTable(tmpTableName);}tblInfoTemp.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(map.GetDisplayCoordSys()));tblInfoTemp.Columns.Add(ColumnFactory.CreateStyleColumn());tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Name", 40));tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Dept", 15));tblInfoTemp.Columns.Add(ColumnFactory.CreateIntColumn("Level"));tblTemp = Cat.CreateTable(tblInfoTemp);FeatureLayer lyr = new FeatureLayer(tblTemp);map.Layers.Add(lyr);}private void Draw(FeatureGeometry geometry, Style style){Feature f;FeatureLayer flayer;try{flayer = map.Layers[tmpTableName] as FeatureLayer;if (flayer == null)return;Table fTable = flayer.Table;fTable.BeginAccess(TableAccessMode.Write);f = new Feature(fTable.TableInfo.Columns);f.Geometry = geometry;f.Style = style;fTable.InsertFeature(f);fTable.EndAccess();}catch (Exception ex){//GlobalHelper.ShowError("绘制隐患图元错误,原因:" + ex.Message);}}//添加点public void DrawPoint(DPoint p, double size, Color color){MapInfo.Geometry.Point point = new MapInfo.Geometry.Point(map.GetDisplayCoordSys(), p);SimpleVectorPointStyle style = new SimpleVectorPointStyle();style.PointSize = size;style.Color = color;Draw(point, style);}//添加文字public void DrawText(string txt, DPoint start, double size){//设置样式// Create a SimpleLineStyle to be used as the callout line's style.MapInfo.Styles.SimpleLineStyle lineStyle = new MapInfo.Styles.SimpleLineStyle(new MapInfo.Styles.LineWidth(2.0, MapInfo.Styles.LineWidthUnit.Pixel));// Construct a TextStyle with a SimpleLineStyle for the callout line.MapInfo.Styles.TextStyle textStyle = new MapInfo.Styles.TextStyle(new MapInfo.Styles.Font("arial", size), lineStyle);// TextStyle of the CalloutLine is also allowed to be null.textStyle.CalloutLine = null;//画文字MapInfo.Geometry.DRect rect = new MapInfo.Geometry.DRect(start.x, start.y, start.x + 0.006, start.y + 0.006);MapInfo.Geometry.LegacyText ltxt = new MapInfo.Geometry.LegacyText(map.GetDisplayCoordSys(), rect, txt);Draw(ltxt, textStyle);}//添加线段public void DrawLine(DPoint[] points){SimpleLineStyle style = new SimpleLineStyle();style.Color = Color.FromArgb(255, 0, 0);style.Width = new LineWidth(5, LineWidthUnit.Pixel);style.SetApplyAll();//画线段MultiCurve multiCurve = new MultiCurve(map.GetDisplayCoordSys(), CurveSegmentType.Linear, points);Draw(multiCurve, style);}//添加点public void InsertFeature(string fileName, double x, double y, string GPS_NUMBER){BitmapPointStyle bStyle = new BitmapPointStyle(fileName);    //fileName格式为@"gpscar2_p2.bmp" 这个@代表C:\Program Files\Common Files\MapInfo\MapXtreme\6.7.1\CustSymbbStyle.PointSize = Convert.ToInt16(24);bStyle.NativeSize = true;bStyle.Attributes = StyleAttributes.PointAttributes.BaseAll;bStyle.SetApplyAll();FeatureGeometry pt = new MapInfo.Geometry.Point(map.GetDisplayCoordSys(), new DPoint(y, x)) as FeatureGeometry;Feature ftr = new Feature(tblTemp.TableInfo.Columns);ftr.Geometry = pt;                   //图元地理位置设置ftr.Style = bStyle;                      //图元为位图样式ftr["Name"] = "aaaa";ftr["Dept"] = GPS_NUMBER;    //GPS终端号ftr["Level"] = 2;tblTemp.InsertFeature(ftr);          //插入图元}//加图层标注public void CreatMark(){MapInfo.Data.Table tblTemp = Cat.GetTable(tmpTableName);LabelSource labelSource = new LabelSource(tblTemp);   //给所创建的临时表Animation中的图元加标注//指定要标准字段所在的列labelSource.DefaultLabelProperties.Caption = "Name";     //所要标注的列名labelSource.DefaultLabelProperties.Layout.Offset = 8;    //标注偏移labelSource.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.TopRight;//标注对齐方式labelSource.DefaultLabelProperties.Style.Font.BackColor = System.Drawing.Color.White;        //字体背景labelSource.DefaultLabelProperties.Style.Font.ForeColor = System.Drawing.Color.Red;          //字体颜色labelSource.DefaultLabelProperties.Style.Font.TextEffect = MapInfo.Styles.TextEffect.Box;    //边缘效果labelSource.DefaultLabelProperties.Style.Font.FontWeight = MapInfo.Styles.FontWeight.Bold;   //粗体MapInfo.Styles.SimpleLineStyle simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(0);      //标注注释线labelSource.DefaultLabelProperties.Style.CalloutLine.ApplyStyle(simpleLineStyle);//取消标注注释线LabelLayer labelLayer = new LabelLayer();labelLayer.Name = "jcbz";//设置标注图层的名称labelLayer.Sources.Append(labelSource);//往地图中加入该标注层map.Layers.Add(labelLayer);}//清除临时图层中所有的图元public void ClearFeature(){SearchInfo si;IResultSetFeatureCollection ifs;MapInfo.Data.Table Tm;Tm = Cat.GetTable(tmpTableName);if (Tm != null) //Table exists close it{Tm.BeginAccess(TableAccessMode.Write);si = MapInfo.Data.SearchInfoFactory.SearchWhere("");ifs = MapInfo.Engine.Session.Current.Catalog.Search(tmpTableName, si);foreach (Feature ft in ifs)Tm.DeleteFeature(ft);//删除所有该图层上的图元Tm.EndAccess();}}}
}

Mapxtreme使用心得相关推荐

  1. MapXtreme 2005 学习心得 在地图上创建点/线并显示标注(五)

    新建示例 1:新建项目 新建一个网站,选择MapXtreme 6.7.1 Web Application 在App_Code中,我们新建一个类,起名叫:LayerManager.cs 2:把上节函数放 ...

  2. MapXtreme 2005 学习心得 缩放比例下不显示图层(十一)

    上次将一份上海的地图从wor格式转成gst再转成wms后,能用是能用了,可是每次点击地图时,都需要5-6秒的生成时间,在效率上成了一个问题.主要是图层显示太多引起的,生成后的图片有100多K. 来一张 ...

  3. mapxtreme开发资料全集

    为单值主题图创建自定义标注 http://www.gisdn.net/forum.php?mod=viewthread&tid=295&fromuid=3 创建有范围的主题图 http ...

  4. MapInfo开发心得——控件篇【转】

    前阵做一个项目过程中,需要结合MapInfo进行地方展示开发,积累一点点心得与大家共享 以下所有基于MapXtreme 6.6 MapInfo提供了足够强大的WinForm地图空间,可以很方便地在VS ...

  5. MapInfo开发心得——控件篇

    前阵做一个项目过程中,需要结合MapInfo进行地方展示开发,积累一点点心得与大家共享 以下所有基于MapXtreme 6.6 MapInfo提供了足够强大的WinForm地图空间,可以很方便地在VS ...

  6. Winform下的地图开发控件(GMap.NET)使用心得

    原文地址为: Winform下的地图开发控件(GMap.NET)使用心得 我们先看看GMap.NET的定义: GMap.NET是一个强大.免费.跨平台.开源的.NET控件,它在Windows Form ...

  7. Java EE学习心得

    –Java EE学习心得   1.    称为编程专家的秘诀是: 思考-----编程--------思考------编程--.. 编程不能一步到位,不能一上来就编,必须先思考如何写,怎样写?然后再编程 ...

  8. 测试心得:微图书销售小程序

    测试心得:微图书销售小程序 前言 这个学期差不多也将近结束,经过大半个学期,从项目需求的确认和项目文档的编写,到一步步的设计与实现,现在终于到了测试阶段,但是我们在测试阶段也暴露出了很多bug,但是每 ...

  9. java.lang.OutOfMemoryError:GC overhead limit exceeded填坑心得

    该文章出自:http://www.cnblogs.com/hucn/p/3572384.html 分析工具:http://www.blogjava.net/jjshcc/archive/2014/03 ...

  10. 计算机财务应用实验心得,计算机会计实习心得-20210628124643.doc-原创力文档

    计算机会计实习心得 计算机会计实习心得1 毕业实践环节是大学生在完成全部课程后.走向社会之前最真实的一个模拟实验,对于我们财会专业的学生,平时注意注重理论学习,缺乏实践锻炼,因此实习显得尤为重要.在本 ...

最新文章

  1. Google工程师带你学算法
  2. Android短视频中如何实现720P磨皮美颜录制?
  3. jsp前3章试题分析
  4. Linux下使用g++编译C++程序——Compiling Cpp
  5. 11--移除重复节点
  6. 论文浅尝 - ICLR2020 | 知识图谱中数值规则的可微学习
  7. java log4j权限被否定_SLF4J简介与使用(整合log4j)
  8. 代码编辑器[0] - Vim/gVim[1] - Vim 的快捷键操作
  9. LINUX下载编译python
  10. 上海世博会物联网技术应用
  11. 《迎接互联网的明天——玩转3D Web》
  12. LED灯具检验标准与方法
  13. 网站建设中做到需求分析细致,网站优化也就顺理成章了
  14. 个人云盘:阿里云无影,百度网盘、腾讯微云争霸?
  15. 实战|淘宝用户行为分析案例
  16. Unity实现音乐播放器
  17. matlab中sumf,使用SUMIF函数根据日期区间统计的方法
  18. javascript网页特效(一)
  19. 电商网络推广是干什么,电商网络营销做什么
  20. linux系统禁用声卡,Ubuntu Linux系统下声卡独占的解决方法

热门文章

  1. 【Python】Python核心编程
  2. 《Android Studio开发实战 从零基础到App上线》出版后记
  3. Java自学知识点_良心_精心整理
  4. Spark SQL 从入门到精通 - Spark SQL 行转列、列转行案例
  5. 【Python基础】5-函数编程
  6. 英文版的java项目简历_java开发英文简历范文
  7. java二级考试大纲_计算机二级Java考试内容大纲
  8. C语言练习实例——反向输出
  9. 工具:SQL Server软件使用指南
  10. Hadoop开发环境准备及错误问题解决方法