发表用户:讨论帖
收集整理:James.Liu
相关讨论:http://www.mygis.com.cn/forum/dispbbs.asp?boardID=23&ID=9976
信息原始来源:James MapInfo技术论坛

文章标题:C#+mapxtreme2004实现桌面系统的历史轨迹回放

liuzhong_k

我在 vb.net+mapx 里 用
    '--------------------------------------
    ' 连接两点
    '--------------------------------------
    Public Function creatline()
        '创建连线   GetAStyle自定义图元样式
        Dim Ftr As MapXLib.Feature = AxMap1.FeatureFactory.CreateLine(Pnts, GetAStyle)
        '增加图元
        Me.AxMap1.Layers.Item(1).AddFeature(Ftr)
        '刷新图层
        Me.AxMap1.Layers.Item(1).Refresh()
        '删除所有点信息
        Pnts.RemoveAll()
    End Function
就可以实现两点之间进行连线
请问各位大侠 在 c#+mapxtreme2004 中怎么实现啊?
小弟等待回复,谢谢! 

liuzhong_k

谁有 c#+mapxtreme2004 的历史轨迹的代码啊(桌面系统,非web),只要预先存储几个点坐标,不用从数据库读取。有的话请帖一份,小弟不胜感激。偶刚学 mapxtreme2004 不久,无以回报,只有 mapxtreme2004中文帮助 ,若大侠需要告之,偶将从 qq 或者 popo 上传之,7.79M 

liuzhong_k

小弟正在实验此种方法,可有哪位大侠有更好的方法,请帖之,谢谢!
private void btnGj_Click(object sender, System.EventArgs e)
  {
   //目录
   Catalog Cat = MapInfo.Engine.Session.Current.Catalog;

   //创建临时层 (TableInfoMemTable 内存表/临时表)
   TableInfoMemTable tblInfoTemp = new TableInfoMemTable("Animation");
   //Table 打开的表
   Table tblTemp = Cat.GetTable("Animation");
   // 如果表不为空
   if (tblTemp != null) 
   {
    Cat.CloseTable("Animation");
   }

   //                                    重载.构造新的 GeometryColumn 实例
   tblInfoTemp.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(mapControl1.Map.GetDisplayCoordSys()));
   //                                    构造 Style 类型的新 Column 实例
   tblInfoTemp.Columns.Add(ColumnFactory.CreateStyleColumn());
   //                                    构造 String 类型的新 Column 实例
   tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Name", 40));
   tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Dept", 15));
   //                                    构造 Int 类型的新 Column 实例
   tblInfoTemp.Columns.Add(ColumnFactory.CreateIntColumn("Level"));

   //将临时表 加入 打开的表中
   tblTemp = Cat.CreateTable(tblInfoTemp);

   // 图层
   FeatureLayer lyr = new FeatureLayer(tblTemp);
   mapControl1.Map.Layers.Add(lyr);

   //创建点-车
   FeatureGeometry pt = new MapInfo.Geometry.Point(lyr.CoordSys, new DPoint(113.47456, 33.05009)) as FeatureGeometry;
   //点样式
   CompositeStyle cs = new CompositeStyle(new SimpleVectorPointStyle(37, System.Drawing.Color.Red, 10));
   //图元
   Feature ftr = new Feature(tblTemp.TableInfo.Columns);
   //设置图元
   ftr.Geometry = pt;
   ftr.Style = cs;
   ftr["Name"] = "Kelly";
   ftr["Dept"] = "Sales";
   ftr["Level"] = 3;
   //将图元 加入 表中
   tblTemp.InsertFeature(ftr);

//   FeatureGeometry pt2 = new MapInfo.Geometry.Point(lyr.CoordSys, new DPoint(114.49508, 31.48943)) as FeatureGeometry;
//   CompositeStyle cs2 = new CompositeStyle(new SimpleVectorPointStyle(44, System.Drawing.Color.Purple, 10));
//   Feature ftr2 = new Feature(tblTemp.TableInfo.Columns);
//   ftr2.Geometry = pt2;
//   ftr2.Style = cs2;
//   ftr2["Name"] = "Greg";
//   ftr2["Dept"] = "Marketing";
//   ftr2["Level"] = 2;
//   tblTemp.InsertFeature(ftr2);
  }

  // 对于表中所有对象的移动
  private void timer1_Tick(object sender, System.EventArgs e)
  {
   Catalog cat = MapInfo.Engine.Session.Current.Catalog;
   Table tbl = cat.GetTable("Animation");

   if (tbl != null) 
   {
    //更新点的位置
    tbl.BeginAccess (MapInfo.Data.TableAccessMode.Write );
    //
    foreach (Feature fcar in tbl)
    {
     fcar.Geometry.GeometryEditor.OffsetByXY(0.5,0,MapInfo.Geometry.DistanceUnit.Degree,MapInfo.Geometry.DistanceType.Spherical);
     fcar.Geometry.EditingComplete();
     fcar.Update();
    }
    tbl.EndAccess ();
   }
  } 

liuzhong_k

小弟已经写好了一个动态取点显示的函数,现在不知道怎么连两点画线啊!求助!
// 运动轨迹
  private void contrail(double x,double y)
  {
   try
   {
    //目录
    Catalog Cat = MapInfo.Engine.Session.Current.Catalog;
    //创建临时层 (TableInfoMemTable 内存表/临时表)
    TableInfoMemTable tblInfoTemp = new TableInfoMemTable("contrail");
    //Table 打开的表
    Table tblTemp = Cat.GetTable("contrail");
    // 如果表不为空
    if (tblTemp != null) 
    {
     Cat.CloseTable("contrail");
    }

    //                                    重载.构造新的 GeometryColumn 实例
    tblInfoTemp.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(mapControl1.Map.GetDisplayCoordSys()));
    //                                    构造 Style 类型的新 Column 实例
    tblInfoTemp.Columns.Add(ColumnFactory.CreateStyleColumn());
    //                                    构造 String 类型的新 Column 实例
    tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Name", 40));
    tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Dept", 15));
    //                                    构造 Int 类型的新 Column 实例
    tblInfoTemp.Columns.Add(ColumnFactory.CreateIntColumn("Level"));

    //将临时表 加入 打开的表中
    tblTemp = Cat.CreateTable(tblInfoTemp);

    // 图层
    FeatureLayer lyr = new FeatureLayer(tblTemp);
    mapControl1.Map.Layers.Add(lyr);

    MapInfo.Geometry.DPoint dp;
    dp.x=x;
    dp.y=y;

    //创建点-车
    FeatureGeometry pt = new MapInfo.Geometry.Point(lyr.CoordSys, new DPoint(dp.x, dp.y)) as FeatureGeometry;
    //点样式
    CompositeStyle cs = new CompositeStyle(new SimpleVectorPointStyle(37, System.Drawing.Color.Red, 10));
    //图元
    Feature ftr = new Feature(tblTemp.TableInfo.Columns);
    //设置图元
    ftr.Geometry = pt;
    ftr.Style = cs;
    ftr["Name"] = "Kelly";
    ftr["Dept"] = "Sales";
    ftr["Level"] = 3;
    //将图元 加入 表中
    tblTemp.InsertFeature(ftr);
   }
   catch(Exception ex)
   {
    ex.GetType().ToString();
   }
  }
只用将 DPint 的坐标付进去就ok了,我下载想实现画点的同时两两点之间连线!各位大侠给点意见啊! 

liuzhong_k

偶终于将线也弄出来了,好辛苦啊!呵呵

偶的?历史轨迹回放 啊,晃晃悠悠的也能够跑了,呵呵。