当前位置: 代码迷 >> GIS >> c# mapx5.0 鹰眼,该怎么处理
  详细解决方案

c# mapx5.0 鹰眼,该怎么处理

热度:635   发布时间:2016-05-05 06:41:00.0
c# mapx5.0 鹰眼
 
各位帮我看下为什么以下代码不行。
我想在axMap1中放大后,axMap2中的框能变小,但是现在做出来的axMap2的框不变

 private void axMap1_MapViewChanged(object sender, EventArgs e)
  {
  MapXLib.Feature tempFea;    //声明一个图元,用于鹰眼图中创建的矩形框
  MapXLib.Points tempPoints = new Points();
  MapXLib.Style tempStyle = new Style();
  MapXLib.Point ptMap_1 = new MapXLib.Point();
  MapXLib.Point ptMap_2 = new MapXLib.Point();
  MapXLib.Point ptMap_3 = new MapXLib.Point();
  MapXLib.Point ptMap_4 = new MapXLib.Point();
  MapXLib.Layer m_layer_Eagle;
  MapXLib.Feature m_feature_Eagle;

  //设置矩形框四角坐标为主图边框
  ptMap_1.Set(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMin);
  ptMap_2.Set(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMin);
  ptMap_3.Set(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMax);
  ptMap_4.Set(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMax);
  //添加点到点集
  tempPoints.Add(ptMap_1, 1);
  tempPoints.Add(ptMap_2, 2);
  tempPoints.Add(ptMap_3, 3);
  tempPoints.Add(ptMap_4, 4);

  //以下设置边框样式
  tempStyle.RegionPattern = FillPatternConstants.miPatternNoFill;
  tempStyle.RegionBorderColor = (uint)MapXLib.ColorConstants.miColorBlue;
  tempStyle.RegionBorderWidth = 2;
  //////////////以下创建临时图层/////////////////////////  
  MapXLib.LayerInfo tempLayerInfo = new MapXLib.LayerInfoClass();
  MapXLib.Fields flds = new MapXLib.FieldsClass();
  flds.AddStringField("Name", 100, false);
  tempLayerInfo.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
  tempLayerInfo.AddParameter("Name", "Eagle");
  tempLayerInfo.AddParameter("Fields", flds);
  m_layer_Eagle = axMap2.Layers.Add(tempLayerInfo, 1);         //为鹰眼图添加图层
  //////////////以上创建临时图层////////////////////////// 

  //以下在临时图层添加大小为axMapx2的边界的Rectangle对象 
  tempFea = axMap2.FeatureFactory.CreateRegion(tempPoints, tempStyle);//创建矩形框 
  m_feature_Eagle = axMap2.Layers._Item("Eagle").AddFeature(tempFea, new MapXLib.RowValuesClass());  //添加边框到鹰眼图
  tempStyle = null;

  tempFea.Parts._Item(1).RemoveAll();
  tempFea.Parts._Item(1).AddXY(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMin, 1);
  tempFea.Parts._Item(1).AddXY(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMin, 2);
  tempFea.Parts._Item(1).AddXY(axMap1.CtlBounds.XMax, axMap1.CtlBounds.YMax, 3);
  tempFea.Parts._Item(1).AddXY(axMap1.CtlBounds.XMin, axMap1.CtlBounds.YMax, 4);
  tempFea.Update(tempFea, new MapXLib.RowValuesClass());
   
  }



------解决方案--------------------
这个我以前做过,给你看看我我的代码吧:
C# code
————————————————————————————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) //窗口初始化        {            //鹰眼                        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();        }        private void axMap1_MapViewChanged(object sender, EventArgs e)//地图变化时,重绘鹰眼地图中的矩形框        {            DrawRect();        }