• MapXtreme中鹰眼图与本地地图联动


    第一步:本地地图与鹰眼图载入同一地图

    mapControl.Map.Load(MapInfo.Mapping.MapLoader.CreateFromFile(mapFile.File));
    
                    mapControlOver.Map.Load(MapInfo.Mapping.MapLoader.CreateFromFile(mapFile.File));

    第二步:为mapControl.Map添加viewchang的事件

    this.mapControl.Map.ViewChangedEvent += new MapInfo.Mapping.ViewChangedEventHandler(Map_ViewChangedEvent);

    第三步:根据mapcontro.Map的viewchange事件调整鹰眼图显示的内容

    private void UpdateHawkeyeMap()
            {
                try
                {
                    //如果主图和鹰眼图加载的是同一实例,那么鹰眼图就需要检测是否有效
                    if (mapControlOver.Map != null)
                    {
                        //加载鹰眼矩形临时表
                        Table tblRect;
                        tblRect = Session.Current.Catalog.GetTable("TempRectHawkeye");
                        if (tblRect != null)
                            tblRect.Close();
                        TableInfo tblInfo;
                        tblInfo = TableInfoFactory.CreateTemp("TempRectHawkeye");
                        TableSessionInfo tblSessionInfo = new TableSessionInfo();
    
                        tblRect = Session.Current.Catalog.CreateTable(tblInfo, tblSessionInfo);
                        FeatureLayer feaLayer = new FeatureLayer(tblRect);
    
                        mapControlOver.Map.Layers.Insert(0, feaLayer);
    
                        //实时在鹰眼临时表图上画矩形
                        tblRect = Session.Current.Catalog.GetTable("TempRectHawkeye");
                        (tblRect as ITableFeatureCollection).Clear();//清除当前层上的图元
    
                        //设置矩形的样式
                        DRect rect = mapControl.Map.Bounds;
                        FeatureGeometry feageo = new MapInfo.Geometry.Rectangle(mapControl.Map.GetDisplayCoordSys(), rect);
                        SimpleLineStyle simLineStyle = new SimpleLineStyle(new LineWidth(2, MapInfo.Styles.LineWidthUnit.Point), 2, System.Drawing.Color.Red);
                        SimpleInterior simInterior = new SimpleInterior(9, System.Drawing.Color.Gray, System.Drawing.Color.Green, true);
                        CompositeStyle comStyle = new CompositeStyle(new AreaStyle(simLineStyle, simInterior), null, null, null);
    
                        //将矩形插入到图层中
                        Feature fea = new Feature(feageo, comStyle);
                        tblRect.InsertFeature(fea);
                        //重新定位鹰眼图的中心
                        mapControlOver.Map.Center = mapControl.Map.Center;
                        mapControlOver.Map.Layers["TempRectHawkeye"].Invalidate();
    
                        //清理对象变量
                        tblSessionInfo = null;
                        feageo = null;
                        simLineStyle = null;
                        simInterior = null;
                        comStyle = null;
                        fea = null;
                    }
                }
                catch (Exception ex)
                {
                    ExceptionLog.Log("显示鹰眼图错误," + ex.Message);
                }

    第四步:把此函数放在viewchange事件中

     void Map_ViewChangedEvent(object sender, MapInfo.Mapping.ViewChangedEventArgs e)
            {
    
                UpdateHawkeyeMap();
            }

    第五步:为鹰眼图添加点击事件

     private void mapControlOver_MouseClick(object sender, MouseEventArgs e)
            {
                MoveLocalMap(GetOverviewCoordPt(e.X, e.Y));
            }
     //定位到指定经纬度
            private void MoveLocalMap(DPoint dpt)
            {
                mapControl.Map.SetView(dpt, mapControl.Map.GetDisplayCoordSys(), mapControl.Map.Zoom);
            }
    //鹰眼图坐标转换到经纬度
            private DPoint GetOverviewCoordPt(int x, int y)
            {
                DPoint dpt = new DPoint();
                mapControlOver.Map.DisplayTransform.FromDisplay(new System.Drawing.Point(x, y), out dpt);
                return dpt;
            }

    至此完成本地地图与鹰眼图的联动

     
  • 相关阅读:
    二、java基础-运算符_控制语句_break_continue_return
    一、Servlet之14道面试题
    Java程序员需要掌握的技能
    java内存溢出实战
    java虚拟机JVM基础
    常见数据结构与算法整理总结(下)
    常见数据结构与算法整理总结(上)
    Java实现八大排序算法
    23种设计模式图集
    引用iscroll的一个封装方法
  • 原文地址:https://www.cnblogs.com/nygfcn1234/p/3146319.html
Copyright © 2020-2023  润新知