两个点在地图上移动的源代码(转贴)
private void btnInitializeObjects_Click(object sender, System.EventArgs e)
{
Catalog Cat = MapInfo.Engine.Session.Current.Catalog;
//Create Temp layer
TableInfoMemTable tblInfoTemp = new TableInfoMemTable("Animation");
Table tblTemp = Cat.GetTable("Animation");
if (tblTemp != null) //Table exists close it
{
Cat.CloseTable("Animation");
}
tblInfoTemp.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(mapControl1.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);
mapControl1.Map.Layers.Add(lyr);
//Create Points
FeatureGeometry pt = new MapInfo.Geometry.Point(lyr.CoordSys, new DPoint(-76, 42)) 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(-119, 34)) 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)
{
//Update the position of the points
SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("Name = 'Kelly'");
Feature ftr = cat.SearchForFeature(tbl, si);
SearchInfo si2 = MapInfo.Data.SearchInfoFactory.SearchWhere("Name = 'Greg'");
Feature ftr2 = cat.SearchForFeature(tbl, si2);
if (DateTime.Now.TimeOfDay.Seconds % 4 == 0)
{
ftr.Geometry.GeometryEditor.OffsetByXY(-5, -25, DistanceUnit.Mile, DistanceType.Spherical);
ftr2.Geometry.GeometryEditor.OffsetByXY(0, 25, DistanceUnit.Mile, DistanceType.Spherical);
}
else
{
ftr.Geometry.GeometryEditor.OffsetByXY(-10, 0, DistanceUnit.Mile, DistanceType.Spherical);
ftr2.Geometry.GeometryEditor.OffsetByXY(10, 5, DistanceUnit.Mile, DistanceType.Spherical);
}
ftr.Geometry.EditingComplete();
ftr2.Geometry.EditingComplete();
ftr.Update();
ftr2.Update();
}
}
{
Catalog Cat = MapInfo.Engine.Session.Current.Catalog;
//Create Temp layer
TableInfoMemTable tblInfoTemp = new TableInfoMemTable("Animation");
Table tblTemp = Cat.GetTable("Animation");
if (tblTemp != null) //Table exists close it
{
Cat.CloseTable("Animation");
}
tblInfoTemp.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(mapControl1.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);
mapControl1.Map.Layers.Add(lyr);
//Create Points
FeatureGeometry pt = new MapInfo.Geometry.Point(lyr.CoordSys, new DPoint(-76, 42)) 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(-119, 34)) 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)
{
//Update the position of the points
SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("Name = 'Kelly'");
Feature ftr = cat.SearchForFeature(tbl, si);
SearchInfo si2 = MapInfo.Data.SearchInfoFactory.SearchWhere("Name = 'Greg'");
Feature ftr2 = cat.SearchForFeature(tbl, si2);
if (DateTime.Now.TimeOfDay.Seconds % 4 == 0)
{
ftr.Geometry.GeometryEditor.OffsetByXY(-5, -25, DistanceUnit.Mile, DistanceType.Spherical);
ftr2.Geometry.GeometryEditor.OffsetByXY(0, 25, DistanceUnit.Mile, DistanceType.Spherical);
}
else
{
ftr.Geometry.GeometryEditor.OffsetByXY(-10, 0, DistanceUnit.Mile, DistanceType.Spherical);
ftr2.Geometry.GeometryEditor.OffsetByXY(10, 5, DistanceUnit.Mile, DistanceType.Spherical);
}
ftr.Geometry.EditingComplete();
ftr2.Geometry.EditingComplete();
ftr.Update();
ftr2.Update();
}
}