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

文章标题:请教:谁知道MapXtreme2005中地图上怎样实现GPS导航?

-ljb

请教:谁知道地图上怎样实现GPS导航?
如题,或是怎样制作GPS导航地图啊

jerry429

可以使用animation,例如以下代码:
Code example for using an animation layer in MapXtreme 2004:

C# Sample

private void mapToolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (e.Button.Tag.ToString())
{
case "Start":
timer1.Start();
break;
case "Stop":
timer1.Stop();
break;
}
}

private void timer1_Tick(object sender, System.EventArgs e)
{
MapInfo.Data.MIConnection conn = new MapInfo.Data.MIConnection();
conn.Open();
MapInfo.Data.MICommand cmd = conn.CreateCommand();
if (DateTime.Now.TimeOfDay.Seconds % 4 == 0) 
{
ftr.Geometry.GeometryEditor.OffsetByXY(0, -10, MapInfo.Geometry.DistanceUnit.Mile, MapInfo.Geometry.DistanceType.Spherical);
}
else
{
ftr.Geometry.GeometryEditor.OffsetByXY(10, 0, MapInfo.Geometry.DistanceUnit.Mile, MapInfo.Geometry.DistanceType.Spherical);
}

ftr.Geometry.EditingComplete();
cmd.CommandText = "Update Animation Set obj = @obj Where MI_Key = '1'";
cmd.Parameters.Add("@obj", ftr.Geometry);
cmd.ExecuteNonQuery();
conn.Close();
}

private void btnCreateAnimation_Click(object sender, System.EventArgs e)
{
MapInfo.Data.MIConnection conn = new MapInfo.Data.MIConnection();
MapInfo.Data.Table tbl;
conn.Open();
//Make sure that the temporary table does not exist before creating
tbl = conn.Catalog.GetTable("Animation");
if (tbl != null)
{
conn.Catalog.CloseTable("Animation");
}

//Create temp layer 
MapInfo.Data.TableInfoMemTable ti = new MapInfo.Data.TableInfoMemTable("Animation");
ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(mapControl1.Map.GetDisplayCoordSys()));
ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
ti.Temporary = true;
tbl = conn.Catalog.CreateTable(ti);
MapInfo.Mapping.FeatureLayer lyr = new MapInfo.Mapping.FeatureLayer(tbl, "Animation");
mapControl1.Map.Layers.Add(lyr);

//Create point for animation 
MapInfo.Geometry.FeatureGeometry fg = new MapInfo.Geometry.Point(lyr.CoordSys, -12000000, 4600000);
MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(new MapInfo.Styles.SimpleVectorPointStyle(37, System.Drawing.Color.Purple, 10));

MapInfo.Data.MICommand cmd = conn.CreateCommand();
ftr = new MapInfo.Data.Feature(fg, cs);
tbl.InsertFeature(ftr);
lyr.VolatilityHint = MapInfo.Mapping.LayerVolatilityHint.Animate;
conn.Close();