————————————————————————————
先添加两个mapx地图控件,一个做主视图Map1,另一个做鹰眼地图MapEye。
1.
/// <summary>
/// 在鹰眼地图中添加矩形框
/// </summary>
private void DrawRect() //在鹰眼地图中添加矩形框函数
{
if (MapEye.Layers._Item("Eyelay").AllFeatures.Count == 0)
{
MapXLib.Feature fea = new MapXLib.FeatureClass();
MapXLib.Style sty = new MapXLib.StyleClass();
try
{
sty.RegionPattern = MapXLib.FillPatternConstants.miPatternNoFill;
sty.RegionColor = 155;
sty.RegionBorderWidth = 1;
MapXLib.Points pts = new MapXLib.PointsClass();
pts.AddXY(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMin, 1);
pts.AddXY(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMin, 2);
pts.AddXY(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMax, 3);
pts.AddXY(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMax, 4);
fea = MapEye.FeatureFactory.CreateRegion(pts,sty);
FeaEye = MapEye.Layers._Item("Eyelay").AddFeature(fea,new MapXLib.RowValuesClass());
FeaEye.Update(FeaEye,new MapXLib.RowValuesClass());
}
catch (Exception ea)
{ MessageBox.Show(ea.Message.ToString() + "/n没有矩形图元"); }
}
else
{
try
{
FeaEye.Parts._Item(1).RemoveAll();
FeaEye.Parts._Item(1).AddXY(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMin, 1);
FeaEye.Parts._Item(1).AddXY(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMin, 2);
FeaEye.Parts._Item(1).AddXY(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMax, 3);
FeaEye.Parts._Item(1).AddXY(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMax, 4);
FeaEye.Update(FeaEye, new MapXLib.RowValuesClass());
}
catch (Exception en)
{ MessageBox.Show(en.Message.ToString() + "/n更新图元"); }
}
1.
/// <summary>
/// 在鹰眼地图中添加矩形框
/// </summary>
private void DrawRect() //在鹰眼地图中添加矩形框函数
{
if (MapEye.Layers._Item("Eyelay").AllFeatures.Count == 0)
{
MapXLib.Feature fea = new MapXLib.FeatureClass();
MapXLib.Style sty = new MapXLib.StyleClass();
try
{
sty.RegionPattern = MapXLib.FillPatternConstants.miPatternNoFill;
sty.RegionColor = 155;
sty.RegionBorderWidth = 1;
MapXLib.Points pts = new MapXLib.PointsClass();
pts.AddXY(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMin, 1);
pts.AddXY(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMin, 2);
pts.AddXY(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMax, 3);
pts.AddXY(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMax, 4);
fea = MapEye.FeatureFactory.CreateRegion(pts,sty);
FeaEye = MapEye.Layers._Item("Eyelay").AddFeature(fea,new MapXLib.RowValuesClass());
FeaEye.Update(FeaEye,new MapXLib.RowValuesClass());
}
catch (Exception ea)
{ MessageBox.Show(ea.Message.ToString() + "/n没有矩形图元"); }
}
else
{
try
{
FeaEye.Parts._Item(1).RemoveAll();
FeaEye.Parts._Item(1).AddXY(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMin, 1);
FeaEye.Parts._Item(1).AddXY(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMin, 2);
FeaEye.Parts._Item(1).AddXY(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMax, 3);
FeaEye.Parts._Item(1).AddXY(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMax, 4);
FeaEye.Update(FeaEye, new MapXLib.RowValuesClass());
}
catch (Exception en)
{ MessageBox.Show(en.Message.ToString() + "/n更新图元"); }
}
}
——————————————————————————————————————————————————
2.
private void Map_Emulate_Load(object sender, EventArgs e) //窗口初始化
{
——————————————————————————————————————————————————
2.
private void Map_Emulate_Load(object sender, EventArgs e) //窗口初始化
{
//鹰眼
try //创建临时图层
{
MapXLib.LayerInfo lay=new MapXLib.LayerInfoClass();
MapXLib.Fields fld = new MapXLib.FieldsClass();
fld.AddStringField("ID", 20, false);
fld.AddStringField("Name", 100, false);
lay.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
lay.AddParameter("Name", "Eyelay");
lay.AddParameter("Fields", fld);
LayEye= MapEye.Layers.Add(lay, 1);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
//在鹰眼地图中添加矩形框
DrawRect();
————————————————————————————————————————————————
3.当视图改变时,鹰眼相应改变实现代码
private void MapEye_MouseDownEvent(object sender, AxMapXLib.CMapXEvents_MouseDownEvent e)// 鹰眼。绑定主图的中兴坐标
{
MapEye.MousePointer = MapXLib.CursorConstants.miPanCursor;
if (e.button == 1)
{
MapEye.MousePointer = MapXLib.CursorConstants.miPanCursor;
eyemove = true;
double mapx = 0.0;
double mapy = 0.0;
MapEye.ConvertCoord(ref e.x, ref e.y, ref mapx, ref mapy, MapXLib.ConversionConstants.miScreenToMap);
axMap1.CenterX = mapx;
axMap1.CenterY = mapy;
}
}
try //创建临时图层
{
MapXLib.LayerInfo lay=new MapXLib.LayerInfoClass();
MapXLib.Fields fld = new MapXLib.FieldsClass();
fld.AddStringField("ID", 20, false);
fld.AddStringField("Name", 100, false);
lay.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
lay.AddParameter("Name", "Eyelay");
lay.AddParameter("Fields", fld);
LayEye= MapEye.Layers.Add(lay, 1);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
//在鹰眼地图中添加矩形框
DrawRect();
————————————————————————————————————————————————
3.当视图改变时,鹰眼相应改变实现代码
private void MapEye_MouseDownEvent(object sender, AxMapXLib.CMapXEvents_MouseDownEvent e)// 鹰眼。绑定主图的中兴坐标
{
MapEye.MousePointer = MapXLib.CursorConstants.miPanCursor;
if (e.button == 1)
{
MapEye.MousePointer = MapXLib.CursorConstants.miPanCursor;
eyemove = true;
double mapx = 0.0;
double mapy = 0.0;
MapEye.ConvertCoord(ref e.x, ref e.y, ref mapx, ref mapy, MapXLib.ConversionConstants.miScreenToMap);
axMap1.CenterX = mapx;
axMap1.CenterY = mapy;
}
}
private void axMap1_SizeChanged(object sender, EventArgs e) //主视图改变时,重绘鹰眼地图中的矩形框
{
DrawRect();
}
{
DrawRect();
}
private void axMap1_MapViewChanged(object sender, EventArgs e)//地图变化时,重绘鹰眼地图中的矩形框
{
DrawRect();
}
{
DrawRect();
}